Process the inside of the folder at once with ffmpeg

less than 1 minute read

Convert all video files (avi etc.) in the avi folder to mp4

# ffmpeg -i avi/MOVI0192.avi mp4/MOVI0192.avi.mp4
 ls avi/ | xargs -i ffmpeg -i avi/{} mp4/{}.mp4

Concatenate mp4s in a folder into one mp4

echo -n > list.txt
ls mp4/ | xargs -i echo file mp4/{} >> list.txt
ffmpeg -f concat -i list.txt -c copy concatmp4/$(date "+%Y%m%d").mp4

I wrote a file to be concatenated to a file called list.txt and gave it to ffmpeg as an argument.

I’m passing each line redirected by xargs to {} in the following command. In the above example, the name of the file output by ls is converted to {}, and the command is executed repeatedly.