a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment by user-inactivated
user-inactivated  ·  1557 days ago  ·  link  ·    ·  parent  ·  post: Why is my bash loop not working?

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:

    for d in */

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

    for d in */

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.





Cumol  ·  1555 days ago  ·  link  ·  

Your script solved the issue. I am not sure why but I guess I did overcomplicate things.

Is it possible for me to have both scripts in the same file (or combined)?

Can I simply put both of them in the same file and they would be run one after the other?

user-inactivated  ·  1555 days ago  ·  link  ·  

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.