【发布时间】:2020-02-06 21:55:39
【问题描述】:
我正在尝试使用 FFProbe 提取视频 (.MP4) 的持续时间,并要求将结果输出到文件中。 当我使用命令提示符输入文件时,FFProbe 可以完美地工作并创建包含持续时间信息的文件,但是,当我在我的 VB6 程序中放置相同的语句时,FFProbe 不会创建输出文件.....有什么问题? ?
以下是命令提示符下的语句:
C:\Program Files\FFMpeg\bin>ffprobe -i InputVideo.mp4 -v quiet -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 > c:\temp\Output.txt
这是我的程序中不起作用的代码 sn-p:
Dim Txt As String
Dim AppId As Long
Dim AppHnd As Long
Dim AppRet As Long
Txt = "C:\Program Files\FFMpeg\bin>ffprobe" & _
" -i " & """" & PhotoPathFileName & """" & _
" -v quiet -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 >
""C:\temp\Output.txt"""
AppId = Shell(Txt, vbHide)
AppHnd = OpenProcess(SYNCHRONIZE, 0, AppId)
If AppHnd <> 0 Then
AppRet = WaitForSingleObject(AppHnd, WaitInfinite)
End If
我们正在根据“wqw”的建议使用 cmd /c 取得进展,我现在将输出重定向到一个文件,但并非一直如此。
这是有效的,因为视频文件名没有空格:
cmd /k "C:\Program Files\FFMpeg\bin\ffprobe.exe" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -i \\DLINK\Volume_1\Movies\Arrow.mp4 > c:\temp\Duration.txt
这不起作用:
cmd /k "C:\Program Files\FFMpeg\bin\ffprobe.exe" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -i \\DLINK\Volume_1\Movies\Generation Earth Part 1.mp4 > c:\temp\Duration.txt
cmd /c 似乎在处理文件名中的空格时存在一些问题,即使我用双引号将它们括起来。 cmd 也不支持 UNC 文件名,但 ffprobe 可以正常处理它们。还在解决这个问题,谢谢。
好的,我终于成功了。 使用cmd /c发现如果先切换到ffprobe的目录,再执行ffprobe,就避免了双引号的误操作:
cmd /c cd C:\Program Files\FFMpeg\Bin & ffprobe {参数} > output.txt
【问题讨论】:
-
当您将您编写的 Txt 输出到消息框或 debug.print 时,您看到的正是您所期望的吗?
-
是的,我已经使用以下命令检查了我的声明:Form5.Caption = Txt,该值正是我所需要的,并且与我在命令提示符中输入的内容相匹配。
-
输出重定向是 shell 的一个特性,它不是像
CreateProcess和ShellExecute这样的 OS API 函数内置的。尝试使用cmd /c <<your_command_here_including_redirection>>让shell 进行重定向。