<p>You could do this by looping over the videos in a subshell, and piping to another copy of <code>ffmpeg</code> to generate the RTMP stream. For example:</p>

<pre><code>(for j in *.mp4; do
    ffmpeg -threads 2 -re -fflags +genpts -i $j \
        -i '/c/Users/user/Desktop/ffmpeg_logo/mylogo.png' -filter_complex 'overlay=W-w-50:H-h-25' \
        -vcodec libx264 -profile:v baseline -b:v 2000k -r 24 -maxrate 2000k -bufsize 2000k  \
        -ac 2 -ar 44100 -g 48 -c:a aac -b:a 64k \
        -f mpegts -
done) | ffmpeg -f mpegts -i - -c copy -bsf:a aac_adtstoasc -f flv rtmp://user:password@ip:1935/live/mystream
</code></pre>

<p>Notice the brackets around the <code>for</code> loop; that creates a subshell to run the first read &amp; encode <code>ffmpeg</code> command. The output from that command is sent over the <code>stdout</code> ("standard output") <a href="https://bash.cyberciti.biz/guide/Pipes" rel="nofollow noreferrer">pipe</a> to the input of the second <code>ffmpeg</code> command, which generates the RTMP stream. The syntax for that is using <code>-</code> as the name of the input or output file.</p>

<p>I've had to include a <a href="https://ffmpeg.org/ffmpeg-bitstream-filters.html#aac_005fadtstoasc" rel="nofollow noreferrer">bitstream filter</a> <code>aac_adtstoasc</code> because I've used an <a href="https://en.wikipedia.org/wiki/MPEG_transport_stream" rel="nofollow noreferrer">MPEG Transport Stream</a> as the format on the pipe as well.</p>

CC BY-SA 4.0
2020-01-27T00:44:16.560Z
2020-01-27T00:44:16.560Z
Sam M-G
<p>I am bash user and I want to loop all videos from folder to rtmp, one video at a time. I am facing issue of stream stop after a 1st video finished  I need continuous rtmp after finished 1st video and jump to next video. I am using following codes:</p>

<pre><code>for j in *.mp4;
    do
        ffmpeg -threads 2 -re -fflags +genpts  -i $j -i '/c/Users/user/Desktop/ffmpeg_logo/mylogo.png' -filter_complex 'overlay=W-w-50:H-h-25' -ac 2 -f flv -vcodec libx264 -profile:v baseline -b:v 2000k -maxrate 2000k -bufsize 2000k -r 24 -ar 44100 -g 48 -c:a aac -b:a 64k  "rtmp://user:passwd@ip:1935/live/mystream"  

    done
</code></pre>

<ffmpeg>
loop all videos from folder to rtmp stream
jarin
# loop all videos from folder to rtmp stream

(Asked by: username_0 on 2020-01-25)

I am bash user and I want to loop all videos from folder to rtmp, one video at a time. I am facing issue of stream stop after a 1st video finished  I need continuous rtmp after finished 1st video and jump to next video. I am using following codes:
for j in *.mp4;
    do
        ffmpeg -threads 2 -re -fflags +genpts  -i $j -i '/c/Users/user/Desktop/ffmpeg_logo/mylogo.png' -filter_complex 'overlay=W-w-50:H-h-25' -ac 2 -f flv -vcodec libx264 -profile:v baseline -b:v 2000k -maxrate 2000k -bufsize 2000k -r 24 -ar 44100 -g 48 -c:a aac -b:a 64k  "rtmp://user:passwd@ip:1935/live/mystream"  

    done

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2020-01-27. Score: 4

You could do this by looping over the videos in a subshell, and piping to another copy of ffmpeg to generate the RTMP stream. For example:
(for j in *.mp4; do
    ffmpeg -threads 2 -re -fflags +genpts -i $j \
        -i '/c/Users/user/Desktop/ffmpeg_logo/mylogo.png' -filter_complex 'overlay=W-w-50:H-h-25' \
        -vcodec libx264 -profile:v baseline -b:v 2000k -r 24 -maxrate 2000k -bufsize 2000k  \
        -ac 2 -ar 44100 -g 48 -c:a aac -b:a 64k \
        -f mpegts -
done) | ffmpeg -f mpegts -i - -c copy -bsf:a aac_adtstoasc -f flv rtmp://user:password@ip:1935/live/mystream

Notice the brackets around the for loop; that creates a subshell to run the first read & encode ffmpeg command. The output from that command is sent over the stdout ("standard output") pipe to the input of the second ffmpeg command, which generates the RTMP stream. The syntax for that is using - as the name of the input or output file.
I've had to include a bitstream filter aac_adtstoasc because I've used an MPEG Transport Stream as the format on the pipe as well.


---

