3

I am trying to extract the duration of a video (.MP4) using FFProbe and require that the result be output to a file. FFProbe works perfectly and creates the file with the duration information when I enter it using the Command Prompt, however, when I place the same statement in my VB6 program, FFProbe does not create the output file..... What is the problem??

Here is the statement that works from the Command Prompt:

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

Here is the code snippet from my program that does not work:

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

We are making progress upon the suggestion from "wqw" to use cmd /c , I now get the output redirected to a file but not all the time.

This works because the video file name has no spaces:

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

This does NOT work:

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

It appears that cmd /c has some problems handling spaces in file name even if I surround them with double quotes. Also UNC filenames are not supported by cmd but ffprobe handles them OK. Still working on the problem, Thank you.


Ok, I got it working finally. Using cmd /c I found that if you changed to the directory of ffprobe first, then executed ffprobe, the mishandling of double quotes is avoided:

cmd /c cd C:\Program Files\FFMpeg\Bin & ffprobe {paramters} > output.txt

Duke
  • 31
  • 1
  • 3
  • When you output the Txt you composed to a message box or to debug.print, do you see exactly what you expect? – Jim Mack Feb 07 '20 at 00:11
  • Yes, I have checked my statement by using : Form5.Caption = Txt and the value is exactly what I need and matches what I entered in Command Prompt. – Duke Feb 07 '20 at 01:32
  • Output redirection is a feature of the shell, it's not built-in into the OS API functions like `CreateProcess` and `ShellExecute`. Try to use `cmd /c <>` to have the shell do the redirection. – wqw Feb 08 '20 at 19:08

2 Answers2

4

Somewhat similar problem with ffprobe in Linux for me. I found that ffprobe doesn't write to standard output but instead to standard error. So, use the "2>" syntax to capture standard error to a file.

# ffprobe test.mkv 2>target.txt
# cat target.txt
Input #0, matroska,webm, from 'test.mkv':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
...
Magiczne
  • 1,586
  • 2
  • 15
  • 23
Otho
  • 41
  • 2
0

Probably because of admin rights. Try using ShellExecute.

See this post

or this one

EddiGordo
  • 682
  • 4
  • 10
  • I had already tried running my program as administrator.... Still no go. I tried using ShellExecute instead of Shell... Still no go. I failed to mention in my original post that the my program uses ffmpeg to extract frames from the video and writes the images out to disk.... Works absolutely fine using Shell without Adminstrator Rights Still hoping for a solution. – Duke Feb 07 '20 at 18:14