c++ - Howto get luminance pictrue from AVFrame? -


i working mpeg-4 , h264 streams

first tryed converting rgb24 , use imagemagic make grayscale,it doesnot work

while(av_read_frame(pformatctx, &packet)>=0)     {         // packet video stream?         if(packet.stream_index==videostream)         {             // decode video frame             avcodec_decode_video2(pcodecctx, pframe, &framefinished,                                   &packet);              // did video frame?             if(framefinished)             {                 f++;                 //this->fram->clear();                // if (pframe->pict_type == av_picture_type_i) wxmessagebox("i cadr");                // if (pframe->pict_type != av_picture_type_i)                // printmvmatrix(f, pframe, pcodecctx);                 pframergb->linesize[0]= pcodecctx->width*3; // in case of rgb4  1 plane                  sws_scale(swscontext, pframe->data, pframe->linesize, 0, pcodecctx->height, pframergb->data, pframergb->linesize);                   magick::blob* m_blob = new magick::blob(pframergb->data,pcodecctx->width*pcodecctx->height*3);                 magick::image* image =new magick::image(*m_blob); // doesnotwork                  image->quantizecolorspace( magick::graycolorspace );                 image->quantizecolors( 256 );                 image->quantize( ); 

but ffmpeg gives me yuv picture?! need y component, how it? ypicture[x][y]

i assume have configured swscale yuv420p color space. 420p means 4:2:0 planar. planar means color channels separate.

the luminance data (y) stored in buffer point pframe->data[0] (cb , cr in pframe->data[1] , pframe->data[2] respectively). in yuv420 y plane 1 byte per pixel.

hence:

uint8_t gety(int x, int y, avframe *f) {     return f->data[0][(y*f->linesize)+x]; } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -