[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$f2vdcj0xcu7ys4":3},{"_id":4,"slug":5,"title":6,"subtitle":7,"kind":8,"cards":9,"tags":58,"categories":60,"source":62,"lang":65,"author":66,"audioState":69,"stats":70,"publishedAt":73,"renderer":74},"6ab9d94eca21c797c7e97254","trimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604","Trimming Video in the Browser: Why \"Precise\" and \"Fast\" Give Different Cuts","There are two ways to cut a clip, and they answer different questions.","news",[10,13,18,23,28,33,38,43,48,53],{"headline":6,"body":11,"imageUrl":12,"sourceImageUrl":12},"There are two ways to cut a clip, and they answer different questions. A precise cut re-encodes the video, so the cut lands on exactly the frame you chose. A fast cut copies the compressed stream without decoding it, so the cut snaps to the nearest keyframe and the start can shift. Neither approach is wrong. Each is a trade between accuracy and speed. The rest of this post explains why, with the actual ffmpeg commands for both. Why a cut cannot always be arbitrary","https:\u002F\u002Fmedia2.dev.to\u002Fdynamic\u002Fimage\u002Fwidth=1200,height=627,fit=cover,gravity=auto,format=auto\u002Fhttps%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frerar0s4qzl32fsyfky2.png",{"headline":14,"body":15,"imageUrl":16,"images":17},"Video is not stored as a sequence of","Video is not stored as a sequence of independent frames. Most frames are described relative to other frames. A keyframe, also called an I-frame, is self-contained: it can be decoded on its own. The frames after it carry only the differences. The stretch from one keyframe to the next is a GOP, a group of pictures.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F1.webp",{"local":16},{"headline":19,"body":20,"imageUrl":21,"images":22},"This is why a stream copy cut cannot","This is why a stream copy cut cannot start anywhere. If you ask to start at 4.2 seconds and there is no keyframe at 4.2 seconds, the tool cannot decode from there, because the frames at 4.2 seconds are defined relative to an earlier keyframe. Copying the compressed bits from 4.2 seconds would produce a broken first frame.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F2.webp",{"local":21},{"headline":24,"body":25,"imageUrl":26,"images":27},"Encoders decide where keyframes go. A typical encoder","Encoders decide where keyframes go. A typical encoder places one every few seconds, plus at scene changes where a fresh reference makes sense. That spacing is usually not exposed to you, which is why a stream copy cut can land up to about one GOP away from where you asked. The longer the GOP, the larger the possible offset. Both modes exist because of this constraint. Fast mode never decodes the video. It copies the compressed packets from one point to another: -ss 00:00:04 is the start time. -i input.mp4 is the source. -t 6 keeps 6 seconds from that start. -c copy is the key flag: copy every stream as is, with no re-encode.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F3.webp",{"local":26},{"headline":29,"body":30,"imageUrl":31,"images":32},"Because nothing is re-encoded, this is fast and","Because nothing is re-encoded, this is fast and lossless. The audio and video bytes are identical to the source, just a different slice of them.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F4.webp",{"local":31},{"headline":34,"body":35,"imageUrl":36,"images":37},"The catch is the start point. With -ss","The catch is the start point. With -ss placed before -i, ffmpeg seeks to the nearest point it can actually begin at, which is a keyframe. If the nearest keyframe is at 3.9 seconds and you asked for 4.2 seconds, the output begins at 3.9 seconds. The cut can only ever land on keyframes.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F5.webp",{"local":36},{"headline":39,"body":40,"imageUrl":41,"images":42},"Placing -ss before -i also makes the seek","Placing -ss before -i also makes the seek fast, because ffmpeg jumps to the nearest keyframe instead of decoding from zero. Move -ss after -i and it decodes from the start of the file up to the requested point, which is slower. For a stream copy, the keyframe limit still applies either way. Precise mode decodes and re-encodes the selected range, so the cut lands on the frame you chose: -c:v libx264 re-encodes the video with H.264.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F6.webp",{"local":41},{"headline":44,"body":45,"imageUrl":46,"images":47},"-crf 20 is the quality target. CRF stands","-crf 20 is the quality target. CRF stands for Constant Rate Factor: lower means higher quality and a bigger file, higher means smaller and rougher. 20 is a visually good default.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F7.webp",{"local":46},{"headline":49,"body":50,"imageUrl":51,"images":52},"-preset veryfast trades compression efficiency for speed. A","-preset veryfast trades compression efficiency for speed. A slower preset squeezes a slightly smaller file at the same quality, at the cost of encoding time. -c:a aac -b:a 128k re-encodes the audio to AAC at 128 kbps.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F8.webp",{"local":51},{"headline":54,"body":55,"imageUrl":56,"images":57},"-movflags +faststart moves the MP4 index to the","-movflags +faststart moves the MP4 index to the front of the file, so playback can start before the whole file has downloaded.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-diff-c2445604\u002F9.webp",{"local":56},[59],"dev",[61],"Technology",{"name":63,"url":64},"Dev.to","https:\u002F\u002Fdev.to\u002Faihangsoft\u002Ftrimming-video-in-the-browser-why-precise-and-fast-give-different-cuts-4cfo","en",{"handle":67,"displayName":68},"spots","Spots","queued",{"views":71,"likes":72,"saves":72,"shares":72,"completions":72,"opens":72,"skips":72,"depthSum":72},5,0,"2026-09-28T03:04:46.898Z","local"]