- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 libx264 通过 RTP 流式传输视频捕获。现在,我只是流式传输到本地主机。为了观看流,我使用 ffmpeg 库。当我将 GOP 大小设置为大于 1(仅 I 帧)时,我在接收端得到了伪影 .奇怪的是,当我使用 ffplay 时,图像是完美的 .我做错了什么?
编码设置
output_codec_ctx->bit_rate = 5000000;
output_codec_ctx->width = 1920;
output_codec_ctx->height = 1080;
output_codec_ctx->time_base.den = 30; // frames per second
output_codec_ctx->time_base.num = 1;
output_codec_ctx->gop_size = 10; // gop size
output_codec_ctx->max_b_frames = 0; // B frames
output_codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; // output pixel format
output_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
av_opt_set(output_codec_ctx->priv_data, "preset", "ultrafast", 0);
av_opt_set(output_codec_ctx->priv_data, "tune", "zerolatency", 0);
解码代码
AVFormatContext *pFormatCtx;
AVCodecContext *input_codec_ctx;
AVCode *pCodec;
avdevice_register_all(); // for device
avformat_network_init();
pFormatCtx = avformat_alloc_context();
input_codec_ctx = avcodec_alloc_context3(nullptr);
AVDictionary *options = nullptr;
av_dict_set(&options, "protocol_whitelist", "file,udp,rtp", 0);
av_dict_set(&options, "fflags", "nobuffer",0);
avformat_open_input(&pFormatCtx, "rtp://127.0.0.1:49990", nullptr, &options);
avformat_find_stream_info(pFormatCtx, nullptr);
for (uint i = 0; i < pFormatCtx->nb_streams; i++)
{
if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStream = static_cast<int>(i);
break;
}
}
av_read_play(pFormatCtx); //play stream
pCodec = avcodec_find_decoder(pFormatCtx->streams[videoStream]->codecpar->codec_id);
AVCodecParameters *codec_param = pFormatCtx->streams[videoStream]->codecpar;
avcodec_parameters_to_context(input_codec_ctx, codec_param);
avcodec_open2(input_codec_ctx, pCodec, nullptr);
AVPacket packet;
AVPacket *pkt = &packet;
AVFrame *frame;
frame = av_frame_alloc();
av_init_packet(pkt);
pkt->data = nullptr; // packet data will be allocated by the encoder
pkt->size = 0;
while(true){
av_read_frame(pFormatCtx,pkt);
avcodec_send_packet(input_codec_ctx,pkt);
avcodec_receive_frame(input_codec_ctx,frame);
}
省略了初始化和其他内容。自定义解码的控制台输出:
NULL @ 0x1fb7b80] Opening 'stream.sdp' for reading
[sdp @ 0x1fb7b80] Format sdp probed with size=2048 and score=50
[sdp @ 0x1fb7b80] video codec set to: h264
[sdp @ 0x1fb7b80] RTP Packetization Mode: 1
[udp @ 0x1f34140] end receive buffer size reported is 131072
[udp @ 0x1fb8e40] end receive buffer size reported is 131072
[sdp @ 0x1fb7b80] setting jitter buffer size to 500
Success !
[sdp @ 0x1fb7b80] Before avformat_find_stream_info() pos: 181 bytes read:181 seeks:0 nb_streams:1
[AVBSFContext @ 0x1fa5880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[AVBSFContext @ 0x1fa5880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] Format yuv420p chosen by get_format().
[h264 @ 0x1fa51c0] Reinit context to 1920x1088, pix_fmt: yuv420p
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 57 packets
[h264 @ 0x1fa51c0] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] Invalid level prefix
[h264 @ 0x1fa51c0] error while decoding MB 2 36
[h264 @ 0x1fa51c0] concealing 3887 DC, 3887 AC, 3887 MV errors in I frame
[h264 @ 0x1fa51c0] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 155 packets
[h264 @ 0x1fa51c0] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] corrupted macroblock 32 41 (total_coeff=-1)
[h264 @ 0x1fa51c0] error while decoding MB 32 41
[h264 @ 0x1fa51c0] concealing 3257 DC, 3257 AC, 3257 MV errors in I frame
[h264 @ 0x1fa51c0] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1fa51c0] nal_unit_type: 5(IDR), nal_ref_idc: 3
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 52 packets
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 51 packets
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 10 packets
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 50 packets
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 52 packets
[sdp @ 0x1fb7b80] All info found
[sdp @ 0x1fb7b80] After avformat_find_stream_info() pos: 181 bytes read:181 seeks:0 frames:28
found video stream
The number of elements in stream is 1
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] Format yuv420p chosen by get_format().
[h264 @ 0x1ee3880] Reinit context to 1920x1088, pix_fmt: yuv420p
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 256 packets
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] Invalid level prefix
[h264 @ 0x1ee3880] error while decoding MB 119 41
[h264 @ 0x1ee3880] concealing 3170 DC, 3170 AC, 3170 MV errors in I frame
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 5 packets
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 4 packets
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] out of range intra chroma pred mode
[h264 @ 0x1ee3880] error while decoding MB 100 56
[h264 @ 0x1ee3880] corrupted macroblock 84 65 (total_coeff=-1)
[h264 @ 0x1ee3880] error while decoding MB 84 65
[h264 @ 0x1ee3880] concealing 754 DC, 754 AC, 754 MV errors in I frame
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 160 packets
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] corrupted macroblock 17 36 (total_coeff=-1)
[h264 @ 0x1ee3880] error while decoding MB 17 36
[h264 @ 0x1ee3880] concealing 3872 DC, 3872 AC, 3872 MV errors in I frame
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[sdp @ 0x1fb7b80] max delay reached. need to consume packet
[sdp @ 0x1fb7b80] RTP: missed 53 packets
[h264 @ 0x1ee3880] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x1ee3880] corrupted macroblock 62 39 (total_coeff=-1)
[h264 @ 0x1ee3880] error while decoding MB 62 39
[h264 @ 0x1ee3880] concealing 3467 DC, 3467 AC, 3467 MV errors in I frame
最佳答案
最后我通过与 ffplay 相同的方式实现它解决了它:一个线程执行 av_read_frame() 并将接收到的数据包推送到数据包队列,第二个线程解码数据包。
不知道为什么它不能在一个线程中工作。
您可能会从以下片段中获得示例:
数据包接收者:
must_abort = false; // class member, externally set to true if abort requested
AVPacket packet;
AVPacket *pkt = &packet;
int ret;
while (must_abort == false){
ret = av_read_frame(pFormatCtx,pkt);
if (ret>=0 && !must_abort){
queue->putPacket(pkt);
}
else{
qDebug("no packet received");
}
QApplication::processEvents();
}
数据包队列:
class PacketQueue{
public:
void init(){
abort_request = false;
}
void putPacket(AVPacket *pkt) {
mutex.lock();
queue.enqueue(*pkt);
waitForNewPacket.wakeAll();
mutex.unlock();
}
int getPacket(AVPacket *pkt){
int ret;
mutex.lock();
forever {
if (abort_request) {
ret = -1;
break;
}
if (queue.size() == 0){
if (waitForNewPacket.wait(&mutex, 1000)){
}else{
qDebug("PacketQueue timeout, try again...");
}
continue;
}
*pkt= queue.dequeue();
ret = 1;
break;
}
mutex.unlock();
return ret;
}
void abort(){
mutex.lock();
abort_request = true;
mutex.unlock();
}
bool abort_request;
QQueue<AVPacket> queue;
QMutex mutex;
QWaitCondition waitForNewPacket;
};
解码器:
AVFrame *frame = av_frame_alloc();
AVFrame *frame_RGB = av_frame_alloc();
struct SwsContext *img_convert_ctx = nullptr;
int ret;
int cnt = 0;
int width_current = 0;
int height_current = 0;
avcodec_flush_buffers(mData->input_codec_ctx);
forever{
cnt++;
ret = decodeFrame(frame);
if (ret < 0 ){
break;
}
if (ret == 0){
continue;
}
// check if height and width have changed
if (width_current != frame->width || height_current != frame->height){
av_frame_free(&frame_RGB);
frame_RGB = av_frame_alloc();
frame_RGB->width = width_current = frame->width;
frame_RGB->height = height_current = frame->height;
frame_RGB->format = AV_PIX_FMT_RGB24;
av_image_alloc(frame_RGB->data, frame_RGB->linesize, frame_RGB->width, frame_RGB->height, AV_PIX_FMT_RGB24, 32);
img_convert_ctx = sws_getContext( frame->width,
frame->height,
static_cast<AVPixelFormat>(frame->format),
frame->width,
frame->height,
AV_PIX_FMT_RGB24,
SWS_BICUBIC,
nullptr, nullptr, nullptr);
}
if (img_convert_ctx != nullptr) {
sws_scale(img_convert_ctx, static_cast<uint8_t const * const *>(frame->data),
frame->linesize, 0, frame->height,
frame_RGB->data, frame_RGB->linesize);
// here is the frame available as RGB in frame_RGB
}
av_frame_unref(frame);
}
}
int VideoDecoder::decodeFrame(AVFrame* frame){
int ret = AVERROR(EAGAIN);
forever {
AVPacket pkt;
do {
ret = avcodec_receive_frame(input_codec_ctx, frame);
if (ret >= 0) {
//frame->pts = frame->pkt_dts;
//frame->pts = frame->best_effort_timestamp;
}
if (ret == AVERROR_EOF) {
avcodec_flush_buffers(input_codec_ctx);
return 0;
}
if (ret >= 0)
return 1;
} while (ret != AVERROR(EAGAIN));
if (queue->getPacket(&pkt) < 0)
return -1;
ret = avcodec_send_packet(input_codec_ctx, &pkt);
if (ret == AVERROR(EAGAIN)) {
qFatal("Receive_frame and send_packet both returned EAGAIN, which is an API violation.");
}
if (pkt.buf->buffer != nullptr){
av_packet_unref(&pkt);
}else{
qDebug() << "Packet cannot be freed, pkt.buf->buffer == NULL!";
}
}
}
关于c++ - ffmpeg 流解码 - 不使用 ffplay 时的人工制品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53449946/
我一直在测试使用不同的播放器播放多个实时流,因为我想获得最低的延迟值。我尝试了 gstreamer 播放器 (gst-launch-0.01)、mplayer、totem 和 ffmpeg 播放器 (
我的目标是在开始后 10 分钟检查文件。这是我的脚本。 ffplay.exe -f lavfi "amovie=input.mov,showvolume=b=4:w=640:h=96" 如果我添加搜索
以下代码播放“sample.mp3”并终止。这太令人惊讶了,因为通过管道传递的数据是二进制流,所以 ffplay 应该不知道“sample.mp3”的持续时间,但它会在到达末尾后立即终止。 $ cat
我从 http://ffmpeg.org/doxygen/trunk/ffplay_8c-source.html 获取了 ffplay.c 文件并将其重新编辑为 cpp 文件以嵌入到我的 win32
我想知道是否可以将互联网直播从 ffmpeg 传输到 ffplay? 举例说明: 直播到 test.mp4 作品 ffmpeg -i "https://Some livestream" -c copy
我试图弄清楚在 ffplay 中使用左/右箭头的搜索功能是如何工作的 我进入了他们的开源代码并尝试将值从 10,-10 更改为不同的值,以便我可以查看搜索是否正确移动,但经过几次尝试后,我看到使用左箭
我正在做一个视频编辑项目,我正在使用 ffmpeg 进行视频渲染 要在渲染之前播放视频,我想向用户展示它,我想使用 ffplay ffplay -i C:/Users/thota/OneDrive/D
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
我们想使用 ffplay 来监控直播视频,而不是 VLC。我们遇到了一些限制。我们知道变通办法吗?第一个问题是我们无法通过命令行参数将 ffplay 的窗口定位在屏幕上的不同位置。我们已经尝试了命令行
对于视频文件,我怎样才能只获得 showwave 滤波器而不是 showwave n 频谱。 ffplay -f lavfi 'amovie=abc.mp4,asplit=3[out1][a][b];
我试图获得顶部视频和底部音频波形。但是我不能用左/右键来回擦洗/搜索。普通的 ffplay 命令可用于搜索。 在我的 shell 运行中寻找时出现错误: 示例 1 ffplay -f lavfi \
我有一些 .264 视频文件,我想以一半的播放速度观看,而不是将它们编码到新文件中。记得以前用ffplay做这个,不过是前段时间了,现在好像做不到了。从大量搜索中,这应该是可行的: ffplay -f
我正在使用 pydub,我正在使用 ffplay。出于某种原因,当程序运行时,我得到这个“错误”: /usr/local/lib/python2.7/site-packages/pydub/util
每个人。我有 video 的问题使用ffplay播放。使用了以下命令 ffplay -i input.avi 但是出现了以下错误。 ffplay version N-87353-g183fd30 Co
我有一个视频缓冲区和一个音频缓冲区,我想组合这些缓冲区并使用 ffplay 作为一个组合实体进行播放,目前我正在使用这个命令,这显然不起作用...... ffplay -f rawvideo -pix
如果我做: ffplay -i vid.mp4 ffplay 工作正常,但是如果我尝试无边框选项: ffplay -noborder -i vid.mp4 Failed to set value '-
当您使用 ffplay 播放音频时,或带有 -vn 的视频标志,ffplay显示频谱图。我试图找出 ffplay.c 的哪一部分代码对此负责。 我想通过按下按钮启用/禁用视频,并将音频可视化更改为其他
我试图让 FFplay 在播放时在最后一张图像上简单地停止(暂停)。 FFplay 的默认行为似乎使用 -loops周界,这会导致最后一个音频数据包被循环 - 即使图像出现在暂停状态。 有没有办法在文
我将 ffplay 作为后台进程运行,它为我的主 UI 进程提供图像数据。我设置了“SDL_VIDEODRIVER = dummy”来禁止在 SDL 窗口中显示 ffplay 视频。 问题是即使没有显
我正在尝试使用 ffplay 播放/跳过一些视频剪辑。我跳过第 100 到 400 帧的第一种方法是: ffplay -vf "select='lte(n\,100)+gte(n\,400)'" -i
我是一名优秀的程序员,十分优秀!