jellyfin / jellyfin

The Free Software Media System
https://jellyfin.org
GNU General Public License v2.0
30.97k stars 2.86k forks source link

[Issue]: 10.9.x has large audio delay when watching HDHomeRun over-the-air streams #11723

Closed therumbler closed 1 week ago

therumbler commented 2 weeks ago

Please describe your bug

Since updating to 10.9.x all live TV streams from my HDHomeRun Extend (model: HDTC-2US) have audio delayed by 5 seconds. This happens in Safari and in Chrome.

I've tested both on Ubuntu 22.04.4 (direct install of Jellyfin) and on my Apple laptop using Docker.

Reproduction Steps

To reproduce I ran this docker compose:

---
services:
  jellyfin:
    image: jellyfin/jellyfin:10.9.0
    container_name: jellyfin
    user: 1000:1000
    ports:
      - 8096:8096

once setup with user/password i added my HDHomeRun IP address, and attempted streaming an over-the-air channel. the audio was delayed by almost 5 seconds.

Changing the compose file to use jellyfin/jellyfin:10.8.13 made the streams work perfectly, without audio delay

I did a diff on the ffmpeg command between 10.8.13 and 10.9.0. See below:

> -probesize 1G \
5c6
< -autorotate 0 \
---
> -noautorotate \
20,21d20
< -flags \
< -global_header \
24c23
< -ab 384000 \
---
> -ab 256000 \
32c31,32
< -hls_segment_type mpegts \
---
> -hls_segment_type fmp4 \
> -hls_fmp4_init_filename "91893804987efb6f8e99b63390ab0ac5-1.mp4" \
35c35
< -hls_segment_filename "./transcodes/d07204f3d4840041439162be3e398415%d.ts" \
---
> -hls_segment_filename "./transcodes/91893804987efb6f8e99b63390ab0ac5%d.mp4" \
38c38
< -y "./transcodes/d07204f3d4840041439162be3e398415.m3u8"
---
> -y "./transcodes/91893804987efb6f8e99b63390ab0ac5.m3u8"

Here are the full ffmpeg commands from 10.9 and 10.8. I ran both these commands directly on my laptop (homebrew ffmpeg version 6.1.1), and was able to reproduce the same issue (I ran python3 -m http.server to start a server in the HLS output directory, and streamed from http://127.0.0.1:8000/transcodes/91893804987efb6f8e99b63390ab0ac5.m3u8 )

10.8.13 (working)

ffmpeg \
-analyzeduration 3000000 \
-fflags +igndts \
-f mpegts \
-autorotate 0 \
-i "http://192.168.86.234:5004/auto/v2.1" \
-map_metadata -1 \
-map_chapters -1 \
-threads 0 \
-sn \
-codec:v:0 libx264 \
-preset superfast \
-crf 23 \
-maxrate 20000000 \
-bufsize 40000000 \
-x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none \
-force_key_frames:0 "expr:gte(t,n_forced*3)" \
-sc_threshold:v:0 0 \
-vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale=trunc(min(max(iw\,ih*a)\,min(1920\,1080*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(1920/a\,1080))/2)*2,format=yuv420p" \
-flags \
-global_header \
-codec:a:0 aac \
-ac 2 \
-ab 384000 \
-af "volume=2" \
-copyts \
-avoid_negative_ts disabled \
-max_muxing_queue_size 2048 \
-f hls \
-max_delay 5000000 \
-hls_time 3 \
-hls_segment_type mpegts \
-start_number 0 \
-hls_base_url "/transcodes/" \
-hls_segment_filename "./transcodes/d07204f3d4840041439162be3e398415%d.ts" \
-hls_playlist_type event \
-hls_list_size 0 \
-y "./transcodes/d07204f3d4840041439162be3e398415.m3u8"

10.9.0 (broken)

ffmpeg \
-analyzeduration 3000000 \
-probesize 1G \
-fflags +igndts \
-f mpegts \
-noautorotate \
-i "http://192.168.86.234:5004/auto/v2.1" \
-map_metadata -1 \
-map_chapters -1 \
-threads 0 \
-sn \
-codec:v:0 libx264 \
-preset superfast \
-crf 23 \
-maxrate 20000000 \
-bufsize 40000000 \
-x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none \
-force_key_frames:0 "expr:gte(t,n_forced*3)" \
-sc_threshold:v:0 0 \
-vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale=trunc(min(max(iw\,ih*a)\,min(1920\,1080*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(1920/a\,1080))/2)*2,format=yuv420p" \
-codec:a:0 aac \
-ac 2 \
-ab 256000 \
-af "volume=2" \
-copyts \
-avoid_negative_ts disabled \
-max_muxing_queue_size 2048 \
-f hls \
-max_delay 5000000 \
-hls_time 3 \
-hls_segment_type fmp4 \
-hls_fmp4_init_filename "91893804987efb6f8e99b63390ab0ac5-1.mp4" \
-start_number 0 \
-hls_base_url "/transcodes/" \
-hls_segment_filename "./transcodes/91893804987efb6f8e99b63390ab0ac5%d.mp4" \
-hls_playlist_type event \
-hls_list_size 0 \
-y "./transcodes/91893804987efb6f8e99b63390ab0ac5.m3u8"

Based on the above (even with ffmpeg on my laptop) it seems the fmp4 segment type causes large audio delay, but mpegts does not.

Jellyfin Version

10.9.0

if other:

No response

Environment

- OS: Ubuntu 22.04.0
- Linux Kernel:6.8.4-3-pve
- Virtualization: PRoxmox LCX
- Clients: web client
- Browser: both Chrome and Safari
- FFmpeg Version:  5.1.4-Jellyfin (and reproduced on my mac with 6.1.1)
- Playback Method: web app (both Chrome and Safari)
- Hardware Acceleration: both Intel QSV _and_ CPU-only have the symptoms
- GPU Model: Intel HD Graphics 630 (i5-7500t)
- Plugins:
- Reverse Proxy:
- Base URL:
- Networking:
- Storage:

Jellyfin logs

[14:48:50] [INF] [122] Jellyfin.LiveTv.DefaultLiveTvService: Streaming Channel hdhr_2.1
[14:48:50] [INF] [122] Jellyfin.LiveTv.TunerHosts.HdHomerun.HdHomerunHost: GetChannelStream: channel id: hdhr_2.1. stream id: heavy_b23ebc9442ec90ed5f591ef1683972b1_5a7ced075e5ad1971e35bd9c2f240e82 profile: heavy
[14:48:50] [INF] [122] Jellyfin.LiveTv.TunerHosts.HdHomerun.HdHomerunHost: Opening SharedHttpStream Live stream from http://192.168.86.234:5004/auto/v2.1?transcode=heavy
[14:48:50] [INF] [109] Jellyfin.LiveTv.TunerHosts.HdHomerun.HdHomerunHost: Beginning SharedHttpStream stream to /Users/brumble/Library/Application Support/jellyfin/cache/transcodes/b85815945d68468c878fa3e8389006f8.ts
[14:48:50] [INF] [109] Jellyfin.LiveTv.TunerHosts.HdHomerun.HdHomerunHost: Live stream opened after 245.476ms
[14:48:50] [INF] [109] Jellyfin.LiveTv.DefaultLiveTvService: Returning mediasource streamId heavy_b23ebc9442ec90ed5f591ef1683972b1_5a7ced075e5ad1971e35bd9c2f240e82, mediaSource.Id heavy_b23ebc9442ec90ed5f591ef1683972b1_5a7ced075e5ad1971e35bd9c2f240e82, mediaSource.LiveStreamId null
[14:48:50] [INF] [122] Emby.Server.Implementations.Library.MediaSourceManager: Live tv media info probe took 0.005557 seconds
[14:48:50] [INF] [122] Emby.Server.Implementations.Library.MediaSourceManager: Live stream opened: {"Protocol": "Http", "Id": "heavy_b23ebc9442ec90ed5f591ef1683972b1_5a7ced075e5ad1971e35bd9c2f240e82", "Path": "http://10.147.17.82:8096/LiveTv/LiveStreamFiles/b85815945d68468c878fa3e8389006f8/stream.ts", "EncoderPath": null, "EncoderProtocol": null, "Type": "Default", "Container": "mpegts", "Size": null, "Name": null, "IsRemote": false, "ETag": null, "RunTimeTicks": null, "ReadAtNativeFramerate": false, "IgnoreDts": true, "IgnoreIndex": false, "GenPtsInput": false, "SupportsTranscoding": true, "SupportsDirectStream": true, "SupportsDirectPlay": false, "IsInfiniteStream": true, "RequiresOpening": true, "OpenToken": null, "RequiresClosing": true, "LiveStreamId": "e2329f4997b378e64ccf8fa396deb76e_af999c25a00715699361240d4c6c7a53_heavy_b23ebc9442ec90ed5f591ef1683972b1_5a7ced075e5ad1971e35bd9c2f240e82", "BufferMs": 0, "RequiresLooping": false, "SupportsProbing": true, "VideoType": null, "IsoType": null, "Video3DFormat": null, "MediaStreams": [{"Codec": "h264", "CodecTag": null, "Language": null, "ColorRange": "tv", "ColorSpace": null, "ColorTransfer": null, "ColorPrimaries": null, "DvVersionMajor": null, "DvVersionMinor": null, "DvProfile": null, "DvLevel": null, "RpuPresentFlag": null, "ElPresentFlag": null, "BlPresentFlag": null, "DvBlSignalCompatibilityId": null, "Comment": null, "TimeBase": "1/90000", "CodecTimeBase": null, "Title": null, "VideoRange": "SDR", "VideoRangeType": "SDR", "VideoDoViTitle": null, "AudioSpatialFormat": "None", "LocalizedUndefined": null, "LocalizedDefault": null, "LocalizedForced": null, "LocalizedExternal": null, "LocalizedHearingImpaired": null, "DisplayTitle": "1080i H264 SDR", "NalLengthSize": "0", "IsInterlaced": true, "IsAVC": null, "ChannelLayout": null, "BitRate": 20000000, "BitDepth": 8, "RefFrames": 1, "PacketLength": null, "Channels": null, "SampleRate": null, "IsDefault": false, "IsForced": false, "IsHearingImpaired": false, "Height": 1080, "Width": 1920, "AverageFrameRate": 29.97003, "RealFrameRate": 29.97003, "Profile": "High", "Type": "Video", "AspectRatio": "16:9", "Index": -1, "Score": null, "IsExternal": false, "DeliveryMethod": null, "DeliveryUrl": null, "IsExternalUrl": null, "IsTextSubtitleStream": false, "SupportsExternalStream": false, "Path": null, "PixelFormat": "yuv420p", "Level": 40, "IsAnamorphic": false, "$type": "MediaStream"}, {"Codec": "ac3", "CodecTag": null, "Language": null, "ColorRange": null, "ColorSpace": null, "ColorTransfer": null, "ColorPrimaries": null, "DvVersionMajor": null, "DvVersionMinor": null, "DvProfile": null, "DvLevel": null, "RpuPresentFlag": null, "ElPresentFlag": null, "BlPresentFlag": null, "DvBlSignalCompatibilityId": null, "Comment": null, "TimeBase": "1/90000", "CodecTimeBase": null, "Title": null, "VideoRange": "Unknown", "VideoRangeType": "Unknown", "VideoDoViTitle": null, "AudioSpatialFormat": "None", "LocalizedUndefined": null, "LocalizedDefault": null, "LocalizedForced": null, "LocalizedExternal": null, "LocalizedHearingImpaired": null, "DisplayTitle": "Dolby Digital - 5.1", "NalLengthSize": null, "IsInterlaced": false, "IsAVC": false, "ChannelLayout": "5.1", "BitRate": 384000, "BitDepth": null, "RefFrames": null, "PacketLength": null, "Channels": 6, "SampleRate": 48000, "IsDefault": false, "IsForced": false, "IsHearingImpaired": false, "Height": null, "Width": null, "AverageFrameRate": null, "RealFrameRate": null, "Profile": null, "Type": "Audio", "AspectRatio": null, "Index": -1, "Score": null, "IsExternal": false, "DeliveryMethod": null, "DeliveryUrl": null, "IsExternalUrl": null, "IsTextSubtitleStream": false, "SupportsExternalStream": false, "Path": null, "PixelFormat": null, "Level": 0, "IsAnamorphic": null, "$type": "MediaStream"}], "MediaAttachments": [], "Formats": [], "Bitrate": 20384000, "Timestamp": null, "RequiredHttpHeaders": {}, "TranscodingUrl": null, "TranscodingSubProtocol": "http", "TranscodingContainer": null, "AnalyzeDurationMs": 3000, "TranscodeReasons": "0", "DefaultAudioStreamIndex": null, "DefaultSubtitleStreamIndex": null, "VideoStream": {"Codec": "h264", "CodecTag": null, "Language": null, "ColorRange": "tv", "ColorSpace": null, "ColorTransfer": null, "ColorPrimaries": null, "DvVersionMajor": null, "DvVersionMinor": null, "DvProfile": null, "DvLevel": null, "RpuPresentFlag": null, "ElPresentFlag": null, "BlPresentFlag": null, "DvBlSignalCompatibilityId": null, "Comment": null, "TimeBase": "1/90000", "CodecTimeBase": null, "Title": null, "VideoRange": "SDR", "VideoRangeType": "SDR", "VideoDoViTitle": null, "AudioSpatialFormat": "None", "LocalizedUndefined": null, "LocalizedDefault": null, "LocalizedForced": null, "LocalizedExternal": null, "LocalizedHearingImpaired": null, "DisplayTitle": "1080i H264 SDR", "NalLengthSize": "0", "IsInterlaced": true, "IsAVC": null, "ChannelLayout": null, "BitRate": 20000000, "BitDepth": 8, "RefFrames": 1, "PacketLength": null, "Channels": null, "SampleRate": null, "IsDefault": false, "IsForced": false, "IsHearingImpaired": false, "Height": 1080, "Width": 1920, "AverageFrameRate": 29.97003, "RealFrameRate": 29.97003, "Profile": "High", "Type": "Video", "AspectRatio": "16:9", "Index": -1, "Score": null, "IsExternal": false, "DeliveryMethod": null, "DeliveryUrl": null, "IsExternalUrl": null, "IsTextSubtitleStream": false, "SupportsExternalStream": false, "Path": null, "PixelFormat": "yuv420p", "Level": 40, "IsAnamorphic": false, "$type": "MediaStream"}, "$type": "MediaSourceInfo"}
[14:48:50] [INF] [122] Jellyfin.Api.Helpers.MediaInfoHelper: User policy for brumble. EnablePlaybackRemuxing: True EnableVideoPlaybackTranscoding: True EnableAudioPlaybackTranscoding: True
[14:48:51] [INF] [115] Jellyfin.Api.Controllers.DynamicHlsController: Current HLS implementation doesn't support non-keyframe breaks but one is requested, ignoring that request
[14:48:51] [INF] [115] MediaBrowser.MediaEncoding.Transcoding.TranscodeManager: ffmpeg -analyzeduration 3000000 -probesize 1G -fflags +igndts -f mpegts -noautorotate -i "http://10.147.17.82:8096/LiveTv/LiveStreamFiles/b85815945d68468c878fa3e8389006f8/stream.ts" -map_metadata -1 -map_chapters -1 -threads 0 -sn -codec:v:0 libx264 -preset superfast -crf 23 -maxrate 20000000 -bufsize 40000000 -profile:v:0 high -level 40 -x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none -force_key_frames:0 "expr:gte(t,n_forced*3)" -sc_threshold:v:0 0 -vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,yadif=0:-1:0,scale=trunc(min(max(iw\,ih*a)\,min(1920\,1080*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(1920/a\,1080))/2)*2,format=yuv420p" -codec:a:0 aac_at -ac 6 -ab 640000 -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type fmp4 -hls_fmp4_init_filename "d2411c63ac29a9114b8e1a6971873be4-1.mp4" -start_number 0 -hls_base_url "hls/d2411c63ac29a9114b8e1a6971873be4/" -hls_segment_filename "/Users/brumble/Library/Application Support/jellyfin/cache/transcodes/d2411c63ac29a9114b8e1a6971873be4%d.mp4" -hls_playlist_type event -hls_list_size 0 -y "/Users/brumble/Library/Application Support/jellyfin/cache/transcodes/d2411c63ac29a9114b8e1a6971873be4.m3u8"

FFmpeg logs

No response

Please attach any browser or client logs here

No response

Please attach any screenshots here

No response

Code of Conduct

jellyfin-bot commented 2 weeks ago

Hi, it seems like your issue report has the following item(s) that need to be addressed:

This is an automated message, currently under testing. Please file an issue here if you encounter any problems.

gnattu commented 2 weeks ago

Will disable ignore decoding DTS option in the tuner setting fix it for you? If it still does not work, re-enable it, disable the "prefer fmp4 container" in the playback settings, will it resolve this for you?

rickgitdone commented 1 week ago

Will disable ignore decoding DTS option in the tuner setting fix it for you? If it still does not work, re-enable it, disable the "prefer fmp4 container" in the playback settings, will it resolve this for you?

I run on docker .. can I make these adjustments to test somewhere?

gnattu commented 1 week ago

Will disable ignore decoding DTS option in the tuner setting fix it for you? If it still does not work, re-enable it, disable the "prefer fmp4 container" in the playback settings, will it resolve this for you?

I run on docker .. can I make these adjustments to test somewhere?

What’s wrong with docker? These options are configurable using GUI and should not be a big issue for docker. The DTS one is in your Tuner config, the fmp4 one is in playback settings.

rickgitdone commented 1 week ago

Will disable ignore decoding DTS option in the tuner setting fix it for you? If it still does not work, re-enable it, disable the "prefer fmp4 container" in the playback settings, will it resolve this for you?

I run on docker .. can I make these adjustments to test somewhere?

What’s wrong with docker? These options are configurable using GUI and should not be a big issue for docker. The DTS one is in your Tuner config, the fmp4 one is in playback settings.

I am running docker image 10.9.2 and have a HDHR4-2US tuner. There are no GUI sections I cam make changes to..under edit I get 2 check boxes 1) Restrict to channels marked as favorite, 2) Allow hardware transcoding

Also under playback I searched for DTS also don't find any item related. I feel I am just not finding the settings you are referring.. sorry

junobomb commented 1 week ago

There is no DTS option for HDHomeRun under tuner settings only shows that option for M3U playlists

image

gnattu commented 1 week ago

There is no DTS option for HDHomeRun under tuner settings only shows that option for M3U playlists

So does disable fMP4 in Settings->Playback make things better then?

therumbler commented 1 week ago

Will disable ignore decoding DTS option in the tuner setting fix it for you? If it still does not work, re-enable it, disable the "prefer fmp4 container" in the playback settings, will it resolve this for you?

Thank you for your suggestion, @gnattu !

As others have said, there is no DTS setting in the tuner settings for HD Home Run devices.

Unchecking the "Prefer fMP4-HLS Media Container" checkbox (under User settings) fixes the issue!

Live TV streams video/audio is in perfect sync now!

I'll just have to let other users of my server to do the same 😊

🎊

gnattu commented 1 week ago

Will disable ignore decoding DTS option in the tuner setting fix it for you? If it still does not work, re-enable it, disable the "prefer fmp4 container" in the playback settings, will it resolve this for you?

Thank you for your suggestion, @gnattu !

As others have said, there is no DTS setting in the tuner settings for HD Home Run devices.

Unchecking the "Prefer fMP4-HLS Media Container" checkbox (under User settings) fixes the issue!

Live TV streams video/audio is in perfect sync now!

I'll just have to let other users of my server to do the same 😊

🎊

Ideally the LiveTV should use its own setting override and not always use the global settings due to its specialities. I may add an override for LiveTV so that it will never use fmp4 even if that is enabled as global setting.

therumbler commented 1 week ago

to fix the problem (per @gnattu's suggestion) :

User -> Settings -> Playback -> uncheck "Prefer fMP4-HLS Media Container"

Screenshot 2024-05-21 at 10 06 09 AM