[Mono-osx] OutputDataReceived event not raised when using the Process class together with Ffmpeg?

johot johan.otterud at gmail.com
Thu Jun 7 10:36:16 UTC 2012


So I made some more tests, I tested this under Windows now and here the
problem does not exist. This is the very simple code I used and got it
working with under Windows (but with a different ffmpeg path):

public void EncodeIt ()
		{
			string argument = "-i " + _inputFileName + " -t 60 -acodec aac -ac 2 -ab
160k -b 3000k -f mp4 " + _outputFileName;
		
			Process p = new Process ();
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardError = true;
			p.StartInfo.RedirectStandardOutput = true;
			p.StartInfo.FileName = "usr/local/bin/ffmpeg";
			p.StartInfo.Arguments = argument;
			p.EnableRaisingEvents = true;

			p.OutputDataReceived += (o, e) =>
			{

				Console.WriteLine ("DATA:" + e.Data);
			};

			p.ErrorDataReceived += (o, e) =>
			{

				Console.WriteLine ("ERR:" + e.Data);

			};

			p.Start ();

			p.BeginErrorReadLine ();
			p.BeginOutputReadLine ();
			
		}

The difference is that on the Mac I get all the encoding output in one large
chunk. The program no longer freezes during the encode (which I previously
encountered, probably for other reasons).

I am starting to suspect that ffmpeg doesn't return the correct new line
characters or something and that is why I don't get any output.

This is the output I get when using MonoMac:

ERR:FFmpeg version SVN-r19382, Copyright (c) 2000-2009 Fabrice Bellard, et
al.
ERR:  configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl
--enable-nonfree --enable-pthreads --disable-ffplay --disable-ffserver
--enable-postproc --enable-libfaac --enable-libfaad --enable-libmp3lame
--enable-libgsm --enable-libtheora --enable-libvorbis --enable-libx264
--enable-libxvid
ERR:  libavutil     50. 3. 0 / 50. 3. 0
ERR:  libavcodec    52.32. 0 / 52.32. 0
ERR:  libavformat   52.36. 0 / 52.36. 0
ERR:  libavdevice   52. 2. 0 / 52. 2. 0
ERR:  libswscale     0. 7. 1 /  0. 7. 1
ERR:  libpostproc   51. 2. 0 / 51. 2. 0
ERR:  built on Jul  8 2009 18:06:21, gcc: 4.0.1 (Apple Inc. build 5490)
ERR:
ERR:Seems stream 0 codec frame rate differs from container frame rate: 47.95
(48000/1001) -> 23.98 (24000/1001)
ERR:Input #0, matroska, from '/Users/myusername/Desktop/Ffmpeg/testmov.mkv':
ERR:  Duration: 00:19:23.16, start: 0.000000, bitrate: N/A
ERR:    Stream #0.0(eng): Video: h264, yuv420p, 1280x720, PAR 1:1 DAR 16:9,
23.98 tbr, 1k tbn, 47.95 tbc
ERR:    Stream #0.1: Audio: ac3, 48000 Hz, 6 channels, s16
ERR:    Stream #0.2: Subtitle: 0x0000
ERR:Output #0, mp4, to
'/Users/myusername/Desktop/Ffmpeg/testmov.mkv.Converted.mp4':
ERR:    Stream #0.0(eng): Video: mpeg4, yuv420p, 1280x720 [PAR 1:1 DAR
16:9], q=2-31, 3000 kb/s, 24k tbn, 23.98 tbc
ERR:    Stream #0.1: Audio: aac, 48000 Hz, 2 channels, s16, 160 kb/s
ERR:Stream mapping:
ERR:  Stream #0.0 -> #0.0
ERR:  Stream #0.1 -> #0.1
ERR:Press [q] to stop encoding
ERR:frame=   16 fps=  0 q=2.1 size=     362kB time=0.75
bitrate=3977.1kbits/s    
frame=   31 fps= 30 q=4.8 size=     733kB time=1.67 bitrate=3601.6kbits/s    
frame=   37 fps= 24 q=2.3 size=     947kB time=2.67 bitrate=2907.0kbits/s    
frame=   43 fps= 21 q=2.3 size=    1129kB time=3.67 bitrate=2519.8kbits/s    
frame=   58 fps= 23 q=2.0 size=    1503kB time=4.55 bitrate=2708.8kbits/s    
frame=   82 fps= 26 q=2.7 size=    2043kB time=5.55 bitrate=3017.4kbits/s    
frame=  105 fps= 29 q=2.6 size=    2542kB time=6.51 bitrate=3199.9kbits/s    
frame=  124 fps= 30 q=2.4 size=    2909kB time=7.30 bitrate=3265.4kbits/s    
frame=  146 fps= 31 q=2.6 size=    3280kB time=8.22 bitrate=3270.4kbits/s    
frame=  168 fps= 33 q=2.6 size=    3604kB time=9.13 bitrate=3232.4kbits/s    
frame=  187 fps= 33 q=4.3 size=    3989kB time=9.93 bitrate=3292.1kbits/s    
frame=  213 fps= 35 q=3.4 size=    4425kB time=11.01 bitrate=3292.1kbits/s    
frame=  232 fps= 35 q=4.4 size=    4758kB time=11.80 bitrate=3302.3kbits/s    
frame=  252 fps= 35 q=4.4 size=    5052kB time=12.64 bitrate=3274.9kbits/s    
frame=  272 fps= 35 q=4.7 size=    5387kB time=13.47 bitrate=3275.8kbits/s    
frame=  293 fps= 36 q=5.9 size=    5751kB time=14.35 bitrate=3283.6kbits/s    
frame=  310 fps= 36 q=3.6 Lsize=    5978kB time=15.06 bitrate=3252.6kbits/s    
ERR:video:5658kB audio:311kB global headers:0kB muxing overhead 0.155147%
ERR:
DATA:

As you can see all the "frame =" parts comes in a single call that is why it
is starting with the string "ERR" which I add before the output.

Can you read the output buffer without waiting for new line characters?

--
View this message in context: http://mono.1490590.n4.nabble.com/OutputDataReceived-event-not-raised-when-using-the-Process-class-together-with-Ffmpeg-tp4649705p4649767.html
Sent from the Mono - OSX mailing list archive at Nabble.com.


More information about the Mono-osx mailing list