Problem with System.Diagnostics.Process

  • Thread starter Thread starter M1iS
  • Start date Start date
M

M1iS

I’m having a problem automating a command line application (FFmpeg). I’m
able to manually pull up a command window and type in my arguments and run
the application however when I try to automate it with
System.Diagnostics.Process it fails:

Here’s my code:

Process ffmpeg = new Process();
ffmpeg.StartInfo.WorkingDirectory = FFmpegDirectory;
ffmpeg.StartInfo.FileName = "ffmpeg.exe";
ffmpeg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
ffmpeg.StartInfo.Arguments = arguments;
ffmpeg.Start();
ffmpeg.WaitForExit();


Here are my command line arguments:

ffmpeg -i D:\MediaTools\test\test.wmv -pass 2 -vcodec libx264 -s 512x288 -r
29.97 -vpre D:\MediaTools\test\libx264-normal.ffpreset -b 768kb -bt 256k
-acodec libfaac -ar 22050 -ab 96k -threads 0
D:\MediaTools\test\55a3e152-830c-4bfa-a62d-8c7f7b6be5db.mp4


It seems after I made some changes to my arguments FFmpeg is outputting some
other messages that weren’t there before. Could this be causing my process
object to trip up? Thanks,

Scott
 
Yes, I can take the arguments and manually run the process in a command
window and it converts the video without any problems. The extra information
it is returning is info related to the conversion that didn't use show up.

Here is what is getting produced in my command window:

d:\MediaTools\test>ffmpeg -i D:\MediaTools\test\test.wmv -pass 2 -vcodec
libx264
-s 512x288 -r 29.97 -vpre D:\MediaTools\test\libx264-normal.ffpreset -b
768kb -
bt 256k -acodec libfaac -ar 22050 -ab 96k -threads 0
D:\MediaTools\test\55a3e152
-830c-4bfa-a62d-8c7f7b6be5db.mp4
FFmpeg version SVN-r15986, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --extra-cflags=-fno-common --enable-memalign-hack
--enable-pthr
eads --enable-libmp3lame --enable-libxvid --enable-libvorbis
--enable-libtheora
--enable-libspeex --enable-libfaac --enable-libgsm --enable-libx264
--enable-lib
schroedinger --enable-avisynth --enable-swscale --enable-gpl
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 6. 0 / 52. 6. 0
libavformat 52.23. 1 / 52.23. 1
libavdevice 52. 1. 0 / 52. 1. 0
libswscale 0. 6. 1 / 0. 6. 1
built on Dec 3 2008 01:59:37, gcc: 4.2.4

Seems stream 1 codec frame rate differs from container frame rate: 1000.00
(1000
/1) -> 29.97 (30000/1001)
Input #0, asf, from 'D:\MediaTools\test\test.wmv':
Duration: 00:00:53.34, start: 4.000000, bitrate: 3548 kb/s
Stream #0.0: Audio: wmav2, 48000 Hz, stereo, s16, 192 kb/s
Stream #0.1: Video: wmv3, yuv420p, 1280x720, 3072 kb/s, 29.97 tb(r)
Output #0, mp4, to
'D:\MediaTools\test\55a3e152-830c-4bfa-a62d-8c7f7b6be5db.mp4'
:
Stream #0.0: Video: libx264, yuv420p, 512x288, q=10-51, pass 2, 768
kb/s, 29
..97 tb(c)
Stream #0.1: Audio: libfaac, 22050 Hz, stereo, s16, 96 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Stream #0.0 -> #0.1
[libx264 @ 0x2bf340]using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x2bf340]profile High, level 2.1
Press [q] to stop encoding
frame= 1629 fps= 40 q=-2.0 Lsize= 5642kB time=54.29 bitrate= 851.4kbits/s

video:5104kB audio:506kB global headers:1kB muxing overhead 0.559483%
[libx264 @ 0x2bf340]slice I:42 Avg QP:21.32 size: 12579
[libx264 @ 0x2bf340]slice P:1012 Avg QP:22.81 size: 3973
[libx264 @ 0x2bf340]slice B:575 Avg QP:23.43 size: 1177
[libx264 @ 0x2bf340]consecutive B-frames: 36.9% 41.7% 11.5% 3.5% 6.3%
[libx264 @ 0x2bf340]mb I I16..4: 10.9% 56.8% 32.3%
[libx264 @ 0x2bf340]mb P I16..4: 2.3% 10.0% 3.6% P16..4: 37.2% 13.8% 7.6%
0.0% 0.0% skip:25.4%
[libx264 @ 0x2bf340]mb B I16..4: 3.3% 0.0% 0.0% B16..8: 22.6% 3.0% 1.9%
direct: 7.0% skip:62.1% L0:36.3% L1:44.9% BI:18.8%
[libx264 @ 0x2bf340]8x8 transform intra:56.3% inter:52.2%
[libx264 @ 0x2bf340]direct mvs spatial:79.1% temporal:20.9%
[libx264 @ 0x2bf340]ref P L0 81.4% 18.6%
[libx264 @ 0x2bf340]ref B L0 84.0% 16.0%
[libx264 @ 0x2bf340]ref B L1 96.0% 4.0%
[libx264 @ 0x2bf340]SSIM Mean Y:0.9793992
[libx264 @ 0x2bf340]kb/s:769.2

d:\MediaTools\test>
 
The question is why is .NET unable to run this process when I can run the
exact same command line arguments manually without any issues? The reason I
think the extra output information has something do with it is that the only
difference I can see between the my old command line arguments (which used to
work fine) versus my new command line is the extra output info.
 
Vague? I’m not sure how I can be any more specific, I’ve given the command
line arguments that I’m using and the output in the command window and the
code that I’ve used to try and automate this. Unfortunately the Process
object doesn’t give me any useful information about what is going wrong, it
just fails with no indication of why. What else can I do?

And again like I said before when I run the exact command line manually
(that I’ve copied right out my code) it works like it is supposed to and
outputs a converted video so there is definitely nothing wrong with command
line arguments.
 
M1iS said:
Vague? I’m not sure how I can be any more specific, I’ve given the
command
line arguments that I’m using and the output in the command window and the
code that I’ve used to try and automate this. Unfortunately the Process
object doesn’t give me any useful information about what is going wrong,
it
just fails with no indication of why. What else can I do?

And again like I said before when I run the exact command line manually
(that I’ve copied right out my code) it works like it is supposed to and
outputs a converted video so there is definitely nothing wrong with
command
line arguments.


Does your code run under the same account as the command line execution?
This is a common mistake when creating a service or web site tool.

Are you positive that waiting for the process you create to end is
sufficient? This is a common mistake in assuming that the launched
processes is the key. Some processes launch a child process to do the true
work. If you try and get to the output before the child is done, you mess
things up.

Just my $0.02...
 
Back
Top