Created
August 25, 2014 18:36
-
-
Save BtbN/f717dc5b2e0876712a87 to your computer and use it in GitHub Desktop.
tv.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd "$(dirname "$0")" | |
source .qstr.bash | |
echo -ne "Content-Type: video/x-matroska\r\n\r\n" | |
if [ -f /tmp/tv.pid ]; then | |
if kill -0 $(cat /tmp/tv.pid) >/dev/null 2>&1; then | |
exit | |
fi | |
fi | |
echo $$ > /tmp/tv.pid | |
export DISPLAY=:0 | |
URL="http://localhost:9981/stream/channelnumber/${GET[vid]}?weight=50" | |
ffmpeg -loglevel quiet -i "${URL}" -frames 10 -c:v copy -map 0:v:0 -f matroska - 2>/dev/null | ffprobe - -show_frames -loglevel quiet > /tmp/framedata.txt 2>/dev/null || exit | |
IS_INTERLACED="$(grep interlaced_frame /tmp/framedata.txt | head -n 1 | sed -r 's|^.*?=||g')" | |
HEIGHT="$(grep height /tmp/framedata.txt | head -n 1 | sed -r 's|^.*?=||g')" | |
if [ "$IS_INTERLACED" == "1" ]; then | |
if [ "$HEIGHT" -gt 720 ]; then | |
VFILTER="-vf scale=w=trunc(oh*a/2)*2:h=min(720\,ih):interl=1,yadif=1:-1:1" | |
else | |
VFILTER="-vf yadif=1:-1:1,scale=w=trunc(oh*a/2)*2:h=min(720\,ih)" | |
fi | |
else | |
VFILTER="-vf scale=w=trunc(oh*a/2)*2:h=min(720\,ih)" | |
fi | |
AENCODER="-c:a libfdk_aac -ac 2 -ar 44100 -b:a 128k" | |
VENCODER="-c:v libx264 -preset veryfast -profile:v high -crf 22 -maxrate 5500k -bufsize 5500k" | |
exec ffmpeg -loglevel quiet -hwaccel vdpau -i "${URL}" $VFILTER $VENCODER $AENCODER -map 0:v:0 -map 0:a:0 -f matroska - 2>ffmpeg.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment