I'm able to convert a mp4 to a mp3 in ffmpeg, but I'm not sure how I would add in a thumbnail of the video.

Currently have this to convert from mp4 to mp3

ffmpeg -i video.mp4 -acodec libmp3lame -metadata title=video -b:a 256 -f input.mp3

Would I then have to run that through ffmpeg again with this command?

ffmpeg -i input.mp3 -i cover.jpg -map_metadata 0 -map 0 -map 1 output.mp3

or is there any way to use complex filters to achive this is one run?

I know that this works for FLV but it does not seem to work for mp4

ffmpeg -i video.flv -i cover.jpg -map 0:a -map 1 -c:v copy -metadata title=video -b:a 256k out.mp3
  • Do you really want the convert to automatically set the thumbnail? Because otherwise you could change it manually but I'm not sure if you are after that. If you can do it with FLV but not with MP4 I would just make a script that runs both commands. – RamonRobben Feb 28 '17 at 22:04
  • @RamonRobben I'm trying to avoid having to run ffmpeg twice – nadermx Feb 28 '17 at 22:22
  • you could try something like this ffmpeg -i in.mp4 -i test.png -map 0:0 -map 1:0 -c copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" out.mp3 I'm downloading ffmpeg myself to start testing with it. – RamonRobben Feb 28 '17 at 22:29

Better answer, with explanation, incorporating smart suggestions from slhck and Mulvya, stripped of non-essential parameters.

ffmpeg -i video.mp4 -i cover.jpg -acodec libmp3lame -b:a 256k -c:v copy -map 0:a:0 -map 1:v:0 output.mp3

ffmpeg audio/video manupulation tool: already selected by the OP, it is particularly fit for this job.

-i video.mp4 first input file: a video with some audio that we want to extract.

-i cover.jpg second input file, an image that we want displayed when we play the resulting audio file.

-acodec libmp3lame we want to create an .mp3 file, using the LAME encoder.

-b:a 256k this sets the bitrate for the audio track to a constant 256Kb/s. A smarter option would be to encode with a variable bitrate, specifying the quality parameter: -q:a 0 asks for the maximum quality, while -q:a 4 often represents a good compromise between perceived audio quality and bitrate (and hence, file size).

-c:v copy this indicates that the video stream (the .jpg image) is not to be reencoded but must be copied as it is. This is useful to avoid unnecessary processing and potential quality loss when reencoding to a lossy format. In our case, without this parameter the image would be decoded from .jpg and encoded to .png, which apparently is the native format that gets chosen by default. This would not represent a loss in quality since .png is lossles, but more often than not will cause the file size to increase, due to the fact that .jpg (being lossy) generally offers a better compression rate.

-map 0:a:0 this selects the stream to be used from the first (0:) input file: it has to be the first (:0) audio (a) stream it contains.

-map 1:v:0 this selects the first (:0) video (v) stream from the second (1:) input file.

output.mp3 the name of this parameter was cunningly chosen in order to already suggest that this must be the name to be given to the output audio (.mp3) file with incorporated image that we want to create.

Original answer

This creates an audio (.mp3) file with a static image by putting together a video (.mp4) and a picture (.jpg) from my wedding:

ffmpeg -i video.mp4 -i cover.jpg -acodec libmp3lame -metadata title=video -b:a 256k -map_metadata 0 -map 0:1 -map 1 output.mp3

See ffmpeg documentation on selecting input streams with -map, which is the relevant option here.

I first ran the command with simply -map 0 -map 1 and got this info:

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> png (native))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
  Stream #1:0 -> #0:2 (mjpeg (native) -> png (native))

Thus I knew I wanted stream 1 (aac audio) from the file which has an index number of 0, i.e. the video file; therefore it had to be explicitly selected with -map 0:1 -map 1.

  • I've tried this, yet it gives me Stream map '0:1' matches no streams. To ignore this, add a trailing '?' to the map. – nadermx Mar 2 '17 at 22:00
  • Run it with ´-map 0 -map 1´ and see what the available streams are. – simlev Mar 2 '17 at 22:08
  • Stream mapping: Stream #0:0 -> #0:0 (aac (native) -> mp3 (libmp3lame)) Stream #1:0 -> #0:1 (mjpeg (native) -> png (native)) – nadermx Mar 2 '17 at 22:12
  • 1
    @nadermx You can do -map 0:a:0 -map 1:v:0 to select the first audio and video streams of the first and second file, respectively. – slhck Mar 3 '17 at 8:28
  • 1
    Avoid encoding the image input, especially with JPG. -c:v copy. – Gyan Mar 3 '17 at 11:52

you can make use of vlc media player -

Step 1: Open the VLC and select “Media”. Click on the convert/save.

Step 2: On the next window that appears, select “add” and choose the video file (MP4) to be converted.

Step 3: Next, click down arrow on the “Convert/Save” then click “Convert”.

Step 4: On the next window that appears, make sure the “Convert” button is selected. Proceed to choose the type of audio file you wish to create. In our case its MP3 file we are converting to.

Step 5: Choose an output destination, and then press “Start”. The VLC will then commence converting.

for adding thumbnail you can refer this link (explained very well).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.