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;
        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"  


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.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.