[mythtv] mediacodec errors

Peter Bennett pb.mythtv at gmail.com
Mon Jul 2 20:06:30 UTC 2018


Hi Aman

This workaround that I sent you (see below) is not successful. On 
Android 8 I am getting illegal state exceptions with FF with 720p 
recordings, with the workaround in place.

Peter


On 06/29/2018 05:40 PM, Peter Bennett wrote:
> The method dequeueOutputBuffer can throw IllegalStateException. 
> According to the MediaCodec documentation that means it is not in the 
> Executing state, or codec is configured in asynchronous mode. I don't 
> have enough understanding of how it works to know why that would be.
>
> I believe that this may only happen with 1080i interlaced video.
>
> The situation only occurs if you send several packets until there are 
> frames available, then receive only one frame from the codec context 
> and then flush, expecting to lose any remaining frames. Doing this 
> sequence repeatedly causes the error after about 10 or 15 times. 
> Somehow those available frames are not being correctly flushed. By 
> adding my own code to discard those frames I avoid the problem.
>
> Add this code before avcodec_flush_buffers:
>
>                 int ret = 0;
>                 while (ret == 0)
>                 {
>                     AVFrame *frame = av_frame_alloc();
>                     ret = avcodec_receive_frame(enc, frame);
>                     av_frame_free(&frame);
>                 }
>
> No More exceptions!!
>
> It should not be necessary to receive all available frames and discard 
> them like this before flushing. Perhaps something like this code 
> snippet should be added to avcodec_flush_buffers.
>
> Please let me know if you make any change in ffmpeg to solve this 
> issue so that I can remove this piece of code.
>
> Peter
>



More information about the mythtv-dev mailing list