Setting currentTime yields wrong frame
조회 수: 3 (최근 30일)
이전 댓글 표시
I try to access specific frames from a video file. After opening it with a VideoReader and setting a time via currentTime in seconds readFrame will return the wrong frame. Interestingly, when increasing the currentTime from 0 to 0.1 to 0.2 and so on nothing changes, readFrame will always return the first frame. Only after reaching second 1 it will return a new frame, however this is the 30th frame (as my video has slightly more than 30 fps). Why did it skip all the other 29 frames?
Here an example set of instructions to show what the problem is:
video = VideoReader('videos/myvideo.mp4');
>> video.CurrentTime
ans =
0
>> A = readFrame(video);
>> video.CurrentTime
ans =
0.0419
>> B = readFrame(video);
>> video.CurrentTime
ans =
0.0752
>> video.CurrentTime = 0.05
video =
VideoReader with properties:
General Properties:
Name: 'myvideo.mp4'
Path: 'path/to/videos'
Duration: 69.1200
CurrentTime: 0.0500
NumFrames: 2068
Video Properties:
Width: 2160
Height: 3840
FrameRate: 30.0171
BitsPerPixel: 24
VideoFormat: 'RGB24'
>> C = readFrame(video);
>> isequal(A,B)
ans =
logical
0
>> isequal(A,C)
ans =
logical
1
>> isequal(A,B)
ans =
logical
0
>> video.CurrentTime = 0.6
video =
VideoReader with properties:
General Properties:
Name: 'myvideo.mp4'
Path: 'path/to/videos'
Duration: 69.1200
CurrentTime: 0.6000
NumFrames: 2068
Video Properties:
Width: 2160
Height: 3840
FrameRate: 30.0171
BitsPerPixel: 24
VideoFormat: 'RGB24'
>> D = readFrame(video);
>> isequal(A,D)
ans =
logical
1
I'm saving the first frame in A and the second one in B. They are different. After setting currentTime to 0.05 which is after the time of A and before the time of B I retrieve another frame C. Surprisingly this frame is identical with A and not with B, although the video object stored the currenttime as 0.0500 correctly. The same happens with currentTime at 0.6 which is a lot after frame B. The retrieved frame D is identical with A.
Only after setting current time to 1 or 1.1 or so and retrieving a frame it yields a frame that is not identical to frame A. However, it is also not identical to frame B, it is identical to the frame with the number of the frame rate.
Is this a problem with my video file or is it a problem with the currentTime or readFrame function in MATLAB? Has anyone experienced the same issue before?
댓글 수: 0
답변 (1개)
Jyotsna Talluri
2019년 12월 4일
Each frame of the video is read in a specific time depending on the video Frequency. When we set the 'CurrentTime' to a certain value readFrame reads a frame from the starting time of a frame in which this time is included .From your question frames B,C and not the frames A and C .I tried with an example video and it worked fine.
video = VideoReader('PIL.mp4');
>> video.CurrentTime
ans =
0
>> A = readFrame(video);
>> video.CurrentTime
ans =
0.0333
>> B = readFrame(video);
>> video.CurrentTime
ans =
0.0667
>> video.CurrentTime = 0.04;
>> C = readFrame(video);
>> isequal(A,B)
ans =
logical
0
isequal(A,C)
ans =
logical
0
>> isequal(B,C)
ans =
logical
1
Try with another video and sometimes it depends on the Operating System
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for IP Cameras에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!