0
我与MPEG-4,H264工作流如何从AVFrame获取亮度图片?
首先我tryed转换为RGB24和使用imagemagic使灰度,它亘古不变的工作
while(av_read_frame(pFormatCtx, &packet)>=0)
{
// Is this a packet from the video stream?
if(packet.stream_index==videoStream)
{
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished,
&packet);
// Did we get a 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 one 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); // this doesnotwork
image->quantizeColorSpace(Magick::GRAYColorspace);
image->quantizeColors(256);
image->quantize();
但是ffmpeg的给我YUV图片?所以只需要Y组件,如何得到它?得到Ypicture [x] [y]
谢谢!在什么颜色空间下ffmpeg avcodec_decode_video2默认打包未编码的视频帧? – user3177342
无论视频编码的颜色空间是多少,并且可以从编解码器到编解码器/文件到文件有所不同。由于历史原因,大多数编解码器使用YUV420或YUV422。但我相信未来会有更多的人开始使用YUV444。您随时可以查看AVCodecCtx.pix_fmt以了解您所得到的结果。 – szatmary
此外,如果这有助于您请upvote并添加接受答案。 – szatmary