#!/bin/sh # SPDX-License-Identifier: GPL-2.0 # Copyright (C) 2011-present Alex@ELEC (http://alexelec.in.ua) ################################################################################ # VLC & FFmpeg options for Tvheadend IPTV ################################################################################ ################################################################################ # Log level: quiet | info ################################################################################ LOG_VLC="quiet" LOG_FFMPEG="quiet" ################################################################################ # User-Agent ################################################################################ USER_AGENT="'Restream/5.20408.171030'" ################################################################################ CH_NAME="$@" WRK_DIR=`dirname $0` CH_FILE="$WRK_DIR/tvh-channels.list" CH_FFPLAY="$WRK_DIR/tvh-ffmpeg.check" STREAM_PTV="FFmpeg" CACHE_PTV=1 IP4_TIME=3000 CONFIG_FILE="/storage/.cache/services/ptv.conf" [ -f "$CONFIG_FILE" ] && . $CONFIG_FILE play_empty (){ echo "*** IPTV stream --- Not found URL for ---: [$CH_NAME] ***" >&2 URL="${WRK_DIR}/../logo/empty-stream.mp4" /usr/bin/ffmpeg -v quiet -hide_banner -i "$URL" -c copy -f mpegts pipe:1 sleep 3 exit 3 } FIND_CH_NAME=`echo "$CH_NAME" | sed 's|\[|\\\[|g; s|\]|\\\]|g'` URL_PTV=`grep -m 1 "^$FIND_CH_NAME #" $CH_FILE | awk -F\\# '{print $2}' | sed 's/^[ \t]*//; s/[ \t]*$//'` [ -z "$URL_PTV" ] && play_empty URL=`curl -s $URL_PTV` [ -z "$URL" ] && play_empty PROSTO_URL=`echo $URL | grep 'iptv.prosto.tv'` [ -n "$PROSTO_URL" ] && USER_AGENT="'VLC/3.0.8'" if [ "$STREAM_PTV" == "VLC" ] && [ -f "$CH_FFPLAY" ]; then IS_FFMPEG=`/usr/bin/python $CH_FFPLAY "$URL"` [ "$IS_FFMPEG" == "True" ] && STREAM_PTV="FFmpeg" fi echo "*** IPTV stream play --- $CH_NAME --- [$URL] ***" >&2 echo "*** IPTV stream agnt -- $USER_AGENT -- ***" >&2 if [ "$STREAM_PTV" == "VLC" ]; then if [ "$LOG_VLC" == "info" ]; then DEBUG="-vvv" else DEBUG="--quiet" fi BUF_TIME=$(expr $CACHE_PTV \* 1000) IS_HLS=`echo $URL | grep '.m3u8'` if [ -n "$IS_HLS" ]; then NET_CACHE=0 MUX_CACHE=$BUF_TIME MODE_CACHE='Output' else NET_CACHE=$BUF_TIME MUX_CACHE=0 MODE_CACHE='Input' fi echo "*** IPTV stream mode --- VLC --- ($MODE_CACHE cache time: $CACHE_PTV sec.)***" >&2 /usr/bin/cvlc $DEBUG --ipv4-timeout=$IP4_TIME --network-caching=$NET_CACHE \ --no-drop-late-frames --no-skip-frames --play-and-exit \ "$URL" :http-user-agent="$USER_AGENT" \ --sout-mux-caching=$MUX_CACHE --sout '#std{mux=ts,access=file,dst=-}' else echo "*** IPTV stream mode --- FFmpeg --- ***" >&2 /usr/bin/ffmpeg -v $LOG_FFMPEG -hide_banner -user_agent $USER_AGENT \ -i "$URL" -flags nobuffer -flags low_delay -avioflags direct -strict experimental \ -max_muxing_queue_size 9999 -c copy -ignore_unknown -map 0 -f mpegts pipe:1 fi