Discussion:
[Libav-user] Questions about decoding broken streams
Vasiliy Volkov
2018-10-03 09:38:08 UTC
Permalink
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
Niraj Gandha
2018-10-03 09:58:36 UTC
Permalink
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-***@ffmpeg.org> on behalf of Vasiliy Volkov <***@gmail.com>
Sent: Wednesday, October 3, 2018 3:08:08 PM
To: libav-***@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. *************************************************************************************************************************************************************
Vasiliy Volkov
2018-10-03 10:14:49 UTC
Permalink
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 <***@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-***@ffmpeg.org> on behalf of Vasiliy
> Volkov <***@gmail.com>
> *Sent:* Wednesday, October 3, 2018 3:08:08 PM
> *To:* libav-***@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-***@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
Niraj Gandha
2018-10-03 10:31:15 UTC
Permalink
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-***@ffmpeg.org> on behalf of Vasiliy Volkov <***@gmail.com>
Sent: Wednesday, October 3, 2018 3:44:49 PM
To: libav-***@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 <***@einfochips.com<mailto:***@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-***@ffmpeg.org<mailto:libav-user-***@ffmpeg.org>> on behalf of Vasiliy Volkov <***@gmail.com<mailto:***@gmail.com>>
Sent: Wednesday, October 3, 2018 3:08:08 PM
To: libav-***@ffmpeg.org<mailto:libav-***@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. *************************************************************************************************************************************************************
Anton Shekhovtsov
2018-10-03 10:48:02 UTC
Permalink
ср, 3 Пкт. 2018 г. в 13:31, Niraj Gandha <***@einfochips.com>:

> Use below code and might help you in solving your problem.
>
> while (av_read_frame(refrenceFormatCtx, &packet) >= 0) {
>
> if (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_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-***@ffmpeg.org> on behalf of Vasiliy
> Volkov <***@gmail.com>
> *Sent:* Wednesday, October 3, 2018 3:44:49 PM
> *To:* libav-***@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 <***@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-***@ffmpeg.org> on behalf of Vasiliy
>> Volkov <***@gmail.com>
>> *Sent:* Wednesday, October 3, 2018 3:08:08 PM
>> *To:* libav-***@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-***@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
> _______________________________________________
> Libav-user mailing list
> Libav-***@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user


What you wanted to show with this example? That's true, some (or all)
decoders don't return errors.
Example in ffv1dec.c
av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!", crc);
No error code returned from here. It is possible to abuse log hook somehow.
Vasiliy Volkov
2018-10-03 14:36:58 UTC
Permalink
So there is no way to determine decoding errors except parsing log
messages? It smells terrible )
I see only way to detect such green images by analyzing color of decoded
frames, but it can be CPU-intensive

Also of course it's possible to patch some decoders, but It's also not
correct way I guess.

ср, 3 Пкт. 2018 г. в 13:48, Anton Shekhovtsov <***@gmail.com>:

>
>
> ср, 3 Пкт. 2018 г. в 13:31, Niraj Gandha <***@einfochips.com>:
>
>> Use below code and might help you in solving your problem.
>>
>> while (av_read_frame(refrenceFormatCtx, &packet) >= 0) {
>>
>> if (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_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-***@ffmpeg.org> on behalf of Vasiliy
>> Volkov <***@gmail.com>
>> *Sent:* Wednesday, October 3, 2018 3:44:49 PM
>> *To:* libav-***@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 <***@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-***@ffmpeg.org> on behalf of Vasiliy
>>> Volkov <***@gmail.com>
>>> *Sent:* Wednesday, October 3, 2018 3:08:08 PM
>>> *To:* libav-***@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-***@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/libav-user
>>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-***@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>
>
> What you wanted to show with this example? That's true, some (or all)
> decoders don't return errors.
> Example in ffv1dec.c
> av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!", crc);
> No error code returned from here. It is possible to abuse log hook somehow.
>
> _______________________________________________
> Libav-user mailing list
> Libav-***@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
Yurii Monakov
2018-10-04 13:11:34 UTC
Permalink
Vasiliy, you can check AV_FRAME_FLAG_CORRUPT in AVFrame::flags and
FF_DECODE_ERROR_XXX bits in AVFrame::decode_error_flags.

Yurii

ср, 3 Пкт. 2018 г. в 17:37, Vasiliy Volkov <***@gmail.com>:

> So there is no way to determine decoding errors except parsing log
> messages? It smells terrible )
> I see only way to detect such green images by analyzing color of decoded
> frames, but it can be CPU-intensive
>
> Also of course it's possible to patch some decoders, but It's also not
> correct way I guess.
>
> ср, 3 Пкт. 2018 г. в 13:48, Anton Shekhovtsov <***@gmail.com>:
>
>>
>>
>> ср, 3 Пкт. 2018 г. в 13:31, Niraj Gandha <***@einfochips.com>:
>>
>>> Use below code and might help you in solving your problem.
>>>
>>> while (av_read_frame(refrenceFormatCtx, &packet) >= 0) {
>>>
>>> if (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_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-***@ffmpeg.org> on behalf of Vasiliy
>>> Volkov <***@gmail.com>
>>> *Sent:* Wednesday, October 3, 2018 3:44:49 PM
>>> *To:* libav-***@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 <***@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-***@ffmpeg.org> on behalf of
>>>> Vasiliy Volkov <***@gmail.com>
>>>> *Sent:* Wednesday, October 3, 2018 3:08:08 PM
>>>> *To:* libav-***@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-***@ffmpeg.org
>>>> http://ffmpeg.org/mailman/listinfo/libav-user
>>>>
>>> _______________________________________________
>>> Libav-user mailing list
>>> Libav-***@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>>
>> What you wanted to show with this example? That's true, some (or all)
>> decoders don't return errors.
>> Example in ffv1dec.c
>> av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!", crc);
>> No error code returned from here. It is possible to abuse log hook
>> somehow.
>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-***@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
> _______________________________________________
> Libav-user mailing list
> Libav-***@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
Loading...