7

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.

8

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

2

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
2

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.

0

Copy your mp3 files (or what ever you want to encode, change your audio format accordingly.) to one folder. Also put an instance of ffmpeg in it, with a cover picture titled herringbone.jpg.

Then go to CMD and navigate to the folder.

Copy this:

for %a in (*.mp3) do "ffmpeg" -loop 1 -r 1 -i "Herringbone.jpg" -vcodec mpeg4 -i %a -acodec copy -shortest %a".mp4"

(To paste to CMD window click on the cmd line window upper left. Choose EDIT / Paste.)

Press enter.

Works with latest version of ffmpeg encoder (4.1.1)

I imagine you can change the video format too. Just change from mp4 to whatever you desire and what ffmpeg supports.

I found this at another forum, but it did not work until I switched the place of the -shortest in the script.

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.