Skip to content

Instantly share code, notes, and snippets.

@autch
Created March 28, 2011 16:20
Show Gist options
  • Save autch/890759 to your computer and use it in GitHub Desktop.
Save autch/890759 to your computer and use it in GitHub Desktop.
tcpで生TSをもらってVLCでトランスコード結果をHTTPストリーミング
#!/bin/sh
if [ "x$1" = "x" -o "x$2" = "x" ]; then
echo "Usage: $0 inport outport"
exit 1
fi
if [ "x$3" = "x" ]; then
BITRATE=128
else
BITRATE=$3
fi
if [ "x$VLC" = "x" ]; then
VLC=cvlc-git
fi
INPORT=$1
OUTPORT=$2
FPS=15
KEYINT=$(expr $FPS \* 2)
WIDTH=480
HEIGHT=$(expr $WIDTH \* 9 / 16)
PHYS_DIR=/var/www/example.jp/ts/$INPORT
URL_DIR=http://example.jp/ts/$INPORT
FILE_MASK=stream-########.ts
FILE_WILDCARD=$(echo $FILE_MASK | tr -s \# \*)
PLAYLIST=stream.m3u8
HTTP_OUT=127.0.0.1:$OUTPORT/ts
mkdir -p $PHYS_DIR
rm -f $PHYS_DIR/{$FILE_WILDCARD,$PLAYLIST}
XCODE_OPTS=transcode{venc=x264{profile=baseline,keyint=$KEYINT,fps=$FPS,bitrate=$BITRATE},vcodec=h264,vb=$BITRATE,acodec=mp4a,ab=96,fps=$FPS,deinterlace,threads=4,vfilter=canvas{width=$WIDTH,height=$HEIGHT,aspect=16:9}}
LIVE_OPTS=std{access=livehttp{numsegs=10,index=$PHYS_DIR/$PLAYLIST,index-url=$URL_DIR/$FILE_MASK},mux=ts{use-key-frames},dst=$PHYS_DIR/$FILE_MASK}
HTTP_OPTS=std{access=http,mux=ts{use-key-frames},dst=$HTTP_OUT}
exec $VLC -q -d tcp://127.0.0.1:$INPORT \
--sout "#$XCODE_OPTS:duplicate{dst=$LIVE_OPTS,dst=$HTTP_OPTS}"
@autch
Copy link
Author

autch commented Mar 28, 2011

HTTP Live Download サポートのために、VLC は git HEAD が必要。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment