VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 16 of 16
Thread
  1. I extracted a raw video frame with "spirit ffms" (bindings for python to the ffmpegsource), and i opened the file in an hex editor to get the YUV values and i dont know how to do it since the h264 specification says that for each component (luma e chrominances) must have from 8 to 14 bits with a total of 1 luma for each pixel + 1 of each U and V every 4 pixels square, and i can get only the Y component because:

    -frame resolution = 1920x1080 = 2073600 pixels
    -total of bytes of the frame: 2108160

    2108160 - 2073600 = 34560 remaining bytes


    which means that i have to convert from only the Y component or all three components are in just one byte. I dont think the UV components are in the remaining bytes for two reasons: 1- 34560 * 8 = 276480 bits and 2073600 / 4 = 518400 (2x2 squares), so even if it have just one chrominance component with one bit, for each 2x2 square it would not fit all (squares), and even dividing 276480 / 129600 (16x16 squares) = 2,133.... it doesnt match the calculations.
    2- analising the final of the frames in the hex editor i found that they are the same.

    All the frames are "I" frames, and i know the frame is right because i converted the video to raw video with ffmpeg and the resultas are the same. Anyone knows anything that can help?
    Last edited by toshyuki; 7th Oct 2012 at 05:22.
    Quote Quote  
  2. Hmmm - reading and don't understand - where is place for RGB from title? ffmpeg is able to output raw RGB so where is hint in Your question?
    Quote Quote  
  3. Yes, assuming 8 bit channels you should have a 1920x1080 luma plane followed by two 960x540 chroma planes.

    Code:
    2,073,600
    + 518,400
    + 518,400
    ---------
    3,110,400
    You don't have enough data. I suspect your frame isn't a full 1920x1080. Maybe black borders were cropped? How does the luma plane look if you view it as grey scale?
    Quote Quote  
  4. Originally Posted by pandy View Post
    Hmmm - reading and don't understand - where is place for RGB from title? ffmpeg is able to output raw RGB so where is hint in Your question?
    I want to convert from YUV to RGB but i dont know how extract the necessary data from this frame. In ffmpeg i used the command: ffmpeg -i "file" -codec rawvideo "output file" and he gaves me raw video with YUV values, how do you got raw RGB?
    Quote Quote  
  5. add -pix_fmt rgb24 to use swscale to convert yuv=>rgb

    e.g.

    ffmpeg -i input.ext -vcodec rawvideo -pix_fmt rgb24 -an output.rgb
    Quote Quote  
  6. Originally Posted by jagabo View Post
    Yes, assuming 8 bit channels you should have a 1920x1080 luma plane followed by two 960x540 chroma planes.

    Code:
    2,073,600
    + 518,400
    + 518,400
    ---------
    3,110,400
    You don't have enough data. I suspect your frame isn't a full 1920x1080. Maybe black borders were cropped? How does the luma plane look if you view it as grey scale?
    Im sure it is full 1920x1080 because the frame is filled blanc. All frames have the same size in bytes, so all the data must be there compressed someway.
    Quote Quote  
  7. -pix_fmt rgb24
    Quote Quote  
  8. Originally Posted by jagabo View Post
    -pix_fmt rgb24
    Got it, but i still need know how convert from the original YUV values.
    Quote Quote  
  9. Exaclty what are you asking for? The equation for YUV to RGB ?

    http://www.fourcc.org/fccyvrgb.php
    Quote Quote  
  10. Since your source is high definition you probably need the rec.709 matrix (unless the video is flagged differently).

    http://en.wikipedia.org/wiki/YUV#BT.709_and_BT.601
    Quote Quote  
  11. Originally Posted by poisondeathray View Post
    Exaclty what are you asking for? The equation for YUV to RGB ?

    http://www.fourcc.org/fccyvrgb.php
    I want to know how to get the YCbCr values from the frame to convert to RGB since the total number of bytes doesnt match the necessary data required.
    Quote Quote  
  12. What's the command line you're using? I'll see if I can duplicate the problem.

    I made a 10 frame 1920x1080 MP4 file and used the following command line to create a raw YV12 file:

    Code:
     ffmpeg -i bn.mp4 -vcodec rawvideo -pix_fmt yuv420p -an output.yuv
    The output file was 31,104,000 bytes, exactly 10 times the size of a single 1920x1080 YV12 frame. I was able to import each plane of the first frame into a paint program as raw binary data to make three greyscale images.

    Y:
    Click image for larger version

Name:	y.png
Views:	6970
Size:	96.3 KB
ID:	14176

    V:
    Click image for larger version

Name:	v.png
Views:	6446
Size:	26.3 KB
ID:	14177

    U:
    Click image for larger version

Name:	u.png
Views:	6424
Size:	24.2 KB
ID:	14178
    Last edited by jagabo; 7th Oct 2012 at 21:23.
    Quote Quote  
  13. Did you use the ffmpeg command line above ? This is what I got from a single frame raw YUV 4:2:0 source 1920x1080 , and converted to RGB in ffmpeg

    raw RGB: 6,220,800 bytes
    raw YUV 4:2:0 : 3,110,400 bytes
    Quote Quote  
  14. Originally Posted by toshyuki View Post
    Originally Posted by poisondeathray View Post
    Exaclty what are you asking for? The equation for YUV to RGB ?

    http://www.fourcc.org/fccyvrgb.php
    I want to know how to get the YCbCr values from the frame to convert to RGB since the total number of bytes doesnt match the necessary data required.

    To get individual MB and pixel values from a YCbCr h264 stream, you need a comprehensive stream parser e.g h264visa

    But the bytes match with the ffmpeg conversion. Maybe you have a bad binary ?
    Quote Quote  
  15. Originally Posted by jagabo View Post
    Since your source is high definition you probably need the rec.709 matrix (unless the video is flagged differently).

    http://en.wikipedia.org/wiki/YUV#BT.709_and_BT.601
    But even if something is wrong and incorrectly signaled - difference will quite subtle and for most normal colors unnoticeable even for hex values (and even for this case error can be calculated) - i still don't understand what is purpose of the author question and how to solve his problem.

    Originally Posted by toshyuki View Post
    I want to know how to get the YCbCr values from the frame to convert to RGB since the total number of bytes doesnt match the necessary data required.
    Perhaps author ask how to upsample data from 4:2:0 to 4:4:4? then how to perform YCbCr>RGB conversion?
    But this is only guessing - intention of author question(s) are completely unclear for me.
    Quote Quote  
  16. Originally Posted by jagabo View Post
    What's the command line you're using? I'll see if I can duplicate the problem.

    I made a 10 frame 1920x1080 MP4 file and used the following command line to create a raw YV12 file:

    Code:
     ffmpeg -i bn.mp4 -vcodec rawvideo -pix_fmt yuv420p -an output.yuv
    The output file was 31,104,000 bytes, exactly 10 times the size of a single 1920x1080 YV12 frame. I was able to import each plane of the first frame into a paint program as raw binary data to make three greyscale images.

    Y:
    Image
    [Attachment 14176 - Click to enlarge]


    V:
    Image
    [Attachment 14177 - Click to enlarge]


    U:
    Image
    [Attachment 14178 - Click to enlarge]

    This solves my question, now i have the YUV components to convert to RGB. Thanks everybody.
    Quote Quote  



Similar Threads