Jellyfin Forum
LiveTV deinterlacing behavior with possible format changes mid-stream - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: Troubleshooting (https://forum.jellyfin.org/f-troubleshooting)
+--- Thread: LiveTV deinterlacing behavior with possible format changes mid-stream (/t-livetv-deinterlacing-behavior-with-possible-format-changes-mid-stream)



LiveTV deinterlacing behavior with possible format changes mid-stream - spatula - 2023-10-08

Using my HDHomerun Flex 4K tuners, I'm seeing some unusual behavior this afternoon whilst watching the Vikings/Kansas City game on KPIX: lots of interlaced video artifacts, as you'd expect if the image had not been deinterlaced at all, notable especially with a lot of side-to-side motion as you'd expect.

Curiously, the commercials look perfect; it's only the game itself which contains interlacing artifacts.  My suspicion is the commercials might be in a progressive format (e.g., 720p) but the game might be interlaced (e.g., 1080i).

I tried disabling hardware acceleration both on the tuners themselves and in Jellyfin, just to see if it would make any difference, but it did not have any effect.  I also tried both deinterlacers and with frame rate doubling both on and off; this similarly did not change anything.

Then I checked Plex and the behavior was similar, but slightly different: if I start watching *while the game is on*, it correctly detects that the video is interlaced and deinterlaces it (albeit without frame rate doubling).  If I start watching during a commercial, not so much- as soon as the game comes back on, it's full of interlacing artifacts... so it seems to be correctly detecting that the stream is interlaced, but only when the stream starts, not if the format changes mid-stream.

I attempted to reproduce this workaround in Jellyfin, but this did not bear fruit; regardless of whether I start watching during the game or during commercials, the interlacing artifacts remain.

The native HDHomerun app seems to handle the video correctly in all cases; it looks as though it is correctly deinterlacing and doubling the frame rate.

I made a copy of the live video streaming buffer in case that should be helpful later to see what might be going on there:  https://www.dropbox.com/scl/fi/vge0ar4orxqbhg72kdquo/Live-channel-5.1-interlacing-artifacts-for-troubleshooting-cee79fd4.mpg?rlkey=kpo8nkptdwju9veluu5p92vke&dl=0

Interestingly, VLC deinterlaces this video properly, but only after showing a few frames that appear to have interlacing artifacts (like it takes it a few frames to figure out what's going on there).

Any ideas?


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - spatula - 2023-10-11

Digging into this a little bit more, I noticed from the logs that despite having deinterlacing configured in the transcode interface, no filters are actually selected to perform deinterlacing in the ffmpeg command that gets generated for streaming either live TV content or recorded TV content. This holds true whether hardware acceleration is enabled or not. The -vf argument just looks like this:

-vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,bwdif=1Thumbs-down0,scale=trunc(min(max(iw\,ih*a)\,min(704\,480*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(704/a\,480))/2)*2,format=yuv420p"

(in this case the content I was streaming was 480i, but 1080i is similar)


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - TheDreadPirate - 2023-10-11

"bwdif=1" is the deinterlace type being used.


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - TheDreadPirate - 2023-10-11

I downloaded your video.  Definitely detected as interlaced.  And commercials confirmed progressive AND a different frame rate.  Also, after I watched to the progressive scan commercial at the end and then skipped back to the game MPC-BE no longer de-interlaced the interlaced portion of the video.

I'm wondering if this is some sort of driver issue.


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - spatula - 2023-10-12

(2023-10-11, 03:15 PM)TheDreadPirate Wrote: "bwdif=1" is the deinterlace type being used.

Oh good catch, my old eyes went right past it.

Quote:I downloaded your video.  Definitely detected as interlaced.  And commercials confirmed progressive AND a different frame rate.  Also, after I watched to the progressive scan commercial at the end and then skipped back to the game MPC-BE no longer de-interlaced the interlaced portion of the video. 

At least I'm not crazy and the issue can be reproduced from the video.  I'm afraid that it's soooo far out of my wheelhouse to adequately explain or to try to fix it though...


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - spatula - 2023-10-13

Not sure if this is relevant, but it looks like the syntax for the bwdif filter may have changed at some point:

https://forum.videohelp.com/threads/408684-Direct-MPEG2-deinterlacing-doesn-t-work-anymore-in-ffmpeg#post2681695

But it also seems like 0 : -1 : 0 should be the desired set of options too, unless somehow the filter wants these to be named parameters versus ordered parameters.

I suppose I could actually take the recording I have and run it through a recent ffmpeg to see how it copes with it.  I see Jellyfin is shipping with 5.1.3-Jellyfin, based on the latest 5.x release, so I might try 6.0 against the file and see if the behavior is any different, or if "stock" 5.1.3 is any different.


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - TheDreadPirate - 2023-10-13

The version of ffmpeg that is packaged with jellyfin isn't simply a copy and paste. One of the jellyfin devs back ports fixes from ffmpeg 6 into Jellyfin's fork of ffmpeg 5.1.3, in addition to some of their own fixes that apply to Jellyfin.

But definitely worth a try. I'm not informed enough to say what the main differences are between vanilla ffmpeg 5.1.3 and vanilla ffmpeg 6.


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - spatula - 2023-10-14

I think I found the trouble (maybe?).  [TLDR: on KPIX 5.1 1080i content, Jellyfin omits the bwdif filter, but it includes it on KQED 9.1 1080i content; it also includes it for various subchannels' 480i content.]

It seems like sometimes Jellyfin does not include the bwdif filter at all when transcoding to HLS for Live TV.  Here's a recent ffmpeg command from the log, on this occasion when I was using the web player for a KPIX news broadcast on my local network:


ffmpeg -analyzeduration 3000000 -fflags +igndts -f mpegts -autorotate 0 -i "http://192.168.1.160:8096/LiveTv/LiveStreamFiles/bb79e844fd5b4c109f50360764f882f7/stream.ts" -map_metadata -1 -map_chapters -1 -threads 0 -sn -codec:v:0 libx264 -preset fast -crf 21 -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 libfdk_aac -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 mpegts -start_number 0 -hls_base_url "hls/ca5a2038ed46d6cd3d11cbb80451f3c6/" -hls_segment_filename "W:\Transcodes\ca5a2038ed46d6cd3d11cbb80451f3c6%d.ts" -hls_playlist_type event -hls_list_size 0 -y "W:\Transcodes\ca5a2038ed46d6cd3d11cbb80451f3c6.m3u8"


I saved off a copy of a few seconds of that stream, and issued the same command, but removed -copyts and the HLS splitting, just so I could save it off to an mp4 I could view with VLC, and in fact, it produces an interlaced video at 1080i just as I saw watching it live in Jellyfin.

If I simply add bwdif=1:-1:0 before scale=, I get a beautifully deinterlaced output file.

If I watch a different sub-channel of KPIX that's broadcasting 480i, then Jellyfin *does* include bwdif in the ffmpeg command!


ffmpeg -analyzeduration 3000000 -fflags +igndts -f mpegts -autorotate 0 -i "http://192.168.1.160:8096/LiveTv/LiveStreamFiles/912c9df44ed64fa2b84fe85a3140feb1/stream.ts" -map_metadata -1 -map_chapters -1 -threads 0 -sn -codec:v:0 libx264 -preset fast -crf 21 -maxrate 5000000 -bufsize 10000000 -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,bwdif=1:-1:0,scale=trunc(min(max(iw\,ih*a)\,min(720\,480*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(720/a\,480))/2)*2,format=yuv420p" -flags -global_header -codec:a:0 copy -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 "hls/9b3479ea353cb7ccf109fb9b445ec3ac/" -hls_segment_filename "W:\Transcodes\9b3479ea353cb7ccf109fb9b445ec3ac%d.ts" -hls_playlist_type event -hls_list_size 0 -y "W:\Transcodes\9b3479ea353cb7ccf109fb9b445ec3ac.m3u8"


So it looks like for some reason, with SOME 1080i OTA content, Jellyfin is omitting the deinterlacing filter.  It's also omitting the filter on various HD channels that broadcast in 720 lines, but I could see that being intentional given that many of these channels are broadcasting in 720p (ie, it's already progressive video so deinterlacing would add no value).

To make matters weirder, with KQED, channel 9, which broadcasts in 1080i also, Jellyfin *is* adding the deinterlacing filter:


ffmpeg -analyzeduration 3000000 -fflags +igndts -f mpegts -autorotate 0 -i "http://192.168.1.160:8096/LiveTv/LiveStreamFiles/ab8a8be03b504c96a16bc76bd9f88ef2/stream.ts" -map_metadata -1 -map_chapters -1 -threads 0 -sn -codec:v:0 libx264 -preset fast -crf 21 -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,bwdif=1:-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" -flags -global_header -codec:a:0 copy -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 "hls/6da3e68be217a05cf4e256bc242dbcf0/" -hls_segment_filename "W:\Transcodes\6da3e68be217a05cf4e256bc242dbcf0%d.ts" -hls_playlist_type event -hls_list_size 0 -y "W:\Transcodes\6da3e68be217a05cf4e256bc242dbcf0.m3u8"


So the problem seems down to what it is that makes Jellyfin decide that KPIX should not have bwdif added to the filter chain, but that KQED should; it does not appear to be anything wrong with what ffmpeg is doing (which probably makes this a lot easier to resolve).


RE: LiveTV deinterlacing behavior with possible format changes mid-stream - spatula - 2023-10-14

A little more info from the log; it looks like the stream is indeed being misidentified as progressive, though it is definitely interlaced (IsInterlaced: False). Curiously it is also identified with AverageFrameRate: 29.97003, RealFrameRate: 59.94006



[2023-10-13 18:11:21.252 -07:00] [INF] [80] Emby.Server.Implementations.LiveTv.LiveTvManager: Opening channel stream from "Emby", external channel Id: "hdhr_5.1"
[2023-10-13 18:11:21.253 -07:00] [INF] [80] Emby.Server.Implementations.LiveTv.EmbyTV.EmbyTV: Streaming Channel "hdhr_5.1"
[2023-10-13 18:11:21.253 -07:00] [INF] [80] Emby.Server.Implementations.LiveTv.EmbyTV.EmbyTV: Live stream "native_ff80f93c46e0a0b178f0c4d61a5abab3_e62418439c1e65c2f1c4be062296b3d1" consumer count is now 2
[2023-10-13 18:11:21.255 -07:00] [INF] [19] Emby.Server.Implementations.Library.MediaSourceManager: Live tv media info probe took "0.0002459" seconds
[2023-10-13 18:11:21.255 -07:00] [INF] [19] Emby.Server.Implementations.Library.MediaSourceManager: Live stream opened: MediaSourceInfo { Protocol: Http, Id: "native_ff80f93c46e0a0b178f0c4d61a5abab3_e62418439c1e65c2f1c4be062296b3d1", Path: "http://192.168.1.160:8096/LiveTv/LiveStreamFiles/c15b2a2ddf1f49fcb5fcff10b7c5a566/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: "a17c75760a04e99b68cf766e11316e1c_09efa0d56b934a82adec00a87b837fb0_native_ff80f93c46e0a0b178f0c4d61a5abab3_e62418439c1e65c2f1c4be062296b3d1", BufferMs: 0, RequiresLooping: False, SupportsProbing: True, VideoType: null, IsoType: null, Video3DFormat: null, MediaStreams: [MediaStream { Codec: "mpeg2video", 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, LocalizedUndefined: null, LocalizedDefault: null, LocalizedForced: null, LocalizedExternal: null, DisplayTitle: "1080p MPEG2VIDEO SDR", NalLengthSize: null, IsInterlaced: False, IsAVC: null, ChannelLayout: null, BitRate: 20000000, BitDepth: 8, RefFrames: 1, PacketLength: null, Channels: null, SampleRate: null, IsDefault: False, IsForced: False, Height: 1080, Width: 1920, AverageFrameRate: 29.97003, RealFrameRate: 59.94006, Profile: "Main", 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: 4, IsAnamorphic: False }, 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: null, VideoRangeType: null, VideoDoViTitle: null, LocalizedUndefined: null, LocalizedDefault: null, LocalizedForced: null, LocalizedExternal: null, DisplayTitle: "Dolby Digital - 5.1", NalLengthSize: null, IsInterlaced: False, IsAVC: null, ChannelLayout: "5.1", BitRate: 384000, BitDepth: null, RefFrames: null, PacketLength: null, Channels: 6, SampleRate: 48000, IsDefault: False, IsForced: 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 }], MediaAttachments: [], Formats: [], Bitrate: 20384000, Timestamp: null, RequiredHttpHeaders: [], TranscodingUrl: null, TranscodingSubProtocol: null, TranscodingContainer: null, AnalyzeDurationMs: 3000, TranscodeReasons: 0, DefaultAudioStreamIndex: null, DefaultSubtitleStreamIndex: null, VideoStream: MediaStream { Codec: "mpeg2video", 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, LocalizedUndefined: null, LocalizedDefault: null, LocalizedForced: null, LocalizedExternal: null, DisplayTitle: "1080p MPEG2VIDEO SDR", NalLengthSize: null, IsInterlaced: False, IsAVC: null, ChannelLayout: null, BitRate: 20000000, BitDepth: 8, RefFrames: 1, PacketLength: null, Channels: null, SampleRate: null, IsDefault: False, IsForced: False, Height: 1080, Width: 1920, AverageFrameRate: 29.97003, RealFrameRate: 59.94006, Profile: "Main", 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: 4, IsAnamorphic: False } }



RE: LiveTV deinterlacing behavior with possible format changes mid-stream - uglytruck - 2023-10-20

So, I've got a similar issue to you in my area. First, the one problem channel started showing to be interlaced for a couple of weeks, now it won't play at all. I get errors saying it's not compatible with my video player. I've got the HD Homerun Flex and the stream plays fine locally through VLC and the HD Homerun app on Android TV (no interlace artifacts). I've tried Jellyfin locally through loopback, but it still fails. I haven't had a lot of time to mess with it, but I did look at the logs through Dozzle. The only thing it shows is it's taking longer than expected and after a few tries, it times out. I've tried a number of Hardware Transcoding options, but nothing changes. The other 1080i channels play fine. The other sub channels from the problem channel play fine. I don't know what else to do with it. My server is a N100 with the most current Ubuntu Server image and HA is fine throughout the rest of Jellyfin. I'm at a loss. Hopefully, either me, you or someone else can figure out the fix soon.