[FFmpeg-user] Codec flac change values in output file after LUFS normalization
CMG DiGiTaL
cmarciog at gmail.com
Tue Mar 29 13:15:09 EEST 2022
Em ter., 29 de mar. de 2022 às 05:16, CMG DiGiTaL <cmarciog at gmail.com>
escreveu:
> I made a batch for LUFS normalization that works perfectly for mp3 and I'm
> creating another one to normalize flac files. The normalization of flac
> files also works perfectly, but in the output files, the flac codec changes
> the bit-depth to 24 and the bitrate also changes.
>
> I use tokens to retrieve the sample rate from the input file and write it
> to the output file. It happens that the flac file doesn't have a bitrate
> field so I can also retrieve it with the tokens.
>
> How do I make the output file have the same audio settings as the input
> file after performing LUFS normalization?
>
> see the batch below and the input file and output file information, note
> that the bit-depth and the bitrate have changed:
>
> batch file:
>
> echo.-------------------------------------------------------------------------------------------------------------------------
>
> echo LUFS Audio Converter
>
> echo.-------------------------------------------------------------------------------------------------------------------------
> set /p audios_folder= Type the Folder Name:
> set /p vLUF= Type the LUFS Value:
> set /p vPEAK= Type the True Peak Values:
>
> echo.-------------------------------------------------------------------------------------------------------------------------
> cd\Users\%username%\Desktop\%audios_folder%
> FOR %%a IN (*.flac) DO (
> SET "filename=%%~na"
> ffmpeg -hide_banner -i "%%a" -af "[0:a]loudnorm=print_format=summary" -f
> null NUL 2> "%%~na.log"
> @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Integrated" "%%~na.log"')
> DO (SET II=%%b)
> @FOR /F "tokens=4" %%b IN ('FINDSTR /C:"Input True Peak" "%%~na.log"')
> DO (SET ITP=%%b)
> @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input LRA" "%%~na.log"') DO (SET
> ILRA=%%b)
> @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Threshold" "%%~na.log"')
> DO (SET IT=%%b)
> @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Target Offset" "%%~na.log"') DO
> (SET TO=%%b)
> DEL "%%~na.log"
> SETLOCAL ENABLEDELAYEDEXPANSION
> ECHO !II! is the Input Integrated
> ECHO !ITP! is the Input True Peak
> ECHO !ILRA! is the Input LRA
> ECHO !IT! is the Input Threshold
> ECHO !TO! is the Target Offset
> FOR /F "tokens=1 delims=," %%b IN ('ffprobe -v 0 -select_streams a
> -show_entries "stream=sample_rate" -of "csv=p=0" "!filename!.flac"') DO (
> ffmpeg -hide_banner -i "!filename!.mp3" -af
> "loudnorm=linear=true:I=!vLUF!:LRA=11:tp=!vPEAK!:measured_I=!II!:measured_LRA=!ILRA!:measured_tp=!ITP!:measured_thresh=!IT!:offset=!TO!:print_format=summary"
> -map 0:0 -c:a flac -ar:a %%b "..\LUFS Audio\!filename!_LUFS_CONVERTED.flac"
> )
> ENDLOCAL
> )
>
> input information file:
>
> Input #0, flac, from 'C:\Users\CMG\Desktop\Cazuza - Brasil.flac':
> Metadata:
> ARTIST : Cazuza
> TITLE : Brasil
> ALBUM : Ideologia
> DATE : 1988
> track : 06
> GENRE : Rock
> COMMENT : Track 6
> disc : 1
> TOTALDISCS : 1
> TOTALTRACKS : 12
> Duration: 00:03:12.09, start: 0.000000, *bitrate: 952 kb/s*
> Stream #0:0: Audio: flac, 44100 Hz, stereo, *s16*
>
> "streams":
> "index": 0,
> "codec_name": "flac",
> "codec_long_name": "FLAC (Free Lossless Audio Codec)",
> "codec_type": "audio",
> "codec_tag_string": "[0][0][0][0]",
> "codec_tag": "0x0000",
> *"sample_fmt": "s16"*,
> "sample_rate": "44100",
> "channels": 2,
> "channel_layout": "stereo",
> "bits_per_sample": 0,
> "r_frame_rate": "0/0",
> "avg_frame_rate": "0/0",
> "time_base": "1/44100",
> "start_pts": 0,
> "start_time": "0.000000",
> "duration_ts": 8471316,
> "duration": "192.093333",
> *"bits_per_raw_sample": "16"*,
> "extradata_size": 34,
>
>
>
> output information file:
>
> Output #0, flac, from 'C:\Users\CMG\Desktop\Cazuza -
> Brasil_normalized.flac':
> Metadata:
> ARTIST : Cazuza
> TITLE : Brasil
> ALBUM : Ideologia
> DATE : 1988
> track : 06
> GENRE : Rock
> comment : Track 6
> disc : 1
> TOTALDISCS : 1
> TOTALTRACKS : 12
> encoder : Lavf59.17.102
> Duration: 00:03:12.09, start: 0.000000, *bitrate: 1691 kb/s*
> Stream #0:0: Audio: flac, 44100 Hz, stereo,* s32 (24 bit)*
>
> "streams":
> "index": 0,
> "codec_name": "flac",
> "codec_long_name": "FLAC (Free Lossless Audio Codec)",
> "codec_type": "audio",
> "codec_tag_string": "[0][0][0][0]",
> "codec_tag": "0x0000",
> * "sample_fmt": "s32"*,
> "sample_rate": "44100",
> "channels": 2,
> "channel_layout": "stereo",
> "bits_per_sample": 0,
> "r_frame_rate": "0/0",
> "avg_frame_rate": "0/0",
> "time_base": "1/44100",
> "start_pts": 0,
> "start_time": "0.000000",
> "duration_ts": 8471316,
> "duration": "192.093333",
> *"bits_per_raw_sample": "24"*,
> "extradata_size": 34,
>
================================
I think I found a solution!
I changed the following fields in the command line that generates the
output audio:
FOR /F "tokens=1 to FOR /F "tokens=*1,2 *
-map 0:0 -c:a flac -ar:a %%b to -map 0:0 -c:a flac *-sample_fmt:a %%b*
-ar:a %%c
See below the information of the input and output files after my change:
Informações áudio original:
Input audio information:
Input #0, flac, from 'C:\Users\CMG\Desktop\Cazuza - Brasil.flac':
Metadata:
ARTIST : Cazuza
TITLE : Brasil
ALBUM : Ideologia
DATE : 1988
track : 06
GENRE : Rock
COMMENT : Track 6
disc : 1
TOTALDISCS : 1
TOTALTRACKS : 12
Duration: 00:03:12.09, start: 0.000000, bitrate: *952* kb/s
Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
"streams":
"index": 0,
"codec_name": "flac",
"codec_long_name": "FLAC (Free Lossless Audio Codec)",
"codec_type": "audio",
"codec_tag_string": "[0][0][0][0]",
"codec_tag": "0x0000",
"sample_fmt": "s16",
"sample_rate": "44100",
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/44100",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 8471316,
"duration": "192.093333",
"bits_per_raw_sample": "16",
"extradata_size": 34,
Output audio information:
Output #0, flac, from 'C:\Users\CMG\Desktop\Cazuza -
Brasil_normalized.flac':
Metadata:
ARTIST : Cazuza
TITLE : Brasil
ALBUM : Ideologia
DATE : 1988
track : 06
GENRE : Rock
comment : Track 6
disc : 1
TOTALDISCS : 1
TOTALTRACKS : 12
encoder : Lavf59.17.102
Duration: 00:03:12.09, start: 0.000000, bitrate: *991* kb/s
Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
"streams":
"index": 0,
"codec_name": "flac",
"codec_long_name": "FLAC (Free Lossless Audio Codec)",
"codec_type": "audio",
"codec_tag_string": "[0][0][0][0]",
"codec_tag": "0x0000",
"sample_fmt": "s16",
"sample_rate": "44100",
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/44100",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 8471316,
"duration": "192.093333",
"bits_per_raw_sample": "16",
"extradata_size": 34,
See that *only the bitrate* was not exactly the same as the input
file... Could this be a problem or is it normal?
Note:
If the solution I found is not correct, please let me know!
If there is another way, more optimized, than my solution, let me know too!
More information about the ffmpeg-user
mailing list