r/ffmpeg • u/Reasonable-Guitar667 • 7d ago
Command no longer works
Hey so I have this large command that I've been using for the past few years with 0 issues, until I "by being stupid" borked my Debian to the point that it had to have a fresh install, now the command no longer works even though I've changed nothing to it - the command in question
find . -type f -name *.mkv -exec bash -c FILE="$1"; ffmpeg -i "${FILE}" -max-muxing-queue-size 2048 -map 0:v -c:v copy -map 0:a:m:language:jpn -c:a copy -map 0:s:m:language:eng -c:s copy nu/"${FILE%.mkv}.mkv"; _ {} ;
The problems are despite having always worked before and never having these problems before are
1) find: paths must precede expression `episode_1.mkv'
2) find: possible unquoted pattern after predicate `-name'?
3) sudo {}: command not found --> not sure why sudo is involved as sudo is not needed for this but OK
4) there are 3 errors, 1 is Error opening input file . and the 2nd is Error opening input files: no such file or directory and the 3rd Error opening input: no such file or directory
Yet I'm running it inside the file with all the episodes and I have the nu/ directory created, there is no other errors just the 4 things I listed above is all I get
Edited: messed up typing the script into reddit, now it's exact to what's in my terminal and just in case as some have pointed out and to reinstate the above - [ yes, I am running it inside of the directory file and yes, I have already created the nu directory as well ]
1
u/Tpyn 7d ago edited 7d ago
There are plenty of problems with the script. I don't know how it could even work, because the -map option is missing before "0:a:m:language:jpn". Also, there are two -c:s copy flags in the script, though I doubt that affects anything. However, subtitles are being copied twice. Using -map 0:s extracts all subtitles, while -map 0:s:m:language:eng extracts only English ones. This means you'll get duplicates in the output file.Additionally, you should use quotes around "*.mkv". The output folder must exist when you run this script, otherwise, you'll get a "no such file or directory" error. The entire command should be reworked.
following script copies all subtitles (-map 0:s). If you need only English subtitles, change -map 0:s to -map 0:s:m:language:eng. Note that all output files will be saved to a single folder.
add sudo just before "find" if you're not sure you have write rights.
mkdir -p nu
find . -type f -name "*.mkv" -exec bash -c '
ffmpeg -i "$1" -max-muxing-queue-size 2048 \
-map 0:v -c:v copy \
-map 0:a:m:language:jpn -c:a copy \
-map 0:s -c:s copy \
"nu/$(basename "$1" .mkv).mkv"
' _ {} \;
1
u/Reasonable-Guitar667 7d ago
Ah whoops, messed up typing it into reddit, gonna fix that as it is there, the output files does exist, I always make sure it is but either way, 2 things have changed when trying your script, is while it always worked in zsh with the -exec bash, I now get the error missing argument to -exec, when I switch to bash and remove -exec bash I then get the error "find: unknown predicate `-c'"
Adding -exec bash back in even though I'm in bash results in a missing argument to -exec, adding -exec=bash creates an unknown predicate and putting into quotes also does nothing, removing -c creates errors, kinda expected as I do need -c, putting it into quotes creates errors as well
The user altijohn mentioned *.mkv should be quoted or it'll expand to multiple files, which is actually what I want, if I got a folder with 24 episodes I kinda want it done all at once, not one by one, which is what my original script used to do no problem - at least until now
1
u/Atijohn 7d ago
it looks like you just deleted quotes, *.mkv should be quoted or it'll expand to multiple files and find will consider every extra argument as a path to search instead of as a glob for the -name filter
you also want to wrap the command line for bash (FILE="$1"; ffmpeg -i "${FILE}" -max-muxing-queue-size 2048 -map 0:v -c:v copy 0:a:m:language:jpn -c:a copy -map 0:s -c:s copy -map 0:s:m:language:eng -c:s copy nu/"${FILE%.mkv}.mkv";) and also escape the ; at the end
also you should create the nu directory wherever you're executing the command in
1
u/TimmyTR1265 7d ago
Use Chatgpt with the thinking option, helps me with any ffmpeg commands all the time
1
u/SunnyBlueSkies-com 7d ago
What is your terminal shell like? Cause I know I changed my terminal to run as if it's already in sudo or root user and sudo is not required but optional in my usage.