2

I have a video file that lasts 9.3s and was recorded at FPS=10. I would like to use FFMPEG in order to extract frames from this video at arbitrary FPS (e.g. FPS=3). Example command:

ffmpeg -i input.mp4 -filter:v "fps=3" image_index_timestamp.jpg

But, I need to know which frame from original video FFMPEG has extracted. What I mean by that is, I would like to include in file name a timestamp (e.g. image_00_00:00:00.1.jpg, where 00 is index generated by FFMPEG and 00:00:00.1 is timestamp from which frame was extracted.).

I want to be able to SEEK to that specific timestamp and extract the same frame FFMPEG has generated for me.

By using following command I am able to draw timestamp (pts) on each frame. But, what I need is that timestamp inside filename and I dont know how to get it.

ffmpeg -i input.mp4 -filter:v "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: text='%{pts\:hms}': x=(w-tw)/2: y=h-(2*lh): fontcolor=red: box=1: boxcolor=0x00000000@1,fps=3" -start_number 0 image_%03d.jpg
0

4 Answers 4

2

ffmpeg docs suggests this to timestamp ALL frames- ffmpeg -i input.mp4 -f image2 -frame_pts true %d.jpg

If you check out https://ffmpeg.org/ffmpeg-all.html and search for "expand the filename with pts"

but I dont think its the true Presentation Time Stamp, rather its an index.

1

According to the following post, we may use the following command for setting the file to Time Stamps in milliseconds:

ffmpeg -vsync 0 -i video.mkv -r 1000 -f image2 -frame_pts 1 %d.jpg

  • -vsync 0 - Each frame is passed with its timestamp from the demuxer to the muxer.
  • -r 1000 - set the framerate to the output to 1000Hz, for converting the index to milliseconds.
  • -frame_pts 1 - Use current frame pts for filename.

For setting the file name as if the framerate is 3Hz, we have to know the original video framerate.

For example, if the original framerate is 25fps, use the following command:

ffmpeg -vsync 0 -i video.mkv -r 1000*25/3 -f image2 -frame_pts 1 %d.jpg


There is also an option to use setpts filter:

ffmpeg -vsync 0 -i video.mkv -vf "setpts=N*333.333" -f image2 -frame_pts 1 -enc_time_base -1 %d.jpg

The above command sets the filename to count in steps of 333.

0

According to the post How can l use ffmpeg to extract frames with a certain fps and scaling this could work:

ffmpeg -i video.avi -vf "fps=3" frames/c01_%04d.jpeg
0
ffmpeg -i rtsp://localhost:8554/mystream -vf "select=not(mod(n\,10)),showinfo" -vsync vfr -frame_pts true frame_%04d_%010d.jpeg

This worked for me !.

You must log in to answer this question.