ffprobe如何同时检索音频和视频信息并输出到单行? [英] ffprobe how to retrieve both audio and video info and output to single line?
问题描述
我可以使用以下方法检索音频和视频编解码器以及视频帧的高度:
I can use the following to retrieve the audio and video codec and the video frame height:
ffprobe -v quiet -show_entries stream=index,codec_name,height -of csv input.mp4
但是输出是两行,并且包含我不需要的文本:
But the output is on two lines and includes text that I don't need like so:
stream,0,h264,720
stream,1,mp3
我唯一想要的输出是以下形式:
The only output I want is to be in the form of:
mp3,h264,720
我曾尝试在同一命令行中两次使用-show_entries,但每次都会忽略第一次调用.我也尝试过使用
I've tried using -show_entries twice in the same command line, but it ignores the first call every time. I've also tried using
ffprobe -v quiet -select_streams v -show_entries stream=codec_name,height, -select_streams a -show_entries stream=codec_name
但是那什么也没做.
如何获得上述指定的简化输出?
How can I get the simplified output as specified above?
推荐答案
我们在评论中进行了交谈之后,我认为您正在寻找类似的内容.这是一个批处理+ JScript混合脚本.我正在使用JScript解析和物化ffprobe
的JSON输出.加盐调味,并在准备执行脚本时从第31行中删除echo
.
After our conversation in the comments, I think something like this is what you're looking for. It's a Batch + JScript hybrid script. I'm using JScript to parse and objectify the JSON output by ffprobe
. Salt to taste, and remove echo
from line 31 when you're ready for the script to act.
@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');
}
这篇关于ffprobe如何同时检索音频和视频信息并输出到单行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!