1

Source Community

I've been trying to figure out an ffmpeg command with following requirements while converting 'avi' to 'mp4' with H264 video codecs. One command I tried was generic one like this which is recommended on most forums.

ffmpeg -I input.avi -acodec copy -vcodec copy output.mp4

But this copies same video codec & doesn't convert to H264. Can anyone of you guys help me compose a line of code that would do the task with following requirements.

=> Video Options

Codec: H264 Video  Aspect  Ratio: No Change Video  Resolution: No Change Video  FPS: No Change

=> Audio Options

Codec: AC Audio  Channels: No Change Audio  Frequency: No Change Audio  Normalization: No Change

Thanks in advance!

3
  • 1
    -c:v libx264 ? (i.e. instead of -c:v copy, also -c:v is the same as -vcodec)
    – grochmal
    Aug 13 '16 at 22:10
  • @grochmal thanks friend, I'll try this now & give my feedback to you soon.
    – Sollosa
    Aug 14 '16 at 7:18
  • @grochmal it didn't work really, says 'error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit-rate, rate, width or height'
    – Sollosa
    Aug 14 '16 at 7:34
1

Let us enumerate the parameters to ffmpeg then.

  • -acodec is better written -c:a (menmonic codec for audio)
  • -vcodec is better written -c:v (same mnemonic)
  • -i is the input file (not -I)

ffmpeg does a pretty good guesswork based on file extensions, therefore doing:

ffmpeg -i file.wem file.mp4

Will convert things, but probably in a pretty poor quality.


For H264 you are after the libx264 codec therefore it should go:

ffmpeg -i file.avi -c:v libx264 -c:a copy file.mp4

As a test let's use the classic webm example:

$ wget http://video.webmfiles.org/big-buck-bunny_trailer.webm
...
$ ffmpeg -i big-buck-bunny_trailer.webm -c:a copy -c:v libx264 bbb.mp4
...
$ ffprobe bbb.mp4
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bbb.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:32.50, start: 0.000000, bitrate: 414 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 341 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: vorbis (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

And that looks promising, stream #0:0 is a H264 encoded video stream.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.