[FFmpeg-user] Get sample rate in mp3 files
Reino Wijnsma
rwijnsma at xs4all.nl
Mon Feb 21 00:38:05 EET 2022
Hello Clamarc,
(late reply as I'm a bit behind with cleaning up e-mails)
On 2022-02-07T22:47:29+0100, CMG DiGiTaL <cmarciog at gmail.com> wrote:
> I have a folder "General Audios" and I created another one called "Audios
> 48000 sample rate"
>
> I'm running the ffprobe command that returns the sample rate value of each
> song.. but when I try to save the value in a string to be able to use the
> IF and copy only the ones with 48000 hz, I get a message that the command
> is a command input? what is wrong?... I just want to be able to take
> advantage of the if sulted the ffprobe command and you can do the if!...
> that's all!
>
> md "C:\Users\%username%\Desktop\48000 sample rates Audio" ---> created
> folder
>
> cd\Users\%username%\Desktop\General Audios
> ---> original folder
>
> ffprobe command that separates only the
> sample rate of the songs in the folder:
> set var if var
> Generate files in folder
> for %%F IN (*) do (ffprobe -i "%%F" -v error -show_entries
> stream=sample_rate -of default=noprint_wrappers=1:nokey=1 *set* *%%S
> if %%S*==48000
> ("C:\Users\%username%\Desktop\48000 sample rates Audio\%%F")
> )
> pause
No need for a Batch-file. Just navigate to the appropriate dir...
cd "Users\%username%\Desktop\General Audios"
...and enter the following one-liner:
FOR %A IN (*.mp3) DO @FOR /F "delims=" %B IN ('ffprobe -v 0 -show_entries stream^=sample_rate -of default^=nk^=1:nw^=1 "%A"') DO @IF %B EQU 48000 ffmpeg -hide_banner -i "%A" -c:a libmp3lame -b:a 320k -ar 44100 "..\48000 sample rates Audio\%~nA_converted.mp3"
...or the same FOR-loops a bit more readable (prettified):
FOR %A IN (*.mp3) DO @(
FOR /F "delims=" %B IN ('ffprobe -v 0 -show_entries stream^=sample_rate -of default^=nk^=1:nw^=1 "%A"') DO @(
IF %B EQU 48000 ffmpeg -hide_banner -i "%A" -c:a libmp3lame -b:a 320k -ar 44100 "..\48000 sample rates Audio\%~nA_converted.mp3"
)
)
- Don't forget to escape the equals signs in the ffprobe command, or the FOR-loop will execute the ffprobe command without them.
- In the process you'll only see ffmpeg converting the 48kHz mp3-files. If you want more verbosity, just remove one or both of the "@" signs.
--
Reino
More information about the ffmpeg-user
mailing list