[FFmpeg-user] convert mp3 to 3gp or MP4

Lou lou at lrcd.com
Fri Jun 7 01:46:55 CEST 2013


On Fri, 7 Jun 2013 00:47:18 +0200
Moritz Barsnick <barsnick at gmx.net> wrote:

> On Thu, Jun 06, 2013 at 11:50:54 +0100, Keith Beaumont wrote:
> > So I would like to fool MePlayer. Is there a simple way with ffmpeg to convert MP3 to MP4 or 3GP in batch mode?
> 
> With ffmpeg, you can supply a lavfi filter as video input source:
> e.g. 10 fps blank 640x480 video
> ffmpeg -f lavfi -i color=black,scale=640:480 -codec:v mpeg2video -t 00:01:00 -r 10 blank.mpg

You can specify size, rate, and duration within the color video source
filter:

ffmpeg -f lavfi -i color=s=640x480:r=10:d=60 output

Although duration isn't needed because you can use "-shortest"

> The video codec does matter in terms of conversion speed and size. I
> don't know which codec would be a good tradeoff, I don't have much
> experience. For me, mpeg2video was about 1 MB in size per minute, but
> really quick to create. libx264 on the other hand was about 50 kB per
> minute, but quite slow. YMMV.

libx264 is faster and creates a smaller output:

ffmpeg -f lavfi -i color=s=160x120:r=2 -i audio.mp3 -c:v libx264 \
-preset ultrafast -c:a copy -shortest output.mp4

This is a case where ultrafast is really useful due to the simplicity
of the input. If a player doesn't like r=2 then increase it or remove
":r=2". Same for the size if the player or phone is picky.

> (There may be a way to make ffmpeg stop converting when it's
> out of audio. Someone else will need to answer to that.)

-shortest

A bash "for loop" to encode all files:

$ mkdir out
$ for f in *.mp3; do ffmpeg -f lavfi -i color=s=160x120:r=2 -i "$f" \
  -c:v libx264 -preset ultrafast -c:a copy -shortest \
  out/"${f%.mp3}.mp4"; done

Of course if a blank, black screen is too boring then use an image
input instead or one of the other video source filters (mandelbrot,
cellauto, life, etc) but they would be slower to encode. Or play around
with the drawtext filter and print the metadata to the video (also
don't forget you can play around with "-metadata" too).


More information about the ffmpeg-user mailing list