Processing EBU's YUV files with FFmpeg

To process YUV files (i.e. raw video), you need to know:

  • size (WxH)
  • framerate

We stumbled upon YUV8 and YUV10 files as provided by the EBU (http://www.ebu.ch/en/technical/hdtv/test_sequences.php). Every frame is a seperate file; fortunately, YUV files can be concatenated.

  • YUV8 files have a byte format of "YUV422 = Cb0 Y0 Cr0 Y1 Cb1 Y2 Cr1 Y3" ("U Y V Y U Y V Y") and can be processed using
    ffmpeg -s 1920x1080 -r 50 -f rawvideo -pix_fmt uyvy422 -i input.yuv output.mp4
    
    
  • YUV10 files cannot be processed by FFmpeg directly, because FFmpeg does not support 10 bits/pixel. One way to get around this is to convert it to YUV8. The following program takes YUV10 on stdin and provides YUV8 on stdout:
    #include <stdio.h>
    
    void main() {
    
      int a,b,c,d;
    
      unsigned int k,l,m;
    
      for(;;) {
    
         // read 32 bits
    
         a = getchar();
    
         if(a<0) return;
    
         b = getchar();
    
         c = getchar();
    
         d = getchar();
    
    
    
         // first 30 bits contain 3 x 10 bit values
    
         k = (a << 2) | (b >> 6);
    
         l = ((b & 0x3F) << 4) | (c >> 4);
    
         m = ((c & 0x0F) << 6) | (d >> 2);
    
    
    
         // crude downsample
    
         putchar(k >> 2);
    
         putchar(l >> 2);
    
         putchar(m >> 2);
    
      }
    
    }