IPTV Plugin and ffmpeg

  • I have spent some days with Rolf's IPTV plugin, attempting to use ffmpeg as the transcode/streaming alternative to the VLC based script that is included and I am wondering if anyone else has succeeded?


    The channel I'm receiving is an HTTP Live (HLS) one, which plays without issue in a few standalone media players and am using the following ffmpeg command to produce a UDP mpegts stream:


    ffmpeg -loglevel fatal -probesize 10M -analyzeduration 0 -fpsprobesize 0 -headers "X-Forwarded-For:\ 202.89.4.222\r\nUser-Agent:\ Mozilla/5.0\ (Windows\ NT\ 10.0;\ Win64;\ x64)\ AppleWebKit/537.36\ (KHTML,\ like\ Gecko)\ Chrome/84.0.4147.105\ Safari/537.36\r\n" -i https://i.mjh.nz/nz/tv.9.m3u8 -map 0:20 -map 0:21 -vcodec copy -acodec copy -metadata service_name=tv.9 -f mpegts udp://127.0.0.1:${PORT} &


    This takes the highest resolution audio and video streams, does no re-encoding and remulitplexes them. If I run this script locally and enable logging, I get the following:


    Output #0, mpegts, to 'udp://127.0.0.1:4321':

    Metadata:

    service_name : tv.9

    encoder : Lavf57.37.101

    Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc

    Metadata:

    variant_bitrate : 2929080

    Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, 140 kb/s

    Metadata:

    variant_bitrate : 2929080

    Stream mapping:

    Stream #0:20 -> #0:0 (copy)

    Stream #0:21 -> #0:1 (copy)

    Press [q] to stop, [?] for help

    [hls,applehttp @ 0x1785420] No longer receiving playlist 0

    [hls,applehttp @ 0x1785420] No longer receiving playlist 1

    [hls,applehttp @ 0x1785420] No longer receiving playlist 2

    [hls,applehttp @ 0x1785420] No longer receiving playlist 3

    frame= 374 fps=0.0 q=-1.0 size= 2506kB time=00:00:14.88 bitrate=1379.5kbits

    frame= 544 fps=520 q=-1.0 size= 4985kB time=00:00:21.68 bitrate=1883.8kbits

    frame= 600 fps= 91 q=-1.0 size= 5961kB time=00:00:24.02 bitrate=2033.0kbits

    frame= 750 fps= 58 q=-1.0 size= 7445kB time=00:00:30.01 bitrate=2031.9kbits

    frame= 900 fps= 47 q=-1.0 size= 9626kB time=00:00:36.00 bitrate=2189.8kbits

    frame= 1050 fps= 42 q=-1.0 size= 11326kB time=00:00:42.00 bitrate=2209.0kbits

    frame= 1199 fps= 38 q=-1.0 Lsize= 12746kB time=00:00:48.02 bitrate=2174.4kbits/s

    speed=1.53x


    and I can connect a local player which works fine, but so far no combination of options and tweaks to the channels.conf file yield anything other than very intermittent bursts of recognisable audio. The log consistently outputs:


    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 60 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 96 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 156 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 156 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 81 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 75 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 156 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 156 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 50 bytes to sync on TS packet

    Jul 5 09:53:55 vdr vdr: [1078] IPTV: Skipped 106 bytes to sync on TS packet


    I've attached the output of DVB Inspector, which to my admittedly inexperienced eye, doesn't show an obvious problem.

    The channels conf entry is: TV6;IPTV:60:S=1|P=1|F=EXT|U=iptvstream.sh|A=0:I:0:256:257=@4:0:0:1:1:1:0

    and I'm using vdr 2.4.6 and a TT S2 6400 card.


    Any help/advice much appreciated and I apologise for no German. Please feel free to reply in German and I can translate.


    Regards.

  • Thanks for the reply. I'm not familiar with mpv, but it looks like it's a software decoder. The TT S2 6400 card I have, is a hardware MPEG/H264 decoder as well as doing the OSD, so using IPTV would make sense if I can use it. I'm only using ffmpeg for remultiplexing, which is a pretty lightweight task.


    Edit later: Software decoder not true, as it can use GPU hardware, but I have a low powered system and would like to stick with the TT card as the backend.

  • Hello


    You can increase upd streaming performance with these commands:

    sysctl -w net.core.rmem_max=2097152

    sysctl -w net.core.rmem_default=2097152

    sysctl -w net.core.wmem_max=2097152

    sysctl -w net.core.wmem_default=2097152



    Just send after boot of the server or start of VDR

  • If you re-mux it then you can give it a dedicated SID and TID like in:


    Code
    -mpegts_original_network_id 65281 -mpegts_transport_stream_id 'TID' -mpegts_pmt_start_pid 4096 -mpegts_service_id 'SID'  -mpegts_original_network_id 65281'


    And the audio and video PIDs as in:


    Code
    -streamid 0:'VPID' -streamid 1:'APID'


    Then use these in your channels.conf


    Example ffmpeg line:


    Code
    ffmpeg -re -f mpegts -i URL -codec:v copy -codec:a copy -streamid 0:100 -streamid 1:200 -flush_packets 0 -f mpegts -mpegts_transport_stream_id 22579 -mpegts_pmt_start_pid 4096 -mpegts_service_id 1931 -mpegts_original_network_id 65281 udp://thuis2:4321?pkt_size=1316&reuse=1&buffer_size=65536


    Note the buffer size


    Cheers

  • Hi Carel,


    Many thanks for that. The single change that made the most difference, is the buffer_size=65536 one. When I added that, I was able to play 1-2 second bursts and I've since spent some time playing with fifo_size as well as a few others but nothing so far is perfect, but have a couple of other ideas. Looking in the plugin info page shows the buffer filling to 10-15% and then draining to zero. The only time I can get uninterupted play, is with low bitrate portions of video and then only if I use the -re option, which I am a bit confused about, as it's only recommended for playing files rather than streaming.


    Anyway, very much appreciate the advice and will carry on tinkering - the options in ffmpeg are quite formidable. I haven't found any reference to one you used here, -flush_packets 0.


    Edit: Some hours later. Well I'm still not sure of the exact relationship between ffmpeg's fifo, buffer and packet size, IPTV plugin's buffer and maybe vdr's buffer as well, but am now getting a perfect result with pretty much the settings you gave me:


    ffmpeg -loglevel fatal -probesize 10M -headers "X-Forwarded-For:\ 202.89.4.222\r\nUser-Agent:\ Mozilla/5.0\ (Windows\ NT\ 10.0;\ Win64;\ x64)\ AppleWebKit/537.36\ (KHTML,\ like\ Gecko)\ Chrome/84.0.4147.105\ Safari/537.36\r\n" -re -i https://i.mjh.nz/nz/tv.9.m3u8 -map 0:20 -map 0:21 -vcodec copy -acodec copy -metadata service_name=tv.9 -flush_packets 0 -f mpegts udp://127.0.0.1:${PORT}?pkt_size=1316&reuse=1&overrun_nonfatal=1&buffer_size=65536 &


    I'll add the PID extras later. Thanks again.


    Kind regards

  • Hi ras


    Does this still work for you with Freeview in NZ? I've been a vdr user since the early 2000s, am in Wellington and used DVB-C and then DVB-S but am trying to get IPTV working with the help of Matt Huisman's page. I did try using vlc (am using yavdr) in iptv but can't get it to work.


    Can you help?

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!