wpfwannabe
wpfwannabe

Reputation: 14877

Getting log line for each extracted frame from FFMPEG

I am using FFMPEG.exe to extract frames from various videos. As this is a programmatic solution and getting the total frame count and/or duration can prove tricky (with ffprobe), I am thinking I could use the console output to detect individual frames' timestamps but I am getting a single output line every N frames like this:

frame=   20 fps=0.0 q=0.0 size=       0kB time=00:00:01.72 bitrate=   0.0kbits/s
frame=   40 fps= 38 q=0.0 size=       0kB time=00:00:04.02 bitrate=   0.0kbits/s
frame=   60 fps= 39 q=0.0 size=       0kB time=00:00:06.14 bitrate=   0.0kbits/s
frame=   70 fps= 38 q=0.0 Lsize=       0kB time=00:00:07.86 bitrate=   0.0kbits/s

Is there a command line option to force output for each and every frame? If so, I could extract the time= portion. This is the command line currently used:

ffmpeg.exe -i video.avi -y -threads 0 -vsync 2 %10d.jpeg

Ideally, replacing %10d.jpeg with some other format that writes frame's timestamp but I don't think this exists.

Upvotes: 3

Views: 6678

Answers (2)

Isantipov
Isantipov

Reputation: 20949

You can use showinfo filter like this:

ffmpeg -nostats -i  input.wmv -vsync passthrough -an -vf showinfo %10d.png

It produces output as follows:

 <..>
    Stream mapping:
      Stream #0:0 -> #0:0 (wmv2 -> png)
    Press [q] to stop, [?] for help    
    n:0 pts:16550 pts_time:16.55 pos:4205325 fmt:rgb24 sar:0/1 s:640x480 i:P iskey:1 type:I checksum:95895BC9 plane_checksum:[95895BC9]
    n:1 pts:24591 pts_time:24.591 pos:6685325 fmt:rgb24 sar:0/1 s:640x480 i:P iskey:0 type:P checksum:FF4CC015 plane_checksum:[FF4CC015]
    'n=...' lines are repeated for each of the extracted frames.

Than parse the stream and use pts_time portion.

Upvotes: 5

av501
av501

Reputation: 6729

Wrong way to get timestamps. To get the timestamps use ffprobe -show_packets or ffprobe -show_frames and parse the output. The time in ffmpeg pipeline there is just updated once every few ms not every frame\

EDIT ffprobe will run as fast as possible because it is running on a file. The timestamps it prints are the actual display and decode timestamps for the frames if the file were played back.

If you want timestamps as ffmpeg is running change the code in ffmpeg . There is a function called do_video_stats where all of it gets printed in ffmpeg.c. Should be able to manipulate it to your liking.

Upvotes: 6

Related Questions