0

Okay guys looks like I have another question to ask, which is kind of related to my last question, which can be found on here: How to start ffprobe with Windows PowerShell. There I was asking how to start ffprobe with Windows PowerShell and after trying out a few things I got it, well lets say, started for a second before it closes again. I tried it with following commands in PowerShell:

$env:Path = ';C:\Users\Administrator\bin\'
$title = "A_Day_for_Cake_and_Accidents"
Start-Process ff-prompt.bat -ArgumentList "ffprobe -show_streams -select_streams v -print_format xml -count_frames C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\$title.mov > C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\totalframes.xml"

The result, and that is the strange thing, is the xml file with only the standard text from the ff-prompt.bat, which looks like this:

C:\Users\Administrator>ECHO OFF ffmpeg version N-60959-g669043d built on Feb 27 2014 22:01:58 with gcc 4.8.2 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib libavutil 52. 66.100 / 52. 66.100 libavcodec 55. 52.102 / 55. 52.102 libavformat 55. 33.100 / 55. 33.100 libavdevice 55. 10.100 / 55. 10.100 libavfilter 4. 2.100 / 4. 2.100 libswscale 2. 5.101 / 2. 5.101 libswresample 0. 18.100 / 0. 18.100 libpostproc 52. 3.100 / 52. 3.100 For help run: ffmpeg -h For formats run: ffmpeg -formats | more For codecs run: ffmpeg -codecs | more Current directory is now: "C:\Users\Administrator\bin" The bin directory has been added to PATH

My first thought was, that it did not work at all, but then I was wondering why I get an XML file when it is not working at all. PowerShell executes the ff-prompt.bat for maybe a second, before PowerShell shuts down the ff-prompt.bat again without doing half of my commands. Does anybody know why ff-prompt gets closed before executing all of my commands?

EDIT: So what I tried is something that should execute it directly, but in fact I get a shitload of errors:

$title = "A_Day_for_Cake_and_Accidents"
$Cmd = ‘C:\Users\Administrator\ffmpeg\bin\ffprobe.exe’
$Arg1 = ’ffprobe '
$Arg2 = ‘-show_streams ’
$Arg3 = ‘-select_streams v '
$Arg4 = ‘-print_format xml '
$Arg5 = ‘-count_frames '
$Arg6 = "C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\$title.mov >"
$Arg7 = " C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\totalframes.xml"
& $Cmd $Arg1 $Arg2 $Arg3 $Arg4 $Arg5 $Arg6 $Arg7

Error message(s) I get:

"ffprobe.exe Failed to set value '-select_streams v ' for option 'show_streams ': Option not found"

The problem I am facing now is that -show_streams does not get a value, so maybe that is the reason why he uses the next parameter as a value, is there anything I can do?

Community
  • 1
  • 1
sebastian
  • 179
  • 1
  • 4
  • 10
  • Why are you using a bat file at all? You'll find it much easier to call ffprobe directly from powershell. And it will also be easier to specify the full path to the .exe rather than modifying PATH on the fly. – arco444 Mar 07 '14 at 12:05
  • @arco444 That sounds nice and easy but how do I do that? Do I have to install some software or do I need other commands? Problem is I have a bunch of movies where I have to extract the total frames number out of an XML file and I thought it would be easier if I could do that automatically without much effort, thats why I am using this parameter `$title` for all my videos. – sebastian Mar 07 '14 at 12:31
  • Everything you need to know about launching external commands here: http://edgylogic.com/blog/powershell-and-external-commands-done-right/ – andyb Mar 07 '14 at 12:43
  • @andyb Thanks for this link, I will read it and if it helps I will come back to you. – sebastian Mar 07 '14 at 13:21
  • @sebastian - I have posted an answer to your first ff-prompt.bat question. – andyb Mar 07 '14 at 13:30
  • Your code is sending a set of command line parameters (ffprobe -showstreams etc.) to ff-prompt.bat. Unfortunately, ff-prompt.bat is not designed to work this way. It does nothing with command line parameters and provides very little of value other than some reminders of syntax. If you are wanting to run ff-probe, then launch it directly from PowerShell. Forget about ff-prompt. – andyb Mar 07 '14 at 13:34
  • Oh - and the reason you get an XML file is because -argumentList contains the redirection operator '>' which sends all output to a file instead of the console. – andyb Mar 07 '14 at 13:40
  • @andyb Okay I have tried directly from PowerShell (see my first post marked with edit) and it looks like I still have some errors. – sebastian Mar 07 '14 at 13:59
  • I added a couple of comments to the answer below. Art 6 & 7 need changing. Take the > off the end of arg6. For now, drop arg7. Once we have the ffprobe command working, then we will worry about piping output to XML file. – andyb Mar 08 '14 at 01:23

2 Answers2

1

The following worked for me:

$title = "A_Day_for_Cake_and_Accidents"
$inputFile = "C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\$title.mov"
$outputFile = "C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\totalframes.xml"

&.\bin\ffprobe.exe -show_streams -select_streams v -print_format xml -count_frames -loglevel quiet $inputFile | out-file $outputFile

I should have realised that '-select_streams v' counts a 2 command line parameters, so wrapping them up in a single argument will not work.

I removed the '>' redirection and added the | out-file .... clause.

The main issue with FFPROBE is that it writes it's logging information to the STDERR channel. PowerShell spots this and throws a NativeCommandError exception.

I tried trapping NativeCommandError, using $ErrorActionPreference = 'stop' and a try...catch construction, but the exception fires before the XML output is generated. In the end, I RTFM for FFPROBE and added the -loglevel quiet parameter which stops FFPROBE writing any log info.

NB - this code assumes it is executed from the directory above 'bin'.

andyb
  • 2,722
  • 1
  • 18
  • 17
  • Thank you for taking your time to help me but I tried it myself and I am getting an error message "& : Die Benennung ".\bin\ffprobe.exe" wurde nicht als Name eines Cmdlet In Zeile:5 Zeichen:2 + &.\bin\ffprobe.exe -show_streams -select_streams v -print_format xml -count_fram ..." telling me that PowerShell does not recognize `.\bin\ffprobe.exe` as a command. My "ffprobe path" is still the same `C:\Users\Administrator\ffmpeg\bin\ffprobe.exe`. – sebastian Mar 10 '14 at 08:48
  • okay I do not know how to thank you, I have used the full path to `ffprobe.exe` and finally that did the trick. You sir, got yourself the answer, well done and totally deserved. – sebastian Mar 10 '14 at 09:10
0

Assuming ffmpeg is in C:\users\Administrator\ffmpeg:

$title = "A_Day_for_Cake_and_Accidents"
& C:\users\Administrator\ffmpeg\bin\ffprobe -show_streams -select_streams v -print_format xml -count_frames C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\$title.mov > C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\totalframes.xml
arco444
  • 22,002
  • 12
  • 63
  • 67
  • Does this also work in PowerShell v.1? Or do I need to update my PowerShell? Because I have tried it your way but get an error message, which says that PowerShell does not know this command. – sebastian Mar 07 '14 at 13:20
  • What is the exact error? Does `C:\users\Administrator\ffmpeg\bin\ffprobe.exe` exist? You might need to change the path to the program if not. I'm only guessing it is there based on your other question. – arco444 Mar 07 '14 at 13:58
  • I have worked a bit with your command (see my first post under EDIT) looks like it could be working if I get this error cleared. – sebastian Mar 07 '14 at 14:05
  • Yep you're on the right track now. You can probably use `C:\Users\Administrator\ffmpeg\bin\ffprobe.exe -help` to find out exactly which options you need. – arco444 Mar 07 '14 at 14:23
  • I need every option I have listed here, the problem is, that damn thing thinks that I wanted to use the command `-select_streams v` for `show_streams`. I have tried all commands on ff-prompt before and it worked perfectly thats why I do not know why he is thinking that one command is a parameter of the other command. – sebastian Mar 07 '14 at 14:29
  • First, drop arg1 - its not required. Second, try wrapping arts in double quotes e.g. $cmd $arg2 $arg3 etc. If this does not work, try changing art assignments where spaces are required to be $arg3 = '"-select_streams v"' – andyb Mar 07 '14 at 21:54
  • Also, trim white space from ends of all arg assignments e.g `$Arg5 = ‘-count_frames '` - remove space after "frames" so `$Arg5 = ‘-count_frames'` – andyb Mar 07 '14 at 22:04
  • Just realized my comment above relating wrapping args in double quotes does not show them properly. Here's what I meant: `$cmd "$arg2" "$arg3" ...` – andyb Mar 08 '14 at 21:34