ffmpeg 的宽高比问题

ffmpeg 的宽高比问题

我正在使用 vbs 命令文件转换我的 .flv 文件。我在下面附上了代码:

Set shell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set darRegex = New RegExp
With darRegex
    .Pattern = "Video:.*DAR (\d+):(\d+)"
    .IgnoreCase = True
End With
Set resolutionRegex = New RegExp
With resolutionRegex
    .Pattern = "Video:.*, (\d+)x(\d+)"
    .IgnoreCase = True
End With
Dim line
Dim width
Dim height
Dim command
Dim FFMPEG_EXECUTABLE_PATH
Dim OUTPUT_PATH
FFMPEG_EXECUTABLE_PATH = "bin\\ffmpeg.exe"
OUTPUT_PATH = "out.alpha.3g2"
If Not fs.FileExists(WScript.Arguments(0)) Then
    WScript.Echo("Video file does not exist: " & WScript.Arguments(0))
    WScript.Quit(1)
End If
Set exec = shell.exec("CMD /S /C "" " & FFMPEG_EXECUTABLE_PATH & " -i """ & WScript.Arguments(0) & """ >video.info 2>&1 """)
Do While exec.Status = 0
    WScript.Sleep(50)
Loop
Set aspectRatioFile = fs.OpenTextFile("video.info", 1)
line = ""
Do While aspectRatioFile.AtEndOfStream <> True
    line = line & aspectRatioFile.ReadLine()
Loop
Set darRegexMatch = darRegex.Execute(line)
If darRegexMatch.Count > 0 Then
    width = darRegexMatch.Item(0).Submatches(0)
    height = darRegexMatch.Item(0).Submatches(1)
Else
    Set resolutionRegexMatch = resolutionRegex.Execute(line)
    If resolutionRegexMatch.Count = 0 Then
        WScript.Echo("Could not find aspect ratio of video")
        WScript.Quit(1)
    End If
    width = resolutionRegexMatch.Item(0).Submatches(0)
    height = resolutionRegexMatch.Item(0).Submatches(1)
End If
WScript.Echo("Video display aspect ratio determined to be " & width & ":" & height)
height2 = CStr(2 * CInt(height))
REM Entered characters won't print while ffmpeg is executing, so take over ffmpeg's task of asking user whether to overwrite
If fs.FileExists(OUTPUT_PATH) Then
    WScript.StdOut.Write("Output file " & OUTPUT_PATH & " already exists, do you want to overwrite? [yN] ")
    answer = WScript.StdIn.ReadLine
    if Not InStr(answer, "y") = 1 And Not InStr(answer, "Y") = 1 Then
        WScript.Quit(1)
    End If
End If
command = "CMD /S /C "" " & FFMPEG_EXECUTABLE_PATH & " -i """ & WScript.Arguments(0) & """ -vf ""[orig] transpose=dir=2 [rotated]; [rotated] split [a][b]; [b] alphaextract [alphaAsGrayscale]; [alphaAsGrayscale] pad=iw*2:ih:iw:0 [alphaAsGrayscalePadded]; [alphaAsGrayscalePadded][a] overlay"" -vcodec mpeg4 - 512x512 -aspect " & height & ":" & width & " -vb 215000 -r 20 -acodec aac -strict experimental -ar 22050 -y " & OUTPUT_PATH & " 2>&1 """
WScript.Echo(command)
Set conversionExec = shell.exec(command)
Do While conversionExec.Status = 0
    Do While Not conversionExec.StdOut.AtEndOfStream
        WScript.StdOut.Write(conversionExec.StdOut.Read(1))
    Loop
    WScript.Sleep(50)
Loop
REM Print any remaining stdout lines
WScript.StdOut.Write(conversionExec.StdOut.ReadAll())

该进程立即停止并显示此错误:

无法找到视频的宽高比

我错在哪里?
考虑到我不是程序员,而且我使用的是第三方网站,我从那里找到了这个 .vbs 文件。

答案1

我认为你有

  1. 已下载ffmpeg到与脚本相同的文件夹

  2. 同一文件夹中的有效 FLV 视频(在我的示例中为 input.flv)

    在 Windows 上它应该看起来像
    在此处输入图片描述

您可以使用 来从命令行调试脚本cscript encode.vbs input.flv > log.txt
它会将输出和所有错误传送到日志文件。


除此之外,我还修改了 ffmpeg 命令,修复了脚本

command = "CMD /S /C "" " & FFMPEG_EXECUTABLE_PATH & " -i """ & WScript.Arguments(0) & " "" -c:v libx264 -c:a aac -strict experimental " & OUTPUT_PATH & " 2>&1 """

WScript.Arguments(0)是输入 FLV 文件,OUTPUT_PATH是输出文件名

您可以从以下位置复制脚本的工作版本github
感谢@slhck。

相关内容