Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Programming and Hacking > Development
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th May 2019, 01:49   #1  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
How to batch convert audio files in a portable way?

My long term goal is to learn how to do things the command line and portable way and maybe try Linux and MacOS in the future.

How would you batch convert audio files?

Here is my solution in PowerShell and only tested in Windows:

Code:
$inputFolder = "C:\Users\frank\Daten\Music Temp"
$outputFolder = "C:\Users\frank\Desktop\mp3 files"

Get-ChildItem $inputFolder |
Foreach-Object {
    $targetpath = $outputFolder + "\" + $_.BaseName + ".mp3"
    ffmpeg -i $_.FullName -b:a 320k $targetpath
}
GUI is fine as long as it is portable.
stax76 is offline   Reply With Quote
Old 18th May 2019, 11:41   #2  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Well, FFmpeg already is portable, so is this mostly a question about the scripting?

If so, I think shell script (e.g. Bash) is the way to go:

Code:
readonly input_folder="/home/johndoe/Music"
readonly output_folder="/home/johndoe/Desktop"

for source_path in "$input_folder/"*; do
    target_path="$output_folder/$(basename -s .wav "$source_path").mp3"
    ffmpeg -i "$source_path" -b:a 320k "$target_path"
done
This should work on any Unix and Unix-like OS (e.g. Linux or macOS ) out of the box. On Windows, you can use MSYS/MinGW or Cygwin, for example (I recommend giving MobaXterm a try to get started).

Could even use BusyBox for Win32 as a minimal Unix shell on Windows. And, of course, Microsoft's PowerShell is more or less "portable" now, as well...
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 18th May 2019 at 11:54.
LoRd_MuldeR is offline   Reply With Quote
Old 18th May 2019, 13:17   #3  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,420
Another Bash example. This is the script I use to process my audio CD backups:
Code:
#!/bin/bash -x
set -e
cd FLAC
for n in *.wav ; do
flac --no-preserve-modtime -V -8 "$n"
done

cd ..
for n in *.wav ; do
qaac --abr 192 --no-smart-padding --rate keep -o "MP4/${n%.*}.m4a" "$n"
done

for n in *.wav ; do
opusenc  --bitrate 192 --comp 10 --framesize 60 --ignorelength "$n" "Opus/${n%.*}.opus"
done
Not that I'm saying anything for/against using the format tools, it was more about the shell substitution and regex abilities ( ${n%.*} ).

Last edited by qyot27; 18th May 2019 at 13:20.
qyot27 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 13:04.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.