算法与计算机科学sidbala.com编辑精选
H.264 是魔法
H.264 is Magic
2016 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇博文用通俗方式拆解 H.264 视频编码为什么像“魔法”:从压缩冗余信息讲起,介绍帧内/帧间预测、运动补偿、变换与量化等关键思路,说明视频如何在可接受的画质损失下大幅缩小体积。
为什么经久不衰:它用极简类比把复杂的视频压缩讲清楚,是理解现代视频编码的经典入门。
HN 评论精选
用抛硬币类比直观解释压缩的本质。
我太喜欢这个例子了:假设你有一枚奇怪的硬币——抛了10次,每次都正面。你会怎么把这件事告诉别人?你不会说 HHHHHHHHH,而只会说“抛了10次,全是正面”——砰!你刚刚压缩了数据!就这么简单。我帮你省去了几小时烧脑讲座。
lostgame查看英文原文
Absolutely love this: 'Suppose you have some strange coin - you've tossed it 10 times, and every time it lands on heads. How would you describe this information to someone? You wouldn't say HHHHHHHHH. You would just say "10 tosses, all heads" - bam! You've just compressed some data! Easy. I saved you hours of mindfuck lectures.' This is a really great, simple way to explain what is otherwise a fairly complex concept to the average bear. Great work.
去除冗余和差分编码比有损变换更关键。
有损变换很重要,但我认为视频压缩中最重要的是去除冗余——H.264 实际上有一种不使用该变换的无损模式,仍然压缩得相当好,尤其对无噪声画面(如屏幕录制)。与 MJPEG(基本每帧独立编码为 JPEG)对比就能看出差别。关键思想是编码差异;即使在 I 帧中,宏块也可以编码为相对先前宏块的差异,并应用各种滤波,从而减少帧内空间冗余,而运动补偿减少帧间时间冗余。
userbinator查看英文原文
The lossy transform is important, but I think what's actually most important in video compression is getting rid of redundancy --- H.264 actually has a lossless mode in which that transform is not used, and it still compresses rather well (especially for noiseless scenes like a screencast.) You can see the difference if you compare with something like MJPEG which is essentially every frame independently encoded as a JPEG. The key idea is to encode differences; even in an I-frame, macroblocks can be encoded as differences from previous macroblocks, and with various filterings applied: https://www.vcodex.com/h264avc-intra-precition/ This reduces the spatial redundancies within a frame, and motion compensation reduces the temporaral redundancies between frames. You can sometimes see this when seeking through video that doesn't contain many I-frames, as all the decoder can do is try to decode and apply differences to the last full frame; if that isn't the actual preceding frame, you will see the blocks move around and change in odd ways to create sometimes rather amusing effects, until it reaches the next I-frame. The first example I found on the Internet shows this clearly, likely resulting from jumping immediately into the middle of a file: http://i.imgur.com/G4tbmTo.png That frame contains only the differences from the previous one. As someone who has written a JPEG decoder just for fun and learning purposes, I'm probably going to try a video decoder next; although I think starting from something simpler like H.261 and working upwards from there would be much easier than starting immediately with H.264. The principles are not all that different, but the number of modes/configurations the newer standards have --- essentially for the purpose of eliminating more redundancies from the output --- can be overwhelming. H.261 only supports two frame sizes, no B-frames, and no intra-prediction. It's certainly a fascinating area to explore if you're interested in video and compression in general.
文章过于泛化,很多内容对更老的编码标准也适用。
我本以为能学到 H.264 的特别之处,但这里所有信息都是高层且通用的。比如把 H.264 换成 1993 年的 MPEG-1,每句话仍然成立,除了“这是30多年工作的成果”这一句 :)
szemet查看英文原文
I thought I'll learn something special about H.264, but all information here is high level and generic. For example if you replace H.264 with a much older technology like mpeg-1 (from 1993) every sentence stays correct, except this: "It is the result of 30+ years of work" :)
澄清运动补偿不是简单复用静态背景,而是对运动块做位移预测。
好文章!不过运动补偿部分可以改进:复用背景并不是运动补偿——那是通过编码帧间差异,使不变部分被高效编码。运动补偿是当镜头跟随球移动、背景也在动时,不是直接编码帧间差异,而是发现大部分画面移动了,于是编码相对上一帧中移位后的块的差异。运动补偿对网球不会特别有效,因为它快速旋转(连续帧看起来明显不同),更重要的是它只占画面很小一部分,帮助不大。对移动汽车和人会好得多。
amluto查看英文原文
Nice article! The motion compensation bit could be improved, though: > The only thing moving really is the ball. What if you could just have one static image of everything on the background, and then one moving image of just the ball. Wouldn't that save a lot of space? You see where I am going with this? Get it? See where I am going? Motion estimation? Reusing the background isn't motion compensation -- you get that by encoding the differences between frames so unchanging parts are encoded very efficiently. Motion compensation is when you have the camera follow the ball and the background moves. Rather than encoding the difference between frames itself, you figure out that most of the frame moved and you encode the different from one frame to a shifted version of the blocks from a previous frame. Motion compensation won't work particularly well for a tennis ball because it's spinning rapidly (so the ball looks distinctly different in consecutive frames) but more importantly because the ball occupies a tiny fraction of the total space so it doesn't help that much. Motion compensation should work much better for things like moving cars and moving people.
历次讨论
同类还值得读
位运算技巧集
Bit Twiddling Hacks
斯坦福页面上的经典位运算技巧合集,收录了 popcount、前导/尾随零、位反转、交换、舍入等大量技巧,并附有解释和性能讨论。
算法与计算机科学上首页 8 次 · 2011–2024graphics.stanford.edu编辑精选如何不按平均评分排序
How Not To Sort By Average Rating
经典文章解释了为什么按平均评分排序不可靠:只有少量评价的条目(比如仅一条五星)会轻易排到最前,而评价数量的差异被忽略。
算法与计算机科学上首页 7 次 · 2009–2024evanmiller.org编辑精选数据结构可视化
Data Structure Visualizations
旧金山大学 David Galles 教授制作的数据结构与算法交互式可视化网站,涵盖 B 树、红黑树、排序、图算法等,可逐步操作观察其运行过程。
算法与计算机科学上首页 6 次 · 2011–2021cs.usfca.edu编辑精选1996 年以来的计算机科学最佳论文奖
Best Paper Awards in Computer Science since 1996
Jeff Huang 维护的一个汇总页面,收录了自 1996 年以来计算机科学各主要会议的“最佳论文奖”获奖名单,并按年份和会议整理,方便读者一站式浏览历届获奖论文。
算法与计算机科学上首页 6 次 · 2010–2018jeffhuang.com编辑精选算法(Jeff Erickson)
Algorithms, by Jeff Erickson
伊利诺伊大学 Jeff Erickson 教授的算法课教材,免费在线开放。
算法与计算机科学上首页 5 次 · 2018–2022jeffe.cs.illinois.edu编辑精选