Monthly Archives: March 2019

Streaming youtube-dl to FFMPEG

youtube-dl -o - "https://www.youtube.com/watch?v=xxx" | ffmpeg -i - -c:a aac -strict -2 -vf "transpose=1","scale=iw:ih","drawtext=fontcolor=white:fontsize=40:fontfile='/path/font.ttf':textfile='/path/msg.txt':reload=1:y=h-line_h-52:x=w-(mod(4*n\,w+tw)-tw/40)" -c:v h264 -f flv rtmp://xxx/live/xxxx

Ffmpeg streaming

In all the examples below we’ll assume you do not know the codecs and will want to replace them with H264/AAC. (source : https://news.mistserver.org/news/71/An+introduction+to+encoding+and+pushing+with+ffmpeg)

  • RTMP stream Input to FLV file, reencode

ffmpeg -i rtmp://IP:PORT/live/STREAMNAME -c:a aac -strict -2 -c:v h264 OUTPUT.flv

  • MP4 file Input to RTMP stream, reencode

ffmpeg -re -i INPUT.mp4 -c:a aac -strict -2 -c:v h264 -f flv rtmp://IP:PORT/live/STREAMNAME

  • HLS stream input to RTMP stream, reencode

ffmpeg -i http://IP:PORT/hls/STREAMNAME/index.m3u8 -c:a aac -strict -2 -c:v h264 -f flv rtmp://IP:PORT/live/STREAMNAME

  • MP4 file input to RTSP stream, reencode

ffmpeg -re -i INPUT.mp4 -c:a aac -strict -2 -c:v h264 -f rtsp -rtsp_transport tcp rtsp://IP:PORT/STREAMNAME

  • HLS stream input to RTSP stream, reencode

ffmpeg -i http://IP:PORT/hls/STREAMNAME/index.m3u8 -c:a aac
-strict -2 -c:v h264 -f rtsp -rtsp_transport tcp
rtsp://IP:PORT/STREAMNAME

  • RTSP stream input over TCP to RTMP stream, copy

*Using ffmpeg to ingest over TCP instead of UDP makes sure you don’t have the packet loss problem that UDP has and gives a better and more stable picture for your stream. -rtsp_transport tcp -i CameraURL -c copy -f flv rtmp://IP:PORT/live/STREAMNAME

 

run.sh

@echo on

:START
ffmpeg -i input_ch -c:a aac -strict -2 -vf "transpose=1","scale=iw/2:ih/2","drawtext=fontcolor=white:fontsize=40:fontfile='/font.ttf':textfile='/msg.txt':reload=1:y=h-line_h-52:x=w-(mod(4*n\,w+tw)-tw/40)" -c:v h264 -f flv rtmp://...
if errorlevel 3 goto START

pause
:fin