2

I am facing some problems with spaces in variables:

ALBUM=' -metadata album="Peregrinações Alheias"'

This command:

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k "$ALBUM" -y $OUT

Returns:

Unable to find a suitable output format for ' -metadata album="Peregrinações Alheias"'

And if I take out the "" from the variable:

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $ALBUM -y $OUT

Returns:

Unable to find a suitable output format for 'Alheias"'

And I am sure I am missing something in the bash sintax...


UPDATE:

So it looks that the matter is not with spaces but with the "-metadata" argument...

The problem is that I have many metadata and I'd like to put them in just one variable. Like this:

META=' -metadata album="Peregrinações" -metadata title="Passeio ao PETAR" -metadata author="Rogério Madureira" -metadata date="2012" -metadata description="Áudio de um passeio ao PETAR" -metadata comment="Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS" '

And then:

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT

5 Answers 5

2

Bash interprets words in quotes as a single argument. Try

ALBUM='album="Peregrinações Alheias"'
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND \
  -acodec libmp3lame -ab 128k -metadata "$ALBUM" -y $OUT
Sign up to request clarification or add additional context in comments.

3 Comments

The problem is that I have many metadata and I'd like to put them in just one variable. Like this META=' -metadata album="Peregrinações" -metadata title="Passeio ao PETAR" -metadata author="Rogério Madureira" -metadata date="2012" -metadata description="Áudio de um passeio ao PETAR" -metadata comment="Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS" '
"Peregrinações Alheias"(double-quotes are unnecessary)
Well, with or without double quotes I am getting this: Unable to find a suitable output format for ' -metadata album=Peregrinações -metadata title=Passeio ao PETAR -metadata author=Rogério Madureira -metadata date=2012 -metadata description=Áudio de um passeio ao PETAR -metadata comment=Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS'
2

Put your command in an array instead.

1 Comment

+1 this is the way to go: META=(-metadata album="Peregrinações" ...); ffmpeg ... "${META[@]}"
1
ALBUM='album=Peregrinações Alheias'

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k -metadata "$ALBUM" -y $OUT

Comments

1

If you always want to set ALBUM, then Adam's answer is OK. But if you want to optionally set ALBUM then use this:

ALBUM="Peregrinações Alheias"
TITLE="Passeio ao PETAR"
OPTIONAL=
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND \
    -acodec libmp3lame -ab 128k \
     ${ALBUM:+-metadata album="$ALBUM"} \
     ${TITLE:+-metadata title="$TITLE"} \
     ${OPTIONAL:+-metadata optional="$OPTIONAL"} \
    -y $OUT

When not setting ALBUM the complete ${var:+subst} block is omitted. Other vars are just the same of course-

Of course this scales up to several -metadata options if there is a fixed set of data you want to set.

Comments

1

Using eval can do what you want... Depending on what you have in $R_IMG, $SOUND and $OUT, they may need double-quote escaping, eg. \"$SOUND\" ....

Your $META (which I assume is another name for youur originally named $ALBUM) doesn't need to be laid out like this, but it surely helps (me) ... Just spaces, as in your original works just as well.

META='
-metadata album="Peregrinações"
-metadata title="Passeio ao PETAR"
-metadata author="Rogério Madureira"
-metadata date="2012"
-metadata description="Áudio de um passeio ao PETAR"
-metadata comment="Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS"
'; META="$(echo "$META" |sed 's|"|\\\\"|g' |tr '\n' ' ')" 

eval "ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT"

If you prefer to not use the sed conversion line, you simply need to change each " in $META to \\" as in this next example:

META=' -metadata album=\\"Peregrinações\\" -metadata title=\\"Passeio ao PETAR\\" -metadata author=\\"Rogério Madureira\\" -metadata date=\\"2012\\" -metadata description=\\"Áudio de um passeio ao PETAR\\" -metadata comment=\\"Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS" '
eval "ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT"

I've tested it successfully with the following ffmpeg encoding parameters:

eval "ffmpeg -i ~/input.flv -sameq -acodec libmp3lame -ab 128k $META -y ~/output.mp3"

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.