Jump to content

How to make emby transcode ac4 when using embyforkodi 7.x?


randallspicher

Recommended Posts

randallspicher

I've recently added Emby to my environment, mostly to use it's DVR functionality to replace tvheadend, especially with my new silocondust HR that supports the new ATSC3.0 broadcasting standard.

I've managed to get it working, and emby is transcoding the ac4 audio on other devices/clients (when needed), but I have had no luck figuring out how to get it to transcode it when sending to the kodi plugin. On my current kodi setup, it's likely I *only* need ac4 transcoded, but I've got other kodi devices (such as kodi on my android tablet) that may have different capabilities.

As far as I can figure out, I should be using (in some fashion) the DLNA profiles to accomplish this,  But nothing I've done on them has had any effect on what the emby plugin plays. The server always says it's streaming the video and audio as direct to the kodi device, and it gives no indication what dlna profile it even is using.

And, from looking at the debug  Emby logs, I'm not seeing any of the various "identification" parameters on the url from the kodi plugin that all the other Emby clients seem to send when connecting, so I'm not clear what the proper values would even be used to identify the kodi device in the profile.  I've tried overriding the generic profile to make everything transcode, but that doesn't seem to work either.

I'm stumped as to how to get this working.

The documentation for how to set up DLNA profiles is, as far as I can tell, non-existent, so I'm not sure what half the settings are even for or what they do or the valid values to add to them.  And I'm not clear if the embyforkodi plugin actually connects to the emby server the way other Emby clients do, and if DLNA profiles would even work for it.

Anyone have any hints?  (I assume someone must have done this before)

Thanks.

 

 

 

Link to comment
Share on other sites

quickmic

Next-gen has its own transconding options. Look into the plugin setting -> playback -> scroll down to transcoding. Probably I need to add an addition option for ac4, but have a look.

 

Edited by quickmic
Link to comment
Share on other sites

randallspicher

All I see are settings to force transcoding for video  I don't actually need or want to transcode the video, that plays fine as-is, and I want it to play that direct.  And even when setting every one of those transcoding settings to "on", live TV still streams both audio and video direct without attempting to transcode anything.. What I need to transcode (in this case) is a particular audio codec that the device (eg, Kodi) cannot handle. And on other devices, such as my android tablet or the kodi box on a different TV that doesn't' have a fancy AVR attached,  I'd may need to be able to blacklist other audio codecs (or video codecs) which that TV/Receiver combo can't handle (for example dts for my upstairs TV).   I'd even be OK with editing advancedsettings.xml (or some other xml config) to configure a whitelist/blacklist of codecs/containers.  

All the stand-alone Emby apps seem to be able to manage it (I assume via DLNA profiles).  Currently, I need to resort to the using the Roku for half the channels I watch because Emby will transcode the audio for that, and I hate using the Roku....

 

 

 

 

Link to comment
Share on other sites

quickmic
Quote

All the stand-alone Emby apps seem to be able to manage it (I assume via DLNA profiles).

They use a different approach as next-gen. I can add a ac4 transcode option, but this will take some re-designs in the plugin.

btw, do you have a sample ac4 file for me (just a small one)? I need to know, how Emby server reports that kind of format via API.

Link to comment
Share on other sites

quickmic

If you want, you can try this version. It's EXPERIMENTAL and not all edge cases are tested yet, but I completely re-wrote the transencoding options.

According to my tests, ac4 can only be transcoded by ffmpeg 5.1 or higher (not sure about hardware encoders -> cuda etc.). I used Emby server's beta versions to make it working (actually also works with ffmpeg's from beta copied in stable version).

However, if you use an Emby server beta version, don't use versions higher than 4.8.0.19.

DON'T USE 4.8.0.21 due to an performance issue!

Also a (Kodi) database resync is mandatory.

If you are patching/updating Emby server, take a COMPELTE backup before you fiddle around! It's your risk!

plugin.video.emby-next-gen-7.14.0-build 12.zip

Link to comment
Share on other sites

randallspicher

I'll give the updates plugin a try.

I'm running it from a docker container:     image: emby/embyserver

Which appears to be running Emby ver. 4.7.11.0

The transcode logs say the container is running ffmpeg version 5.0.0-emby_2022_05_27-u1, and it is trancoding ac4 to acc and/or ac3 when sending to my roku or samsung tv.  

I've also managed to get it to transcode the atsc3 live streams to kodi via the api urls, but only for short bursts (only plays for about 5 or 6 seconds)  I assume I'd need one of the mpu8 based api calls to get continuous play, but have not figured out how to get any of them to work at all, only the streams.ts call seems to play in my tests, (I"m wondering how accurate/up-to-date the documentation for the api is)

http://192.168.1.2:8096/emby/Videos/424517/stream.ts?api_key=<myapikey>&AudioCodec=aac&MaxAudioChannels=6

 

Edited by randallspicher
Link to comment
Share on other sites

quickmic
28 minutes ago, randallspicher said:

http://192.168.1.2:8096/emby/Videos/424517/stream.ts?api_key=<myapikey>&AudioCodec=aac&MaxAudioChannels=6

 

I think you should use hls streams. next-gen uses them for transcoding.

e.g.

http://‌‍‍192.168.0.207‌/emby/videos/4257/master.m3u8?TranscodeReasons=ContainerBitrateExceedsLimit&VideoCodec=h264&AudioCodec=ac3&VideoBitrate=664000&AudioBitrate=128000&MediaSourceId=b298c1adfd2472ebb676202dc81ca17a&PlaySessionId=b95821fc2c82427da2d61978e4c1afd1&DeviceId=1e1e9cd5-3650-4d1b-b04a-9032eb57675d&=71__2014_.mkv

btw.

artwork cache is broken in 7.14.0

Edited by quickmic
Link to comment
Share on other sites

randallspicher

I bumped my Emby server up to use the 4.8.0.19 beta docker image and updated to your latest modified plugin, and turned on transcoding for ac4 in it.

On Live TV it has no effect, and Emby is still just sending the raw TS stream.  Even after telling the plugin to transcode HEVC, and setting a low bitrate (3.7, lower than the reported rate for the whole TS stream), Emby seems to just forward the raw TS feed without even looking at it's contents.

Emby for Kodi Next Gen 7.14.0
osmc2
192.168.1.11 http/1.1
Stream
TS (4 mbps 61 fps)

 

The Samsung TV app is using HLS and transcoding  like this:

Emby for Samsung 1.2.6
Samsung Smart TV (UN65NU800D)
192.168.1.30 http/1.1
Stream
HLS (15 mbps 60 fps)
Reducing bitrate due to quality setting
Video
1080p HEVC
Transcode (H264 15 mbps)
Audio
Spanish AC4 stereo
Transcode (AAC 192 kbps)

 

(both of those are the same ATSC3 channel playing at the same time).  I have no idea why emby reports the "Spanish" audio stream,as it's actually playing the 5.1 English one.

I've also tried recording a show from the ATSC3 channel, but kodi is just hanging when I attempt to play the recording.

When trying to play the recording, it shows this in the logs:

2023-01-05 20:54:33.199 T:12391    INFO <general>: VideoPlayer::OpenFile: http://127.0.0.1:57342/dynamic/e-9be101b2499e427dae14f9ab5024f7bc-754011-e5b471a49f3dffe5b43bdedcb8e53ebb-0-0-0-1-0-0-0-0-hevc-4925416-ac4-None-Great_Day_Connecticut__2021-09-13.ts
2023-01-05 20:54:33.201 T:28979    INFO <general>: Creating InputStream
2023-01-05 20:54:33.208 T:28982   ERROR <general>: Exception ignored in thread started by
2023-01-05 20:54:33.208 T:28982   ERROR <general>: :
2023-01-05 20:54:33.208 T:28982   ERROR <general>: <function worker_Query at 0xcb49e4a8>
2023-01-05 20:54:33.208 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.208 T:28982   ERROR <general>: Traceback (most recent call last):
                                                   
2023-01-05 20:54:33.208 T:28982   ERROR <general>:   File "/home/osmc/.kodi/addons/plugin.video.emby-next-gen/hooks/webservice.py", line 236, in worker_Query
                                                   
2023-01-05 20:54:33.219 T:28982   ERROR <general>:     
2023-01-05 20:54:33.219 T:28982   ERROR <general>: http_Query(client, IncomingData[1], IncomingData[0])
2023-01-05 20:54:33.219 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.219 T:28982   ERROR <general>:   File "/home/osmc/.kodi/addons/plugin.video.emby-next-gen/hooks/webservice.py", line 323, in http_Query
                                                   
2023-01-05 20:54:33.220 T:28982   ERROR <general>:     
2023-01-05 20:54:33.220 T:28982   ERROR <general>: QueryData = GetParametersFromURLQuery(Payload)
2023-01-05 20:54:33.220 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.220 T:28982   ERROR <general>:   File "/home/osmc/.kodi/addons/plugin.video.emby-next-gen/hooks/webservice.py", line 707, in GetParametersFromURLQuery
                                                   
2023-01-05 20:54:33.223 T:28982   ERROR <general>:     
2023-01-05 20:54:33.223 T:28982   ERROR <general>: QueryData.update({'MediasourceID': Data[3], 'KodiId': Data[4], 'KodiFileId': Data[5], 'ExternalSubtitle': Data[6], 'MediasourcesCount': int(Data[7]), 'IntroStartPositionTicks': int(Data[8]), 'IntroEndPositionTicks': int(Data[9]), 'CreditsPositionTicks': int(Data[10]), 'Remote': int(Data[11]), 'VideoCodec': Data[12], 'VideoBitrate': int(Data[13]), 'AudioCodec': Data[14], 'AudioBitrate': int(Data[15]), 'Filename': Data[16]})
2023-01-05 20:54:33.223 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.223 T:28982   ERROR <general>: ValueError
2023-01-05 20:54:33.223 T:28982   ERROR <general>: :
2023-01-05 20:54:33.223 T:28982   ERROR <general>: invalid literal for int() with base 10: 'None'
2023-01-05 20:54:33.223 T:28982   ERROR <general>:

 

 

Edited by randallspicher
add some error messages
Link to comment
Share on other sites

quickmic
5 hours ago, randallspicher said:

I bumped my Emby server up to use the 4.8.0.19 beta docker image and updated to your latest modified plugin, and turned on transcoding for ac4 in it.

On Live TV it has no effect, and Emby is still just sending the raw TS stream.  Even after telling the plugin to transcode HEVC, and setting a low bitrate (3.7, lower than the reported rate for the whole TS stream), Emby seems to just forward the raw TS feed without even looking at it's contents.

Emby for Kodi Next Gen 7.14.0
osmc2
192.168.1.11 http/1.1
Stream
TS (4 mbps 61 fps)

 

The Samsung TV app is using HLS and transcoding  like this:

Emby for Samsung 1.2.6
Samsung Smart TV (UN65NU800D)
192.168.1.30 http/1.1
Stream
HLS (15 mbps 60 fps)
Reducing bitrate due to quality setting
Video
1080p HEVC
Transcode (H264 15 mbps)
Audio
Spanish AC4 stereo
Transcode (AAC 192 kbps)

 

(both of those are the same ATSC3 channel playing at the same time).  I have no idea why emby reports the "Spanish" audio stream,as it's actually playing the 5.1 English one.

I've also tried recording a show from the ATSC3 channel, but kodi is just hanging when I attempt to play the recording.

When trying to play the recording, it shows this in the logs:

2023-01-05 20:54:33.199 T:12391    INFO <general>: VideoPlayer::OpenFile: http://127.0.0.1:57342/dynamic/e-9be101b2499e427dae14f9ab5024f7bc-754011-e5b471a49f3dffe5b43bdedcb8e53ebb-0-0-0-1-0-0-0-0-hevc-4925416-ac4-None-Great_Day_Connecticut__2021-09-13.ts
2023-01-05 20:54:33.201 T:28979    INFO <general>: Creating InputStream
2023-01-05 20:54:33.208 T:28982   ERROR <general>: Exception ignored in thread started by
2023-01-05 20:54:33.208 T:28982   ERROR <general>: :
2023-01-05 20:54:33.208 T:28982   ERROR <general>: <function worker_Query at 0xcb49e4a8>
2023-01-05 20:54:33.208 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.208 T:28982   ERROR <general>: Traceback (most recent call last):
                                                   
2023-01-05 20:54:33.208 T:28982   ERROR <general>:   File "/home/osmc/.kodi/addons/plugin.video.emby-next-gen/hooks/webservice.py", line 236, in worker_Query
                                                   
2023-01-05 20:54:33.219 T:28982   ERROR <general>:     
2023-01-05 20:54:33.219 T:28982   ERROR <general>: http_Query(client, IncomingData[1], IncomingData[0])
2023-01-05 20:54:33.219 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.219 T:28982   ERROR <general>:   File "/home/osmc/.kodi/addons/plugin.video.emby-next-gen/hooks/webservice.py", line 323, in http_Query
                                                   
2023-01-05 20:54:33.220 T:28982   ERROR <general>:     
2023-01-05 20:54:33.220 T:28982   ERROR <general>: QueryData = GetParametersFromURLQuery(Payload)
2023-01-05 20:54:33.220 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.220 T:28982   ERROR <general>:   File "/home/osmc/.kodi/addons/plugin.video.emby-next-gen/hooks/webservice.py", line 707, in GetParametersFromURLQuery
                                                   
2023-01-05 20:54:33.223 T:28982   ERROR <general>:     
2023-01-05 20:54:33.223 T:28982   ERROR <general>: QueryData.update({'MediasourceID': Data[3], 'KodiId': Data[4], 'KodiFileId': Data[5], 'ExternalSubtitle': Data[6], 'MediasourcesCount': int(Data[7]), 'IntroStartPositionTicks': int(Data[8]), 'IntroEndPositionTicks': int(Data[9]), 'CreditsPositionTicks': int(Data[10]), 'Remote': int(Data[11]), 'VideoCodec': Data[12], 'VideoBitrate': int(Data[13]), 'AudioCodec': Data[14], 'AudioBitrate': int(Data[15]), 'Filename': Data[16]})
2023-01-05 20:54:33.223 T:28982   ERROR <general>:
                                                   
2023-01-05 20:54:33.223 T:28982   ERROR <general>: ValueError
2023-01-05 20:54:33.223 T:28982   ERROR <general>: :
2023-01-05 20:54:33.223 T:28982   ERROR <general>: invalid literal for int() with base 10: 'None'
2023-01-05 20:54:33.223 T:28982   ERROR <general>:

 

 

I'll check if transcoding is possible for live TV. At least it will be tricky, I think Emby server has not Mediastream infos available for Live TV.

Second issue, I'll fix it. Actually the issue comes from a (not detected) Audio bitrate for your ac4 file. Not a showstopper, but also not nice.

Link to comment
Share on other sites

randallspicher
18 hours ago, quickmic said:

I'll check if transcoding is possible for live TV. At least it will be tricky, I think Emby server has not Mediastream infos available for Live TV.

The stand alone apps (Samsung TV [tizun os], Roku, and Android) all transcode the live tv, and appear to pull them as hls streams. while the Kodi plugin is grabbing it as a .ts stream. My guess is that by grabbing the raw ts stream it's bypassing Emby's transcoder logic.

 

Link to comment
Share on other sites

randallspicher
14 hours ago, quickmic said:

Added additional options in transcoding menu for livetv.

That works, and it can now transcode the ac4 audio of atsc3 live streams.  Good job !

However, there is one complication:  All the audio is only on the left channel, except for some commercials.  Which I believe is caused by it always picking the "Spansh 2ch (SAP)" audio stream, rather than the 5.1ch English one.  (it appears the 5.1 English is always the second available audio-stream on atsc3 channels)  Ideally, it would still report to kodi that there are multiple audio streams available, so that the user could switch between them. (atsc3 standard is supposed allow for multiple audio streams, including Atmos)

 

Also, recordings from the atsc3 channels still error out when trying to play.  Although presumably with recordings I can just set emby up to auto-convert them afterwards somehow.


ERROR <general>: Open - Error, could not open file http://127.0.0.1:57342/dynamic/e-9be101b2499e427dae14f9ab5024f7bc-771592-92fc973375ac3669481e091115faa8a4-0-0-0-1-0-0-0-0-hevc-4763650-ac4-0-Eyewitness_News_at_5_00pm_2023_01_06_17_00_00.ts

atsc1 based recordings all play fine however.

INFO <general>: VideoPlayer::OpenFile: http://127.0.0.1:57342/dynamic/e-9be101b2499e427dae14f9ab5024f7bc-771612-088fcb73dcbb199ce3b8af6e5246df0b-0-0-0-1-0-0-0-0-mpeg2video-7003066-ac3-448000-FOX_61_News_at_6_30_2023_01_06_18_30_00.ts

 

Link to comment
Share on other sites

quickmic
8 hours ago, randallspicher said:

However, there is one complication:  All the audio is only on the left channel, except for some commercials.  Which I believe is caused by it always picking the "Spansh 2ch (SAP)" audio stream, rather than the 5.1ch English one.  (it appears the 5.1 English is always the second available audio-stream on atsc3 channels)  Ideally, it would still report to kodi that there are multiple audio streams available, so that the user could switch between them. (atsc3 standard is supposed allow for multiple audio streams, including Atmos)

That's not that easy for live TV. Are you using Emby server on Linux? The Emby server ffmpeg transcoding script must be patched.

Edited by quickmic
Link to comment
Share on other sites

randallspicher

I'm running off the docker image,  https://hub.docker.com/layers/emby/embyserver/4.8.0.19/images/sha256-b21d8bee904ea9b2dac1ff1067653d4eac25652ca49c42d94923f58621386ddb?context=explore

Which appears to be a stripped-down version of ubuntu

Do you mean I'd need to patch and recompile ffmpeg?  or are you referring to a shell script that needs patched?

I've managed to figure out the api url for an HLS stream (after adding the PlaySessionId param which is not mentioned in the documentation)

http://192.168.1.3:8096/emby/Videos/424518/live.m3u8?AudioCodec=aac,ac3&Static=false&AudioStreamIndex=1&api_key=<my key>&Container=ts&PlaySessionId=3&AudioChannels=5

However, no matter which AudioStreamIndex I tell it to play, it always returns the spanish/alternate audio, rather than the primary audio.    Is there some other way to flag which audio stream I want back?

 

 

 

Link to comment
Share on other sites

quickmic

 

You need to find the ffmpeg file Emby server uses for transencoding.

This ffmpeg could already be a shell script (It was in my setup).

If so, you need to patch it.

If not, you need to rename the ffmpeg binary file to something else, create a script file with the ffmpg filename.

Transcoding trigger should work this way: Emby Server -> bash script -> ffmpeg binary.

 

The patched scripts in the link above is NOT copy paste. You need to adjust the paths.

Link to comment
Share on other sites

quickmic
4 hours ago, randallspicher said:

 

http://192.168.1.3:8096/emby/Videos/424518/live.m3u8?AudioCodec=aac,ac3&Static=false&AudioStreamIndex=1&api_key=<my key>&Container=ts&PlaySessionId=3&AudioChannels=5

 

 

I think this is used by Emby server "internally".

For Live TV I still use the stream API.

videos/%s/stream?static=true

or

videos/%s/stream.ts?VideoCodec=%s&AudioCodec=%s

optional parameters are: PlaySessionId, DeviceId

for regular content I use the Dynamic HLS service:

/Videos/{Id}/master.m3u8

 

 

Your AudioCodec parameter is wrong. This is the target codec and cannot be both. Also include the VideoCodec parameter. If not, Emby server transencode this one too with some default codec settings.

If you wannakeep the video stream, use  VideoCodec=copy

Actually, Emby server uses the ffmpeg parameters and maps them.

If you really wanna know what Emby is doing, review the Emby transcoding logs and study the  docu:

https://ffmpeg.org/ffmpeg.html

 

 

What my patched script is does, is removing the mapping parameters from ffmpeg. Those are used to select the streams.

e.g.

regular Emby server ffmpeg transcoding parameters:

-loglevel +timing -y -print_graphs_file /opt/programdata/logs/ffmpeg-transcode-8672e96f-a786-44ad-ae5d-dfe19f02e6e2_1graph.txt -copyts -start_at_zero -analyzeduration 3000000 -f mpegts -c:v:0 h264 -user_agent VLC/3.0.0-git LibVLC/3.0.0-git -i http://127.0.0.1:80/LiveTv/LiveStreamFiles/9cc1ff9f6974485c99d56f8db5d0ab1a/stream.ts -map 0:0 -map 0:1 -sn -c:v:0 copy -c:a:0 copy -metadata:s:a:0 language=ger -disposition:a:0 default -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 /opt/programdata/transcoding-temp/043701/043701.ts

 

 

patched:

-loglevel +timing -y -print_graphs_file /opt/programdata/logs/ffmpeg-transcode-8672e96f-a786-44ad-ae5d-dfe19f02e6e2_1graph.txt -copyts -start_at_zero -analyzeduration 3000000 -f mpegts -c:v:0 h264 -user_agent VLC/3.0.0-git LibVLC/3.0.0-git -i http://127.0.0.1:80/LiveTv/LiveStreamFiles/9cc1ff9f6974485c99d56f8db5d0ab1a/stream.ts -map 0:a -map 0:v -sn -c:v:0 copy -c:a copy -metadata:s:a:0 language=ger -disposition:a:0 default -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 /opt/programdata/transcoding-temp/043701/043701.ts

 

"-map 0:0 -map 0:1" is Emby's stream selection. Usually 0:0 is the video stream, and 0:1 the first audio stream. Depends on the content file.

-map 0:0 -map 0:1 -map 0:2 would be video + two audio streams etc.

The patch replaces them with -map 0:a -map 0:v which means all audio and all video streams are selected.

Also patched -c:a:0 and the -ab:a:0

I think you got the concept, also the patches are just a proof of concept and could have bugs (uncovered cases).

 

Finally, try this version. I fixed the liveTV when played in without transcoding. (-> it transcoded the container format to ts if it shouldn't)

 

 

 

 

plugin.video.emby-next-gen-7.14.0-build 20.zip

Edited by quickmic
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...