3

I have around 8000 audio files (~6 GB in total) mostly in either m4a or mp3 format. Is there a way to convert these audio files to video with filename appearing as a static poster image in video. I was able to find drawtext filter in ffmpeg which might be helpful. But don't know how to write it out in one command so that I just pass in name of the audio file (mp3/m4a) and as output I get a video containing name of audio file as a display (with 256 by 144 pixel resolution).

So far I have been able to do this all by using ImageMagick convert commmand to first create static images and then combine using ffmpeg.

Since, there are many files I want this to be done programmatically using ffmpeg/python/javascript. I want to do this to archive my audio recordings in Google Photos. Google photos accept unlimited storage for High Quality videos.

Prateek Singla
  • 679
  • 2
  • 10
  • 22

2 Answers2

2

Just try to do something like code below:

ffmpeg -i 1.mp3 -i cover.jpg -f mp4 out.mp4
  • I want to create cover.jpg programmatically, that cover.jpg should have the audio file name (1.mp3) in case as you mentioned above. – Prateek Singla Jul 06 '20 at 13:54
2

You can get that result by using ImageMagick to create a label image, and piping it into ffmpeg before reading in the audio file to assemble the output. I worked up a command in Windows syntax...

set FNAME="My Audio.mp3"

convert -pointsize 24 label:%FNAME% -gravity center -extent 720x480 png:- ^
   | ffmpeg -y -f image2pipe -i - -i %FNAME% ^
      -filter_complex "loop=-1:1:0" -shortest out_%FNAME%.mp4

To translate that to *nix syntax should be almost as simple as changing the continued-line carets "^" to backslashes "\" and changing the way it sets and reads the variable.

That command starts by setting a variable with the name of your audio file. Then it runs the ImageMagick "convert" command to create a label with that filename centered on a 720x480 canvas. The output is forced to PNG format and piped into ffmpeg as the video input.

After your audio file is read in, ffmpeg uses "filter_complex" to run the video image as an endless loop, and uses "-shortest" to limit it to the length of the audio.

The result is an MP4 video with your input as the audio, and the file name in black on a white background centered in the video frame. Use additional ImageMagick and/or ffmpeg options to suit your own needs.

To run that on a directory full of images, put the command inside a "for" loop so it runs through all the images and changes the variable to each next filename in the directory.

If you're using ImageMagick v7 use "magick" instead of "convert".

GeeMack
  • 4,486
  • 1
  • 7
  • 10
  • This works well, but I am having large number of files and ImageMagick is very slow in creating files. FFmpeg seems to work faster. Is there anyway both work can be done using ffmpeg only? – Prateek Singla Jul 08 '20 at 09:08