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

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 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... –  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! –  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
  • @muru - what I meant was: please post an answer, or, if YOU prefer not to, I'll post YOUR info for you. :) It's done now! –  Sep 14 '15 at 18:12

1 Answers1

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.

muru
  • 69,900
  • 13
  • 192
  • 292