0

I am trying to create a waveform png for a bunch of videos using ffmpeg -filter_complex

The single line command works fine & produces the expected waveform graphic for a single video file:

ffmpeg -i INPUT.mp4 -filter_complex:a "showwavespic=s=1080x120" -frames:v 1 OUTPUT.png

When I try to automate the process for multiple files

for f in *.mp4
do
 ffmpeg 
  -i "$f"
  -filter_complex:a "showwavespic=s=1080x120" 
  -frames:v 1 
  '"${f%.mp4}.png"'
done

ffmpeg returns an error:

Unable to find a suitable output format for '"INPUT.png"'

'"INPUT.png"': invalid argument

I also tried the stripped down command:

for f in *.mp4
do
 ffmpeg -i "$f" -filter_complex 'showwavespic' -frames:v 1 “${f%.mp4}.png”
done

but got the same argument error.

I'm guessing the problem is because of bash syntax, and I am not escaping the quoted arguments properly. I tried multiple versions of the command, but to no success. How do I fix this for loop?

1 Answer 1

3

Remove the single quotes (') around "${f%.mp4}.png".

Your second command seems to use typographer's quotes () instead of plain double quotes ("), which is what you want.

Double quotes (") tells Bash that what's within the quotes should be treated as one parameter to the called command, even if it has a space within it. The quotes will not be passed to the called command. Bash does not consider typographer's quotes to be special so it will pass them to the command, and your script won't work because they aren't actually part of the filename.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm not sure how the hell this happened. I tried like a dozen versions with all kinds of quotes, including the version you suggest. Anyway, this worked. :)
@user1891836 Possibly one of those "helpful" text editors that meddle with your content? I've seen similar issues from some OS X users editing their scripts or commands with TextEdit.
Great catch with the quotes. And yup. TextEdit it was! Even though I never use anything other than plain text mode, I got these errors anyway. Will switch entirely to Sublime for now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.