video - RGB-frame encoding - FFmpeg/libav -
i learning video encoding & decoding in ffmpeg. tried code sample on page (only video encoding & decoding part). here dummy image being created in ycbcr format. how achieve similar encoding creating rgb frames? stuck at:
firstly, how create rgb dummy frame?
secondly, how encode it? codec use? of them work yuv420p only...
edit: have ycbcr encoder , decoder given on page. thing is, have rgb frame-sequence in database , need encode it. encoder ycbcr. so, wondering convert rgb frames ycbcr (or yuv420p) somehow , encode them. @ decoding end, decoded ycbcr frames , convert them rgb. how go ahead it?
i did try swscontext thing, converted frames lose color information , scaling errors. thought of doing manually using 2 loops , colorspace conversion formulae not able access individual pixel of frame using ffmpeg/libav library! in opencv can access like: mat img(x,y) no such thing here! totally newcomer area...
someone can me?
many thanks!
the best way convert use swscale. can manually, version slower. there not api access pixel data in ffmpeg. must access buffers directly yuv420p planar format, first buffer y plane, 1 byte per pixel. u/v planes 1 byte 4 pixels. because u , v planes scaled 1/4 size of y plane under assumption luminance (y) channel contains information.
00250 picture->data[0] = picture_buf; 00251 picture->data[1] = picture->data[0] + size; 00252 picture->data[2] = picture->data[1] + size / 4;
second, lets @ colorspace conversion.
void yuvfromrgb(double& y, double& u, double& v, const double r, const double g, const double b) { y = 0.257 * r + 0.504 * g + 0.098 * b + 16; u = -0.148 * r - 0.291 * g + 0.439 * b + 128; v = 0.439 * r - 0.368 * g - 0.071 * b + 128; }
and plug in dummy values:
r = 255, g = 255, b = 255 y = 235 r = 0, g = 0, b = 0 y = 16
as can see, range 0 -> 255 squished 16 -> 235. have shown there colors in rgb colorspace not exist in (digital) yuv color space. why use yuv? colorspace television uses going way 1950 when color channels (u/v) added existing black , white channel (y).
read more here: http://en.wikipedia.org/wiki/ycbcr
the scaling errors not using swscale correctly. not understand line stride: http://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx.
i not know of video codecs operate in rgb color space. can convert (slightly lossy) between rgb , yuv using libswscale.
this video explain: https://xiph.org/video/vid2.shtml
Comments
Post a Comment