15

If I import a file to use with ffmpeg but dont specify anything about the codecs of any of the streams, will ffmpeg do anything? Is the default action to just copy the codecs? Or will ffmpeg encode the input file using some default codec?

Would the following two commands be the same? Or will the second re-encode and take ages?

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

ffmpeg -i input.mkv output.mp4
sion
  • 1,367
  • 6
  • 17
  • 21

2 Answers2

18

If I import a file to use with ffmpeg but dont specify anything about the codecs of any of the streams, will ffmpeg do anything?

ffmpeg will re-encode each stream in the input using default encoders. The encoders used will depend on how you configured ffmpeg. For example, if available libx264 will be the default encoder for mp4 output, but if not then mpeg4 will be used. By default ffmpeg will only re-encode one stream of each type and will ignore the rest (see stream selection).

Of your two commands the first one will use stream copy mode for the video and audio. Your second command will re-encode.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • What if I import an mp4 file that already has an h.264 video stream? Will it try to encode it again, not changing anything but taking a long time anyway? Or will it recognise that it is already the default codec and just copy it? – sion Jul 22 '13 at 21:29
  • 3
    @Sam `ffmpeg` will always re-encode unless you tell it otherwise. – llogan Jul 23 '13 at 06:05
  • If it re-encodes to the exact same codec (i.e. h.264->h.264) will there be any quality loss? Will it be quicker than going from a different codec to h.264? I doubt there is any point in doing this but I'm interested anyway... – sion Jul 23 '13 at 13:43
  • 1
    It mostly depends on the output format if there will be quality loss. An exception is lossless formats, but quality loss can still occur if colorspace conversion is required. However, for example, if you output to lossy H.264 video, with the right options you may be able to to make it look "visually lossless"; meaning that it technically is not lossless but it's good enough that most people will not be able to tell a difference. See the [FFmpeg and x264 Encoding Guide](https://trac.ffmpeg.org/wiki/x264EncodingGuide). – llogan Jul 23 '13 at 17:25
  • 2
    "The encoders used will depend on how you configured ffmpeg:" so where's the doc explaining that? For audio as well as video? – Camille Goudeseune Aug 05 '14 at 16:49
  • @CamilleGoudeseune There is some relevant information at [FFmpeg Codecs Documentation: Encoders](http://ffmpeg.org/ffmpeg-codecs.html#Encoders). – llogan Aug 05 '14 at 18:20
  • 2
    I must be dense. That doc still doesn't mention defaults, neither in options to `./configure` nor in `ffmpeg -encoders`. – Camille Goudeseune Aug 05 '14 at 22:02
8

To discover the default codecs (both audio and video) used by the second command,
ffmpeg -i input.mkv output.mp4, on your computer:

  • Run that command, perhaps with -t 5 so it finishes faster (encode only 5 seconds).

  • Run ffprobe output.mp4. Scan the output for "Video" and "Audio" to see which codecs ended up being used. For example, my Ubuntu 12 installation uses h264 and aac.

Camille Goudeseune
  • 2,934
  • 2
  • 35
  • 56
  • 3
    Thanks for this. Another approach: `ffmpeg -h muxer=mp4` should print the default codecs used for a muxer. It prints `Default video codec: h264; Default audio codec: aac` on my machine. Of course, it only gives the codecs, not the actual encoder used. For instance `-h encoder=h264` shows `libx264`, `h264_amf`, `h264_mf`, `h264_nvenc`, `h264_qsv`, etc. meaning there're more than one encoders for a codec. – legends2k Nov 07 '22 at 04:07