[Libav-user] [External] Questions about decoding broken streams

Niraj Gandha niraj.gandha at einfochips.com
Wed Oct 3 13:31:15 EEST 2018


Use below code and might help you in solving your problem.

while (av_read_frame(refrenceFormatCtx, &packet) >= 0) {

if (packet.stream<http://packet.stream/>_index == video_stream_index) { //packet is video

if (stream == NULL) { //create stream in file

stream = avformat_new_stream(output_ctx, refrenceFormatCtx->streams[video_stream_index]->codec->codec);

avcodec_copy_context(stream->codec, refrenceFormatCtx->streams[video_stream_index]->codec);

stream->sample_aspect_ratio = refrenceFormatCtx->streams[video_stream_index]->codec->sample_aspect_ratio;

}
int check = 0;
 packet.stream<http://packet.stream/>_index = stream->id;
int result = avcodec_decode_video2(codec_ctx, picture_yuv, &check, &packet);

av_free_packet(&packet);

av_packet_unref(&packet);

if(result <= 0 || check == 0){

continue;

}

if(initialize_rgb_requirements) {

sizeofrgbpicture = avpicture_get_size(AV_PIX_FMT_RGB24, codec_ctx->width, codec_ctx->height);

picture_rgb = av_frame_alloc();

picture_buffer_rgb = (uint8_t*) (av_malloc(sizeofrgbpicture));

avpicture_fill((AVPicture *) picture_rgb, picture_buffer_rgb, AV_PIX_FMT_RGB24, codec_ctx->width, codec_ctx->height);

img_convert_ctx = sws_getContext(codec_ctx->width, codec_ctx->height, AV_PIX_FMT_YUV420P, codec_ctx->width, codec_ctx->height,AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
initialize_rgb_requirements=0;

}

int height = 0;

if(picture_yuv->data != NULL) {
height = sws_scale(img_convert_ctx, ((AVPicture*)picture_yuv)->data, ((AVPicture*)picture_yuv)->linesize, 0, codec_ctx->height, ((AVPicture*)picture_rgb)->data,((AVPicture*)picture_rgb)->linesize);

}

rgb_image_data = (uint8_t *)malloc(sizeofrgbpicture * sizeof(uint8_t));

int ret = avpicture_layout((AVPicture *)picture_rgb, AV_PIX_FMT_RGB24, codec_ctx->width, codec_ctx->height, rgb_image_data, sizeofrgbpicture);

emit imageQueued(rgb_image_data, codec_ctx->width,codec_ctx->height);

}
}

Get Outlook for Android<https://aka.ms/ghei36>

________________________________
From: Libav-user <libav-user-bounces at ffmpeg.org> on behalf of Vasiliy Volkov <volk.vasiliy at gmail.com>
Sent: Wednesday, October 3, 2018 3:44:49 PM
To: libav-user at ffmpeg.org
Subject: Re: [Libav-user] [External] Questions about decoding broken streams

Well there is no anything unusual in our code. We're simply use this API:
https://ffmpeg.org/doxygen/4.0/group__lavc__encdec.html

avcodec_send_packet
avcodec_receive_frame

And for context we setup:
context->err_recognition = AV_EF_EXPLODE | AV_EF_BITSTREAM | AV_EF_BUFFER | AV_EF_CAREFUL | AV_EF_COMPLIANT | AV_EF_AGGRESSIVE;


ср, 3 окт. 2018 г. в 12:58, Niraj Gandha <niraj.gandha at einfochips.com<mailto:niraj.gandha at einfochips.com>>:
Hi Vasiliy,

Can you share the code in which you are decoding the stream?

Thanks,
Niraj Gandha

Get Outlook for Android<https://aka.ms/ghei36>

________________________________
From: Libav-user <libav-user-bounces at ffmpeg.org<mailto:libav-user-bounces at ffmpeg.org>> on behalf of Vasiliy Volkov <volk.vasiliy at gmail.com<mailto:volk.vasiliy at gmail.com>>
Sent: Wednesday, October 3, 2018 3:08:08 PM
To: libav-user at ffmpeg.org<mailto:libav-user at ffmpeg.org>
Subject: [External] [Libav-user] Questions about decoding broken streams

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Hi,

I'm trying to deal with broken streams with libav. Sometimes streams can be broken due to nature of incoming network channel (UDP multicast) but i'd like to "fix them" as much as possible. I'm trying to fill broken frames with last good decoded frame. There are situations when I can do such thing and everything is ok but most of time it's not helping: libav tries to decode broken stream and add some green frames (h264 decoding) which really catch your eyes when you watch this stream after encoding.
Is it possible to change this color to black for example? Can libav while decoding set some flags to frames and mark them as broken or "green"?
It will be helpful because next I'll can replace such frames with correctly decoded which fix it.

Thanks
************************************************************************************************************************************************************* eInfochips Business Disclaimer: This e-mail message and all attachments transmitted with it are intended solely for the use of the addressee and may contain legally privileged and confidential information. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to this message and please delete it from your computer. Any views expressed in this message are those of the individual sender unless otherwise stated. Company has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email. *************************************************************************************************************************************************************
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org<mailto:Libav-user at ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20181003/17ccc669/attachment.html>


More information about the Libav-user mailing list