Skip to content

Instantly share code, notes, and snippets.

@Cyxo
Forked from olasd/stream_to_youtube.sh
Last active April 30, 2024 16:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Cyxo/e4192f58e738446f3491d839eaa50ed7 to your computer and use it in GitHub Desktop.
Save Cyxo/e4192f58e738446f3491d839eaa50ed7 to your computer and use it in GitHub Desktop.
Stream video to youtube via ffmpeg
#! /bin/bash
#
# Diffusion youtube avec ffmpeg
# Configurer youtube avec une résolution 720p. La vidéo n'est pas scalée.
VBR="2500k" # Bitrate de la vidéo en sortie
FPS="30" # FPS de la vidéo en sortie
QUAL="medium" # Preset de qualité FFMPEG
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" # URL de base RTMP youtube
FOLDER="videos" # Source UDP (voir les annonces SAP)
KEY="...." # Clé à récupérer sur l'event youtube
SOURCE=""
n=0
filter=""
for f in $FOLDER/*.mp4
do
SOURCE="$SOURCE -i $f"
filter="$filter [$n:v:0] [$n:a:0]"
((n++))
done
filter="$filter concat=n=$n:v=1:a=1 [v] [a]"
echo "ffmpeg $SOURCE -filter_complex '$filter'"
ffmpeg \
$SOURCE -filter_complex "$filter" \
-map "[v]" -map "[a]" -deinterlace \
-vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \
-acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k \
-f flv "$YOUTUBE_URL/$KEY"
@samuelduckworth
Copy link

This is working great for me. But it only plays one time then stops. I am using one .mp4 video in the folder. Plays the first time then stops. Any way to have it loop the video forever?

[flv @ 0x560cb9327ea0] Failed to update header with correct duration.146.4kbits/s speed=1.47x
[flv @ 0x560cb9327ea0] Failed to update header with correct filesize.

frame= 4666 fps= 35 q=-1.0 Lsize= 27409kB time=00:03:14.43 bitrate=1154.8kbits/s speed=1.47x
video:19605kB audio:7596kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.764337%

@xcko
Copy link

xcko commented Nov 26, 2017

Found this through upwork.
To loop the input forever, try changing line 30 to
ffmpeg -stream_loop -1 \
From the manpage:
-stream_loop number (input) Set number of times input stream shall be looped. Loop 0 means no loop, loop -1 means infinite loop.

Changing the script so it supports looping mp3s with a still image or video would be pretty simple too if you need help.

@lucario1001
Copy link

@xcko can you help me do looping ogg files with a gif/video

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