Andy
Andy

Reputation: 613

How to tell ffmpeg to loop through all files in directory in order

ffmpeg has concat option for this but all streams start working really bad and breaking sound after a day of streaming.

I tried looking at loops but i couldnt figure out how to execute a loop with ffmpeg command so it transcodes all files in 1 directory

/lely/ffmpeg -y -re -i /home/ftp/kid1.mp4 -vcodec copy -acodec copy -dts_delta_threshold 1000 -ar 44100 -ab 32k -f flv rtmp://10.0.0.17:1935/live/kid

In folder /home/ftp/ there are files kid1, kid2, kid3 - all *.mp4 files

So basically i would like a loop to change the input to next file every time previous ends.

Upvotes: 2

Views: 8756

Answers (2)

Denio Mariz
Denio Mariz

Reputation: 1195

You can concatenate the video files to a "named pipe" and use the pipe as a source for ffmpeg. For example:

    mkfifo pipeFile            # create a FIFO file (named pipe)
    cat $(find /home/ftp -name "*.mp4") > pipeFile &  # concatenate video files do the pipe (do not forget the "&" for running in background)
    /lely/ffmpeg -y -re -i pipeFile -vcodec copy -acodec copy -dts_delta_threshold 1000 -ar 44100 -ab 32k -f flv rtmp://10.0.0.17:1935/live/kid  # run ffmpeg with the pipe as the input

Notes:

  1. The order of files in the input will be that the find generates. You can add a "sort" command after the find to produce files in a sorted manner.
  2. I have not tested this, since a I do not have ffmpeg installed. However, it should work :-)

Upvotes: 0

julumme
julumme

Reputation: 2366

Maybe you could use find and xargs to help you feed the files for ffmpeg:

find /home/ftp -name "*.mp4" | xargs -I $ /lely/ffmpeg -y -re -i $ -vcodec copy -acodec copy -dts_delta_threshold 1000 -ar 44100 -ab 32k -f flv rtmp://10.0.0.17:1935/live/kid

Here you first ask find to look for all mp3 files in /home/ftp.

Then you feed the results to xargs. For xargs you tell it to replace input it receives with token $ in your ffmpeg string.

Upvotes: 7

Related Questions