jiwazii:楼主您好,我有个问题,我自己也用qt做了一个播放器,但是放视频的时候,前几帧是绿屏的,后来就好正常了,这是什么情况。视频格式是mp4的。
(2014-05-04 14:09) 
嘿嘿,你的解码输出缓冲区全是0,视频输出基本上都是YUV数据,全0就是绿色(如果是rgb当然是黑的),刚开始几帧可能并没有解码出图像,然后你就拿全0的YUV去显示了,就一片绿了,你初始化视频输出内存的时候初始化填充下YUV数据就好。
/**
* @brief I420图像类
* @details I420图像存储,初始化,更新类
* @author xuwei
* @version 1.0.x
* @date 2011-2012
*/
#ifndef AVENGINE_COMMOM_VIDEO_FRAME_I420_H_
#define AVENGINE_COMMOM_VIDEO_FRAME_I420_H_
namespace utils {
/**
*
@class VideoFrameI420 video_frame_i420.h
* @brief I420图像类
*/
class VideoFrameI420 {
public:
VideoFrameI420(long width, long height)
: image_width_(width)
, image_height_(height)
, image_(NULL)
, image_size_(0)
, image_pts_(0)
, plane_y_(NULL)
, plane_u_(NULL)
, plane_v_(NULL)
, has_video_set_(false)
, new_video_stream_(true){
}
~VideoFrameI420(void) {
if (image_) {
free(image_);
}
}
/*分配图像空间*/
long AllocMemory() {
if (0 >= image_width_ || 0 >= image_height_)
{
/*kErrorCommonInvalidParameter*/
return 0x90500001;
}
/*确保偶数宽高的内存分配*/
long width_adjust = image_width_ % 2 ? image_width_ + 1 : image_width_;
long height_adjust = image_height_ % 2 ? image_height_ + 1 : image_height_;
image_size_ = width_adjust * height_adjust * 3 / 2;
if (NULL != image_) {
free(image_);
}
try {
/*为SSE,MMX指令集多分配32字节*/
image_ = reinterpret_cast<unsigned char*>(malloc(image_size_ + 32));
}
catch (...) {
image_ = NULL;
/*kErrorCommonCreateObjectException*/
return 0x90500005;
}
/*获取三个平面的位置*/
long size_y = image_width_ * image_height_;
long size_uv = size_y / 4;
plane_y_ = image_;
plane_u_ = plane_y_ + size_y;
plane_v_ = plane_u_ + size_uv;
has_video_set_ = false;
/*初始化图像,使其为黑色画面*/
memset(plane_y_, 0, size_y);
memset(plane_u_, 128, size_y / 2);
return 0;
}
/*更新图像*/
long Updata(const unsigned char* frame) {
if (NULL == image_)
{
/*kErrorCommonNeverInitialize*/
return 0x90500004;
}
if (frame) {
/*非空为复制图像*/
memcpy(image_, frame, image_size_);
}
else {
/*为空为清空图像*/
long size_y = image_width_ * image_height_;
memset(plane_y_, 0, size_y);
memset(plane_u_, 128, size_y / 2);
}
has_video_set_ = true;
return 0;
}
public:
/*图像宽*/
long image_width_;
/*图像高*/
long image_height_;
/*图像大小*/
long image_size_;
/*呈现时间*/
__int64 image_pts_;
/*图像数据*/
unsigned char* image_;
/*Y平面*/
unsigned char* plane_y_;
/*U平面*/
unsigned char* plane_u_;
/*V平面*/
unsigned char* plane_v_;
/*图像被设置过*/
bool has_video_set_;
/*新画面标识*/
bool new_video_stream_;
};
}
#endif AVENGINE_COMMOM_VIDEO_FRAME_I420_H_