Dmitry Minkovsky
Dmitry Minkovsky

Reputation: 38143

What are good settings for transcoding videos uploaded to my app?

I am working on an app that allows users to share videos. The problem is that many videos are very high bitrate. For example, A 4-minute H264 video from an old iPhone is encoded at 1080p and runs ~17,000 kb/s (~500 megabytes). Accepting and distributing such videos at this bitrate/resolution is not practical for a social application.

I have been playing with ffmpeg to transcode videos to smaller sizes and higher compression, but have not achieved acceptable results. For example:

ffmpeg \
    -i in.mov \
    -vf scale=w='if(gt(iw\,ih)\,780\,-2)':h='if(gt(iw\,ih)\,-2\,780)' \ 
    -c:v libx264 \
    -crf 28 \
    -preset medium \
    -pix_fmt yuv420p \
    -movflags +faststart \
    out.mp4

This command transcodes the above-mentioned 500MB file down to 70MB. It scales the larger dimension of the video to 780 pixels and compresses the video quite a bit. The results are okay, but the file is still large.

Taking the longer dimension down to 480 pixels, the file is reduced to 40MB. Still quite large, and now significantly degraded. Also, the transcoding still takes quite a long time: about 1-1.5x on my 4 year old i7 Macbook Pro with 16GB RAM.

I'm not sure how to improve on this. H265 is not supported in browsers. I am wondering:

Is this as good as it gets?

Upvotes: 1

Views: 578

Answers (1)

szatmary
szatmary

Reputation: 31110

Is this as good as it gets?

Yes. There is no such thing as a free lunch in video encoding.

You can speed up encoding if the machine has a hardware encoder like QuickSync on some intel CPUs, or nvenc on Nvidia Gpus (or videotoolbox on some Macs/iOS). But the file size will be the same, or even a little bigger.

Upvotes: 2

Related Questions