1

Currently trying to loop a stream of audio files loaded from a .txt file:

 #! /bin/bash
    
        VBR="1500k"
        FPS="30"
        QUAL="ultrafast"
        YOUTUBE_URL=" rtmp://a.rtmp.youtube.com/live2"
        YOUTUBE_KEY="****"
        VIDEO_SOURCE="video.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

The result is that the playlist gets played once and then stops. How can I force the loop?

4
  • 1) Your command should be giving you error: Unrecognized option 'I'. Change -I to -i. 2) Do all of your inputs listed in audiofiles.txt have the same attributes (format, sample rate, channel layout, number of streams)?
    – llogan
    Commented Nov 28, 2020 at 1:24
  • 1
    1) yes, just fixed 2) yes they are all .mp3 with the same sample rate and they all work well during the streaming test: they will loop if directly inserted in the script and played singularly but play only once if in the .txt list.
    – Claus
    Commented Nov 28, 2020 at 17:30
  • 1
    See Is it possible to create an endless loop using concat?
    – llogan
    Commented Nov 28, 2020 at 18:06
  • That was the key! it works now. Maybe you want to post the last comment as an answer so I accept it and close the question. Thank you so much
    – Claus
    Commented Nov 30, 2020 at 11:46

1 Answer 1

2

The concat demxuer input text file can refer to itself to create an endless loop.

Example contents of audio.txt:

ffconcat version 1.0
file 'audio1.mp3'
file 'audio2.mp3'
file 'audio.txt'

The header ffconcat version 1.0 is required for this to work.

Simple example command to continuously loop 2 audio files listed in audio.txt and end output duration at the same duration as video.mp4:

ffmpeg -i video.mp4 -f concat -i audio.txt -shortest output.mp4

Adapted from Is it possible to create an endless loop using concat?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .