Mia Lon
Mia Lon

Reputation: 23

bash scripting: pass string containing multiple parameters and filenames with spaces to ffmpeg

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

Upvotes: 1

Views: 1203

Answers (2)

Joan Esteban
Joan Esteban

Reputation: 1021

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

Upvotes: 0

user000001
user000001

Reputation: 33307

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[@]}"

Upvotes: 3

Related Questions