I have many MP3 files on my website and I have decided to upload them to Youtube, but unfortunately for me, Youtube does not allow me to do that. It requires video format only.

How can I convert these MP3s to video and add same set of images (one or more images) to the resulted video format.

I need to do this in bulk, not individually, I have hundreds of MP3 files.

It can be either a Windows-based or Linux-based application.

There's some info about using ffmpeg to encode audio with a still image for YouTube, here, and some advice for doing bulk conversions in Windows, here.

As for encoding, I find that this works:

ffmpeg -loop 1 -r 1 -i pic.jpg -i audio.mp3 -c:a copy -shortest output.avi

There are some solutions for Ubuntu and other Linux systems at http://ubuntuforums.org/showthread.php?t=1686664. Most are shell commands or some other quick scripting language that can be looped for all of the MP3s, outputting video files. Then, you can just queue the video files for upload to YouTube. Among the solutions listed on the page:

  1. FFmpeg, then upload files to YouTube
    ffmpeg -loop 1 -i picture.jpg -i music.mp3 -shortest -acodec copy video.mp4 Loop accordingly for all mp3 files, then upload all the resulting video files.

  2. Python, convert to mp4 then upload files to YouTube

    #! /usr/bin/env python

    import sys, os

    inputOne = sys.argv[1] inputTwo = sys.argv[2]

    for i in sys.argv[1:]: if '.mp3' in i: output = i.replace('mp3','mp4')

    cmd = 'ffmpeg -loop_input -i "'+inputOne+'" -i "'+inputTwo+'" -shortest -acodec copy "'+output+'"'

    os.system(cmd)

It also uses ffmpeg, and accepts music and picture as arguments.

  • loop_input is deprecated in ffmpeg—you need to use -loop 1 now. – slhck Jan 12 '14 at 3:45
  • Can we have more than one picture in the first solution (1. FFmpeg)? – Rasoul Apr 15 '15 at 18:10

You could also consider simple bash oneliner instead of python script -

for i in *.mp3; do ffmpeg -v quiet -i "picture.jpg" -i "$i" -shortest -acodec copy "`sed 's/mp3/mp4/g'<<<$i`"; done

This will convert all mp3 files in your current dir into mp4 videos with picture.jpg.

For converting flac to mp3 that would be

for i in *.flac; do ffmpeg -v quiet -i "$i" -ab 320k -ac 2 -ar 48000 "`sed 's/flac/mp3/g'<<<$i`"; done

Notice "-v quiet", which shuts ffmpeg's loud mouth and also double quotes around $i and sed - this will ensure it won't fail with filenames containing spaces.

A tip: converting to video takes quite some time (at least for me). Try using -threads 4 (or any other value, of course. It won't make any sense on single-core cpu)

Edit: I've found out that "-loop 1" (suggested by others) creates loop (how surprising!) which is actually infinite. On my gentoo that means it will eat all your tasty bites. Without "-loop 1" it works just fine, so I suggest you to go with that.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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