2
Background
I need to convert AVI files to H264 (MP4). I am successfully doing so with the following:
-i mymovie.avi -c:v libx264 -crf 19 -preset slow -c:a libfaac -pix_fmt yuv420p -f mp4 -b:a 192k -y -an output.mp4
I am calling the command via a C# .Net Winforms applications, although I suspect this will have little impact on the answer.
The Question
How do I add an audio track? I need to add one, as I need to be able to upload the videos to Instagram, which it seems rejects files without an audio track (to my annoyance). In reality I do not need an audio track that is very long. My thoughts were a couple of seconds of "silence" in MP3 format.
I think I will need AAC audio as the output.
For the record I also realise the -an
command will provide no audio and I have taken this away in my later attempts.
Attempts so far
I have gathered I will need to use the -shortest
command as the audio will be shorter than the video. In reality I will be adding a blank MP3 (or similar) just so while encoding I get an audio stream embedded in the video.
I also have tried using the -map
command but without success.
Note that of all the AAC encoders you can use with ffmpeg, libvo_aacenc offers the worst quality. Better to use
-c:a aac -strict experimental
and a bitrate of over 96k. This is the ffmpeg-internal encoder. – slhck – 2013-12-03T11:36:48.783How do I add the bitrate or will it take it from the source file? Thanks for improving my answer! Have I done anything else wrong? – Graham Smith – 2013-12-03T11:40:06.133
1
-b:a
sets the audio bitrate, so in your example you'd only need to change the encoder part. Some minor things: the-y
option should go before the inputs, and-f mp4
is not needed. Apart from that it looks good to me! – slhck – 2013-12-03T11:43:25.727Also see the FFmpeg and AAC Encoding Guide.
– llogan – 2013-12-03T18:47:39.720