Mailing List Archive

Mediacodec problem with fire stick 4K
Hi Aman

When running with mediacodec on the fire stick 4K, there is a problem
with MPEG2. Perhaps the 4K does not support MPEG2 or the interlacing is
causing a problem. What appears to happen is that we get the situation
where we have done avcodec_send_packet until it returns AVERROR(EAGAIN).
The avcodec_receive_frame also returns AVERROR(EAGAIN) and this
continues forever, we never get a frame out of it. With h264 it works
fine. If there is no MPEG2 support, maybe we should get an error return
or it should revert to software decoding. Is there anything ffmpeg can
do to avoid this, or do I have something wrong in my code?

I have set ffmpeg debug logging and captured the log. That is here ->
https://pastebin.com/ZF9JiMTX
The code where we process packets is here ->
https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686

Peter
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Tue, Nov 20, 2018 at 2:28 PM Peter Bennett <pb.mythtv@gmail.com> wrote:

> Hi Aman
>
> When running with mediacodec on the fire stick 4K, there is a problem
> with MPEG2. Perhaps the 4K does not support MPEG2 or the interlacing is
> causing a problem. What appears to happen is that we get the situation
> where we have done avcodec_send_packet until it returns AVERROR(EAGAIN).
> The avcodec_receive_frame also returns AVERROR(EAGAIN) and this
> continues forever, we never get a frame out of it. With h264 it works
> fine. If there is no MPEG2 support, maybe we should get an error return
> or it should revert to software decoding. Is there anything ffmpeg can
> do to avoid this, or do I have something wrong in my code?
>

The hardware mpeg2 decoder on that device is extremely buggy.

For some interlaced streams, it will generate flashing green output:
https://github.com/amzn/exoplayer-amazon-port/issues/58

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).

These are issues in the underlying codec/hardware/OS and not something
ffmpeg can work-around.

Aman


>
> I have set ffmpeg debug logging and captured the log. That is here ->
> https://pastebin.com/ZF9JiMTX
> The code where we process packets is here ->
>
> https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686
>
> Peter
>
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Tue, Nov 20, 2018 at 10:33 PM Aman Gupta <aman@tmm1.net> wrote:

> The hardware mpeg2 decoder on that device is extremely buggy.

At least a few companies have reported the issue to Amazon.
I have not heard about any explicit commitment regarding a
fix (let alone a date). At least one company has stated that
they have some mitigations in place to try to avoid the issues,
but the underlying hardware/firmware/OS need to be fixed.
I suspect that as it does not effect Prime Video nor Netflix
they have not made it a highest priority to address.
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 21/11/2018 00:57, Gary Buhrmaster wrote:

> On Tue, Nov 20, 2018 at 10:33 PM Aman Gupta <aman@tmm1.net> wrote:
>
>> The hardware mpeg2 decoder on that device is extremely buggy.
> At least a few companies have reported the issue to Amazon.
> I have not heard about any explicit commitment regarding a
> fix (let alone a date). At least one company has stated that
> they have some mitigations in place to try to avoid the issues,
> but the underlying hardware/firmware/OS need to be fixed.
> I suspect that as it does not effect Prime Video nor Netflix
> they have not made it a highest priority to address.


That's a shame I was just about to pull the trigger and get one to use
as an additional FE since they are on special offer at the moment. Glad
I saw this before I did :)


Anyone tried one of the cheap Android boxes as a FE? Any recommendations
I'm going round in circles trying to figure out which one to get.


Regard Paul


_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 11/21/18 7:05 AM, Paul Harrison wrote:
> That's a shame I was just about to pull the trigger and get one to use
> as an additional FE since they are on special offer at the moment. Glad
> I saw this before I did:)
>
>
> Anyone tried one of the cheap Android boxes as a FE? Any recommendations
> I'm going round in circles trying to figure out which one to get.
I am looking at it. It does play 1080i perfectly well using software
decoding. I am hopeful I can get the issues sorted out soon and use it
as a viable front end.

Peter

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 21/11/18 12:05, Paul Harrison wrote:
> On 21/11/2018 00:57, Gary Buhrmaster wrote:
>
>> On Tue, Nov 20, 2018 at 10:33 PM Aman Gupta <aman@tmm1.net> wrote:
>>
>>> The hardware mpeg2 decoder on that device is extremely buggy.
>> At least a few companies have reported the issue to Amazon.
>> I have not heard about any explicit commitment regarding a
>> fix (let alone a date). At least one company has stated that
>> they have some mitigations in place to try to avoid the issues,
>> but the underlying hardware/firmware/OS need to be fixed.
>> I suspect that as it does not effect Prime Video nor Netflix
>> they have not made it a highest priority to address.

The file formats listed for the device as offered in the UK don't list
anything that looks to me like mpeg2

Video: Dolby Vision, HDR 10, HDR10+, HLG, H.265, H.264 and VP9. Audio:
AAC-LC, AC3, eAC3 (Dolby Digital Plus), FLAC, MP3, PCM/Wave, Vorbis and
Dolby Atmos (EC3_JOC). Photo: JPEG, PNG, GIF and BMP.

>
>
> That's a shame I was just about to pull the trigger and get one to use
> as an additional FE since they are on special offer at the moment. Glad
> I saw this before I did :)
>
>
> Anyone tried one of the cheap Android boxes as a FE? Any recommendations
> I'm going round in circles trying to figure out which one to get.
>
>
> Regard Paul
>
>
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev@mythtv.org
> http://lists.mythtv.org/mailman/listinfo/mythtv-dev
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org
>

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Wed, Nov 21, 2018 at 2:34 PM John Pilkington <johnpilk222@gmail.com> wrote:

> The file formats listed for the device as offered in the UK don't list
> anything that looks to me like mpeg2

True, Amazon does not really advertise the capability.
However, on the developer device specific pages they do:
https://developer.amazon.com/docs/fire-tv/device-specifications.html

But is is (known) buggy with hardware decode. And
the "?"'s after some of the details suggest someone
who was doing the docs had some questions about
the capabilities (and for what ever reason, the docs
still got published with the "?"s).
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Tue, Nov 20, 2018 at 2:32 PM Aman Gupta <aman@tmm1.net> wrote:

>
>
> On Tue, Nov 20, 2018 at 2:28 PM Peter Bennett <pb.mythtv@gmail.com> wrote:
>
>> Hi Aman
>>
>> When running with mediacodec on the fire stick 4K, there is a problem
>> with MPEG2. Perhaps the 4K does not support MPEG2 or the interlacing is
>> causing a problem. What appears to happen is that we get the situation
>> where we have done avcodec_send_packet until it returns AVERROR(EAGAIN).
>> The avcodec_receive_frame also returns AVERROR(EAGAIN) and this
>> continues forever, we never get a frame out of it. With h264 it works
>> fine. If there is no MPEG2 support, maybe we should get an error return
>> or it should revert to software decoding. Is there anything ffmpeg can
>> do to avoid this, or do I have something wrong in my code?
>>
>
> The hardware mpeg2 decoder on that device is extremely buggy.
>
> For some interlaced streams, it will generate flashing green output:
> https://github.com/amzn/exoplayer-amazon-port/issues/58
>
> 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).
>

The green screen issue is definitely hardware specific, but this freezing
issue may actually be an ffmpeg bug.

I recall that I've seen the freeze happen on other FireOS devices, like the
older FireTV boxes.

Further, none of these devices (including the new 4K stick) seem to
reproduce the hang when using Exoplayer or VLC.

However I'm not sure what ffmpeg could do differently to avoid this issue.
The code in ffmpeg is already very similar to Exoplayer.

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.

If anyone wants to spend time on this I'm happy to advise, but I have given
up on trying to fix this myself.

Aman


> These are issues in the underlying codec/hardware/OS and not something
> ffmpeg can work-around.
>
> Aman
>
>
>>
>> I have set ffmpeg debug logging and captured the log. That is here ->
>> https://pastebin.com/ZF9JiMTX
>> The code where we process packets is here ->
>>
>> https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686
>>
>> Peter
>>
>
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 22/11/18 05:46, Aman Gupta wrote:
>
> On Tue, Nov 20, 2018 at 2:32 PM Aman Gupta <aman@tmm1.net
> <mailto:aman@tmm1.net>> wrote:
>
>
>
> On Tue, Nov 20, 2018 at 2:28 PM Peter Bennett <pb.mythtv@gmail.com
> <mailto:pb.mythtv@gmail.com>> wrote:
>
> Hi Aman
>
> When running with mediacodec on the fire stick 4K, there is a
> problem
> with MPEG2. Perhaps the 4K does not support MPEG2 or the
> interlacing is
> causing a problem. What appears to happen is that we get the
> situation
> where we have done avcodec_send_packet until it returns
> AVERROR(EAGAIN).
> The avcodec_receive_frame also returns AVERROR(EAGAIN) and this
> continues forever, we never get a frame out of it. With h264 it
> works
> fine. If there is no MPEG2 support, maybe we should get an error
> return
> or it should revert to software decoding. Is there anything
> ffmpeg can
> do to avoid this, or do I have something wrong in my code?
>
>
> The hardware mpeg2 decoder on that device is extremely buggy.
>
> For some interlaced streams, it will generate flashing green output:
> https://github.com/amzn/exoplayer-amazon-port/issues/58
>
> 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).
>
>
> The green screen issue is definitely hardware specific, but this
> freezing issue may actually be an ffmpeg bug.
>
> I recall that I've seen the freeze happen on other FireOS devices, like
> the older FireTV boxes.
>
> Further, none of these devices (including the new 4K stick) seem to
> reproduce the hang when using Exoplayer or VLC.

I got a 4K FireStick yesterday, and have VLC playing DVD-format stuff
from my NAS. It played fine for several minutes, until the picture
froze and the sound played on...

John P

>
> However I'm not sure what ffmpeg could do differently to avoid this
> issue. The code in ffmpeg is already very similar to Exoplayer.
>
> 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.
>
> If anyone wants to spend time on this I'm happy to advise, but I have
> given up on trying to fix this myself.
>
> Aman
>
>
> These are issues in the underlying codec/hardware/OS and not
> something ffmpeg can work-around.
>
> Aman
>
>
> I have set ffmpeg debug logging and captured the log. That is
> here ->
> https://pastebin.com/ZF9JiMTX
> The code where we process packets is here ->
> https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686
>
> Peter


_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 22/11/18 05:46, Aman Gupta wrote:
>

>
> Further, none of these devices (including the new 4K stick) seem to
> reproduce the hang when using Exoplayer or VLC.

I got a 4K FireStick yesterday, and have VLC playing DVD-format stuff
from my NAS. It played fine for several minutes, until the picture
froze and the sound played on...

-------------
Apologies. That was with the VLC default 'Preferences'

With 'Hardware Acceleration' Disabled (and video chroma as YUV) it
worked well.


John P

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Wed, Nov 21, 2018 at 9:46 PM Aman Gupta <aman@tmm1.net> wrote:

>
> On Tue, Nov 20, 2018 at 2:32 PM Aman Gupta <aman@tmm1.net> wrote:
>
>>
>>
>> On Tue, Nov 20, 2018 at 2:28 PM Peter Bennett <pb.mythtv@gmail.com>
>> wrote:
>>
>>> Hi Aman
>>>
>>> When running with mediacodec on the fire stick 4K, there is a problem
>>> with MPEG2. Perhaps the 4K does not support MPEG2 or the interlacing is
>>> causing a problem. What appears to happen is that we get the situation
>>> where we have done avcodec_send_packet until it returns AVERROR(EAGAIN).
>>> The avcodec_receive_frame also returns AVERROR(EAGAIN) and this
>>> continues forever, we never get a frame out of it. With h264 it works
>>> fine. If there is no MPEG2 support, maybe we should get an error return
>>> or it should revert to software decoding. Is there anything ffmpeg can
>>> do to avoid this, or do I have something wrong in my code?
>>>
>>
>> The hardware mpeg2 decoder on that device is extremely buggy.
>>
>> For some interlaced streams, it will generate flashing green output:
>> https://github.com/amzn/exoplayer-amazon-port/issues/58
>>
>
Amazon has verified this bug and says they are waiting on a vendor driver
update to resolve it.

<https://github.com/amzn/exoplayer-amazon-port/issues/58>
>>
>> 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).
>>
>
> The green screen issue is definitely hardware specific, but this freezing
> issue may actually be an ffmpeg bug.
>

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.

Since this seems like some sort of race condition, one thing to try would
be adjusting the timeouts used when dequeuing input/output buffers:
https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/mediacodecdec_common.c#L84-L85

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.

Aman


> I recall that I've seen the freeze happen on other FireOS devices, like
> the older FireTV boxes.
>
> Further, none of these devices (including the new 4K stick) seem to
> reproduce the hang when using Exoplayer or VLC.
>
> However I'm not sure what ffmpeg could do differently to avoid this issue.
> The code in ffmpeg is already very similar to Exoplayer.
>
> 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.
>
> If anyone wants to spend time on this I'm happy to advise, but I have
> given up on trying to fix this myself.
>
> Aman
>
>
>> These are issues in the underlying codec/hardware/OS and not something
>> ffmpeg can work-around.
>>
>> Aman
>>
>>
>>>
>>> I have set ffmpeg debug logging and captured the log. That is here ->
>>> https://pastebin.com/ZF9JiMTX
>>> The code where we process packets is here ->
>>>
>>> https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686
>>>
>>> Peter
>>>
>>
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 12/5/18 6:13 PM, Aman Gupta wrote:
> 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.
>
I have been running mediacodec playing h264 video on a fire stick 4K for
a few hours each day for a couple of weeks and I have not seen any freeze.

Peter
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Wed, Dec 5, 2018 at 4:01 PM Peter Bennett <pb.mythtv@gmail.com> wrote:

>
>
> On 12/5/18 6:13 PM, Aman Gupta wrote:
> > 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.
> >
> I have been running mediacodec playing h264 video on a fire stick 4K for
> a few hours each day for a couple of weeks and I have not seen any freeze.


Good to know. It's possible the h264 freezes are happening only in the UK
with interlaced h264.

Are you experiencing freezes on mpeg2 decoding right away or several
minutes after playback begins?

Aman



>
> Peter
>
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 12/6/18 1:01 PM, Aman Gupta wrote:
>
> On Wed, Dec 5, 2018 at 4:01 PM Peter Bennett <pb.mythtv@gmail.com
> <mailto:pb.mythtv@gmail.com>> wrote:
>
>
>
> On 12/5/18 6:13 PM, Aman Gupta wrote:
> > 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.
> >
> I have been running mediacodec playing h264 video on a fire stick
> 4K for
> a few hours each day for a couple of weeks and I have not seen any
> freeze.
>
>
> Good to know. It's possible the h264 freezes are happening only in the
> UK with interlaced h264.
>
> Are you experiencing freezes on mpeg2 decoding right away or several
> minutes after playback begins?
>
> Aman
>
>
>
mpeg2 decoding freezes immediately I start playing. I may see one or two
frames, but no more than that.

Peter
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Thu, Dec 6, 2018 at 1:52 PM Peter Bennett <pb.mythtv@gmail.com> wrote:

>
>
> On 12/6/18 1:01 PM, Aman Gupta wrote:
>
>
> On Wed, Dec 5, 2018 at 4:01 PM Peter Bennett <pb.mythtv@gmail.com> wrote:
>
>>
>>
>> On 12/5/18 6:13 PM, Aman Gupta wrote:
>> > 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.
>> >
>> I have been running mediacodec playing h264 video on a fire stick 4K for
>> a few hours each day for a couple of weeks and I have not seen any freeze.
>
>
> Good to know. It's possible the h264 freezes are happening only in the UK
> with interlaced h264.
>
> Are you experiencing freezes on mpeg2 decoding right away or several
> minutes after playback begins?
>
> Aman
>
>
>
> mpeg2 decoding freezes immediately I start playing. I may see one or two
> frames, but no more than that.
>

Interesting, in my testing it decodes fine for 20-40minutes before locking
up. However I am using Surface-based (zero-copy) rendering.


>
> Peter
>
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 07/12/2018 00:40, Aman Gupta wrote:
>
> On Thu, Dec 6, 2018 at 1:52 PM Peter Bennett <pb.mythtv@gmail.com
> <mailto:pb.mythtv@gmail.com>> wrote:
>
>
>
> On 12/6/18 1:01 PM, Aman Gupta wrote:
>>
>> On Wed, Dec 5, 2018 at 4:01 PM Peter Bennett <pb.mythtv@gmail.com
>> <mailto:pb.mythtv@gmail.com>> wrote:
>>
>>
>>
>> On 12/5/18 6:13 PM, Aman Gupta wrote:
>> > 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.
>> >
>> I have been running mediacodec playing h264 video on a fire
>> stick 4K for
>> a few hours each day for a couple of weeks and I have not seen
>> any freeze.
>>
>>
>> Good to know. It's possible the h264 freezes are happening only in
>> the UK with interlaced h264.
>>
>> Are you experiencing freezes on mpeg2 decoding right away or
>> several minutes after playback begins?
>>
>> Aman
>>
>>
>>
> mpeg2 decoding freezes immediately I start playing. I may see one or
> two frames, but no more than that.
>
>
> Interesting, in my testing it decodes fine for 20-40minutes before
> locking up. However I am using Surface-based (zero-copy) rendering.
>
>
>
> Peter

I just retried my first (two weeks ago) tests of VLC with full
acceleration on a recording from BBC FOUR remuxed to a DVD-like mpg. As
before, playback was good for several minutes; then the video hung and
the sound played on.

Now mythfrontend is working well for me in the UK with the settings
recommended in the wiki and DVB-T/T2 material. I haven't recently tried
other settings.

John P

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 12/6/18 7:40 PM, Aman Gupta wrote:
> Interesting, in my testing it decodes fine for 20-40minutes before
> locking up. However I am using Surface-based (zero-copy) rendering.
>
Another topic - I need to change to direct rendering at some point. I
may have questions about that in future. The API seems to default to
copying frames to memory.

Peter
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Fri, Dec 7, 2018 at 7:27 AM Peter Bennett <pb.mythtv@gmail.com> wrote:

>
>
> On 12/6/18 7:40 PM, Aman Gupta wrote:
> > Interesting, in my testing it decodes fine for 20-40minutes before
> > locking up. However I am using Surface-based (zero-copy) rendering.
> >
> Another topic - I need to change to direct rendering at some point. I
> may have questions about that in future. The API seems to default to
> copying frames to memory.


It's pretty straightforward. I included an overview in
https://speakerdeck.com/tmm1/video-decoding-with-ffmpeg-on-ios-and-android


>
> Peter
>
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On Wed, Dec 5, 2018 at 3:13 PM Aman Gupta <aman@tmm1.net> wrote:

>
> On Wed, Nov 21, 2018 at 9:46 PM Aman Gupta <aman@tmm1.net> wrote:
>
>>
>> On Tue, Nov 20, 2018 at 2:32 PM Aman Gupta <aman@tmm1.net> wrote:
>>
>>>
>>>
>>> On Tue, Nov 20, 2018 at 2:28 PM Peter Bennett <pb.mythtv@gmail.com>
>>> wrote:
>>>
>>>> Hi Aman
>>>>
>>>> When running with mediacodec on the fire stick 4K, there is a problem
>>>> with MPEG2. Perhaps the 4K does not support MPEG2 or the interlacing is
>>>> causing a problem. What appears to happen is that we get the situation
>>>> where we have done avcodec_send_packet until it returns
>>>> AVERROR(EAGAIN).
>>>> The avcodec_receive_frame also returns AVERROR(EAGAIN) and this
>>>> continues forever, we never get a frame out of it. With h264 it works
>>>> fine. If there is no MPEG2 support, maybe we should get an error return
>>>> or it should revert to software decoding. Is there anything ffmpeg can
>>>> do to avoid this, or do I have something wrong in my code?
>>>>
>>>
>>> The hardware mpeg2 decoder on that device is extremely buggy.
>>>
>>> For some interlaced streams, it will generate flashing green output:
>>> https://github.com/amzn/exoplayer-amazon-port/issues/58
>>>
>>
> Amazon has verified this bug and says they are waiting on a vendor driver
> update to resolve
>

I'm hearing that this green flash issue is fixed in the latest FireOS
update.

it.
>
> <https://github.com/amzn/exoplayer-amazon-port/issues/58>
>>>
>>> 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).
>>>
>>
>> The green screen issue is definitely hardware specific, but this freezing
>> issue may actually be an ffmpeg bug.
>>
>
> 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.
>
> Since this seems like some sort of race condition, one thing to try would
> be adjusting the timeouts used when dequeuing input/output buffers:
>
> https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/mediacodecdec_common.c#L84-L85
>
> 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.
>
> Aman
>
>
>> I recall that I've seen the freeze happen on other FireOS devices, like
>> the older FireTV boxes.
>>
>> Further, none of these devices (including the new 4K stick) seem to
>> reproduce the hang when using Exoplayer or VLC.
>>
>> However I'm not sure what ffmpeg could do differently to avoid this
>> issue. The code in ffmpeg is already very similar to Exoplayer.
>>
>> 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.
>>
>> If anyone wants to spend time on this I'm happy to advise, but I have
>> given up on trying to fix this myself.
>>
>> Aman
>>
>>
>>> These are issues in the underlying codec/hardware/OS and not something
>>> ffmpeg can work-around.
>>>
>>> Aman
>>>
>>>
>>>>
>>>> I have set ffmpeg debug logging and captured the log. That is here ->
>>>> https://pastebin.com/ZF9JiMTX
>>>> The code where we process packets is here ->
>>>>
>>>> https://github.com/MythTV/mythtv/blob/a1349d7f535dfcc5993a1f515e4ee2cb257e3aa6/mythtv/libs/libmythtv/avformatdecoder.cpp#L3686
>>>>
>>>> Peter
>>>>
>>>
Re: Mediacodec problem with fire stick 4K [ In reply to ]
On 12/15/18 2:46 PM, Aman Gupta wrote:
>
> On Fri, Dec 7, 2018 at 7:27 AM Peter Bennett <pb.mythtv@gmail.com
> <mailto:pb.mythtv@gmail.com>> wrote:
>
>
>
> On 12/6/18 7:40 PM, Aman Gupta wrote:
> > Interesting, in my testing it decodes fine for 20-40minutes before
> > locking up. However I am using Surface-based (zero-copy) rendering.
> >
> Another topic - I need to change to direct rendering at some point. I
> may have questions about that in future. The API seems to default to
> copying frames to memory.
>
>
> It's pretty straightforward. I included an overview in
> https://speakerdeck.com/tmm1/video-decoding-with-ffmpeg-on-ios-and-android
>
>
>
> Peter
>
Thank you Aman that will be very helpful.
Peter