【发布时间】:2019-04-20 19:35:53
【问题描述】:
我稍微修改了 here 中的 @rojo 代码以查找 h264/AC3 并递归运行所有子文件夹。我唯一的问题是它总是说视频有 h264 和 AC3,但是当我手动运行 ffprobe 命令时,它的状态不同。我错过了什么吗?
@if (@CodeSection == @Batch) @then
@echo off & setlocal
for /R %%f in (*.mkv, *.mp4) do (
echo Testing %%f
set ffprobe=C:\ffmpeg-4.0.2-win64-static\bin\ffprobe -v quiet -show_entries "stream=codec_name,height" -of json "%%f"
for /f "delims=" %%I in ('%ffprobe% ^| cscript /nologo /e:JScript "%~f0"') do set "%%~I"
set "pre=-hide_banner -fflags +genpts+discardcorrupt+fastseek -analyzeduration 100M"
set "pre=%pre% -probesize 50M -hwaccel dxva2 -y -threads 3 -v error -stats"
set "global="
set "video=-c:v h264_nvenc"
set "audio=-c:a ac3"
if defined h264 if defined ac3 (
echo %%~nf already in x264 + AC3 format.
)
if not defined h264 if not defined ac3 (
if not defined ac3 (
echo Already has AC3 audio. Re-encoding video only.
set "audio=-c:a copy"
)
if not defined h264 (
echo Already has h264 video. Re-encoding audio only.
set "video=-c:v copy"
)
echo output "%%~df%%~pf%%~nf.new.mkv"
echo C:\ffmpeg-4.0.2-win64-static\bin\ffmpeg %pre% -i "%%f" %global% %video% %audio% "%%~df%%~pf%%~nf.new.mkv"
pause
echo del "%%f" /f /q
echo ren "%%~df%%~pf%%~nf.new.mkv" "%%f"
)
)
@end // end Batch / begin JScript
var stdin = WSH.CreateObject('Scripting.FileSystemObject').GetStandardStream(0),
htmlfile = WSH.CreateObject('htmlfile'),
JSON;
htmlfile.write('<meta http-equiv="x-ua-compatible" content="IE=9" />');
htmlfile.close(JSON = htmlfile.parentWindow.JSON);
var obj = JSON.parse(stdin.ReadAll());
for (var i = obj.streams.length; i--;) {
if (/h264/i.test(obj.streams[i].codec_name)) WSH.Echo('h264=true');
if (/ac3/i.test(obj.streams[i].codec_name)) WSH.Echo('ac3=true');
}
我有这样的工作一秒钟然后它无缘无故地停止了。
@if (@CodeSection == @Batch) @then
@echo off & setlocal & goto run
:run
for /R %%f in (*.mkv, *.mp4) do (
echo Testing %%f
set "file=%%f"
set "drive=%%~df"
set "dir=%%~pf"
set "name=%%~nf"
set "ext=%%~xf"
for /f "delims=" %%I in ('C:\ffmpeg-4.0.2-win64-static\bin\ffprobe.exe -v quiet -show_entries "stream=codec_name,height" -of json "%%f" ^| cscript /nologo /e:JScript "%~f0"') do (set "%%~I")
set "pre=-hide_banner -fflags +genpts+discardcorrupt+fastseek -analyzeduration 100M"
set "pre=%pre% -probesize 50M -hwaccel dxva2 -y -threads 3 -v error -stats"
set "global="
set "video=-c:v h264_nvenc"
set "audio=-c:a ac3"
if defined ac3 if defined h264 call :both
if not defined ac3 call :either
if not defined h264 call :either
)
:both
echo %name% already in x264 + AC3 format.
goto :EOF
:either
if not defined h264 (
echo Already has AC3 audio. Re-encoding video only.
set "audio=-c:a copy"
)
if not defined ac3 (
echo Already has h264 video. Re-encoding audio only.
set "video=-c:v copy"
)
echo "C:\ffmpeg-4.0.2-win64-static\bin\ffmpeg %pre% -i "%file%" %global% %video% %audio% "%drive%%dir%%name%.new.mkv""
echo del "%file%" /f /q
echo ren "%drive%%dir%%name%.new.mkv" "%name%%ext%"
goto :EOF
@end // end Batch / begin JScript
var stdin = WSH.CreateObject('Scripting.FileSystemObject').GetStandardStream(0),
htmlfile = WSH.CreateObject('htmlfile'),
JSON;
htmlfile.write('<meta http-equiv="x-ua-compatible" content="IE=9" />');
htmlfile.close(JSON = htmlfile.parentWindow.JSON);
var obj = JSON.parse(stdin.ReadAll());
for (var i = obj.streams.length; i--;) {
if (/h264/i.test(obj.streams[i].codec_name)) WSH.Echo('h264=true');
if (/ac3/i.test(obj.streams[i].codec_name)) WSH.Echo('ac3=true');
}
h264 的ffprobe 输出
{
"programs": [
],
"streams": [
{
"codec_name": "h264",
"height": 528
},
{
"codec_name": "aac"
}
]
}
ac3 的输出
{
"programs": [
],
"streams": [
{
"codec_name": "h265",
"height": 528
},
{
"codec_name": "ac3"
}
]
}
ac3/h264 的输出
{
"programs": [
],
"streams": [
{
"codec_name": "h264",
"height": 528
},
{
"codec_name": "ac3"
}
]
}
【问题讨论】:
标签: batch-file ffmpeg ffprobe