Methodology, Formulas & Parameter Reference
FFmpeg processes media through a pipeline that demuxes an input container into encoded packets, decodes those packets into uncompressed frames when filtering or re-encoding is required, passes frames through a filtergraph, encodes the resulting frames with the chosen codec, and muxes packets into the target container. Selecting -c:v copy bypasses the decode, filter, and encode stages entirely, copying compressed video packets directly to the output container at disk speed. However, whenever you apply a visual filter such as scaling, cropping, or frame-rate conversion, FFmpeg must decode and re-encode the video stream.
When re-encoding with libx264 or libx265, the Constant Rate Factor (-crf) parameter controls visual quality on a logarithmic scale from 0 (lossless) to 51 (heaviest compression). Each decrease of 6 in the CRF value roughly doubles the resulting bitrate, while each increase of 6 cuts the bitrate in half. For 8-bit web delivery, combining -crf 18 to -crf 23 with -pix_fmt yuv420p ensures hardware decoder compatibility across desktop and mobile browsers. Adding -movflags +faststart relocates the MP4 moov atom to the beginning of the file after muxing so web players can begin playback before downloading the entire file.
For frame-accurate trimming, placing -ss before -i instructs the demuxer to seek to the nearest preceding keyframe (IDR frame), which is fast when combined with re-encoding because modern FFmpeg versions automatically discard decoded frames prior to the exact target timestamp. When paired with -c copy, input seeking cuts only on keyframes; if you need exact frame cuts without re-encoding, that is not possible in inter-frame codecs without re-encoding at least the GOP surrounding the cut point. The in-browser runner loads @ffmpeg/ffmpeg from jsDelivr CDN on demand and executes the same flags inside a WebAssembly virtual filesystem so no media leaves your machine.
| Parameter Flag | Stream Scope | Typical Value | Engineering Function |
|---|---|---|---|
-c:v libx264 |
Video Encoder | H.264 / AVC | Encodes video using the x264 software encoder for universal playback compatibility. |
-crf 18..28 |
Rate Control | 20 (x264) / 24 (x265) | Allocates variable bitrate dynamically to maintain constant perceptual quality. |
-preset slow |
Encoder Speed | ultrafast to veryslow | Trades CPU encoding time for better motion-estimation compression efficiency. |
-pix_fmt yuv420p |
Pixel Format | 4:2:0 Planar 8-bit | Downsamples chroma from 4:2:2 or 4:4:4 sources so standard web players can decode. |
-movflags +faststart |
MP4 Muxer | Header relocation | Moves the MP4 index (moov atom) to byte offset 0 for progressive HTTP streaming. |
-stream_loop N |
Input Demuxer | Integer count (e.g. 3) | Repeats the input stream N additional times without concatenating duplicate files. |
Production Workflow Verification & Quality Control
Before committing a full batch transcode or publishing a final master, verify the generated parameters against a five-second test slice of your source timeline. In post-production pipelines, container metadata headers, variable frame rate (VFR) timebases from mobile or screen-capture recordings, and non-square pixel aspect ratios can alter how downstream players interpret stream flags. Running every calculation and file conversion locally in browser memory ensures your production assets remain private while providing deterministic numbers you can paste directly into terminal automation scripts, NLE export presets, or camera prep checklists.