[ffmpeg] 不能正常播放视频,播放窗口绿屏
popcorn player 使用 ffmpeg-2.3 + Linux + SDL1.2
【[ffmpeg] 不能正常播放视频,播放窗口绿屏】
【问题】popcorn播放视频, 播放窗口绿屏幕
【分析】dump AVFrame 图像帧(数据源) --> dump SDL_Overlay 图像帧(目标数据)
【结果】dump AVFrame 图像帧(数据源), OK;dump SDL_Overlay 图像帧(目标数据), Fail.
【原因】
错误的做法:
static int videoImage_display(VideoState *video_states, AVFrame *frame)
{
//传递AVFrame 的数据给SDL_Overlayer
//AVPicture picture;
SDL_Rect rect;
AVPicture pict = {{0}};
SDL_LockYUVOverlay(video_states->layer1);
// SDL_Overlayer的pixels指针指向AVFrame的数据
video_states->layer1->pixels[0] = frame->data[0];
video_states->layer1->pixels[1] = frame->data[1];
video_states->layer1->pixels[2] = frame->data[2];
video_states->layer1->pitches[0] = frame->linesize[0];
video_states->layer1->pitches[1] = frame->linesize[2];
video_states->layer1->pitches[2] = frame->linesize[1];
SDL_DisplayYUVOverlay(video_states->layer1,&rect),
正确的做法:
static int videoImage_display(VideoState *video_states, AVFrame *frame)
{
//AVPicture picture;
SDL_Rect rect;
AVPicture pict = {{0}};
SDL_LockYUVOverlay(video_states->layer1);
//video_states->layer1->pixels[0] = frame->data[0];
//video_states->layer1->pixels[1] = frame->data[1];
//video_states->layer1->pixels[2] = frame->data[2];
//video_states->layer1->pitches[0] = frame->linesize[0];
//video_states->layer1->pitches[1] = frame->linesize[2];
//video_states->layer1->pitches[2] = frame->linesize[1];
pict.data[0] = video_states->layer1->pixels[0];
pict.data[1] = video_states->layer1->pixels[2];
pict.data[2] = video_states->layer1->pixels[1];
pict.linesize[0] = video_states->layer1->pitches[0];
pict.linesize[1] = video_states->layer1->pitches[2];
pict.linesize[2] = video_states->layer1->pitches[1];
//AVFrame的数据拷贝到SDL_Overlay存放数据的内存区域
/*scale_image call sws_scale() */
scale_image(frame->data, frame->linesize,
frame->width, frame->height, frame->format,
pict.data, pict.linesize,
frame->width, frame->height, AV_PIX_FMT_YUV420P,
SWS_BICUBIC);
SDL_DisplayYUVOverlay(video_states->layer1,&rect);
推荐阅读
- ffmpeg|从零开始仿写一个抖音App——基于FFmpeg的极简视频播放器
- ffmpeg|ffmpeg windwos 编译+现成脚本
- 多媒体|H264 Profile对比分析
- python|python实现下载网络视频资源
- ffmpeg|分辨率、帧率、码率关系
- [ffmpeg] 音视频同步之提取PTS