VideoBB
Upload Premium Sign in

Video transcoding, explained

Transcoding turns one source file into a set of aligned versions ready for adaptive streaming. Here is what happens at each stage, and which settings decide the result.

Transcoding decodes a video to raw frames and encodes them again with new settings. In between it can filter the frames, for example to scale them or fix the frame rate. For streaming it usually makes several renditions at once. Every rendition must share keyframe positions, so a player can switch between them.

Abstract illustration of a single thick beam of light passing through a prism and splitting into several parallel beams of decreasing width

Upload a single 4 GB file and wait a few minutes. A viewer on a phone is now watching a 360p rendition of it. A viewer on a television is watching 1080p. Both can switch to anything in between at a segment boundary. The work done in those minutes is transcoding. It is the most computing-heavy thing a video platform does.

This deep dive follows the pipeline from source to ladder. It covers probing, decoding, filtering, encoding with rate control, keyframe alignment and packaging. It also covers the checks that catch a bad output before a viewer does. It ends with a real ffmpeg command that makes a two-rendition HLS ladder. The container vs codec explainer gives the words this guide relies on. The video streaming hub shows what happens to the ladder after transcoding.

Transcoding, transmuxing, transrating

Three similar words describe three different amounts of work. Transmuxing (remuxing) changes only the container: an H.264 stream is copied from MKV into MP4 or cut into HLS segments without being decoded. Transrating re-encodes at a different bitrate but the same resolution and codec. Transcoding in the full sense decodes to raw frames and re-encodes, possibly with a different codec, resolution, frame rate or colour format. A streaming ladder needs the full version, because it produces multiple resolutions from one source. The free video converter is a small everyday example. It decodes your file and encodes it again, for instance to H.264 and AAC in an MP4.

The cost follows the same order. Transmuxing is limited by disk speed. Transrating and transcoding are limited by the encoder. As a rule of thumb, encoding H.264 at 1080p with a careful software preset runs at about real time on a modern processor. AV1 is slower still, as the codec comparison discusses.

The pipeline, stage by stage

  1. Probe

    Read the container and stream metadata: codecs, resolution, frame rate, whether the frame rate is constant, interlacing, colour primaries and transfer characteristics, audio channels, duration. Everything downstream is configured from this. A corrupt index or a missing duration is caught here.

  2. Demux and decode

    Split the container into elementary streams and decode the video to raw frames, typically 8-bit or 10-bit YUV in 4:2:0 chroma. Hardware decoders speed this up considerably; software decoders handle the exotic cases.

  3. Filter

    Scale each rendition with a good resampling filter. Deinterlace if the probe found interlaced fields. Convert the frame rate, or force a constant one for variable sources. Tone map if HDR must also be delivered as SDR.

  4. Encode

    Compress each rendition with a codec and rate-control settings chosen for streaming. Constrained bitrates keep the BANDWIDTH a playlist advertises honest. A fixed keyframe interval makes every rendition segment at the same instants.

  5. Encode audio

    Decode and re-encode the audio to AAC, normally at 128 to 192 kbps stereo, shared across all video renditions. Multiple language tracks become alternate renditions.

  6. Package

    Segment each rendition, write the media playlists and the multivariant playlist, generate thumbnails and scrub previews, and upload everything to storage from which it is delivered.

  7. Verify

    Probe every output: duration matches the source, segment counts match across renditions, keyframes sit at segment starts, audio and video stay in sync. Then mark the video ready.

Rate control: CRF versus constrained bitrate

A one-off encode for archiving uses constant quality (CRF in x264 and x265). It spends bits wherever the picture needs them and lets file size fall where it may. Streaming cannot use pure CRF, because the playlist must advertise a peak bitrate that the player can rely on. The usual compromise is capped CRF or constrained VBR. That is a quality target plus -maxrate and -bufsize limits, which bound how far the bitrate can spike over any short window. The buffer size models the decoder's buffer. A rule of thumb is one to two times the target bitrate.

Two-pass encoding analyses the whole file before encoding it. It gives a more even result at a chosen average bitrate, but it doubles the time. Some platforms go further with per-title or content-aware encoding. They analyse each source and choose bitrates for its own ladder, instead of one ladder for everything. A static talking head and a sports match do not need the same bits at 720p. The bitrate guide gives working ranges.

Keyframe alignment: the rule that makes switching work

Every segment must begin with a keyframe, called an IDR frame in H.264 terms. Every rendition must also place its keyframes at the same timestamps. If not, a player switching renditions at a segment boundary would land in the middle of a group of pictures. It would have nothing to decode from. In ffmpeg with x264, you fix the GOP length with -g and -keyint_min. You also turn off scene-cut detection with -sc_threshold 0. Then the encoder cannot add an extra keyframe at a scene change in one rendition but not in another. -force_key_frames with an expression is the alternative when the interval must be in seconds rather than frames.

The keyframe interval also sets the minimum segment length. Apple recommends keyframes at least every two seconds with six-second segments, so each segment holds three groups of pictures. Longer intervals compress slightly better. Shorter intervals make seeking and switching snappier. Two seconds is the widely used compromise, and the adaptive bitrate guide explains what the player does with the result.

Settings that decide the output

Settingx264 optionEffectStreaming guidance
Preset-presetSpeed versus compression efficiencymedium or slow for on-demand; faster presets for live
Quality target-crfPerceptual quality level18-23 for the top rung, capped by maxrate
Peak bitrate-maxrateUpper bound over the VBV windowSet per rung; matches the advertised BANDWIDTH
VBV buffer-bufsizeWindow over which maxrate is enforced1-2× the target bitrate
GOP length-g, -keyint_minFrames between keyframesFrame rate × 2 seconds, identical across rungs
Scene cut-sc_thresholdExtra keyframes at scene changes0, to keep rungs aligned
Profile and level-profile:v, -levelDecoder feature setHigh profile, level 4.1 for 1080p30
Pixel format-pix_fmtChroma and bit depthyuv420p for universal playback

A two-rendition HLS ladder in one ffmpeg command

The command below makes 1080p and 720p renditions with aligned keyframes at 24 or 25 frames per second. For other frame rates, set -g to twice the frame rate. Each rendition gets its own AAC audio and six-second fMP4 segments, plus a multivariant playlist:

ffmpeg -i source.mp4 -filter_complex "[0:v]split=2[v1][v2];[v1]scale=-2:1080[v1o];[v2]scale=-2:720[v2o]" -map "[v1o]" -map 0:a -map "[v2o]" -map 0:a -c:v libx264 -preset medium -crf 21 -g 48 -keyint_min 48 -sc_threshold 0 -pix_fmt yuv420p -maxrate:v:0 5000k -bufsize:v:0 7500k -maxrate:v:1 2800k -bufsize:v:1 4200k -c:a aac -b:a 128k -f hls -hls_time 6 -hls_playlist_type vod -hls_segment_type fmp4 -hls_segment_filename "rung_%v_%03d.m4s" -master_pl_name master.m3u8 -var_stream_map "v:0,a:0 v:1,a:1" rung_%v.m3u8

The split filter decodes the source once and feeds both scalers, which is the single largest efficiency win in a multi-rendition encode. Adding rungs is a matter of extending the split, the maps and the var_stream_map.

Where pipelines go wrong

  • Variable frame rate sources, common from phones and screen recorders, produce renditions whose segment boundaries drift apart unless the pipeline forces a constant frame rate first.
  • Interlaced sources that are not deinterlaced show combing on every progressive display; the AVI conversion guide covers the filter.
  • Scene-cut keyframes left enabled in one rung and not another break alignment silently; playback works until the first switch across the misaligned point.
  • Upscaling a low-resolution source to fill a ladder adds bytes without detail. Renditions above the source resolution should be skipped, which is why a 720p upload does not gain a 1080p rung.
  • Double compression. A source that was already heavily compressed gives the encoder artefacts to keep instead of detail. The blurry after upload guide shows the effect, and the preparation guide the remedy.

Frequently asked questions

How long does transcoding take after upload?

It depends on the source length, resolution and codec, and on how many renditions are produced. As a rule of thumb, software H.264 encoding of a 1080p source at a medium preset runs close to real time per rendition on a capable machine. Platforms spread the work across renditions and across chunks of the file. A short clip is usually ready in a minute or two. A long 4K source takes longer and produces more rungs. The help page on encoding times after upload explains what to expect on VideoBB.

Does transcoding reduce quality?

Every lossy encode discards some information, so yes in principle; the goal is to make the loss invisible at each rendition's intended viewing size. A high-quality source gives the encoder detail to keep, while a heavily compressed source forces it to spend bits preserving artefacts. The largest quality lever you control is therefore the upload itself, not the transcoder.

Why does my 720p upload not have a 1080p option?

Because a 1080p rendition upscaled from 720p would contain no more detail than the 720p rendition while using roughly twice the bandwidth. Transcoders build rungs at or below the source resolution. To offer 1080p, 1440p or 2160p, upload a source at that resolution; VideoBB produces 1440p and 2160p renditions when the source supports them, and Premium members can watch them.

Can I skip transcoding by uploading a ready-made HLS package?

Not on VideoBB; the platform accepts source files in the supported containers and builds the ladder itself, so that every rendition is aligned and packaged consistently. On a self-hosted setup you can package your own ladder with ffmpeg or a dedicated packager and serve it directly, which is exactly what the command in this guide produces.

Sources

transcodingencoding ladderffmpegkeyframeshls packaging

Related guides