TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Share your FFmpeg settings for video hosting

72 pointsby indulona10 months ago
I am working on a website that has video hosting capability. Users can upload video files and i will generate multiple versions with different qualities or just audio, thumbnails and things like that.<p>I have chosen the mp4 container because of how widely supported it is. To prevent users having to fetch whole files, i use the fast start option, where the container&#x27;s metadata is written at the beginning of the file, instead of at the end.<p>Next, I have picked h264 codec because of how widely supported it is. VP8&#x2F;VP9&#x2F;AV1&#x2F;x265&#x2F;x266 are certainly better but the h264 software encoding is often beating hardware encoding due to highly optimized and time-proven code and supported hardware. And the uploaded videos are already compressed, users won&#x27;t be uploading some 8k raw videos where most advanced codes would be useful for preserving &quot;quality&quot;.<p>For audio, i have picked opus codec. Seems like good value over others. Not much else to add.<p>I run the ffmpeg to convert video with command like this:<p>ffmpeg -hide_banner -loglevel error -i input.mp4 -g 52 -c:v h264 -maxrate:v vbr -bufsize vbr -s HxW -c:a libopus -af aformat=channel_layouts=7.1|5.1|stereo -maxrate:a abr -ar 48000 -ac 2 -f mp4 -movflags faststart -map 0:v:0 -map 0:a:0 output.mp4<p>where vbr is video bitrate like 1024k(1mbps), abr is audio bitrate like 190k and HxW is video dimensions in case of resizing.<p>I wonder how are folks that handle video encoding process and generate their videos?<p>How did you pick your settings, what issues have you encountered and any tips you can share are certainly appreciated.<p>Quite a niche segment when it comes to operations and not being merely consumer&#x2F;customer.

11 comments

visualblind10 months ago
Video codec transcoding is very CPU resource expensive. If you do a lot of it, you should be looking into doing hardware-accelerated transcoding. <a href="https:&#x2F;&#x2F;trac.ffmpeg.org&#x2F;wiki&#x2F;HWAccelIntro" rel="nofollow">https:&#x2F;&#x2F;trac.ffmpeg.org&#x2F;wiki&#x2F;HWAccelIntro</a><p>My ffmpeg how-to&#x2F;examples&#x2F;scratchfile can be viewed here: <a href="https:&#x2F;&#x2F;paste.travisflix.com&#x2F;?ce12a91f222cc3d7#BQPKtw6sEs9cECW7ZZgjthcpj4eyWsao1EHNn8tBTVyj" rel="nofollow">https:&#x2F;&#x2F;paste.travisflix.com&#x2F;?ce12a91f222cc3d7#BQPKtw6sEs9cE...</a>
评论 #41056080 未加载
评论 #41056126 未加载
Apreche10 months ago
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.
评论 #41056842 未加载
评论 #41056733 未加载
adamzochowski10 months ago
Last 3 years I traveled extensively and had limited and flakey bandwidth.<p>You should have a low bandwidth setting that also uses new codecs.<p>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.<p>Anything beyond is a waste unless we are talking about more than stereo.<p>Also if you want, you can use mpeg dash to stream video. Here you encode video into small series of chunks&#x2F;files. When player can&#x27;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.<p><a href="https:&#x2F;&#x2F;www.cloudflare.com&#x2F;en-ca&#x2F;learning&#x2F;video&#x2F;what-is-mpeg-dash&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.cloudflare.com&#x2F;en-ca&#x2F;learning&#x2F;video&#x2F;what-is-mpeg...</a>
评论 #41057640 未加载
joenot44310 months ago
&gt; How did you pick your settings, what issues have you encountered and any tips you can share are certainly appreciated.<p>The settings are picked based on what format, resolution, bitrate, and codec I&#x27;d like. I don&#x27;t think this is something you need to spend time nitpicking, admittedly. :)<p>You mention you&#x27;re working on a site for video hosting. Have you thought about how you&#x27;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&#x27;re charging out the gate. Cloudflare has some plans which let you deliver for nearly free, but your content needs to be fairly static.<p>Good luck! Don&#x27;t sweat the small stuff - just keep building.
评论 #41057215 未加载
Am4TIfIsER0ppos10 months ago
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&#x27;d use a separate program to put the &quot;header&quot; at the start.<p>As for your command line, what do you think -g 52 does? Why do you give conflicting audio channel settings?
评论 #41031390 未加载
评论 #41055795 未加载
deicidist10 months ago
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&#x2F;captions or you lose all of h.264&#x27;s broad support to missing audio and text support.<p>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.
评论 #41067795 未加载
efilife10 months ago
There&#x27;s one thing I learned from asking questions like this. You never get a satisfying answer, and you ultimately have to <i>just pick something</i>. This is not about the quality of answers, this is just how the world works. No definitive solutions, just compromises
评论 #41059230 未加载
ddorian4310 months ago
Go on a specialized video forum and not just ask on HN. Example: <a href="https:&#x2F;&#x2F;www.video-dev.org" rel="nofollow">https:&#x2F;&#x2F;www.video-dev.org</a>
评论 #41069779 未加载
seper810 months ago
If you&#x27;re building a product, maybe use a CDN during MVP phase while you validate?<p>Don&#x27;t think your end customers will care who&#x27;s serving the video?
评论 #41057844 未加载
anileated10 months ago
If you want browser-friendly video, look into HLS, simply MP4 with faststart is not enough. Plenty of ffmpeg snippets around.<p>Care to share what the site is?
评论 #41057238 未加载
phantomathkg10 months ago
What&#x27;s the target usage? Is it to allow user to download the converted file? Or for streaming?
评论 #41057676 未加载