I am using ffmpeg to get some jpg from my video at a specific rate (one screenshot every 5 seconds) with this command :
ffmpeg -i source -f image2 -r 1/5 %d.jpg
This works and give me sequential filenames :
1.jpg
2.jpg
3.jpg
4.jpg
What if I need to know at which time those screenshots have been taken ? Something like a timestamp :
00:00:00.0000.jpg
00:00:05.0000.jpg
00:00:10.0000.jpg
00:00:15.0000.jpg
or the number of seconds :
0.jpg
5.jpg
10.jpg
15.jpg
I tried again with the new -frame_pts option :
ffmpeg -i source -f image2 -r 1/5 -frame_pts 1 %d.jpg
I got similar sequential filenames, but now they are starting from zero :
0.jpg
1.jpg
2.jpg
3.jpg
You can select the output format of each frame with ffmpeg by specifying the audio and video codec and format. For example to compute the CRC of the input audio converted to PCM unsigned 8-bit and the input video converted to MPEG-2 video, use the command:
Use ffmpeg to encode the input, and send the output to three different destinations. The dump_extra bitstream filter is used to add extradata information to all the output video keyframes packets, as requested by the MPEG-TS format. The select option is applied to out.aac in order to make it contain only audio packets.
You can print the CRC to stdout with the command: You can select the output format of each frame with ffmpeg by specifying the audio and video codec and format. For example to compute the CRC of the input audio converted to PCM unsigned 8-bit and the input video converted to MPEG-2 video, use the command:
out1.mkv is a Matroska container file and accepts video, audio and subtitle streams, so ffmpeg will try to select one of each type. For video, it will select stream 0 from B.mp4, which has the highest resolution among all the input video streams. For audio, it will select stream 3 from B.mp4, since it has the greatest number of channels.
Use
ffmpeg -i source -vf fps=1,select='not(mod(t,5))' -vsync 0 -frame_pts 1 z%d.jpg
frame_pts will assign a serial number to the image name, where the number represents the frame position as per the output timebase. So the calculated time position is frame #
x timebase
. The timebase is the reciprocal of the output framerate e.g. for a 12 fps stream, timebase is 1/12. So output file image212
represents a time of 212
x 1/12
= 17.67s
To represent seconds, you need to generate a 1 fps stream and then pick every 5th frame, to get a frame from every 5th second. The vsync 0
is added to prevent ffmpeg from duplicating frames to generate a constant frame rate stream.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With