Author Topic: Copy and convert audio. Can I do this as a script?  (Read 26975 times)

force_redo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Copy and convert audio. Can I do this as a script?
« on: January 08, 2016, 20:32:53 »
Hi,

I have a little problem that I hope the Multi Commander scripting could help me with but I'm not much of a programmer. I was hoping someone here could help me with this.

- I have an old mp3 player that really only plays mp3 files, no other formats.
- I regularly download podcasts, but not all of them come as mp3 format. Some are m4a etc.

So, what I would like to do is to have a script that copies all files (recursively) from one place to another as long as they're mp3s. If they're not, it should convert it to mp3 and then copy it. (e.g. via lame with some standard settings)
In other words the resulting file/folder structure should look like the source, only that all files are mp3 files.

Is this possible with scripting?

Thanks a lot in advance!
FR

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Copy and convert audio. Can I do this as a script?
« Reply #1 on: January 10, 2016, 16:53:09 »
It might be possible with script.

From script you can get list of files, build command line commands and execute them,  Start copy operations.

Reset

  • Junior Member
  • **
  • Posts: 10
    • View Profile
Re: Copy and convert audio. Can I do this as a script?
« Reply #2 on: November 06, 2017, 08:23:12 »
I know it's an old post but maybe it will help someone else ;-)

It is possible by means of ffmpeg. https://www.ffmpeg.org/download.html
Here is a small script which converts a file from any format supported by ffmpeg from the active window to mp3 and places it in the inactivated window.

You just have to install a loop counter ;-)



Code: [Select]
@var $SourceFile = GetSourceFocusPath();
@var $TargetFile = GetTargetFocusPath();

@var $path = PathGetPathPart($TargetFile);
@var $name = PathGetNamePart($SourceFile, 1);

@var $s =' -i ' + '"' + $SourceFile + '" ' + '"' + $path + $name + '.mp3"';

MC.Run CMD="C:\ffmpeg\bin\ffmpeg.exe" ARG="{$s}"

Gruß

force_redo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Copy and convert audio. Can I do this as a script?
« Reply #3 on: November 18, 2017, 20:05:48 »
Hi Reset,

it was an old post, but I hadn't solved it myself yet. With your help and a bit of copy & paste I came up with this now, which does the trick for the selected files in the current directory. No idea how this would work with recursive subdirectories, but this does the trick for now:

Code: newbielink:javascript:void(0); [nonactive]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $path = GetTargetPath();

@var $SourceFile
@var $s
@var $name

@var $n = 0;

//loop

for( $n = 0; $n < $items; $n++ )
{
  $SourceFile = $arr[ $n ];
  $name = PathGetNamePart($SourceFile, 1);
  $s =' -i ' + '"' + $SourceFile + '" ' + '-map a "' + $path + $name + '.mp3"';
  MC.Run CMD="C:\Program Files\ffmpeg\bin\ffmpeg.exe" ARG="{$s}"

}

P.S.: What is the difference between GetSelectedPaths and GetSourceSelectedPaths? The documentation says:
"An array of the complete paths for all the selected files and folders in the source view" for one
and
"Get an array with the full paths of all selected items in the source view" for the other.

Thanks again!

Reset

  • Junior Member
  • **
  • Posts: 10
    • View Profile
Re: Copy and convert audio. Can I do this as a script?
« Reply #4 on: January 08, 2018, 12:01:29 »
You can speed up the Process, if you add the "-threads x" (where x is the Number of your CPU-Cores) to the ffmpeg Command.

Gruß
« Last Edit: January 16, 2018, 11:19:50 by Reset »

Reset

  • Junior Member
  • **
  • Posts: 10
    • View Profile
Re: Copy and convert audio. Can I do this as a script?
« Reply #5 on: January 16, 2018, 11:21:30 »
A better way with a batch script:

Code: [Select]
for %%a in ("*.*") do ffmpeg -i "%%a" -acodec libmp3lame -b:a 192k -threads 2 "%%~na.mp3"
@echo "********** All Jobs done ***********"
@pause

Gruß