<div><br></div><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 5, 2018 at 3:13 PM Aman Gupta <<a href="mailto:aman@tmm1.net">aman@tmm1.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 21, 2018 at 9:46 PM Aman Gupta <<a href="mailto:aman@tmm1.net" target="_blank">aman@tmm1.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 20, 2018 at 2:32 PM Aman Gupta <<a href="mailto:aman@tmm1.net" target="_blank">aman@tmm1.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 20, 2018 at 2:28 PM Peter Bennett <<a href="mailto:pb.mythtv@gmail.com" target="_blank">pb.mythtv@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Aman<br>
<br>
When running with mediacodec on the fire stick 4K, there is a problem <br>
with MPEG2. Perhaps the 4K does not support MPEG2 or the interlacing is <br>
causing a problem. What appears to happen is that we get the situation <br>
where we have done avcodec_send_packet until it returns AVERROR(EAGAIN). <br>
The avcodec_receive_frame also returns AVERROR(EAGAIN) and this <br>
continues forever, we never get a frame out of it. With h264 it works <br>
fine. If there is no MPEG2 support, maybe we should get an error return <br>
or it should revert to software decoding. Is there anything ffmpeg can <br>
do to avoid this, or do I have something wrong in my code?<br></blockquote><div><br></div><div>The hardware mpeg2 decoder on that device is extremely buggy.</div><div><br></div><div>For some interlaced streams, it will generate flashing green output: <a href="https://github.com/amzn/exoplayer-amazon-port/issues/58" target="_blank">https://github.com/amzn/exoplayer-amazon-port/issues/58</a></div></div></div></div></blockquote></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Amazon has verified this bug and says they are waiting on a vendor driver update to resolve</div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">I'm hearing that this green flash issue is fixed in the latest FireOS update.</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div dir="auto"> it.</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><a href="https://github.com/amzn/exoplayer-amazon-port/issues/58" target="_blank"></a></div><div><br></div><div>For videos where it works, the decoder will randomly lock up after some time and stop accepting new packets and also stop returning new frames (as you noticed).</div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">The green screen issue is definitely hardware specific, but this freezing issue may actually be an ffmpeg bug.</div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">I've gotten reports that this freeze issue also happens with h264 MediaCodec decoding on the 4K Stick, which further suggests this is an issue with ffmpeg's mediacodec wrapper.</div><div dir="auto"><br></div><div dir="auto">Since this seems like some sort of race condition, one thing to try would be adjusting the timeouts used when dequeuing input/output buffers: <div><a href="https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/mediacodecdec_common.c#L84-L85" target="_blank">https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/mediacodecdec_common.c#L84-L85</a></div><div dir="auto"><br></div><div dir="auto">Another (much bigger) change would be to introduce threads and use one dedicated thread for output buffers. VLC uses a similar technique and I got similar advice from a developer on the Android media team- mediacodec is thread safe and using separate threads for input and output is recommended.</div></div></div></div><div><div class="gmail_quote"><div dir="auto"><div dir="auto"><br></div><div dir="auto">Aman</div></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div dir="auto"></div><div dir="auto"><br></div><div dir="auto">I recall that I've seen the freeze happen on other FireOS devices, like the older FireTV boxes.</div><div dir="auto"><br></div><div dir="auto">Further, none of these devices (including the new 4K stick) seem to reproduce the hang when using Exoplayer or VLC.</div><div dir="auto"><br></div><div dir="auto">However I'm not sure what ffmpeg could do differently to avoid this issue. The code in ffmpeg is already very similar to Exoplayer.</div><div dir="auto"><br></div><div dir="auto">I've spent dozens of hours trying to debug this at various times this year and sadly made no progress. It seems to happen quite regularly on the 4K stick, which at least makes it easier to try out potential fixes.</div><div dir="auto"><br></div><div dir="auto">If anyone wants to spend time on this I'm happy to advise, but I have given up on trying to fix this myself.</div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto">Aman</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div></div><div><br></div><div>These are issues in the underlying codec/hardware/OS and not something ffmpeg can work-around.</div></div></div></div><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>Aman</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I have set ffmpeg debug logging and captured the log. That is here -> <br>
<a href="https://pastebin.com/ZF9JiMTX" rel="noreferrer" target="_blank">https://pastebin.com/ZF9JiMTX</a><br>
The code where we process packets is here -> <br>
<a href="https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686" rel="noreferrer" target="_blank">https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686</a><br>
<br>
Peter<br>
</blockquote></div></div></div>
</blockquote></div></div>
</blockquote></div></div>
</blockquote></div></div>