0

I work on a Mac Terminal. I have 250 video files in a directory. For each one, I want a 20seconds subclip between seconds 10 and 20, and 179 and 207. I would like the output file to be named the same as the input file plus a "_1" suffix so I can distinguish them. At the moment, I have the following code:

#!/bin/bash

for %%f in (*.mp4) do ffmpeg -i "%%f" -vf "select='between(t, 10, 20) +
between(t, 197, 207)', setpts=N/FRAME_RATE/TB" -qscale 0 -af "aselect='between(t, 10, 20) + 
between(t, 197, 207)', asetpts=N/SR/TB" "%%~nf_1.mp4"

When I execute, it gives me the following error: syntax error near unexpected token `('

If I remove the loop and just try with a specific "inputfilename.mp4" and "inputfilename_1.mp4" (i.e. my desired output filename), it works. As for the output filename in the above code, this post suggests that the "~nf" removes the extension (i.e. ".mp4") from the inputfile, so I added the _1.mp4 afterwards.

Any suggestions? Thank you in advance.

2
  • %%f syntax is batch windows cmd but the first line indicates you're using bash, which language do you want to use? Commented Jun 29, 2018 at 12:52
  • @Nahuel Fouilleul using bash. I am on a Mac terminal. Commented Jun 29, 2018 at 15:10

2 Answers 2

1

Finally, the one that works looks like:

for file in *.mp4; do ffmpeg -i "$file" -vf "select='between(t, 10, 20) + between(t, 197, 207) + between(t, 10, 20) + between(t, 197, 207)', setpts=N/FRAME_RATE/TB" -qscale 0 -af "aselect='between(t, 10, 20) + between(t, 197, 207) + between(t, 10, 20) + between(t, 197, 207)', asetpts=N/SR/TB" "${file%.mp4}_1.mp4"; done
Sign up to request clarification or add additional context in comments.

Comments

0

Your loop should be

for %%f in *.mp4 do

in other words, lose the parenthesis. The "in" part of the loop expects a list of parameters. The *.mp4 will expand to include all filenames that match.

If you have two files a.mp4 and b.mp4 then the *.mp4 will be expanded before the loop executes to be:

for %%f in a.mp4 b.mp4 do

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.