Converting .mkv to h.264 FFmpeg

2019-04-02 08:07发布

问题:

I would like to convert my .mkv files to .mp4 using FFmpeg. I have tried the following code:

ffmpeg -i input.mkv -c:v libx264 -c:a libvo_aacenc output.mp4

But I get the error:

Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height.

Is there any way to get around this? I have tried setting the bitrate of the audio but the problem seems to persist.

回答1:

I suggest you first check whether your .mkv file already has H.264/AAC streams in the first place. Because if it does, all you have to do is copy the streams and change the container:

ffmpeg -i input.mkv -vcodec copy -acodec copy output.mp4

If it doesn't, you probably got rejected because you didn't specify a bitrate to libvo_aacenc. Try the following:

ffmpeg -i input.mkv -c:v libx264 -c:a libvo_aacenc -b:a 128k output.mp4

But again, if your .mkv already contains H.264/AAC, USE THE FIRST SOLUTION. It'll be faster and will have a better quality.