[英]C++ h264 ffmpeg/libav encode/decode(lossless) issues
使用ffmpeg h264编码/解码视频的见解(无损)
所以我在编码部分做了一些工作,在264中编码了一个avi,但是VLC不会播放,但是图腾会。 解码相同的文件证明很麻烦。 (我希望输入的数据/帧与输出的完全一样),我得到了这些;
saving frame 5
Video decoding
[h264 @ 0x1d19880] decode_slice_header error
frame :6
saving frame 6
Video decoding
[h264 @ 0x1d19880] error while decoding MB 15 7, bytestream -27
[h264 @ 0x1d19880] concealing 194 DC, 194 AC, 194 MV errors in I frame
frame :7
saving frame 7
Video decoding
[h264 @ 0x1d19880] decode_slice_header error
最后这
[H264 Decoder @ 0x7f1320766040] frame :11
Broken frame packetizing
[h264 @ 0x1d19880] SPS changed in the middle of the frame
[h264 @ 0x1d19880] decode_slice_header error
[h264 @ 0x1d19880] no frame!
Error while decoding frame 11
游戏结束。
现在,我怀疑我必须回到1.编码部分,这是VLC不会播放的一个很好的理由!
我这样编码。
void encode(char *Y,char *U,char *V){
av_init_packet(&pkt);
pkt.data = NULL; // packet data will be allocated by the encoder
pkt.size = 0;
fflush(stdout);
frame->data[0] = (uint8_t*)Y;
frame->data[1] = (uint8_t*)U;
frame->data[2] = (uint8_t*)V;
frame->pts = ++i;
ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
if (ret < 0) {
fprintf(stderr, "Error encoding frame\n");
exit (EXIT_FAILURE);
}
if (got_output) {
printf("Write frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
}
}
编解码器的设置如下:
AVCodecID dasd = AV_CODEC_ID_H264;
codec = avcodec_find_encoder(dasd);
c = avcodec_alloc_context3(codec);
c->bit_rate = 400000;
c->width = 320;
c->height = 240;
c->time_base= (AVRational){1,25};
c->gop_size = 10;
c->max_b_frames=1;
c->pix_fmt = AV_PIX_FMT_YUV420P;
av_opt_set(c->priv_data, "preset", "slow", 0);
avcodec_open2(c, codec, NULL);
由于我追求无损,所以我不会处理延迟的帧(这是正确的假设吗?)我可能实际上并不是在编码无损,看来我可能不得不处理类似的问题
AVDictionary *param;
av_dict_set(¶m, "qp", "0", 0);
然后打开...
所以我想我的问题是:
谢谢。
您的编码中有些事情是严重错误的。 错误“ I帧中的MV错误”在这里是奇怪的,在I帧中不应有任何MV。 似乎标头解析它本身出错了。 请分享比特流和有关VLC失败的更多详细信息
您正在将原始的Annexb框架写入文件,而无需任何容器包装。 使用mp4或matroska这样的容器,VLC应该很高兴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.