How do I convert multiple mp3 files to mp4 with ffmpeg?

2

1

The following command takes the mp3, attaches an image to it, and converts it to an mp4:

ffmpeg -i input.mp3 -loop 1 -i image.png -c:a copy -c:v libx264 -shortest output.mp4

I need to do this for all the mp3s in a folder. How would I code this?

Doc Chop

Posted 2015-07-02T19:32:27.743

Reputation: 31

Hi Doc Chop, welcome to Super User. What are you trying to achieve? A video of each MP3 with a single image? Or a different image per MP3 file?

– bertieb – 2015-07-02T19:35:10.610

2Which OS? Windows, Mac or Linux? – Zalmy – 2015-07-02T20:37:42.227

Thank you! I'm trying to apply the same image to each mp3 in a folder. The operating system is windows 8 and the desired output for the file is mp4. I appreciate your help. – Doc Chop – 2015-07-07T17:54:20.907

Answers

2

Assuming Linux or some flavor of UNIX and image.png is literal:

cd /media/volume/mp3_directory

ls *.mp3 | while read mp3File ; do outputFile=$(basename "${mp3File}" .mp3) ; ffmpeg -i "${mp3File}" -loop 1 -i image.png -c:a copy -c:v libx264 -shortest "${outputFile}".mp4 ; done

Larssend

Posted 2015-07-02T19:32:27.743

Reputation: 2 941

Thanks for the quick response. Can I get this code for windows please? – Doc Chop – 2015-07-08T02:25:40.010

0

If you want to batch convert you should use the shell for it (assuming Linux). Use find to return all files in a directory and '| xargs' to apply the given ffmpeg command to each.

larkey

Posted 2015-07-02T19:32:27.743

Reputation: 1 590

Can you update your answer with a complete example? – llogan – 2015-07-03T06:35:14.590