A
A
ave_koty2021-01-08 09:56:09
YouTube
ave_koty, 2021-01-08 09:56:09

How to overlay music from a playlist on a looped video in ffmpeg for YouTube streaming?

Hello everyone, I want to make a music stream on YouTube 24/7. For this I have a VDS server.

I uploaded music to a separate folder, there is a video / gif. How to put music on the background from a playlist/folder, but make the video loop, using ffmpeg?

Channel example: https://www.youtube.com/watch?v=5qap5aO4i9A

* The option with rdp and obs does not suit

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-01-08
@ave_koty

Prepare the video in advance to make life easier for ffmpeg and VDS: transcode the original video into a format that does not require encoding. In the same h264 if you will stream a video stream in it. Additional will need to be specified. parameters for a group of frames:

-c:v libx264 -pix_fmt yuv420p -preset medium -r 25 -g 50 -b:v 2500k

here frame rate is 25 and grouping is 25 * 2 = 50 I would store the intermediate file in .ts :
ffmpeg -i input1.mp4 \
  -c:v libx264 \
  -pix_fmt yuv420p \
  -preset medium \
  -r 25 -g 50 \
  -b:v 2500k \
  -bsf:v h264_mp4toannexb -f mpegts \
  video.ts

Audio can be left in mp3 , you can convert everything to aac in advance, once. Again, to reduce stress.
Compose text file audio playlist playlist.txt in format like
# this is a comment
file '/mp3/day1/file1.mp3'
file '/mp3/day1/file2.mp3'
file '/mp3/day1/file3.mp3'

Run video as input in a loop and playlist via concat like this:
ffmpeg \
  -loop 1 -f mpegts  -i video.ts \
  -f concat -safe 0 -i playlist.txt \
  -c:a aac -b:a 128k \
  -c:v copy \
  -f flv \
  rtmp://a.rtmp.youtube.com/live2/ВАШ_КЛЮЧ
I didn't check it, and most likely there is a lot of work on checking and debugging the parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question