1

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"?

  • 1
    Maybe something like: avconv -i %f -map 0:1 -c:a copy ${%f%%.*}.m4a, if the custom actions are run through bash. – muru Sep 14 '15 at 16:59
  • @muru - It's the custom actions in Dolphin/KDE what I use for the moment, and there, in the .desktop file that is used, if I replace my command with yours it does nothing. About bash I have to get more info... – user32012 Sep 14 '15 at 17:05
  • 1
    Run your commands through bash: bash -c 'avconv -i "$0" -map 0:1 -c:a copy "${0%%.*}".m4a' %f – muru Sep 14 '15 at 17:08
  • It works. Would you mind posting as answer too? Thank you for the swift reply! – user32012 Sep 14 '15 at 17:17
  • If you have an improved command, I'll delete my answer, no problem. – muru Sep 14 '15 at 17:24
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy