[FFmpeg-user] Get sample rate in mp3 files

CMG DiGiTaL cmarciog at gmail.com
Mon Feb 21 02:07:12 EET 2022


hi Reino,

at the command prompt go to the General Audios directory and when I run any
of the commands you sent, the following appears in the terminal window:

C:\Users\CMG\Desktop\General Audios>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"
Input #0, mp3, from 'Lobão - Cuidado.mp3':
  Metadata:
    album           : CMG Clássicos Pop Rock Nacionais
    artist          : Lobão
    genre           : Clássico Pop Rock Nacional
    title           : Cuidado!
    TKEY            : E m
    date            : 1988
    encoder         : Lavf59.6.100
  Duration: 00:03:26.64, start: 0.023021, bitrate: 320 kb/s
  Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc59.12
*..\48000 sample rates Audio\Lobão - Cuidado_converted.mp3: No such file or
directory*

ps. do i need to create the 48000 sample rates folder before running your
command, or will it create the folder automatically?

thanks
Clamarc

Em dom., 20 de fev. de 2022 às 19:38, Reino Wijnsma <rwijnsma at xs4all.nl>
escreveu:

> 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
>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-user mailing list