- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 ffmpeg/doc/example/decoding__encoding_8c-source.html 在 ANDROID 上构建一个简单的 FFMPEG MPEG2 视频 PES 解码器。
我使用的是 FFMPEG 2.0 版!
我使用以下代码初始化ffmpeg系统:
int VideoPlayer::_setupFFmpeg()
{
int rc;
AVCodec *codec;
av_register_all();
codec = avcodec_find_decoder(AV_CODEC_ID_MPEG2VIDEO);
if(NULL == codec){
LOGE("_setupFFmpeg. No codec!");
return -1;
}
LOGI("found: %p. name: %s", codec, codec->name);
_video_dec_ctx = avcodec_alloc_context3(codec);
if(NULL == _video_dec_ctx){
LOGE("_setupFFmpeg. Could not allocate codec context space!");
return -1;
}
_video_dec_ctx->debug = FF_DEBUG_PICT_INFO;
if(codec->capabilities & CODEC_CAP_TRUNCATED) _video_dec_ctx->flags |= CODEC_FLAG_TRUNCATED;
rc = avcodec_open2(_video_dec_ctx, codec, NULL);
if(rc < 0) {
LOGE("_setupFFmpeg. Could not open the codec: %s!", _video_dec_ctx->codec->name);
return -1;
}
av_init_packet(&_avpkt);
if(NULL == _video_frame) _video_frame = avcodec_alloc_frame();
if(NULL == _video_frame){
LOGE("_setupFFmpeg. Could not allocate memory for the video frame!");
return -1;
}
LOGI("_setupFFmpeg(exit)");
return 0;
}
然后只有一个循环在调用此函数的解码器处连续发送 PES 数据包:
int VideoPlayer::_playVideoPacket(PesPacket *packet)
{
int len, frameReady;
_avpkt.data = packet->buf;
_avpkt.size = packet->info.bufferSize;
while(_avpkt.size){
len = avcodec_decode_video2(_video_dec_ctx, _video_frame, &frameReady, &_avpkt);
if(len < 0){
LOGE("FFW_decodeVideo");
return len;
}
if(frameReady){
//Draw the picture...
}
_avpkt.size -= len;
_avpkt.data += len;
}
return 1;
}
但是当我运行代码时我得到:调用 avcodec_decode_video2() 后,FFMPEG 出现“无效帧尺寸 0x0”错误。
看来我没有正确设置编解码器。 mpeg12dec.c 中 Mpeg1Context 中的 MpegEncContext 未正确设置。我需要做什么才能正确设置 MpegEncContext?
最佳答案
根据变量名称判断,您正在将 pes 数据包传递到decode_video 中。这是错误的。您必须传入原始 ES 数据包(无 pes header )。最简单的方法是使用 avformat 和 av_read_frame() 为您填充 AVPacket。如果您使用自己的格式解复用器,则必须深入到 Raw ES 层。您可能还需要设置 PTS DTS 值。
注意:我不太了解 mpeg2,但某些编解码器还要求您在编解码器上下文中配置额外数据值。
关于FFMPEG - avcodec_decode_video2 返回 "Invalid frame dimensions 0x0",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20048631/
我最近开始了一个依赖于将 FLV 直接流式传输到 iOS 设备的项目。最著名的是我使用了 ffmpeg(和一个 iOS 包装器 - kxmovie)。令我惊讶的是,iPhone 4 甚至无法播放 SD
我使用 vc++ express,我将使用 ffmpeg .. 但是在第一个程序中我遇到了麻烦。 vc++ 说 '标识符'avcodec_decode_video':找不到标识符'关于编译过程。 我不
我尝试使用以下示例来处理视频: 'An ffmpeg and SDL Tutorial' 。但编译器告诉我:对“avcodec_decode_video”的 undefined reference 。
我是一名优秀的程序员,十分优秀!