I have 1 image (jpg) and 1 audio file (MP3) and I would like to output this as a video file (say AVI for example).
Does anyone know how to use FFMPEG to join the two? I'd like to show the image for the duration of the audio.
Any ideas anyone?
If you are in Windows, You can do it in Windows Movie maker too ... if you need instructions please leave a comment
For FFmpeg use this
ffmpeg -loop_input -vframes 14490 -i imagine.jpg -i audio.mp3 -y -r 30 -b 2500k -acodec ac3 -ab 384k -vcodec mpeg4 result.mp4
vframes 14490 is the number of frames that should be looped in order to have a continuous image for the entire audio.mp3 file
Ex: For 8 minutes and 3 seconds ((8m x 60s + 3s) x 30fps = 14490 vf)
Resource from here
There is a much simpler way than those suggested here, that doesn't require calculating the number of frames or inputting the length of individual files (especially better for batch processing). With a recent version of ffmpeg, you can use the
-shortest option, which stops encoding when the shortest stream ends - in this case, input.mp3 (since the image will loop forever, it has infinite length):
ffmpeg -i input.mp3 -f image2 -loop 1 -r 2 -i input.jpg \ -shortest -c:a copy -c:v libx264 -crf 23 -preset veryfast output.mp4
This uses 2 frames per second for the image/video, which should be fine, but you can set it to a more standard 25 if you want.
subanki almost had it right. The working command line is as follows;
ffmpeg -y -loop 1 -i image.jpg -i audio.mp3 -r 30 -b:v 2500k -vframes 14490 -acodec libvo_aacenc -ab 160k result.mp4
overwrite output files without prompting
The option ‘-loop_input’ is deprecated use -loop 1. See ffmpeg documentation.
Frames Per Second
Could also be expressed as: -r 30000/1001 giving a fps of 29.97nnn
video bit rate; the higher the number, the better the quality and the larger the file size.
As explained above; take the total time of your audio file in seconds (e.g. 00:02:41 (2 minutes 41 seconds) equals 161 total seconds (2 x 60) + 41). Then multiply the total seconds by the Frames Per Second that you specified with -r (e.g. 161 x 30 = 4830).
-vframes can be replaced with -t 161 (-t duration record or transcode “duration” seconds of audio/video)
Use the correct audio codec for the type of file you are creating. For .mp4 it should be an AAC format. The codec libvo_aacenc was the correct encoding codec for my Windows 7 system.
audio bit rate
This is the name of the output file. It can be any legal file name for your system. The extension will help ffmpeg determin the proper video codec if you do not specify one using -vcodec.
That simple bash/cygwin script that AUTOMAGICALLY will encode all files of $AUDIO extension in directory to 10FPS mp4 video file in directory with folder.jpg image embedded,
useful for youtube uploads ;)
AUDIO=m4a; $'\n'; for a in `ls -1 *.$AUDIO `; do ffmpeg -i $a &2> $a.info ; done; cat '' > do.sh IFS=$'\n'; for a in `ls -1 *.$AUDIO`; do D=`grep Duration $a.info | cut -d',' -f1 | cut -d' ' -f4 | cut -d'.' -f1 | head -n1 `; S=$(( $( echo $D | cut -d':' -f2 ) * 60 + 1 + ` echo $D | cut -d':' -f3 ` )) ; echo ffmpeg -loop_input -vframes $(( $S * 10 )) -i folder.jpg -i \"$a\" -y -r 10 -b 2500k -ab 384k -vcodec mpeg4 \"$a.mp4\" >> do.sh; done; split -l5 do.sh xa* &
Download VirtualDub, then do this:
Open the image like you would open a normal video file.
Calculate the duration of the audio in seconds and round it up to the nearest whole second (e.g. 78.34 sec becomes 79 seconds). This value is called x from now on.
Go to "video > frame rate" select "change to frame rate (fps)" and enter "1/x" as value. Additionally, if you want to have a normal frame rate in the resulting file like 25 fps, select "Convert to fps" and enter the wanted frame rate in there.
Select "video > compression" and pick your favorite flavor. It can be that you need to adjust the size of the image with the resize filter.
Go to "audio > audio from other file" and select your audio there. If needed select a compression for the audio.
Save the file.