【问题标题】:FFProbe won't output result to a fileFFProbe 不会将结果输出到文件
【发布时间】: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 &gt; 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 &gt; 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 的一个特性,它不是像CreateProcessShellExecute 这样的 OS API 函数内置的。尝试使用cmd /c &lt;&lt;your_command_here_including_redirection&gt;&gt; 让shell 进行重定向。

标签: vb6 ffprobe


【解决方案1】:

对我来说,Linux 中的 ffprobe 存在一些类似的问题。 我发现 ffprobe 不写入标准输出 但改为标准错误。因此,使用“2>”语法 将标准错误捕获到文件中。

# ffprobe test.mkv 2>target.txt
# cat target.txt
Input #0, matroska,webm, from 'test.mkv':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
...

【讨论】:

  • 正是我的情况。谢谢!我几乎要为此发疯了
【解决方案2】:

可能是因为管理员权限。尝试使用 ShellExecute。

this post

this one

【讨论】:

  • 我已经尝试以管理员身份运行我的程序.... 仍然不行。我尝试使用 ShellExecute 而不是 Shell……还是不行。我没有在我的原始帖子中提到我的程序使用 ffmpeg 从视频中提取帧并将图像写入磁盘......使用没有管理员权限的 Shell 工作得非常好仍然希望有一个解决方案。
猜你喜欢
  • 2020-06-02
  • 2020-06-15
  • 1970-01-01
  • 1970-01-01
  • 2015-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-08
相关资源
最近更新 更多