我有一个 bat 文件,可以规范几个文件夹音频。
我需要从 txt 文件中删除一些行,这些行将用于消除音频文件中的自定义标签。
我使用以下命令通过 bat 文件运行 powershell:\
"%systemroot%\system32\windowspowershell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -Command "gci *.txt | foreach { (cat $_.fullname | ? { $_ -match 'METADATA|title|encoder' }) | set-content $_.fullname }"
我使用-WindowStyle Hidden选项,这样powershell控制台就不会出现,但是当执行powershell命令时,bat控制台屏幕关闭并终止。
代码:
md "C:\Users\%username%\Desktop\Temp_normalizing_lufs" ------> temp folder audio files being normalized
pushd "%Userprofile%\Desktop\µudios LUFS" ------> folder with the original audio files
__
FOR /F "delims=" %%a in ('where .:*.mp3 ^|findstr /vi "_LOUDNORM _EBU"') 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) | set original audio files values
@FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input LRA" "%%~na.log"') DO (SET ILRA=%%b) | to use as parameters in loudnorm
@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
FOR /F "tokens=1,2 delims=," %%b IN ('ffprobe -v 0 -select_streams a -show_entries "stream=bit_rate,sample_rate" -of "csv=p=0" "!filename!.mp3"') ----> getting the sample rate and bitrate of the original audio file to use as parameters in loudnorm
DO (
ffmpeg -hide_banner -i "!filename!.mp3" -an -f ffmetadata -vsync vfr "!filename!.txt"
"%systemroot%\system32\windowspowershell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -Command "gci !filename!.txt | foreach { (cat $_.fullname | ? { $_ -match 'METADATA|title|encoder' }) | set-content $_.fullname }"
ffmpeg -hide_banner -i "!filename!.mp3" -c:a copy -map_metadata -1 -vsync vfr "!filename!_not_tags.mp3"
ffmpeg -hide_banner -i "!filename!_not_tags.mp3" -i "!filename!.txt" -codec copy -id3v2_version 3 -map_metadata 1 -id3v2_version 3 -vsync vfr "!filename!_with_tags.mp3"
ffmpeg -hide_banner -i "!filename!_with_tags.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" -c:v copy -id3v2_version 3 -metadata disc="" -metadata comment="" -metadata lyrics-eng="" -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -acodec mp3 -b:a %%c -ar:a %%b "C:\Users\%username%\Desktop\Normalizando_lufs\!filename!.mp3"
del /q "C:\Users\CMG\Desktop\µudios LUFS\!filename!.txt"
del /q "C:\Users\CMG\Desktop\µudios LUFS\!filename!_not_tags.mp3"
del /q "C:\Users\CMG\Desktop\µudios LUFS\!filename!_with_tags.mp3"
)
ENDLOCAL
)
xcopy "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.mp3" "C:\Users\%username%\Desktop\Normalized µudios Lufs\LOUDNORM\MP3\LUFS %-10.0%" /y /s /i ----> copying the audio files from the temporary folder to the final folder
__
del /q "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.*" |
rmdir "C:\Users\%username%\Desktop\Temp_normalizing_lufs" /s /q | Removing the temporary folder from the desktop
__|
如何运行 powershell 而不出现 powershell 控制台屏幕并保留 bat 文件控制台屏幕?
注意:
powershell 命令位于 SETLOCAL ENABLEDELAYEDEXPANSION 内执行的 for 循环内