July 20th, 2024

Ask HN: Share your FFmpeg settings for video hosting

A user is developing a video hosting site allowing MP4 uploads, utilizing H.264 for video and Opus for audio. They seek advice on encoding settings and challenges faced in the process.

Ask HN: Share your FFmpeg settings for video hosting

The user is developing a video hosting website that allows users to upload video files, which will then be processed to create multiple versions with varying qualities, audio tracks, and thumbnails. The chosen format for video files is MP4 due to its broad compatibility. To enhance user experience, the fast start option is utilized, placing the metadata at the beginning of the file to allow quicker playback. The H.264 codec has been selected for video encoding, as it is widely supported and often outperforms hardware encoding due to its optimized software encoding capabilities. This choice is particularly relevant since users are expected to upload already compressed videos rather than high-resolution raw footage. For audio, the Opus codec is preferred for its efficiency. The user employs FFmpeg for video conversion, using specific command-line options to set parameters such as video and audio bitrates, dimensions, and channel layouts. The user seeks advice from others in the video encoding field regarding their settings, challenges faced, and any tips they might have, acknowledging that this is a specialized area beyond typical consumer use.

Link Icon 13 comments
By @visualblind - 3 months
Video codec transcoding is very CPU resource expensive. If you do a lot of it, you should be looking into doing hardware-accelerated transcoding. https://trac.ffmpeg.org/wiki/HWAccelIntro

My ffmpeg how-to/examples/scratchfile can be viewed here: https://paste.travisflix.com/?ce12a91f222cc3d7#BQPKtw6sEs9cE...

By @Apreche - 3 months
Generally when you are hosting videos you don’t pick one set of transcoding settings and stick with that. You transcode many many renditions and then serve up the appropriate one depending on the client. It’s quite difficult and expensive in terms of both processing and storage. This is why it is so difficult to unseat the incumbent platforms like YouTube. It’s also why so few people do this on their own.
By @adamzochowski - 3 months
Last 3 years I traveled extensively and had limited and flakey bandwidth.

You should have a low bandwidth setting that also uses new codecs.

Like 64kbit stereo opus is to my ears almost imperceptible to CD audio. I think listening tests by professionals recommend using between 64kbit to 96kbit for perfect audio.

Anything beyond is a waste unless we are talking about more than stereo.

Also if you want, you can use mpeg dash to stream video. Here you encode video into small series of chunks/files. When player can't handle high bandwidth, it can switch to lower bandwidth automatically, and vice versa. This is what YouTube and any professional places do. This will also help prevent users from easily downloading complete video. The trick is that you will need to ensure all videos are split on same key frame, so either use two pass encoding, or define that every ?3? seconds exactly is a new video file.

https://www.cloudflare.com/en-ca/learning/video/what-is-mpeg...

By @joenot443 - 3 months
> How did you pick your settings, what issues have you encountered and any tips you can share are certainly appreciated.

The settings are picked based on what format, resolution, bitrate, and codec I'd like. I don't think this is something you need to spend time nitpicking, admittedly. :)

You mention you're working on a site for video hosting. Have you thought about how you're going to deliver video at scale? Sending video over the wire is super expensive and your costs will probably increase faster than your revenue, unless you're charging out the gate. Cloudflare has some plans which let you deliver for nearly free, but your content needs to be fairly static.

Good luck! Don't sweat the small stuff - just keep building.

By @Am4TIfIsER0ppos - 3 months
For synchronized group watching I typically encode to h264 and aac in mp4. Video: render subtitles if available, downscale to 720p if larger, ensure yuv420p, encode with: preset slow, crf 24, and tune animation or film as appropriate. Copy audio if aac, 2 channel, and bitrate is less than 160k otherwise: force 2 channel, encode at 128k. Fast start is needed otherwise I'd use a separate program to put the "header" at the start.

As for your command line, what do you think -g 52 does? Why do you give conflicting audio channel settings?

By @deicidist - 3 months
Your choice of codecs is odd. If you decided you need h.264 for compatibility, that also means you need AAC and burned-in subtitles/captions or you lose all of h.264's broad support to missing audio and text support.

If you can restrict support to just current Android, Chrome, and Firefox, you can use VP9, Opus, and SRT. Willfully-outdated platforms like Apple and Roku have screwed over everyone.

By @efilife - 3 months
There's one thing I learned from asking questions like this. You never get a satisfying answer, and you ultimately have to just pick something. This is not about the quality of answers, this is just how the world works. No definitive solutions, just compromises
By @ddorian43 - 3 months
Go on a specialized video forum and not just ask on HN. Example: https://www.video-dev.org
By @seper8 - 3 months
If you're building a product, maybe use a CDN during MVP phase while you validate?

Don't think your end customers will care who's serving the video?

By @anileated - 3 months
If you want browser-friendly video, look into HLS, simply MP4 with faststart is not enough. Plenty of ffmpeg snippets around.

Care to share what the site is?

By @phantomathkg - 3 months
What's the target usage? Is it to allow user to download the converted file? Or for streaming?