3 ms·
Maybe I can explain it differently? --- Basically, lossy compression codecs store groups of frames, or groups of samples. You just can't "cut" at any frame or
by gwbas1c 2y ago
Maybe I can explain it differently?
---
Basically, lossy compression codecs store groups of frames, or groups of samples. You just can't "cut" at any frame or sample that you want. If you do, you have to re-encode the whole thing.
If you want to understand why, the "delta encoded" thing means that only the difference between frames (or samples) is stored. It usually takes less bits to store the difference between frames, or samples, than it does to store each frame / sample separately.
The reason why "groups" exist is so that you can jump around in a video / audio file. The beginning of each group stores a complete frame / sample. (This also helps if the file is corrupted.)
As long as you cut a compressed audio / video file at the groups / jumps, you can cut it losslessly.
---
(Note: Techniques like companding can use less bits when each frame / sample are stored separately. Some people don't even call this lossless. The technique is basically a digital version of the old "Dolby B" button on tape decks from the 1980s and 1990s.)
- philsnow 2y ago> As long as you cut a compressed audio / video file at the groups / jumps, you can cut it losslessly. If you had a video with keyframes 'd'K and delta frames 'd' like 0 1 |<-->| 2 KdddddddddddKdddddddddddKddddddddddd and you wanted to cut out the indicated frames, could you create a new keyframe from the keyframe marked '1' + the two following delta frames, and then another new keyframe from K{1}dddddddd? Something like 0 1 |<-->| 2 KdddddddddddKdddddddddddKddddddddddd Kdd = keyframe "L" Kdddddddd = keyframe "M" KdddddddddddKdLMddKddddddddddd Or I guess if you're creating new frames that weren't in the original, could you just rewrite all the deltas in between K1 and K2 such that those 5 frames aren't there? 0 1 |<-->| 2 KdddddddddddKdddddddddddKddddddddddd KdddddddddddKddeeeKddddddddddd (where 'e' marks recomputed deltas)
- gwbas1c 2y agoYou're speculating quite a bit about what the codecs support. See https://news.ycombinator.com/item?id=40844633 https://news.ycombinator.com/item?id=40844633. Some container formats support metadata so you can cut without reencoding.
- thegabriele 2y agoHow many frames per group, usually?
- gwbas1c 2y agoVaries by codec.
- _flux 2y agoSome container formats, such as ISO Base Media File Format aka "mpeg4", have features such as edit lists. With edit lists you can have original video in the bitstream, organized in GoPs as you say, but then the final video rendered in the player gets to choose which frames to play from that material. This allows cutting at completely arbitrary places (I'm 99% sure that this can also be at a higher time resolution than the original data), with the cost that the original (unplayed) data remains in the file. However, some players may have incomplete support for them. For example I believe FFmpeg only supports edit lists used at the beginning of the video, which is commonly used to align video and audio properly.