Copying a codec from one video to another is easy and convenient as seen below:
$ ffmpeg -i input.avi -c:v copy -c:a copy output.mp4
-c:v also seen as -vcodec sets the video codec, while -c:a or -acodec sets the audio codec. Adding the option copy after each results in FFMPEG using and copying the codec from the input file.
It is common to see on programming forums, such as Stack Overflow, examples where the author has copied the codec from one format type to another. More often than not, this is risky but due to programs like VLC playback isn’t halted regardless of format type + codec combinations. Below is an example of risky codec copying:
$ ffmpeg -i input.avi -vcodec copy -acodec copy output.mp4
The reason for concern is the avi format supports a wide range of codecs, DivX, Xvid, H.264, and MPEG-4 to name a few. Whereas mp4 does not natively support DivX, Xvid or other codecs. So copying video codecs blindly may result in a faulty playback.
Note: VLC might play a mp4 with a DivX codec but uploading to Instagram may not because it does not have a decoder for DivX playback.
Love FFmpeg? Grab a copy of FFmpeg For Beginners on Kindle or Paperback to learn over 120 ways to master FFmpeg!