๐ Utilizing PowerShell and FFMPEG for M4A to MP3 Conversion
๐ | โฐ 3 minutes
I attempted to use the well-known ‘m4a-to-mp3-converter’ from maniactool to convert audio files from M4A to MP3 format, but unfortunately, it did not function as expected.
Given that many media converters utilize the ‘FFMPEG’ library, and without access to a pre-built solution for converting multiple M4A files to MP3, I opted to create my own using PowerShell.
param (
[Parameter(Mandatory=$true)]
[string[]]$args
)
if ($args[0] -eq "-all") {
Write-Output $args[0]
foreach ($file in Get-ChildItem -Filter *.m4a) {
$filename = $file.BaseName
ffmpeg -i $file.FullName -c:v copy -c:a libmp3lame -q:a 4 "$filename.mp3"
}
} else {
foreach ($var in $args) {
$filename = (Get-Item $var).BaseName
ffmpeg -i $var -c:v copy -c:a libmp3lame -q:a 4 "$filename.mp3"
}
}
it just a simple parser script. Here the output:
PS C:\Users\robbi\Downloads\Spotube> C:\Users\robbi\Desktop\Untitled1.ps1
cmdlet Untitled1.ps1 at command pipeline position 1
Supply values for the following parameters:
args[0]: -all
args[1]:
-all
ffmpeg : ffmpeg version 6.1-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
At C:\Users\robbi\Desktop\Untitled1.ps1:10 char:9
+ ffmpeg -i $file.FullName -c:v copy -c:a libmp3lame -q:a 4 "$f ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ffmpeg version ...mpeg developers:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls
--enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
--enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e
--enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx
--enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf
--enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc
--enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine
--enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex
--enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
libpostproc 57. 3.100 / 57. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\robbi\Downloads\Spotube\U&I - Ho - Kago Tea Time.m4a':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
creation_time : 2018-06-05T03:13:46.000000Z
Duration: 00:04:35.97, start: 0.000000, bitrate: 127 kb/s
Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 4 kb/s (default)
Metadata:
creation_time : 2018-06-05T03:13:46.000000Z
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'U&I - Ho - Kago Tea Time.mp3':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
TSSE : Lavf60.16.100
Stream #0:0(und): Audio: mp3, 44100 Hz, stereo, fltp (default)
Metadata:
creation_time : 2018-06-05T03:13:46.000000Z
handler_name : SoundHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.31.102 libmp3lame
size= 0kB time=N/A bitrate=N/A speed=N/A
size= 256kB time=00:00:17.97 bitrate= 116.7kbits/s speed=35.9x
size= 512kB time=00:00:37.69 bitrate= 111.3kbits/s speed=37.7x
size= 768kB time=00:00:54.41 bitrate= 115.6kbits/s speed=36.2x
size= 1024kB time=00:01:09.22 bitrate= 121.2kbits/s speed=34.6x
size= 1536kB time=00:01:29.54 bitrate= 140.5kbits/s speed=35.8x
size= 1792kB time=00:01:47.54 bitrate= 136.5kbits/s speed=35.8x
size= 2048kB time=00:02:02.56 bitrate= 136.9kbits/s speed= 35x
size= 2304kB time=00:02:23.43 bitrate= 131.6kbits/s speed=35.8x
size= 2816kB time=00:02:44.59 bitrate= 140.2kbits/s speed=36.5x
size= 3072kB time=00:03:05.02 bitrate= 136.0kbits/s speed= 37x
size= 3328kB time=00:03:25.97 bitrate= 132.4kbits/s speed=37.4x
size= 3840kB time=00:03:45.07 bitrate= 139.8kbits/s speed=37.5x
size= 4096kB time=00:04:04.11 bitrate= 137.5kbits/s speed=37.5x
size= 4352kB time=00:04:25.58 bitrate= 134.2kbits/s speed=37.9x
[out#0/mp3 @ 000001cbbcbeef00] video:0kB audio:4678kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.007222%
size= 4679kB time=00:04:35.95 bitrate= 138.9kbits/s speed=38.2x
The log said it have issue with file name, but actually it fine. So let it be.. as long it working haha ๐คฃ
Posted by: Hugo