How do I create a perfect MP4 to HLS encode?
Hi everyone,
I have a VOD MP4 file with:
- Scenario A: 23.976 FPS (CFR Source)
- Scenario B: 23.976 FPS (VFR Source)
- Scenario C: 24.0 FPS (CFR Source)
They are best for HLS? No latency and smooth play on any device?just use handbrake for windows or ffmpeg on linux , just make sure during encoding to set them to H.264/AAC to be supported on all devices
They are best for HLS? No latency and smooth play on any device?
I mean,Huh? What encoding has to do with smooth playing? Encoding has effect only on what you see in the screen (pixelation). Your streaming server is responsible for smooth playback.
I mean,
- Video freeze / black frame at segment start
- iOS / Apple devices stutter
- Seeking inaccurate
The black frame at segment start comes from lack of IDR per segment, for that you need to ensure that each segment starts from keyframe. For 6 second segments you go with
-hls_time 6
-hls_flags independent_segments (This enforces keyframes for each segment).
-force_key_frames "expr:gte(t,n_forced*6)" (This ensures key frames every 6 seconds independently from fps since you have each video with diff fps).
-sc_threshold 0 (This eliminated GOP floating)
Stutter at IOS usually happens if your video is having floating VFR so if you want your videos always working on IOS/Mac you should go with stable CFR eg 25/30. This will fix the seeking as well.
check mail broIs it true?
Dangerous Keyframe Method: -force_key_frames:v expr:'gte(t,n_forced*2.000)' is risky for 23.976fps.
- The Math: 2.000 seconds at 23.976fps = 47.95 frames.
- FFmpeg has to guess whether to put the keyframe at frame 47 or 48. If it drifts, your HLS segments will snap, causing playback glitches.
- The Fix: Use strict frame counting (-g 48).
Please check your PMcheck mail bro
-c:v libx264 -profile:v high -level 4.1 for maximum compatibility-c:a aac -b:a 128k for audio-hls_time 6 -hls_flags independent_segments for proper segment boundaries-g 144 (for 24fps) to force keyframes every 6 seconds at the GOP level instead of using force_key_frames-g approach is more reliable than force_key_frames because it works at the codec level. For 23.976fps, use -g 144 (6 × 24 = 144). This avoids the frame drift issue that Charliee mentioned.-hls_segment_type mpegts if you need backward compatibility with older iOS devices. For newer devices, fMP4 segments work fine and are more efficient.How can i do stable CFR eg 25/30The black frame at segment start comes from lack of IDR per segment, for that you need to ensure that each segment starts from keyframe. For 6 second segments you go with
-hls_time 6
-hls_flags independent_segments (This enforces keyframes for each segment).
-force_key_frames "expr:gte(t,n_forced*6)" (This ensures key frames every 6 seconds independently from fps since you have each video with diff fps).
-sc_threshold 0 (This eliminated GOP floating)
Stutter at IOS usually happens if your video is having floating VFR so if you want your videos always working on IOS/Mac you should go with stable CFR eg 25/30. This will fix the seeking as well.