chrippa / livestreamer

Command-line utility that extracts streams from various services and pipes them into a video player of choice. No longer maintained, use streamlink or youtube-dl instead.
http://livestreamer.io/
BSD 2-Clause "Simplified" License
3.88k stars 582 forks source link

Examples of scripts to watch and transcode #1036

Open mawekuwe opened 9 years ago

mawekuwe commented 9 years ago

Examples of scripts to watch, transcode and broadcast the stream on mswindows:

Download only, with ffmpeg

@echo off
:: usage: stream.cmd <www.twitch.tv/> <thechannel>
set host=%1
set chan=%2

:: set the DATE and TIME
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%-%ldt:~8,2%%ldt:~10,2%

:: set the path
set ffmpeg="C:\path\to\ffmpeg\bin\ffmpeg.exe"
set transcode="%ffmpeg% -re -i - -c:v copy -c:a copy -bsf:a aac_adtstoasc -flags -global_header %chan%-%ldt%.mp4"

::
livestreamer  %host%%chan% high -O | %transcode%

Watch and download (transcode) with VLC in the same time.

@echo off
:: usage: stream.cmd <www.twitch.tv/> <thechannel>
set host=%1
set chan=%2

:: set the DATE and TIME
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%-%ldt:~8,2%%ldt:~10,2%

:: set the path
set file="C:\\\\path\\\\to\\\\the\\\\file\\\\where\\\\to\\\\save\\\\%chan%-%ldt%.mp4"
set vlc="C:\path\to\vlc\vlc.exe
set player="%vlc% --file-caching=5000 --sout=#transcode:duplicate{dst=file{dst=%file%,no-overwrite},dst=display} --sout-all --sout-keep"

::
livestreamer -p %player%  %host%%chan% high

Watch and broadcast on local network with VLC (optionnal: save to file)

(remove '--sout-keep' if you don't want to watch on local machine)

@echo off
:: usage: stream.cmd <www.twitch.tv/> <thechannel>
set host=%1
set chan=%2

:: set the DATE and TIME
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%-%ldt:~8,2%%ldt:~10,2%

:: set the path
set file="C:\\\\path\\\\to\\\\the\\\\file\\\\where\\\\to\\\\save\\\\%chan%-%ldt%.mp4"
set vlc="C:\path\to\vlc\vlc.exe
set broadcast="%vlc%  --file-caching=5000 --sout=#transcode:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/},dst=display} --sout-all --sout-keep"
:: uncomment the following if you need to save the file in addition. Remove '--sout-keep' if you don't want to watch on local machine
::set broadcast="%vlc%  --file-caching=5000 --sout=#transcode:duplicate{dst=file{dst=%file%,no-overwrite},dst=http{mux=ffmpeg{mux=flv},dst=:8080/},dst=display} --sout-all --sout-keep"

:: 
livestreamer -p %broadcast%  %host%%chan% high

But there are some limitations: The first one are with VLC, the transcoded file cannot be played with some device/players (TV, WMP,...) Seems some parameters are missing. The second, are with ffmpeg, I didn't find how I can watch and transcode the stream with ffmpeg on the fly. Any idea?

StarWolf3000 commented 9 years ago

Why remuxing as FLV Container? MP4 Container is the better choice and does not need a special stream splitter for WMP and is widely supported on consumer electronics like TVs, Receivers and DVD/BD players.

Note on first example (Download only, with FFmpeg): It is always better to set the global_header flag instead of removing it: set transcode="%ffmpeg% -re -i - -c:v copy -c:a copy -bsf:a aac_adtstoasc -flags +global_header %chan%-%ldt%.mp4" This circumvents errors/warnings of newer FFmpeg releases when doing stream copy, as FFmpeg will always make sure that the headers for MP4 containers are correct and will fix them if needed, especially when remuxing from a MPEG-TS (Twitch's and CR's default output container format).

mawekuwe commented 9 years ago

Thank you for the correction about "global_header" For "mux=flv" it is only in the third example. This was given by the VLC assistant for broadcasting.