iOS ff-h264-vtb (HW) vs ff-h264 (SW) Decoding
#1
I'm running Kodi 17.6 (Arm64) on an iPad Air with iOS 11.1.1.  For some unknown reason, some of my H.264 video files are decoded with ff-h264 software decoder; while some of my other H.264 video files are decoded with ff-h264-vtb hardware accelerated decoder.  Is there any way that I can force Kodi to use hardware decoder on all my H.264 videos?  

Before I upgraded my iPad to iOS 11.1.1, it was running iOS 8.x and I had an older version of Kodi installed at that time (don't remember which Kodi version).  All my H.264 video files were decoded with hardware acceleration.  The strange thing is some of the video files can no longer use hardware decode after iOS & Kodi version upgrade.  Does anyone know how to force Kodi to do hardware decode on all H.264 videos?
Reply
#2
You can’t force it - there is a reason why the ffmpeg thinks it can’t use hw decoder. Even if this worked in an older Kodi version. We are now using the ffmpeg hw decoder which moves the support burden away from us to ffmpeg.
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#3
(2018-03-25, 17:34)Memphiz Wrote: You can’t force it - there is a reason why the ffmpeg thinks it can’t use hw decoder. Even if this worked in an older Kodi version. We are now using the ffmpeg hw decoder which moves the support burden away from us to ffmpeg.
[EDIT]
Sorry for the newbie question.  I thought ffmpeg is a software decoder.  I'm not sure what you meant by "We are now using the ffmpeg hw decoder".  Are you saying you're now using iOS H.264 hardware decoder for all H.264 videos?
Reply
#4
ffmpeg supports hardware decoding for multiple platforms. We are using this on iOS now. Before we had to interact with the operating system directly - now we can use some common ffmpeg code instead. There are h.264 Encoder settings that can prevent the usage of the hardware decoder. Interlaced content for example will always fall back to software decoding...
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#5
Thanks a lot for your clarification.  Since the ffmpeg is responsible for interfacing directly with the iOS hardware decoder, I think it will be possible to modify the ffmpeg source code to force the use of hardware decoder for all H.264 videos.  Previously, all my H.264 videos were working properly with the older Kodi using hardware decoder.  I beleive this approach should theoretically work on my video files, even though it may break some other H.264 videos.  Please correct me if I am wrong before I dig into the source code.  Thanks again for your support.
Reply
#6
If those worked with our decoder than it’s logical that the ffmpeg vtb decoder can be forced somehow from within the code ... but you should take a look at our interface side first:

https://github.com/xbmc/xbmc/blob/master...B.cpp#L203

If it’s a false positive on interlaced then you should see a printout in the log ... everything that returns false on our side of things would mean fallback to sw decide ... if it’s not our side - then it’s inside ffmpeg
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#7
You're my saviour.  That was the exact problem.  The CDecoder::Open function mistakenly thought the video is interlaced and return false.  I simply commented out the return statement and my previous problematic videos played flawless again with hardware decoder.  Mediainfo listed the Scan Type as "MBAFF" and I guess Kodi thinks it's interlaced.  Searching the term MBAFF reveals that it's a way to encode interlaced video in H.264, but does not say whether the content is actually interlaced or progressive.  In my case, the content is progressive, but encoded as MBAFF.

I've also tested some H.264 interlaced video on the modded Kodi and as expected they failed to play since the iOS hardware decoder couldn't handle.  The interesting thing is my previous version of Kodi from a few years ago can distinguish all these and called up the hardware decoder appropriately.  Maybe we can borrow some of the detection code from it.  Let me if you've any hints in tackling this.  Many thanks again for your kind assistance.

[EDIT]
I've made some changes to the interlaced detection code in the function CBitstreamConverter::parseh264_sps.  I've tested on all my H.264 video files, including interlaced video and it seems to work fine.  
Code:
//*interlaced = !sps_info.frame_mbs_only_flag;
if (!sps_info.frame_mbs_only_flag &&  !sps_info.mb_adaptive_frame_field_flag)
    *interlaced = true;
  else
    *interlaced = false;
Reply
#8
Are you able to do a pull request with this? If not at least a sample that triggers the false detection would be nice (50mb max via drop box for example). In the latter case I could forward that to our video player developer who can find a proper fix aswell Smile

Thx for working on this - you are the first dev since what feels like ages that really touches code for iOS beside me Smile
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#9
From the old CDVDVideoCodecVDA (pulled from the h264 spec)
  how to detect the interlacing used on an existing stream:- progressive is signalled by setting   frame_mbs_only_flag: 1 in the SPS.- interlaced is signalled by setting   frame_mbs_only_flag: 0 in the SPS and   field_pic_flag: 1 on all frames.- paff is signalled by setting   frame_mbs_only_flag: 0 in the SPS and   field_pic_flag: 1 on all frames that get interlaced and   field_pic_flag: 0 on all frames that get progressive.- mbaff is signalled by setting   frame_mbs_only_flag: 0 in the SPS and   mb_adaptive_frame_field_flag: 1 in the SPS and   field_pic_flag: 0 on the frames,   (field_pic_flag: 1 would indicate a normal interlaced frame).
Reply
#10
I'm not an expert in video encoding/decoding, so I don't know if this is a proper fix.  I tried to PM you a download link to a test clip, but it says I don't have permission.  If you can provide me an email address, I can send the clip to you directly (around 2MB in size). 

BTW, I've tested the changes on Kodi 17.6 official release and it worked well on all my H.264 videos, including interlaced ones.  I've also tried the changes on the latest Kodi repo source, but I've encountered various problems which may be caused by the unstable status of the latest source code.
Reply
#11
My nickname @kodi.tv
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#12
(2018-03-28, 17:46)phantom8 Wrote: I'm not an expert in video encoding/decoding, so I don't know if this is a proper fix.  I tried to PM you a download link to a test clip, but it says I don't have permission.  If you can provide me an email address, I can send the clip to you directly (around 2MB in size). 

BTW, I've tested the changes on Kodi 17.6 official release and it worked well on all my H.264 videos, including interlaced ones.  I've also tried the changes on the latest Kodi repo source, but I've encountered various problems which may be caused by the unstable status of the latest source code.
 I'd also like to get a sample as I've been looking for one for this very thing.  My nickname @mrmc.tv
Reply
#13
I've emailed the clips to you both.  Thanks a lot for taking the time to look into the issue.
Reply
#14
Thanks for sample, I'll cycle in some time to check it out.
Reply
#15
this should fix it: https://github.com/xbmc/xbmc/pull/13711
Reply

Logout Mark Read Team Forum Stats Members Help
ff-h264-vtb (HW) vs ff-h264 (SW) Decoding0