How to transcode video stream by changing only the resolution

ffmpeg

I would like to transcode video stream using ffmpeg tool and change only the video stream resolution, i.e. the video and audio parameters should remain the same.

According to the man page of the ffmpeg the following command line should provide the desired result:

ffmpeg -i input.mp4 -vcodec copy -acodec copy -s WxH output.avi

The Video codec of the input stream is compatible with avi container.

The actual result is that the resolution remains unchanged and it seems that the stream is just repacked in avi container.

The resolution of the output stream is changed successfully without -vcodec copy option, but the video codec is changed: h264 (Constrained Baseline) – > mpeg4 (Simple Profile).

Best Answer

When you copy a video stream, you cannot change any of its paramters, sinceā€¦ well, you're copying it. ffmpeg won't touch it in any way, so it can't change the dimensions, frame rate, et cetera.

Also, ffmpeg always chooses a default video codec if you don't specify one. For AVI files, that's mpeg4.

If you want H.264 video, choose -c:v libx264 instead (or -vcodec libx264 which is the same). If you need to keep the original profile, use -profile:v baseline.

Two things:

  • When you change the size, you will recode the video. This lowers the quality and might considerably harm the video. To compensate for this, you might need to set a higher quality level. You do this by setting the Constant Rate Factor to anything below the default of 23, e.g. with -crf 20. Experiment and see how your video looks like. If you have the time, add the -preset slow (or slower, veryslow), which will give you better compression.

  • Not that it matters in your case, since your input uses the Constrained Baseline profile, but note that H.264 in AVI is not properly supported, at least when using B pictures. Baseline doesn't support B pictures though, so you should be fine. It could happen that file can't be played back on some devices or players if you use the Main profile or anything above. I would rather mux it into an MP4 or MKV container, especially if your input file is MP4 anyway.

Related Topic