[FFmpeg-user] Get sample rate in mp3 files
Reino Wijnsma
rwijnsma at xs4all.nl
Mon Feb 21 03:44:47 EET 2022
On 2022-02-21T01:38:30+0100, CMG DiGiTaL <cmarciog at gmail.com> wrote:
> OK, I would also need, along with the sample rate, to get the bitrate of
> the file, because I realized that in the conversion, because I'm using
> --acodec -b:a 320k, it's passing all the aidios to 320 kbps... until even
> 192 kbps audio!. is there a way in the conversion I can get the correct
> bitrate of each file?
You could do...
ffprobe -v 0 -show_entries stream=bit_rate,sample_rate -of csv=p=0 "input.mp3"
...which would return for instance:
48000,128000
Then within the FOR-loop set the delimiter to the comma:
FOR %A IN (*.mp3) DO @FOR /F "tokens=1,2 delims=," %B IN ('ffprobe -v 0 -show_entries stream^=bit_rate^,sample_rate -of csv^=p^=0 "%A"') DO @IF %B EQU 48000 ffmpeg -hide_banner -i "%A" -c:a libmp3lame -b:a %C -ar 44100 "..\48000 sample rates Audio\%A"
...or prettified:
FOR %A IN (*.mp3) DO @(
FOR /F "tokens=1,2 delims=," %B IN ('ffprobe -v 0 -show_entries stream^=bit_rate^,sample_rate -of csv^=p^=0 "%A"') DO @(
IF %B EQU 48000 ffmpeg -hide_banner -i "%A" -c:a libmp3lame -b:a %C -ar 44100 "..\48000 sample rates Audio\%A"
)
)
- Notice the -b:a %C.
- Initially I had %~nA_converted.mp3 for the output, but if you want the original filename (seeing they're being dumped into a separate directory anyway), then you can just as well enter %A.
Note: lossy to lossy conversions are NOT recommended quality wise. Especially with a low bitrate. Always try to use the lossless source as much as possible!
--
Reino
More information about the ffmpeg-user
mailing list