Custom action calling avconv in Thunar and Dolphin

avconvdolphinthunar

I like to use a command like

avconv -i %f -map 0:1 -c:a copy %f.m4a

in the custom actions of Thunar or Dolphin to extract audio from mp4 and flv without transcoding.

But that will output a name that contains the extension of the input file:

From a video "name.mp4" I get an audio file called "name.mp4.m4a".

How to adjust the command so that the output is "name.m4a"?

Best Answer

You could use the string manipulation features of bash, by running your command through bash:

bash -c 'avconv -i "$0" -map 0:1 -c:a copy "${0%%.*}".m4a' %f

(I'm assuming that your file manager will pass a filename like foo bar.mp4 as a single argument.)

Note that bash has both ${var%%suffix} and ${var%suffix} - the former is greedy (foo.bar.mp4 will become foo with the first and foo.bar with the second). In this case, I'm aiming to use the latter, and assuming that %% will be replaced by % by the file manager since % is apparently a special character here.

Related Question