1

I would like to modify my code to convert a folder with FFMPEG instead of converting a whole list of files, and loop this list:

#!/bin/bash

while true; do ffmpeg -re -i /myfolder/10.mp4 -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output; ffmpeg -re -i /myfolder/11.mp4 -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output; ffmpeg -re -i /myfolder/12.mp4 -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output; ffmpeg -re -i /myfolder/13.mp4 -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output; done

my code for convert the folder :

#!/bin/bash

while true; do stream1=/myfolder/*.mp4 ffmpeg -re -i $stream1 -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output; done

This code produces an error:

File '/myfolder/11.mp4' already exists. Overwrite ? [y/N]
Raffa
  • 34,963

1 Answers1

2

In your code snippet:

#!/bin/bash

while true; do

stream1=/myfolder/*.mp4 ffmpeg -re -i $stream1 -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output; done

The unquoted $stream1 (in your case) will expand to:

/myfolder/10.mp4 /myfolder/11.mp4 /myfolder/12.mp4 /myfolder/13.mp4

... and your ffmpeg command-line will look like this:

ffmpeg -re -i /myfolder/10.mp4 /myfolder/11.mp4 /myfolder/12.mp4 /myfolder/13.mp4 -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output

... making /myfolder/11.mp4 the output file for the input one /myfolder/10.mp4 as ffmpeg's option -i expects only one argument as input.

Therefore, ffmpeg asks for confirmation to overwrite the already existing output filename /myfolder/11.mp4:

File '/myfolder/11.mp4' already exists. Overwrite ? [y/N]

... which you don't want to overwrite as this is one of your input filenames and not output.

That's the explanation part ... However, I am not an ffmpeg expert to suggest how you might specify a whole directory's content as input other than what you already know which is looping over the files and providing them one at a time in a shell loop like the one you provided in your question.

If what you want is just to loop over all existing files without the need to specify all the filenames in the script, then you can use something like this:

#!/bin/bash

while true do for f in /myfolder/*.mp4 do ffmpeg -re -i "$f" -vcodec copy -acodec copy -r 30 -s 1280x720 -f flv rtmp://localhost/live/output done
done

Raffa
  • 34,963