View Full Version : x264 to program communication?
Yiu
25th March 2010, 03:06
Hi, developing a program to convert videos (mostly bluray) to x264+flac/mp3 video/audio.
I really only have one step left and that is how to get x264 program to hide on open and send the data (frames, fps, kbits, eta) to my main program.
VB.NET is preferred but C and C# are acceptable solutions.
roozhou
25th March 2010, 12:40
The best way is to use libx264 because you get full control.
If you don't know/want to build/link to libx264 and you are using x264.exe, please read the reference of CreateProcess on MSDN.
stax76
25th March 2010, 13:40
You probably don't want to use a C interface as it's much harder than .NET, you can find a sample in MSDN:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginerrorreadline%28v=VS.90%29.aspx
A short sample using lamba subs and implicit line continuation so you need the VB.NET 2010 compiler:
Dim s = Sub()
Using p As New Process
AddHandler p.ErrorDataReceived,
Sub(sendingProcess As Object,
outLine As DataReceivedEventArgs)
If outLine.Data <> "" Then BeginInvoke(Sub() Text = outLine.Data)
End Sub
p.StartInfo.FileName = "D:\Projekte\StaxMedia\trunk\StaxRip\bin\Applications\x264\x264.exe"
p.StartInfo.Arguments = "--preset fast --tune film --crf 18 --sar 16:11 --output ""D:\Video\Samples\DVD\Pulp Fiction\VTS_01_1 temp files\VTS_01_1_CompCheck.h264"" ""D:\Video\Samples\DVD\Pulp Fiction\VTS_01_1 temp files\VTS_01_1_CompCheck.avs"""
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.Start()
p.BeginErrorReadLine()
p.WaitForExit()
End Using
End Sub
s.BeginInvoke(Nothing, Nothing)
It's a bit difficult to understand where and why you need asynchronous calls.
Since it waits for the process to exit a worker thread is used to prevent
the main thread to block (and the window to freeze). The handler receiving
the output marshals the output back to the main thread since cross thread calls
changing controls are illegal, this is also done asynchronously as it's more efficient.
The compiler translates lamdas to objects so you have to be careful as object
creation is slower than just calling a procedure, the event handler in the sample
will be called very often.
LoRd_MuldeR
25th March 2010, 21:16
Hi, developing a program to convert videos (mostly bluray) to x264+flac/mp3 video/audio.
I really only have one step left and that is how to get x264 program to hide on open and send the data (frames, fps, kbits, eta) to my main program.
VB.NET is preferred but C and C# are acceptable solutions.
What you need to do is redirecting the STDOUT/STDERR of x264.exe to your host application.
Once you have redirected all console output, you can parse the obtained text in order to extract frames, fps, kbits, eta and so on...
This article is what helped me a lot to implement that properly with my applications:
http://support.microsoft.com/?scid=kb%3Ben-us%3B190351&x=8&y=14
Here is my implementation:
http://code.google.com/p/mulder/source/browse/trunk/LameXP/src/Unit_RunProcess.pas
(That all of course only applies if you want to use x264 as a separate console process, not if you want to use the library)
stax76
25th March 2010, 22:41
That looks slightly more difficult.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.