对于遇到这种必要性的任何人,我都会提出这个问题。
需要一个脚本,可以找到 ffmpeg.exe 可以处理的所有视频文件(如 avi、mp4、mov、flv、mkv、webm 等),提取编码和帧大小信息并使用 H 下转换为 1920 x 1080 或更小.264 编码并应用 aacgain.exe(到 aac 音频)
对于遇到这种必要性的任何人,我都会提出这个问题。
需要一个脚本,可以找到 ffmpeg.exe 可以处理的所有视频文件(如 avi、mp4、mov、flv、mkv、webm 等),提取编码和帧大小信息并使用 H 下转换为 1920 x 1080 或更小.264 编码并应用 aacgain.exe(到 aac 音频)
这不是一个问题,而是一个分享我所做工作的帖子。
我最近购买了 Synology DS220J 并在其上安装了 Plex 服务器。在因为我遇到很多“服务器没有能力转换此视频”消息而感到沮丧之后,我发现这发生在以下视频中:
因此,我编写了一个 Windows 批处理脚本,它将批量转换我的视频文件(mkv、avi、webm、mp4、flv 等),以便生成的视频具有以下特征:
您将需要创建以下文件夹结构并添加以下程序:
**Folders**
D:\Vids\bin
D:\Vids\bin\original
D:\Vids\bin\working
D:\Vids\bin\completed
**Files**
D:\Vids\bin\ffmpeg.exe
D:\Vids\bin\ffprobe.exe
D:\Vids\bin\aacgain.exe
D:\Vids\bin\normalize_video_for_plex.bat (copy the batch script below and name it thusly)
将您的视频文件放在 D:\Vids\bin\original 文件夹中,然后运行以下“normalize_video_for_plex.bat”DOS/Windows 批处理文件。
rem echo off
setlocal enableextensions enabledelayedexpansion
set A=0
set /A COUNTER=COUNTER+1
echo on
for %%I in (d:\Vids\bin\original\*.*) DO (
set ORIG_FILE=%%~nI%%~xI
set TEMP_INPUT_FILE=%%~xI
set TEMP_WORK=.bat
rem echo Creating working\.bat
echo echo off
echo cls
echo set ORIG_FILE="%%~nI%%~xI"
echo set TEMP_INPUT_FILE=TEMP_!COUNTER!%%~xI
echo set NEW_FILE="..\completed\%%~nI.mp4"
echo.
echo echo -------------------------------------------------------------------------
echo echo Normalizing: %%I
echo echo -------------------------------------------------------------------------
echo.
echo if not exist "%%I" ^(
echo echo No such file "%%I"
echo goto end
echo ^)
echo.
echo echo Making local copy as ..\working\%%TEMP_INPUT_FILE%%"
echo copy "%%I" "D:\Vids\bin\working\%%TEMP_INPUT_FILE%%"
echo echo -------------------------------------------------------------------------
echo echo.
echo.
echo for %%%%f in ^("%%TEMP_INPUT_FILE%%"^) do set OUTPUT_AUDIO_ONLY=%%%%~nf_audio_only.aac
echo for %%%%f in ^("%%TEMP_INPUT_FILE%%"^) do set OUTPUT_VIDEO_ONLY=%%%%~nf_video_only.mp4
echo for %%%%f in ^("%%TEMP_INPUT_FILE%%"^) do set OUTPUT_FILE=%%%%~nf_new.mp4
echo.
echo rem Set defaults, clean up folder before starting
echo set VIDEO_SCALE=default
echo set VIDEO_ENCODING=default
echo.
echo rem MAX_PIXEL_SIZE will equal 1920 x 1080 ^(2073600 pixels^)
echo set /A MAX_PIXEL_SIZE=1920*1080
echo.
echo if exist "%%OUTPUT_VIDEO_ONLY%%" del /F "%%OUTPUT_VIDEO_ONLY%%"
echo if exist "%%OUTPUT_AUDIO_ONLY%%" del /F "%%OUTPUT_AUDIO_ONLY%%"
echo.
echo echo Determining encoder type and video scale
echo FOR /F "tokens=* USEBACKQ" %%%%g IN ^(`D:\Vids\bin\ffprobe.exe -v error -select_streams v:0 -show_entries stream^^=width^^,height -of csv^^=s^^=x:p^^=0 "%%TEMP_INPUT_FILE%%"`^) do ^(SET "VIDEO_SCALE=%%%%g"^)
echo FOR /F "tokens=* USEBACKQ" %%%%g IN ^(`D:\Vids\bin\ffprobe.exe -v error -select_streams v:0 -show_entries stream^^=codec_name -of default^^=nokey^^=1:noprint_wrappers^^=1 "%%TEMP_INPUT_FILE%%"`^) do ^(SET "VIDEO_ENCODING=%%%%g"^)
echo.
echo rem Convert VIDEO_SCALE in the form of '1920x1080' to '1920*1080' ^(substitute * for x^)
echo rem so that it can be evaluated mathematically.
echo set PIXEL_EQN=%%VIDEO_SCALE:x=*%%
echo.
echo rem Evaluate the pixel size of the current video's single frame
echo set /A PIXEL_SIZE="%%PIXEL_EQN%%"
echo echo Found Video encoder '%%VIDEO_ENCODING%%' @ %%VIDEO_SCALE%% ^(%%PIXEL_SIZE%% pixels^)
echo.
echo rem If we determine that the current video's PIXEL_SIZE is greater than the MAX_PIXEL_SIZE
echo rem for 1920x1080, then set the NEED_SCALING flag to downconvert to 1920x1080
echo if %%PIXEL_SIZE%% GTR %%MAX_PIXEL_SIZE%% ^(set NEED_SCALING=1^) else ^(set NEED_SCALING=0^)
echo.
echo rem If the VIDEO_ENCODING is not equal to h264 ^(libx264^) then set NEED_ENCODING flag
echo if %%VIDEO_ENCODING%% NEQ h264 ^(set NEED_ENCODING=1^) else ^(set NEED_ENCODING=0^)
echo.
echo echo.
echo if %%NEED_SCALING%% EQU 1 ^(
echo if %%NEED_ENCODING%% EQU 1 ^(
echo echo Need to re-encode to h264 and rescale to 1920x1080
echo ^) ELSE ^(
echo echo Need to rescale to 1920x1080 only
echo ^)
echo ^) ELSE ^(
echo if %%NEED_ENCODING%% EQU 1 ^(
echo echo Need to re-encode to h264 only
echo ^) ELSE ^(
echo echo need no changes to video
echo ^)
echo ^)
echo echo -------------------------------------------------------------------------
echo echo.
echo.
echo echo Extracting video and audio streams to temp files
echo if %%NEED_SCALING%% EQU 1 ^(
echo if %%NEED_ENCODING%% EQU 1 ^(
echo echo Extracting audio stream to %%OUTPUT_AUDIO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -q:a 0 -map a -q:a 2 "%%OUTPUT_AUDIO_ONLY%%"
echo echo.
echo echo Extracting video stream to %%OUTPUT_VIDEO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -an -c:s copy -c:v libx264 -vf scale=1920:1080 -crf 20 "%%OUTPUT_VIDEO_ONLY%%"
echo ^) ELSE ^(
echo echo Extracting audio stream to %%OUTPUT_AUDIO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -q:a 0 -map a -q:a 2 "%%OUTPUT_AUDIO_ONLY%%"
echo echo.
echo echo Extracting video stream to %%OUTPUT_VIDEO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -an -c:s copy -vf scale=1920:1080 -crf 20 "%%OUTPUT_VIDEO_ONLY%%"
echo ^)
echo ^) ELSE ^(
echo if %%NEED_ENCODING%% EQU 1 ^(
echo echo Extracting audio stream to %%OUTPUT_AUDIO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -q:a 0 -map a -q:a 2 "%%OUTPUT_AUDIO_ONLY%%"
echo echo.
echo echo Extracting video stream to %%OUTPUT_VIDEO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -an -c:s copy -c:v libx264 "%%OUTPUT_VIDEO_ONLY%%"
echo ^) ELSE ^(
echo echo Extracting audio stream to %%OUTPUT_AUDIO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -q:a 0 -map a -q:a 2 "%%OUTPUT_AUDIO_ONLY%%"
echo echo.
echo echo Extracting video stream to %%OUTPUT_VIDEO_ONLY%%
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats -i "%%TEMP_INPUT_FILE%%" -an -c:s copy -vcodec copy -map 0:v "%%OUTPUT_VIDEO_ONLY%%"
echo ^)
echo ^)
echo echo -------------------------------------------------------------------------
echo echo.
echo.
echo echo Reassembling converted video and audio files
echo D:\Vids\bin\ffmpeg.exe -v 0 -stats %%OVERWRITE_FILE%% -i "%%OUTPUT_VIDEO_ONLY%%" -i "%%OUTPUT_AUDIO_ONLY%%" -codec copy "%%OUTPUT_FILE%%"
echo echo -------------------------------------------------------------------------
echo echo.
echo.
echo echo Normalizing audio track volume
echo D:\Vids\bin\aacgain.exe "%%OUTPUT_FILE%%"
echo echo -------------------------------------------------------------------------
echo echo.
echo.
echo echo Moving file to completed folder
echo move "%%OUTPUT_FILE%%" ..\completed\%%NEW_FILE%%
echo echo -------------------------------------------------------------------------
echo echo.
echo.
echo echo Cleaning up
echo if exist "%%OUTPUT_VIDEO_ONLY%%" del /F "%%OUTPUT_VIDEO_ONLY%%"
echo if exist "%%OUTPUT_AUDIO_ONLY%%" del /F "%%OUTPUT_AUDIO_ONLY%%"
echo if exist "%%TEMP_INPUT_FILE%%" del /F "%%TEMP_INPUT_FILE%%"
echo.
echo :end
echo echo -------------------------------------------------------------------------
echo echo.
echo echo Done
echo echo on
set /A COUNTER=COUNTER+1
) > "working\TEMP_!COUNTER!.bat"
echo off
这将在 D:\Vids\bin\working 文件夹中创建一系列名为 TEMP_1.bat、TEMP_2.bat 等的临时批处理脚本。原始文件夹中的每个视频都有一个,它们将是实际执行转换。
要开始转换,只需执行 TEMP_1.bat,它将:
我发现我可以同时启动多达五个并发转换;设置它并忘记它。等我回来的时候,文件都做好了。
一段时间以来,我一直在批量转换我的视频,这就像一个冠军,与我的 Synology DS220J 配合得很好。我希望它也能帮助你。如果您需要更改最大分辨率或音频编码或任何质量或性能调整,甚至安装位置,请继续!大部分的辛苦工作已经为你完成了。
以下是我博客的链接,以防这篇文章被删除:
https://lumkichi.blogspot.com/2022/02/id-like-to-share-what-i-have-worked-on.html https://lumkichi.blogspot.com/2022/02/windows-10 -bulk-normalize-audio-of-mp4.html
使用的免费软件链接:
~卢姆