jellyfin/jellyfin-plugin-tvheadend

LiveTV FFmpeg Decode Using Negative Bufsize Configuration

articuno1au opened this issue · 1 comments

Jellyfin Version: 10.8.0 (Latest)
Plugin Version: 11.0.0 (Latest)
Environment: Docker

I'm running into an issue there FFmpeg bombs out only when attempting to play LiveTV.

The stack is as follows

[22:14:01] [ERR] [93] Jellyfin.Api.Helpers.TranscodingJobHelper: FFmpeg exited with code 1
[22:14:01] [ERR] [93] Jellyfin.Server.Middleware.ExceptionMiddleware: Error processing request. URL GET /videos/ce8fd676-e695-624b-3404-097c33f30f1d/live.m3u8.
MediaBrowser.Common.FfmpegException: FFmpeg exited with code 1
   at Jellyfin.Api.Helpers.TranscodingJobHelper.StartFfMpeg(StreamState state, String outputPath, String commandLineArguments, HttpRequest request, TranscodingJobType transcodingJobType, CancellationTokenSource cancellationTokenSource, String workingDirectory)
   at Jellyfin.Api.Controllers.DynamicHlsController.GetLiveHlsStream(Guid itemId, String container, Nullable`1 static, String params, String tag, String deviceProfileId, String playSessionId, String segmentContainer, Nullable`1 segmentLength, Nullable`1 minSegments, String mediaSourceId, String deviceId, String audioCodec, Nullable`1 enableAutoStreamCopy, Nullable`1 allowVideoStreamCopy, Nullable`1 allowAudioStreamCopy, Nullable`1 breakOnNonKeyFrames, Nullable`1 audioSampleRate, Nullable`1 maxAudioBitDepth, Nullable`1 audioBitRate, Nullable`1 audioChannels, Nullable`1 maxAudioChannels, String profile, String level, Nullable`1 framerate, Nullable`1 maxFramerate, Nullable`1 copyTimestamps, Nullable`1 startTimeTicks, Nullable`1 width, Nullable`1 height, Nullable`1 videoBitRate, Nullable`1 subtitleStreamIndex, Nullable`1 subtitleMethod, Nullable`1 maxRefFrames, Nullable`1 maxVideoBitDepth, Nullable`1 requireAvc, Nullable`1 deInterlace, Nullable`1 requireNonAnamorphic, Nullable`1 transcodingMaxAudioChannels, Nullable`1 cpuCoreLimit, String liveStreamId, Nullable`1 enableMpegtsM2TsMode, String videoCodec, String subtitleCodec, String transcodeReasons, Nullable`1 audioStreamIndex, Nullable`1 videoStreamIndex, Nullable`1 context, Dictionary`2 streamOptions, Nullable`1 maxWidth, Nullable`1 maxHeight, Nullable`1 enableSubtitlesInManifest)
   at lambda_method991(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Jellyfin.Server.Middleware.ServerStartupMessageMiddleware.Invoke(HttpContext httpContext, IServerApplicationHost serverApplicationHost, ILocalizationManager localizationManager)
   at Jellyfin.Server.Middleware.WebSocketHandlerMiddleware.Invoke(HttpContext httpContext, IWebSocketManager webSocketManager)
   at Jellyfin.Server.Middleware.IpBasedAccessValidationMiddleware.Invoke(HttpContext httpContext, INetworkManager networkManager)
   at Jellyfin.Server.Middleware.LanFilteringMiddleware.Invoke(HttpContext httpContext, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager)
   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Jellyfin.Server.Middleware.QueryStringDecodingMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.ReDoc.ReDocMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Jellyfin.Server.Middleware.RobotsRedirectionMiddleware.Invoke(HttpContext httpContext)
   at Jellyfin.Server.Middleware.LegacyEmbyRouteRewriteMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)
   at Jellyfin.Server.Middleware.ResponseTimeMiddleware.Invoke(HttpContext context)
   at Jellyfin.Server.Middleware.ExceptionMiddleware.Invoke(HttpContext context)

When I jump into the FFmpeg logs, I get the following

/videos/ce8fd676-e695-624b-3404-097c33f30f1d/live.m3u8

{"Protocol":1,"Id":"787246","Path":"http://10.0.0.21:9981/stream/channelid/787246?ticket=9d27d4be0d7d74570407ed87efdaab8e6eb3c9a8","EncoderPath":null,"EncoderProtocol":null,"Type":0,"Container":null,"Size":null,"Name":null,"IsRemote":false,"ETag":null,"RunTimeTicks":null,"ReadAtNativeFramerate":false,"IgnoreDts":false,"IgnoreIndex":false,"GenPtsInput":false,"SupportsTranscoding":true,"SupportsDirectStream":true,"SupportsDirectPlay":true,"IsInfiniteStream":true,"RequiresOpening":false,"OpenToken":null,"RequiresClosing":false,"LiveStreamId":null,"BufferMs":1500,"RequiresLooping":false,"SupportsProbing":true,"VideoType":null,"IsoType":null,"Video3DFormat":null,"MediaStreams":[{"Codec":null,"CodecTag":null,"Language":null,"ColorRange":null,"ColorSpace":null,"ColorTransfer":null,"ColorPrimaries":null,"Comment":null,"TimeBase":null,"CodecTimeBase":null,"Title":null,"VideoRange":"SDR","LocalizedUndefined":null,"LocalizedDefault":null,"LocalizedForced":null,"LocalizedExternal":null,"DisplayTitle":"SDR","NalLengthSize":"0","IsInterlaced":true,"IsAVC":null,"ChannelLayout":null,"BitRate":null,"BitDepth":null,"RefFrames":null,"PacketLength":null,"Channels":null,"SampleRate":null,"IsDefault":false,"IsForced":false,"Height":null,"Width":null,"AverageFrameRate":null,"RealFrameRate":null,"Profile":null,"Type":1,"AspectRatio":null,"Index":-1,"Score":null,"IsExternal":false,"DeliveryMethod":null,"DeliveryUrl":null,"IsExternalUrl":null,"IsTextSubtitleStream":false,"SupportsExternalStream":false,"Path":null,"PixelFormat":null,"Level":null,"IsAnamorphic":null},{"Codec":null,"CodecTag":null,"Language":null,"ColorRange":null,"ColorSpace":null,"ColorTransfer":null,"ColorPrimaries":null,"Comment":null,"TimeBase":null,"CodecTimeBase":null,"Title":null,"VideoRange":null,"LocalizedUndefined":null,"LocalizedDefault":null,"LocalizedForced":null,"LocalizedExternal":null,"DisplayTitle":"","NalLengthSize":null,"IsInterlaced":false,"IsAVC":null,"ChannelLayout":null,"BitRate":null,"BitDepth":null,"RefFrames":null,"PacketLength":null,"Channels":null,"SampleRate":null,"IsDefault":false,"IsForced":false,"Height":null,"Width":null,"AverageFrameRate":null,"RealFrameRate":null,"Profile":null,"Type":0,"AspectRatio":null,"Index":-1,"Score":null,"IsExternal":false,"DeliveryMethod":null,"DeliveryUrl":null,"IsExternalUrl":null,"IsTextSubtitleStream":false,"SupportsExternalStream":false,"Path":null,"PixelFormat":null,"Level":null,"IsAnamorphic":null}],"MediaAttachments":[],"Formats":[],"Bitrate":null,"Timestamp":null,"RequiredHttpHeaders":{},"TranscodingUrl":null,"TranscodingSubProtocol":null,"TranscodingContainer":null,"AnalyzeDurationMs":null,"DefaultAudioStreamIndex":null,"DefaultSubtitleStreamIndex":null}

/usr/lib/jellyfin-ffmpeg/ffmpeg -analyzeduration 200M -init_hw_device cuda=cu:0 -filter_hw_device cu -autorotate 0 -i "http://10.0.0.21:9981/stream/channelid/787246?ticket=9d27d4be0d7d74570407ed87efdaab8e6eb3c9a8" -map_metadata -1 -map_chapters -1 -threads 8 -sn -codec:v:0 h264_nvenc -preset p4 -b:v 1866282667 -maxrate 1866282667 -bufsize -562401962 -profile:v:0 high -vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,yadif=0:-1:0,scale=trunc(min(max(iw\,ih*a)\,2560)/2)*2:trunc(ow/a/2)*2,format=yuv420p" -flags -global_header -codec:a:0 libfdk_aac -ac 2 -ab 384000 -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/77d3aa15c4ce50a990879e81019b13d8/" -hls_segment_filename "/config/transcodes/77d3aa15c4ce50a990879e81019b13d8%d.ts" -hls_playlist_type event -hls_list_size 0 -y "/config/transcodes/77d3aa15c4ce50a990879e81019b13d8.m3u8"


ffmpeg version 5.0.1-Jellyfin Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  configuration: --prefix=/usr/lib/jellyfin-ffmpeg --target-os=linux --extra-libs=-lfftw3 --extra-version=Jellyfin --disable-doc --disable-ffplay --disable-ptx-compression --disable-shared --disable-libxcb --disable-sdl2 --disable-xlib --enable-lto --enable-gpl --enable-version3 --enable-static --enable-gmp --enable-gnutls --enable-chromaprint --enable-libdrm --enable-libass --enable-libfreetype --enable-libfribidi --enable-libfontconfig --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libdav1d --enable-libwebp --enable-libvpx --enable-libx264 --enable-libx265 --enable-libzvbi --enable-libzimg --enable-libfdk-aac --arch=amd64 --enable-libshaderc --enable-libplacebo --enable-vulkan --enable-opencl --enable-vaapi --enable-amf --enable-libmfx --enable-ffnvcodec --enable-cuda --enable-cuda-llvm --enable-cuvid --enable-nvdec --enable-nvenc
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
[mp3float @ 0x558170b88580] Header missing
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[h264 @ 0x558170b70f40] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x558170b70f40] decode_slice_header error
[h264 @ 0x558170b70f40] no frame!
[mpegts @ 0x558170b691c0] Could not find codec parameters for stream 5 (Unknown: none ([5][0][0][0] / 0x0005)): unknown codec
Consider increasing the value for the 'analyzeduration' (200000000) and 'probesize' (5000000) options
Input #0, mpegts, from 'http://10.0.0.21:9981/stream/channelid/787246?ticket=9d27d4be0d7d74570407ed87efdaab8e6eb3c9a8':
  Duration: N/A, start: 1538.587600, bitrate: N/A
  Program 544
    Metadata:
      service_name    : ABC NEWS
      service_provider: ABC
  Program 545
    Metadata:
      service_name    : ABC TV
      service_provider: ABC
  Program 546
    Metadata:
      service_name    : ABCKids/TVPlus
      service_provider: ABC
  Program 548
    Metadata:
      service_name    : ABC ME
      service_provider: ABC
  Program 547
    Metadata:
      service_name    : ABC TV
      service_provider: ABC
  Program 549
    Metadata:
      service_name    : ABCTV HD
      service_provider: ABC
  Stream #0:1[0x910]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn
  Stream #0:2[0x911](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 256 kb/s
  Stream #0:3[0x975](eng): Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp (visual impaired) (descriptions)
  Stream #0:4[0x912](eng): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006), 492x250
  Stream #0:5[0x157c]: Unknown: none ([5][0][0][0] / 0x0005)
  Program 550
    Metadata:
      service_name    : Double J
      service_provider: ABC
  Program 551
    Metadata:
      service_name    : ABC Jazz
      service_provider: ABC
  Program 552
    Metadata:
      service_name    : ABC KIDS Listen
      service_provider: ABC
  Program 553
    Metadata:
      service_name    : triple j
      service_provider: ABC
  Program 554
    Metadata:
      service_name    : triple j Unearthed
      service_provider: ABC
  Program 555
    Metadata:
      service_name    : ABC Classic
      service_provider: ABC
  Program 556
    Metadata:
      service_name    : ABC Country
      service_provider: ABC
  Program 557
    Metadata:
      service_name    : ABC SYDNEY
      service_provider: ABC
  Program 558
    Metadata:
      service_name    : ABC RN
      service_provider: ABC
  Program 559
    Metadata:
      service_name    : ABC NewsRadio
      service_provider: ABC
  No Program
  Stream #0:0[0x12]: Data: epg
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
  Stream #0:2 -> #0:1 (mp2 (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
[mp2 @ 0x5581728e6440] Header missing
Error while decoding stream #0:2: Invalid data found when processing input
[h264 @ 0x558170ca4880] co located POCs unavailable
[h264 @ 0x558171ea54c0] co located POCs unavailable
[h264_nvenc @ 0x558170b77780] InitializeEncoder failed: invalid param (8): Invalid value for VBV buffer size.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[libfdk_aac @ 0x558170ca6d40] 2 frames left in the queue on closing
Conversion failed!

With the error InitializeEncoder failed: invalid param (8): Invalid value for VBV buffer size. I dug into the FFmpeg docs and figured it was probably related to the -bufsize configuration being passed in. That value is -bufsize -562401962.

The problem would appear to be that this value is a negative. When I look into the configuration in my decoder settings, I'm using NVENC/NVDEC but with default settings, and it works just find for local content. It's only bombing out for LiveTV, and it's bombing out for all LiveTV regardless of channel.

I can't see any configuration I can influence to change this. Let me know if there's anything further I can provide to look into this. Thanks in advance :)