Sketching with FFmpeg

I use FFmpeg to extract thumbnails from specific locations of video files.

I found two approaches on the Internet for this:

  • With the -ss (search) option before the -i (input) option:

    ffmpeg -y -ss $SEEK_POINT -i input.ogv -vcodec mjpeg -vframes 1 -an -s 120x90 -f rawvideo output.jpg

  • With the -ss (search) option after the -i (input) option:

    ffmpeg -y -i input.ogv -vcodec mjpeg -ss $SEEK_POINT -vframes 1 -an -s 120x90 -f rawvideo output.jpg

The first method creates a bad thumbnail with gray spots, but it works very quickly. Error returned: [theora @ 0x8097240] vp3: first frame not a keyframe .

The second method always works, but shows an error due to which the extraction takes a lot of time. This time is not fixed and depends on the search point, as I noticed. Sometimes it takes a few seconds to extract a thumbnail, and sometimes a few minutes. I get the error Buffering several frames is not supported. Please consume all available frames before adding a new one. Buffering several frames is not supported. Please consume all available frames before adding a new one. on the next output:

 Input #0, ogg, from 'input.ogv': Duration: 00:21:52.76, start: 0.000000, bitrate: 844 kb/s Stream #0.0: Video: theora, yuv420p, 800x600 [PAR 4:3 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc Stream #0.1: Audio: vorbis, 44100 Hz, stereo, s16, 192 kb/s Metadata: ENCODER : Lavf52.102.0 Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p' [buffer @ 0x9250840] w:800 h:600 pixfmt:yuv420p [scale @ 0x92508a0] w:800 h:600 fmt:yuv420p -> w:120 h:90 fmt:yuvj420p flags:0x4 Output #0, rawvideo, to 'output.jpg': Metadata: encoder : Lavf53.2.0 Stream #0.0: Video: mjpeg, yuvj420p, 120x90 [PAR 4:3 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 25 tbc Stream mapping: Stream #0.0 -> #0.0 Press ctrl-c to stop encoding [buffer @ 0x9250840] Buffering several frames is not supported. Please consume all available frames before adding a new one. frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbit Last message repeated 15448 times frame= 1 fps= 0 q=3.4 Lsize= 3kB time=0.04 bitrate= 598.8kbits/s video:3kB audio:0kB global headers:0kB muxing overhead 0.000000% 

How can I extract thumbnails without any problems using FFmpeg from a custom video position regardless of input format?

+4
source share
1 answer

Try something similar with itsoffset option:

 ffmpeg -itsoffset 4 -i "$INFILE" -vcodec png -vframes 1 -an -f rawvideo -s 120x90 -y "$OUTFILE" 

From the FFmpeg documentation on itsoffset :

Set the input time offset in seconds. The syntax [-] hh: mm: ss [.xxx] is also supported. An offset is added to the time stamps of the input files. Setting a positive offset means that the corresponding flows are delayed for shear seconds.

+4
source

Source: https://habr.com/ru/post/1381745/


All Articles