1

I have a script that generates a text file with entries like:

-ss 5.5 -i "/path/vid 1.mp4" -t 3 "/path/vid out1.mp4"

But when I call ffmpeg with this string attached it fails. If I quote the variable then ffmpeg considers the entire string as a single option, error "Option not found". If I don't quote, then for some reason ffmpeg ignores the double quotes and reports "/path/vid :No such file or directory.

Even though it prints the input correctly as -i "/path/vid 1.mp4".

Replacing the double quotes around the filenames with single quotes doesn't help. But when I pass the string to zenity and then manually copy it into the terminal, it works:

zenity --entry --entry-text "ffmpeg -nostdin $line2"

So I tried assigning the entire command to a var and then running bash $var or exec $var, but no luck. Assigning it to an alias doesn't work either: "command not found"

Solution by Joan Estaban:

echo $stringvar | xargs ffmpeg

A short full script demonstrating the problem:

#!/bin/bash


fffile="/home/vume5/Desktop/dwhelper/bud grafting animation.mp4"

line="-ss 4.920000 -i \"$fffile\" -t 60.000000 -map 0 -c:v copy -c:a copy \"$fffile.cut.mkv\""

zenity --entry --entry-text "$line"

ffmpeg $line

read dummy
6
  • does manually trying the command ffmpeg -ss 5.5 -i "/path/vid 1.mp4" -t 3 "/path/vid out1.mp4" work? Commented Sep 2, 2016 at 9:30
  • Yes. I think the problem is that the double quotes are considered as filename characters. That's what it looks like. And I've no idea how to prevent this. Commented Sep 2, 2016 at 9:54
  • Just guessing, but would this help? -ss 5.5 -i "\"/path/vid 1.mp4\"" -t 3 "\"/path/vid out1.mp4\"" Commented Sep 2, 2016 at 10:10
  • Nope. Then it's ""/path/vid :no such file.. The problem seems to be the opposite. That the quotes DO NOT get interpreted, and treated as filename chars. Commented Sep 2, 2016 at 10:29
  • 1
    You can try xargs: cat my_params.txt | xargs -l ffmpeg Commented Sep 2, 2016 at 10:39

2 Answers 2

3

If your arguments may contain spaces and/or other special characters, then you can use an array to store them.

e.g.:

params=(-ss 5.5 -i "/path/vid 1.mp4" -t 3 "/path/vid out1.mp4")
mycommand "${params[@]}"
Sign up to request clarification or add additional context in comments.

Comments

0

If you have a text file with desired params for each execution you can use xargs:

cat my_list_of_params.txt | xargs -l ffmpeg

This execute ffmpeg as many times as lines on file. Param -l means that for each line on file must execute one time ffmeg

Comments

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.