[FFmpeg-user] Extract audio from video and use one frame as cover image

Bernhard Döbler programmer at bardware.de
Sat Jan 9 04:36:37 EET 2021

Am 08.01.2021 um 05:18 schrieb Gyan Doshi:
> On 08-01-2021 06:37, Bernhard Döbler wrote:
>> I have video files. I want to extract the audio and use one single 
>> frame from the video track as cover image.
>> The command line looks like this
>> ffmpeg.exe -y -i "e:\01. Video.mp4" -filter:v 
>> "select=between(145\,prev_pts*TB\,pts*TB)" -frames:v 1 -c:a copy -c:v 
>> mjpeg -q:v 2 -disposition:v:0 attached_pic "e:\01. Audio.m4a"
>> This is supposed to embed a frame from around second 145 as cover image.
>> The issue is that the whole processing of the file stops after the 
>> single image was extracted and my resulting file has a length of 2:25 
>> minutes. I want the audio file to be as long as the video.
> `-frames` is set to terminate the output when fulfilled. Use trim 
> within the filtergraph.
> ffmpeg.exe -y -i "e:\01. Video.mp4" -filter:v 
> "select=between(145\,prev_pts*TB\,pts*TB),trim=end_frame=1" -c:a copy 
> -c:v mjpeg -q:v 2 -disposition:v:0 attached_pic "e:\01. Audio.m4a"

Thank you for your answer.

The console eventually reads

More than 1000 frames duplicated
[ipod @ 00000299cb43de80] Got more than one picture in stream 0, ignoring.

when I call your command as is.

When I dump the images as individual jpg files, I see it's the same 
image over and over again.

I searched the internet and found a posting on StackOverflow that 
suggested to use filter mpdecimate: 

Final command line that gives no warnings looks like:

ffmpeg.exe -y -i "e:\01. Video.mp4" -filter:v 
-c:a copy -c:v mjpeg -q:v 2 -disposition:v:0 attached_pic "e:\01. 

More information about the ffmpeg-user mailing list