1

In my previously opened topic:

How to make FFmpeg automatically inject mp3 audio tracks in the single cycled muted video

I've got detailed explanation from @llogan how to broadcast looped short muted video on youtube automatically injecting audio tracks in it without interrupting a translation.

I plan to enhance the flow and the next question I faced with is how to dynamically put an additional text to the broadcast.

Prerequisites:

  1. youtube broadcast is up and running by ffmpeg
  2. short 3 min video is paying in infinity loop
  3. audio tracks from playlist are automatically taken by "ffmpeg concat" and injected in the video one by one

this is a basic command to start translation:

ffmpeg -re -fflags +genpts -stream_loop -1 -i video.mp4 -re -f concat -i input.txt -map 0:v -map 1:a -c:v libx264 -tune stillimage -vf format=yuv420p -c:a copy -g 20 -b:v 2000k -maxrate 2000k -bufsize 8000k -f flv rtmp://a.rtmp.youtube.com/live2/my-key

Improvements I want to bring

  1. I plan to store some metadata in audio files (basically it's an artist name and a song name)
  2. At the moment a particular song starts playing artist/song name should be taken from metadata and displayed on the video as text during the whole song is playing.
  3. When the current song finishes and a new one starts playing the previous artist/song text should be replaced with the new one etc

My question is how to properly take metadata and add it to the existing broadcast config using ffmpeg?

Grrzly
  • 43
  • 7
  • It is possible using the [drawtext](https://ffmpeg.org/ffmpeg-filters.html#drawtext) filter with `reload` and `textfile` options (see [Can you insert text from a file in real time with ffmpeg streaming?](https://stackoverflow.com/a/63586443/)). The problem is that the audio files listed in `input.txt` are basically treated as a single input and lose their "individuality". So the question becomes a matter of timing: how will you know when to update the title? – llogan Dec 06 '20 at 00:59
  • So if there is no way to use metadata of audio file as an input for text it becomes a really complex task. What I could assume is if we had files in `input.txt` called like **file1.m4a, file2.m4a** so we'd need to have separate text files corresponding to filenames like **file1.txt, file2.txt** containing text and take text out of them. Then probably each time new song starts we should determine its filename duration or keep a separate file(-s) containing info about all tracks duration. But it doesn't seem a simple solution – Grrzly Dec 06 '20 at 06:41
  • basically this youtube channel is what I want to achieve [lil-peep radio](https://www.youtube.com/watch?v=FgSZ46yRPss) And I realize they can use absolutely different approach like stream using OBS, Streamlabs overlays, some audioplayer as an audio input. But I look towards ffmpeg as a more lightweight and less hardware consuming solution – Grrzly Dec 06 '20 at 06:43

1 Answers1

3

This is a fairly broad question and I don't have a complete solution. But I can provide a partial answer containing several commands that you can use to help implement a solution.

Update text on video on demand

See Can you insert text from a file in real time with ffmpeg streaming?

Get title & artist metadata

With ffprobe:

ffprobe -v error -show_entries format_tags=title -of default=nw=1:nk=1 input.mp3
ffprobe -v error -show_entries format_tags=artist -of default=nw=1:nk=1 input.mp3

Or combined: format_tags=title,artist (note that title will display first, then artist, regardless of order in the command).

Get duration of a song

See How to get video duration in seconds?

What you need to figure out

The hard part is knowing when to update the file referenced in textfile in drawtext filter as shown in Update text on video on demand above.

Lazy solution

Pre-make a video per song including the title and artist info. Simple Bash example:

audio=input.mp3; ffmpeg -stream_loop -1 -i video.mp4 -i "$audio" -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720,setsar=1,fps=25,drawtext=text='$(ffprobe -v error -show_entries format_tags=title,artist -of default=nw=1:nk=1 $audio)':fontsize=18:fontcolor=white:x=10:y=h-th-10,format=yuv420p[v]" -map "[v]" -map 1:a -c:v libx264 -c:a aac -ac 2 -ar 44100 -g 50 -b:v 2000k -maxrate 2000k -bufsize 6000k -shortest "${audio%.*}.mp4"

Now that you already did the encoding, and everything is conformed to the same attributes for proper concatenation, you can probably just stream copy your playlist to YouTube (but I didn't test):

ffmpeg -re -f concat -i input.txt -c copy -f flv rtmp://a.rtmp.youtube.com/live2/my-key

Refer to your previous question on how to dynamically update the playlist.

References:

llogan
  • 121,796
  • 28
  • 232
  • 243