Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

FFmpeg: Loop stream of several audio files and a short video

Writer Matthew Martinez

I saw a code to stream several audio files in another topic of questions here on the site. However, I have some doubts regarding this, because in my case, there is no sound and I really wanted your help to solve this problem. The code is this:

#! /bin/bash
VBR="1500k"
FPS="24"
QUAL="superfast"
YOUTUBE_URL="rtmp://"
YOUTUBE_KEY="****"
VIDEO_SOURCE="/home/ubuntu/BG Fundo 01 480p.mp4"
AUDIO_ENCODER="aac"
ffmpeg \
-stream_loop -1 \
-re \
-i "$VIDEO_SOURCE" \
-thread_queue_size 512 \
-stream_loop -1 \
-re \
-f concat -i audiofiles.txt \
-c:v libx264 -preset $QUAL -r $FPS -g $(($FPS *2)) -b:v $VBR -bufsize 3000k -maxrate $VBR \
-c:a $AUDIO_ENCODER -ar 44100 -b:a 128k -pix_fmt yuv420p \
-f flv $YOUTUBE_URL/$YOUTUBE_KEY

And here I have the following problem: There is no sound from the audio files that I left in "audiofiles.txt", even though the video is looping.

The content that is in "audiofiles.txt" is as follows:

ffconcat version 1.0
file '/home/ubuntu/music/spontaneous01.mp3'
file '/home/ubuntu/music/spontaneous02.mp3'
file '/home/ubuntu/audiofiles.txt'

Notes to make: the video source is 5s long, and each audio is about 1 hour long, both video and audio are in separate folders as an example "/home/ubuntu/video/arquivo.mp4" and with I'm sure the video has no sound, which I don't think is necessary, but if you do, let me know because I'm a very layman on that subject.

Until then, the only real problem is to make the sound come out in the video, because the video was in a loop, but the sound of the files in concat does not come out at all.

I thank everyone who can help me in this, thank you!

I opened a new question because the old one had already been closed, but it didn't quite work out for me:

3

1 Answer

Friends, I managed to solve it in a much simpler way than I imagined. I'll leave here the code I used and the comments will follow below shortly after:

#! /bin/bash
VBR="1500k"
FPS="24"
QUAL="superfast"
YOUTUBE_URL="rtmp://"
YOUTUBE_KEY="spjs-50hd-ujx2-t2ma-1xe9"
VIDEO_SOURCE="/home/ubuntu/video/BG Fundo 01 720p.mp4"
AUDIO_ENCODER="aac"
ffmpeg \
-stream_loop -1 \
-re \
-i "$VIDEO_SOURCE" \
-thread_queue_size 512 \
-stream_loop -1 \
-re \
-f concat -i /home/ubuntu/music/audiofiles.txt \
-map 0:v:0 -map 1:a:0 \
-map_metadata:g 1:g \
-c:v libx264 -preset $QUAL -r $FPS -g $(($FPS *2)) -b:v $VBR -bufsize 3000k -maxrate $VBR \
-c:a $AUDIO_ENCODER -ar 44100 -b:a 128k -pix_fmt yuv420p \
-f flv $YOUTUBE_URL/$YOUTUBE_KEY

By doing this I was able to concatenate the audio files without generating another output.mp3 file for streaming. The observations that I took as a rule and that make a total difference in this type of code are as follows:

  1. I made the mapping of the video input and then audio, since in this case the video input was informed first.

  2. This mapping only works if the lines "-map 0: v: 0 -map 1: a: 0 " and "-map_metadata: g 1: g " are just below the listed concatenated file which is audiofiles.txt and if they are before the call to the Audio and Video Codec that starts from the line "-c: v libx264 -preset (...)" onwards.

  3. The concatenated files are in the same example directory as the "audiofiles.txt" file and their contents are as follows:

    ffconcat version 1.0 file spontaneous01.mp3 file spontaneous02.mp3 file audiofiles.txt

Filenames with quotes or double quotes didn't work at all, I don't know the specific reason for that, but it really didn't work.

These are the observations I made and took as a basis, and now I have the ability to concatenate any audio file in real time just by placing it in the same directory as the others and listing it within the text file. Thanks to @llogan who with his comments, even though I didn't answer my question but opened my mind to explore possible solutions to the problem.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy