文档目录

一、数据量对比

void print_bitrate(int width, int height, int fps) {
    auto yuv420_size = [](int w, int h) {
        return w * h * 3 / 2;  // Y + UV/4 + UV/4
    };

    int frame_bytes = yuv420_size(width, height);
    int second_bytes = frame_bytes * fps;
    int minute_bytes = second_bytes * 60;
    int hour_bytes   = minute_bytes * 60;

    auto to_mb = [](int b) { return b / 1024 / 1024; };

    std::cout << width << "x" << height << " @" << fps << "fps YUV420:\n"
              << "  一帧:    " << to_mb(frame_bytes)   << " MB\n"
              << "  一秒:    " << to_mb(second_bytes)  << " MB\n"
              << "  一分:    " << to_mb(minute_bytes)  << " MB\n"
              << "  一小时:  " << to_mb(hour_bytes)    << " MB ≈ "
              << to_mb(hour_bytes) / 1024 << " GB\n";
}

// print_bitrate(1920, 1080, 60);
// 输出:
//   一帧:     3 MB
//   一秒:     180 MB
//   一分:     10800 MB
//   一小时:   648000 MB ≈ 633 GB
// 一小时就要 633GB,不可接受。
// 编码后(H.264 10Mbps):一小时 ≈ 4.5 GB → 压缩比约 140:1

二、编码器怎么做到的?

编码器利用了两个层面的冗余:

空间冗余(帧内预测):
  一张蓝天照片的 100 万个像素几乎一样 → 只描述第一块,其余说"和第一块相同"
  这是 JPEG 也在做的事

时间冗余(帧间预测):
  视频相邻两帧之间的变化极小 → 只存"哪里变了,怎么变的"
  这是视频编码独有的