vision.videofilereader() produces different number of frames if run on Mac vs PC.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a number of short video clips (.mp4 and .mov) that I need to analyze frame by frame using a tool built in MATLAB. I had been noticing some discrepancies between running the code on Mac vs PC. After a lot of testing, I discovered that the problem is with the number of frames that vision.videofilereader() extracts from the video file. Here is the relevant piece of code:
videoFileReader = vision.VideoFileReader(vfFileName);
obj.numFrames = 0;
obj.videoFrames = {};
while (~isDone(videoFileReader))
obj.numFrames = obj.numFrames + 1;
obj.videoFrames{end + 1} = step(videoFileReader);
end
As an example, if I run this code on a PC it will give obj.numFrames = 71, but on a mac it will give obj.numFrames = 59 for a the same exact .mp4 file.
I did further testing on a number of .mp4 files from various sources and I found that this problem occurs if the videos were trimmed using quicktime, but not in another video editor (Bigsoft).
The best way I can explain what happens is with an example. I have an original video recorded with my camera that is 100 frames long and called myvid.mp4. I open myvid.mp4 file with Quicktime on a Mac, and trim such that I save only frames 40-60. Frames 1-39 and 60-100 are discarded. I save this new trimmed video as myvid_trimmed.mp4.
When I run the code above on myvid.mp4 on Mac or PC, I get that obj.numFrames = 100 as expected. When I run the same code on myvid_trimmed.mp4 on a mac , I get that obj.numFrames = 21 as expected. However, when I run the same code on myvid_trimmed.mp4 on a PC , I get that obj.numFrames is > 21.
When I compare the frames that were imported (obj.videoFrames above) into matlab when running the code on myvid_trimmed.mp4, I find that on a Mac, the imported frames were indeed frames 40-60 of the original myvid.mp4. However, on the PC, the imported frames seem to be 1-60. So it’s as if the lower bound of the trim never took place!
Is there any way I can get MATLAB on the PC to import the correct number of frames? I hope my explanation makes sense. I want to thank you all in advance for taking the time to read it!
For your convenience, I have uploaded two video files as examples. The trimmed video was trimmed using Quicktime. The link can be found here.
More Information + things I have tried:
1) Using a trimming tool other than Quicktime isn’t an option for me, because all of the videos I need to analyze have already been trimmed, and the originals no longer exist.
2) The project involves calculating temporal data from the number of frames capturing an event, so it is very important that the frames extracted be exactly the same whether the code is being on Mac or PC
3) I have tried using videoreader() instead of vision.videofilereader() but the result is the same.
4) I have tried downloading an updated codec package from https://www.codecguide.com/, but the result is the same.
5) I ran across this page in my search for a solution. There is no solution, but the OP talks about having repeated frames inserted into his video objects. So, I used some of his code that runs through each frame and compares it to the frame before, and found that none of the frames are identical. So the extra frames are not explained by duplicate frames. As I said before, the extra frames are frames that were supposed to have been trimmed.
Edit1: The reason why I suspect this to be a MATLAB problem is that the myvid_trimmed.mp4 file (trimmed with quicktime) opens correctly in any PC program other than MATLAB. I have used VLC and Potplayer to open this file, and these programs open the correct number of frames.
0 Kommentare
Antworten (1)
Walter Roberson
am 22 Jun. 2017
My interpretation of that is that when you trim in Quicktime, it somehow writes frames 1 to the last one you trimmed to into the file, but either marks the first series as somehow invalid or else marks a starting time pointing to the first untrimmed frame; and then that the file is interpreted a different way on MS Windows which is not expecting that behavior. That is, I would suspect this as being fundamentally a Quicktime problem.
The simplest route might be to read the trimmed sequence on Mac, writing each frame to a new file. As the reading is only getting the frames that "should" be there, then the write would only have those frames to work with.
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!