Setting Bitrate Control and Keyframe Parameters Jan Ozer www.streaminglearningcenter.com @janozer jozer@mindspring.com/ 276-238-9135 For More Information! Most information derived from this book.! For more in-depth information, check out! http://bit.ly/ozer_multi! Published, April 2013 1
Overview! Duration about 30 minutes! Q&A up to 30 minutes! Ask questions via comments in YouTube! My contact information is on front page! Handouts available at bit.ly/ keyframe_webinar Agenda! Technology precedents! Bitrate control alternatives defined! Optimizing CBR and VBR encoding! Defining keyframes! Choosing a keyframe interval! Configuring keyframe parameters! What about IDR frames 2
Technology Precedents Single File vs. Adaptive Delivery! Single file! Produce a single file for delivery to viewers! Key focus stream quality! Adaptive delivery! Produce multiple files for delivery, depending upon factors like bandwidth and playback platform! HTTP Live Streaming (HLS), HTTP Dynamic Streaming (HDS), Smooth Streaming and DASH! Key focus stream switchability and consistent delivery Bitrate Control! Alternatives! Producing top quality VBR and CBR! Single file! Adaptive delivery! When to use CBR and VBR! A quick look at CQ/CRF 3
800 kbps Bitrate Control Alternatives Constant (CBR) vs Variable Bit Rate (VBR) VBR 500 kbps CBR 300 kbps Low Motion Moderate Motion Low Motion Moderate Motion High Motion CBR File Illustrated! Faint (sorry) wavy blue line is data rate! Relatively consistent throughout 4
VBR File Illustrated! Faint (sorry) wavy blue line is data rate! Relatively consistent throughout Constant vs Variable Bit Rate! Constant Bit Rate (CBR)! One bit rate applied to entire video, irrespective of content! Pros:! Computationally easy! Fast - one pass will do it! Cons: Doesn't optimize quality 5
VBR vs. CBR Biggest difference EVER seen between CBR and VBR Constant vs Variable Bit Rate! Variable Bit Rate (VBR)! Dynamic bit rate matches motion in video! Pros: Best quality! Cons:! Need two or more passes! Can produce stream with significant variability 6
How do I Produce the Best Quality CBR?! Use 2-pass CBR when available! Scans file (like VBR), but packs data into a consistent stream! Best of both worlds when available optimizes quality and stream consistency! 1-pass for live or draft work How Do I Produce the Optimal VBR File?! 2 passes or more! 2-passes minimum! Multi-Pass application dependent! Compressor no choice, all multi-pass! Squeeze 2-Pass quality is equivalent to multi in much less time! Use Constrained VBR! Constrains to data rate to specified max 7
How Does Constrained Work?! Application dependent! Always set target! Some let you set maximum in data rate or % of target! Some let you set minimum and maximum! Rules of thumb! Single file streaming! Max 200% of target! Min 50% of target! Adaptive! It s complicated Adaptive - VBR vs CBR! Live - use CBR! On-Demand! In theory most pundits recommend CBR! More consistent stream! Fewer encoding-related stream switches 8
VBR in Adaptive Delivery Video bitrate Player buffer A B C med chunk A Good delivery 5 sec Buffer OK Status quo No change large chunk B Slow delivery 1 sec Ruh, roh! Buffer too low Switch to lower bitrate Small chunk C Very fast delivery 8 sec Life is good! Switch to higher bitrate Adaptive - VBR vs CBR! Live - use CBR! On-Demand! In theory most pundits recommend CBR! More consistent stream,! Fewer encoding-related stream switches " But no real proof! All agree that adaptive produces the best experience when the optimal data rate is identified and maintained which CBR promotes! In practice many producers use constrained VBR! Some as high as 200% (MTV)! Obviously, they wouldn t if this caused problems 9
My Experience! Consulting Projects! Typically use CBR or highly constrained (125-150% VBR)! Could be superstition, but when the project is on the line, I choose to be conservative! The qualitative difference between CBR and VBR isn t that great, particularly at higher data rates When Should I Use VBR/CBR? Application Single file streaming broadband Single file streaming mobile Progressive delivery Live Adaptive (as discussed) Technology Constrained VBR Highly constrained VBR (125%) or CBR Constrained VBR CBR Highly constrained VBR (125%) or CBR 10
What about CQ/CRF?! Defined! Constant Quality/Constant Rate Factor! Choose quality level, data rate varies! Issue! Can t control data rate spikes and ensure smooth delivery! Some large producers use for progressive download! My recommendations:! Archiving only, not for delivery Container Formats, Transport Streams, Program Streams! Container format:! A meta-file format whose specification describes how data and metadata are stored! Examples: MPG, MP4, MOV, F4V, WMV, FLV! Transport stream:! Transport stream specifies a container format encapsulating packetized elementary streams, with error correction and stream synchronization features for maintaining transmission integrity when the signal is degraded (e.g. - broadcast)! Examples:.ts, 11
I-, B- and P-frames! Defining keyframes (used interchangeably with I-frame)! Choosing a keyframe interval! Configuring keyframe parameters! Note B-frames discussed at bit.ly/h264fun (for fundamentals) What are I, B and P Frames?! I-Frame - encoded without reference to other frames (also called keyframes)! P - looks backward to I and P frames (predictive)! B - looks forward and backward to previous I and P frames (Bi-directional interpolated)! No frames refer to B-Frame (most of the time) 12
Configuring Key Frames! Least efficient so largest (which is bad)! In general, want as few keyframes as possible in the stream! Historically, however, for broadcast and DVD, keyframes were inserted every second! Broadcasters turned compressionists still use this number! This number is WRONG (er, suboptimal) Configuring Key Frames! Though large, key frames enhance interactivity! All playback starts on a keyframe! When seeking to random frame (like the third p-frame), must start playback at preceding key frame! To enhance interactivity, maximum key interval should be 5-10 seconds Has to seek back to here To play this frame 13
Configuring Key Frames! And, key frames "reset" quality:! Useful at scene changes! So, enable natural key frames (Telestream speak)! Or key frames at scene changes! Most other encoders What About Adaptive?! Rules change completely when encoding a group of files for adaptive streaming! Shorter key frame interval! Disable scene change detection 14
What About Adaptive? Chunk A Chunk B Chunk C Chunk D Alternative 1 Alternative 2 Alternative 3 I I I I I I I I I I I I! Adaptive involves multiple streams (alternatives 1, 2, 3) using multiple chunks (A, B, C, D)! Switch streams by retrieving chunks from different alternative! So, need keyframe (I-frame) at start of every chunk! So, keyframe interval must equal chunk size or be divisible into chunk size Keyframes in Adaptive Streaming! Presentation in Sorenson Squeeze! Long form HLS streaming! Most technologies use shorter chunks 2-3 seconds! Keyframe interval should match Keyframe interval should always divide evenly into chunk size (fragment duration) 15
What About Adaptive? Chunk A Chunk B Chunk C Chunk D Alternative 1 Alternative 2 Alternative 3 I I I I I I I I I I I I! Need regular keyframes! Some encoders restart keyframe interval when inserting a keyframe at a scene change! For these, disable scene change detection, or:! Find a control like this (Squeeze) Advanced Frame Options! IDR frames (Instantaneous Decode Refresh)! Two kinds of key frames! IDR key frame no frame can reference frame before key frame! Non-IDR key frames B- and P-frames can reference frames before key frame 16
IDR Frames and Adaptive Chunk A Chunk B Chunk C Chunk D Alternative 1 Alternative 2 Alternative 3 I I I I I I I I I I I I! Switch from Alternative 1 to Alternative 2, the frame the the encoder referenced isn t there!! It s in a different chunk! Non-IDR frames can break adaptive streaming! General rule (for all streaming) -- All keyframes should be IDR frames! Essential for adaptive! Enhances interactivity (faster seeking) in single file streaming What About RTMP Dynamic Streaming?! Older, more mature technology, still widely used! Multiple files, no chunks! Keyframe rules (pretty much the same)! Interval should be short 2-3 seconds (so streams can switch pretty quickly)! Interval must be regular (disable scene change unless fixed I-frame distance)! All keyframes should be IDR frames 17
Questions! Download presentation handouts at bit.ly/ keyframe_webinar! For more information, check out the book! http://bit.ly/ozer_multi! Published, April 2013 18