News for hackers. Stuff that matters.
Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by seeknotfind on Tuesday December 12, 2023 @12:16PM (#38615169)
Video codecs often encode the delta from the previous frame, and because this delta is often small, it's efficient to do it this way. If each thread needed to process the frame separately, you would need to make significant changes to the codec, and I hypothesize it would cause the video stream to be bigger in size.
Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by keehun on Tuesday December 12, 2023 @12:19PM (#38615215)
The parent comment referred to "keyframes" instead of just "frames". Keyframes—unlike normal frames—encode the full image. That is done in case the "delta" you mentioned could be dropped in a stream ending up with strange artifacts in the resulting video output. Keyframes are where the codec gets to press "reset".
Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by seeknotfind on Tuesday December 12, 2023 @12:28PM (#38615351)
Oh right. For non realtime, if you're not IO bound, this is better. Though I'd wonder how portable the codec code itself would be.
Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by actionfromafar on Tuesday December 12, 2023 @12:53PM (#38615712)
The encoder has a lot of freedom in how it arrives at the encoded data.
Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by account42 on Wednesday December 13, 2023 @07:40AM (#38626500)
> That is done in case the "delta" you mentioned could be dropped in a stream ending up with strange artifacts in the resulting video output.

Also to be able to seek anywhere in the steam without decoding all previous frames.

Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by danielrhodes on Tuesday December 12, 2023 @12:45PM (#38615611)
Isn't that delta partially based on the last keyframe? I guess it would be codec dependent, but my understanding is that keyframes are like a synchronization mechanism where the decoder catches up to where it should be in time.
Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by 0x457 on Tuesday December 12, 2023 @02:31PM (#38617145)
Yes, key frames are fully encoded, and some delta frames are based on the previous frame (which could be keyframe or another delta frame). Some delta frames (b-frames) can be based on next frame instead of previous. That's why sometimes you could have a visual glitch and mess up the image until the next key frame.

I'd assume if each thread is working on its own key frame, it would be difficult to make b-frames work? Live content also probably makes it hard.

Re:FFmpeg Lands CLI Multi-Threading as Its "Most Complex Ref... by astrange on Tuesday December 12, 2023 @02:08PM (#38616811)
In most codecs the entropy coder doesn't reset across frames, so there is enough freedom that you can do multithreaded decoding. ffmpeg has frame-based and slice-based threading for this.

It also has a lossless codec ffv1 where the entropy coder doesn't reset, so it truly can't be multithreaded.