I have multiple folders that contain multiple videos. I need the videos in each folder to be concatenated into one video.
I am using one bash loop to create a list of files that need to be concatenated and a second bash loop to run ffmpeg over all the folders.
The first bash loop is working fine: https://pastebin.com/UUQgyRvD
The second loop ( https://pastebin.com/TyhCGZLA ) , however, only runs ffmpeg on the first file found and then stops. When I then go and delete the mylist.txt file of the already concatenated video, it manages to run the second file.
So the loop is working, partially, but the part that calls ffmpeg is not being repeated. I have no clue what I am doing wrong here...
Are you sure ffmpeg was finished before your deleted its input? It sounds like it was just taking longer than you expected. If that's not it, I don't know. The script doesn't look obviously wrong to me, but you're complicating this more than you need to, and simplifying is often an easier way to fix bugs than figuring out why the complicated thing isn't working. For looping over files in the current directory you want for and a glob: do ... done will loop over just the subdirectories of the current directory. */ only matches directories, so you don't need the test. Using a subshell to reset the current working directory is going around the world. pushd/popd are what you want. Try do pushd "$d" ffmpeg -f concat -i mylist.txt -threads 35 -c copy concat.avi popd done Since you're not doing set -e you don't need to worry about ffmpeg failing and leaving you in the last directory the script was working on when it failed. for d in */
for d in */
You could concatenate the scripts, but the only difference between your two scripts is the body of the loop, so you could just combine the loops. That would be cleaner. Or, as bhrgunatha suggested, use process substitution instead of generating mylist.txt then passing it to ffmpeg.
Not sure this will help much, but when I first generate the files (ImageMagick) that I later want to combine into a video, I append on a suffix: filename"_0000".png, filename"_0001".png, etc., and then when I call ffmpeg, I don't feed it a list, I just turn it loose in the subdirectory containing the files with: ffmpeg -r 30 current_directory/filename_%4d.png -vcodec libx264 -pix_fmt yuv420p Maybe your script isn't ingesting mylist.txt correctly, and getting hosed up? Using a new naming convention, with "$4d" instead of feeding it a .txt list, should test that. Note: "filename" is just one string, never changing, for all files. I would say I'm something of a "just bangin' two rocks together" type of programmer, fair warning.
My files are created by a program I cannot edit so I am bound to that. They are in numeric order, however, they are msCam1.avi, msCam2.avi,... msCam15.avi I am using the -v in the first script to get the natural sorting of the files so they are in the correct order and then passing it to ffmpeg Any suggestion how I could achieve the same without going through the first loop?
I'm pretty sure the sorting is doing msCam1.avi, then msCam10.avi, msCam11.avi, all the way up to msCam19, before it makes it to msCam2. I just checked, and that's how my "ls -v" command sorts things. Not sure about the rest, but that's probably gotta get fixed first. I deal with shit like this all of the time, but not in a command shell (bash). I primarily use IDL, Matlab, and Python, so I'm not terribly helpful here. Apologies! Also, I suspect you're working on distilling security cam footage, a cam which is triggered by a motion sensor apparently at least 15 times per day. Did I win?
Nope. :D It is actually some small program that accesses a webcam and saves a video after 1000 frames. They are videos of mouse behavior in a kind of place preference test that is modified to test the preference of the animals to temperature. I wanted to switch to something easier (like micromanager) but because I started all my analysis with that (and trained a neural net to do the analysis for me using these outputs) I am just sticking with it until the project is finished. I was thinking of using python instead as I know I could just use the natsort package to do the sorting and there is probably some python wrapper for ffmpeg like this one.Also, I suspect you're working on distilling security cam footage, a cam which is triggered by a motion sensor apparently at least 15 times per day. Did I win?
Nice. Mice. Yep, you could just make a wrapper script in whatever language you're comfortable renaming and/or handling everything, and pass strings to a terminal for running ffmpeg, but then bfv might kill both of us. Up to you :/. Edit: hahhaha I wrote this before I saw that he solved it :). OK bfv, now I know who to bother when my attempts at parallelizing processes for GPU architectures go up in possibly actual flames
I don't know why, but the ffmpeg wiki says you can avoid generating the input file. I'd be tempted to just loop through the sub directories (ls -d */) and copy/paste the wiki example.