我可以使用以下内容来检索音频和视频编解码器以及视频帧高度:
ffprobe -v quiet -show_entries stream=index,codec_name,height -of csv input.mp4
但输出是两行,包括我不需要的文本,如下所示:
stream,0,h264,720
stream,1,mp3
我想要的唯一输出是以下形式:
mp3,h264,720
我已经尝试在同一命令行中使用 -show_entries 两次,但它每次都会忽略第一次调用。我也尝试过使用
ffprobe -v quiet -select_streams v -show_entries stream=codec_name,height, -select_streams a -show_entries stream=codec_name
但这无济于事。
如何获得上面指定的简化输出?
最佳答案
在我们在评论中进行对话之后,我认为您正在寻找这样的东西。这是一个 Batch + JScript 混合脚本。我正在使用 JScript 通过 ffprobe
解析和对象化 JSON 输出.盐调味,去除echo
当您准备好执行脚本时,从第 31 行开始。
@if (@CodeSection == @Batch) @then
@echo off & setlocal & goto run
:usage
echo Usage: %~nx0 infile outfile
echo This script re-encodes videos to x265 + AAC encoding.
exit /b
:run
if "%~2"=="" goto usage
if not exist "%~1" goto usage
set ffprobe=ffprobe -v quiet -show_entries "stream=codec_name,height" -of json "%~1"
for /f "delims=" %%I in ('%ffprobe% ^| cscript /nologo /e:JScript "%~f0"') do set "%%~I"
if %height% lss 720 (
echo Video is ^< 720p. Not worth it.
exit /b
)
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 libx265 -crf 22 -preset fast"
set "audio=-c:a libfdk_aac -flags +qscale -global_quality 4 -afterburner 1"
if defined hevc if defined aac (
echo Already in x265 + AAC format.
exit /b
)
if defined aac (
echo Already has AAC audio. Re-encoding video only.
set "audio=-c:a copy"
) else if defined hevc (
echo Already has x265 video. Re-encoding audio only.
set "video=-c:v copy"
)
echo ffmpeg %pre% -i "%~1" %global% %video% %audio% "%~2"
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 (obj.streams[i].height) WSH.Echo('height=' + obj.streams[i].height);
if (/hevc/i.test(obj.streams[i].codec_name)) WSH.Echo('hevc=true');
if (/aac/i.test(obj.streams[i].codec_name)) WSH.Echo('aac=true');
}
关于batch-file - ffprobe 如何检索音频和视频信息并输出到单行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45086424/