Extract audio from video and use one frame as cover image

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Extract audio from video and use one frame as cover image

Bernhard Döbler
Hi,

I saw, today, FFMpeg, finally, allows for embedding a single image as
cover image into an .M4A file using the "-disposition:v:1 attached_pic"
argument as explained in an answer on StackOverflow:
https://stackoverflow.com/a/61015965/577052

This works very well, when I convert a .FLAC file, that already has one
single frame embedded as cover, to .M4A using a command line like
ffmpeg.exe -y -i "e:\01. Music.flac" -c:a aac -q:a 2 -c:v mjpeg -q:v 2
-disposition:v:0 attached_pic -movflags +faststart "e:\01. Music.m4a"

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.

To overcome this, I provide the same video file twice as input and
select the audio track of one file and the video track from the other
using the map argument.
ffmpeg.exe -y -i "e:\01. Video.mp4" -i "e:\01. Video.mp4" -filter:v
"select=between(145\,prev_pts*TB\,pts*TB)" -frames:v 1 -map 0:1 -map 1:0
-c:a copy -c:v mjpeg -q:v 2 -disposition:v:0 attached_pic "e:\01. Audio.m4a"

This works!

I'm now wondering if there's a way to make this work providing the input
file only once, selecting a single frame and the whole audio.

Is there a best practice to convert video files to audio files
maintaining one single frame a cover image?


Best,
Bernhard
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Extract audio from video and use one frame as cover image

Gyan Doshi-2


On 08-01-2021 06:37, Bernhard Döbler wrote:

> Hi,
>
> I saw, today, FFMpeg, finally, allows for embedding a single image as
> cover image into an .M4A file using the "-disposition:v:1
> attached_pic" argument as explained in an answer on StackOverflow:
> https://stackoverflow.com/a/61015965/577052
>
> This works very well, when I convert a .FLAC file, that already has
> one single frame embedded as cover, to .M4A using a command line like
> ffmpeg.exe -y -i "e:\01. Music.flac" -c:a aac -q:a 2 -c:v mjpeg -q:v 2
> -disposition:v:0 attached_pic -movflags +faststart "e:\01. Music.m4a"
>
> 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"

Regards,
Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Extract audio from video and use one frame as cover image

Bernhard Döbler
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:
https://stackoverflow.com/a/37089629/577052

Final command line that gives no warnings looks like:

ffmpeg.exe -y -i "e:\01. Video.mp4" -filter:v
"select=between(145\,prev_pts*TB\,pts*TB),trim=end_frame=1,mpdecimate,setpts=N/FRAME_RATE/TB"
-c:a copy -c:v mjpeg -q:v 2 -disposition:v:0 attached_pic "e:\01.
Audio.m4a"

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Extract audio from video and use one frame as cover image

Gyan Doshi-2


On 09-01-2021 08:06 am, Bernhard Döbler wrote:

> 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.

Inefficient, but those extra images aren't muxed into the output. That's
what the ignoring msg means.

You can avoid the duplication by adding  `-vsync vfr`.

For your workaround, mpdecimate is not relevant, only the setpts filter.

Regards,
Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".