本文整理汇总了C#中IMediaControl类的典型用法代码示例。如果您正苦于以下问题:C# IMediaControl类的具体用法?C# IMediaControl怎么用?C# IMediaControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMediaControl类属于命名空间,在下文中一共展示了IMediaControl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: PlayerCore
public PlayerCore(string file)
{
graphBuilder = (new FilterGraph()) as IFilterGraph2;
if (graphBuilder == null) return;
mediaControl = graphBuilder as IMediaControl;
mediaSeeking = graphBuilder as IMediaSeeking;
audioControl = graphBuilder as IBasicAudio;
if (mediaControl == null || mediaSeeking == null || audioControl == null) return;
//int hr = mediaControl.RenderFile(file);
FileInfo info = new FileInfo(file);
ISupport support = Supports.Instance[info.Extension];
int hr = -1;
if (support != null)
hr = support.RenderGraph(graphBuilder, file);
else
hr = mediaControl.RenderFile(file);
fileName = file;
if (hr != 0) errorStack.Push(hr);
if (hr != 0) return;
mediaSeeking.SetTimeFormat(TimeFormat.MediaTime);
isValidate = true;
window = graphBuilder as IVideoWindow;
if (window != null)
{
int width = 0;
int height = 0;
window.get_Width(out width);
window.get_Height(out height);
nativeSize = new Size(width, height);
}
}
开发者ID:crazyender,项目名称:Console-Player,代码行数:32,代码来源:core.cs
示例2: BuildGraph
private void BuildGraph(string fileName)
{
int hr = 0;
try
{
graphBuilder = (IFilterGraph2)new FilterGraph();
mediaControl = (IMediaControl)graphBuilder;
mediaSeeking = (IMediaSeeking)graphBuilder;
mediaPosition = (IMediaPosition)graphBuilder;
vmr9 = (IBaseFilter)new VideoMixingRenderer9();
ConfigureVMR9InWindowlessMode();
hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
DsError.ThrowExceptionForHR(hr);
hr = graphBuilder.RenderFile(fileName, null);
DsError.ThrowExceptionForHR(hr);
}
catch (Exception e)
{
CloseInterfaces();
MessageBox.Show("An error occured during the graph building : \r\n\r\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
开发者ID:andrewjswan,项目名称:mvcentral,代码行数:28,代码来源:framegrabber.cs
示例3: PlayCinematic
// Starts playing a new cinematic
public void PlayCinematic(string file, int x, int y, int w, int h)
{
// Lame bugfix: DirectShow and Fullscreen doesnt like eachother
if (CVars.Instance.Get("r_fs", "0", CVarFlags.ARCHIVE).Integer == 1)
{
if (AlterGameState)
{
playing = true;
StopCinematic();
}
return;
}
// Check if file exists
if (FileCache.Instance.Contains(file))
file = FileCache.Instance.GetFile(file).FullName;
else
{
if (AlterGameState)
{
playing = true;
StopCinematic();
}
Common.Instance.WriteLine("PlayCinematic: Could not find video: {0}", file);
return;
}
// Have the graph builder construct its the appropriate graph automatically
this.graphBuilder = (IGraphBuilder)new FilterGraph();
int hr = graphBuilder.RenderFile(file, null);
DsError.ThrowExceptionForHR(hr);
mediaControl = (IMediaControl)this.graphBuilder;
mediaEventEx = (IMediaEventEx)this.graphBuilder;
videoWindow = this.graphBuilder as IVideoWindow;
basicVideo = this.graphBuilder as IBasicVideo;
// Setup the video window
hr = this.videoWindow.put_Owner(Renderer.Instance.form.Handle);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
// Set the video size
//int lWidth, lHeight;
//hr = this.basicVideo.GetVideoSize(out lWidth, out lHeight);
hr = this.videoWindow.SetWindowPosition(x, y, w, h);
videoWindow.put_FullScreenMode((CVars.Instance.Get("r_fs", "0", CVarFlags.ARCHIVE).Integer == 1) ? OABool.True : OABool.False);
DsError.ThrowExceptionForHR(hr);
// Run the graph to play the media file
hr = this.mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
playing = true;
if (AlterGameState)
Client.Instance.state = CubeHags.common.ConnectState.CINEMATIC;
Common.Instance.WriteLine("Playing cinematic: {0}", file);
EventCode code;
}
开发者ID:maesse,项目名称:CubeHags,代码行数:61,代码来源:Cinematic.cs
示例4: SimplePlayer
/// <summary>
/// This constructor internally build a DirectShow graph using the given file name parameter.
/// </summary>
/// <param name="filename">A media file.</param>
/// <remarks>This constructor use the BlackListManager class to bane the use of the ffdshow Audio and Video decoders during the Intelligent Connect graph building.</remarks>
public SimplePlayer(string filename)
{
if (string.IsNullOrEmpty(filename))
throw new ArgumentNullException("filename");
if (!File.Exists(filename))
throw new FileNotFoundException();
this.graphBuilder = (IFilterGraph2)new FilterGraph();
#if DEBUG
this.rot = new DsROTEntry(this.graphBuilder);
#endif
this.blackListManager = new BlackListManager(this.graphBuilder);
// blacklist the ffdshow Audio Decoder filter
this.blackListManager.AddBlackListedFilter(new Guid("0F40E1E5-4F79-4988-B1A9-CC98794E6B55"));
// blacklist the ffdshow Video Decoder filter
this.blackListManager.AddBlackListedFilter(new Guid("04FE9017-F873-410E-871E-AB91661A4EF7"));
int hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
this.mediaControl = (IMediaControl)this.graphBuilder;
this.mediaEvent = (IMediaEvent)this.graphBuilder;
}
开发者ID:adambyram,项目名称:pimaker,代码行数:32,代码来源:SimplePlayer.cs
示例5: CaptureForm
public CaptureForm()
{
InitializeComponent();
graph_builder = (IGraphBuilder)new FilterGraph();
media_control = (IMediaControl)graph_builder;
events = (IMediaEventEx)graph_builder;
grabber = (ISampleGrabber)new SampleGrabber();
AMMediaType media_type = new AMMediaType();
media_type.majorType = MediaType.Video;
media_type.subType = MediaSubType.RGB24;
grabber.SetMediaType( media_type );
grabber.SetCallback( this, 1 );
cbDevices.Items.AddRange( GetDevices( FilterCategory.VideoInputDevice ) );
}
开发者ID:pbalint,项目名称:Playground,代码行数:17,代码来源:CaptureForm.cs
示例6: ShowMedia
/// <summary>
/// Plays the given mediafile in the internal mediaplayer
/// </summary>
/// <param name="FilePath">File to play</param>
public void ShowMedia(string FilePath)
{
StopMedia();
Lbl_CurrentMedia.Text = Path.GetFileName(FilePath);
m_objFilterGraph = new FilgraphManager();
m_objFilterGraph.RenderFile(FilePath);
m_objBasicAudio = m_objFilterGraph as IBasicAudio;
try
{
m_objVideoWindow = m_objFilterGraph as IVideoWindow;
m_objVideoWindow.Owner = (int)panel2.Handle;
//m_objVideoWindow.Owner = (int)panel1.Handle;
m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
m_objVideoWindow.SetWindowPosition(panel2.ClientRectangle.Left,
panel2.ClientRectangle.Top,
panel2.ClientRectangle.Width,
panel2.ClientRectangle.Height);
}
catch (Exception ex)
{
Console.WriteLine(ex);
m_objVideoWindow = null;
}
m_objMediaEvent = m_objFilterGraph as IMediaEvent;
m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);
m_objMediaPosition = m_objFilterGraph as IMediaPosition;
m_objMediaControl = m_objFilterGraph as IMediaControl;
m_objMediaControl.Run();
m_CurrentStatus = MediaStatus.Running;
UpdateMediaButtons();
//UpdateStatusBar();
//UpdateToolBar();
}
开发者ID:szopenfx,项目名称:code,代码行数:47,代码来源:GraphicalInterface2.cs
示例7: SetControls
public void SetControls()
{
if (selectedDevice == null)
{
launcher = null;
mediaPlayer = null;
mediaControl = null;
tvControl = null;
volumeControl = null;
toastControl = null;
textInputControl = null;
mouseControl = null;
externalInputControl = null;
powerControl = null;
keyControl = null;
playListControl = null;
webAppLauncher = null;
}
else
{
launcher = selectedDevice.GetCapability<ILauncher>();
mediaPlayer = selectedDevice.GetCapability<IMediaPlayer>();
mediaControl = selectedDevice.GetCapability<IMediaControl>();
tvControl = selectedDevice.GetCapability<ITvControl>();
volumeControl = selectedDevice.GetCapability<IVolumeControl>();
toastControl = selectedDevice.GetCapability<IToastControl>();
textInputControl = selectedDevice.GetCapability<ITextInputControl>();
mouseControl = selectedDevice.GetCapability<IMouseControl>();
externalInputControl = selectedDevice.GetCapability<IExternalInputControl>();
powerControl = selectedDevice.GetCapability<IPowerControl>();
keyControl = selectedDevice.GetCapability<IKeyControl>();
playListControl = selectedDevice.GetCapability<IPlayListControl>();
webAppLauncher = selectedDevice.GetCapability<IWebAppLauncher>();
}
SetControlsMedia();
SetWebAppControls();
SetControlControls();
SetControlApps();
SetControlKeys();
SetControlSystem();
}
开发者ID:ConnectSDK,项目名称:Connect-SDK-Windows-Sampler,代码行数:42,代码来源:ModelCommandsImplementation.cs
示例8: cmdOpen_Click
private void cmdOpen_Click(object sender, EventArgs e)
{
// Allow the user to choose a file.
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";
if (DialogResult.OK == openFileDialog.ShowDialog())
{
// Stop the playback for the current movie, if it exists.
if (mc != null) mc.Stop();
mc = null;
videoWindow = null;
// Load the movie file.
FilgraphManager graphManager = new FilgraphManager();
graphManager.RenderFile(openFileDialog.FileName);
// Attach the view to a picture box on the form.
try
{
videoWindow = (IVideoWindow)graphManager;
videoWindow.Owner = (int)pictureBox1.Handle;
videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
videoWindow.SetWindowPosition(pictureBox1.ClientRectangle.Left,
pictureBox1.ClientRectangle.Top,
pictureBox1.ClientRectangle.Width,
pictureBox1.ClientRectangle.Height);
}
catch
{
// An error can occur if the file does not have a vide
// source (for example, an MP3 file.)
// You can ignore this error and still allow playback to
// continue (without any visualization).
}
// Start the playback (asynchronously).
mc = (IMediaControl)graphManager;
mc.Run();
}
}
开发者ID:ehershey,项目名称:development,代码行数:41,代码来源:MoviePlayer.cs
示例9: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(DsDevice dev, int iFrameRate, int iWidth, int iHeight)
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
// Get the graphbuilder object
m_FilterGraph = (IFilterGraph2) new FilterGraph();
m_mediaCtrl = m_FilterGraph as IMediaControl;
try
{
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
// Get the SampleGrabber interface
sampGrabber = (ISampleGrabber) new SampleGrabber();
// Start building the graph
hr = capGraph.SetFiltergraph( m_FilterGraph );
DsError.ThrowExceptionForHR( hr );
// Add the video device
hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
DsError.ThrowExceptionForHR( hr );
IBaseFilter baseGrabFlt = (IBaseFilter) sampGrabber;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter( baseGrabFlt, "Ds.NET Grabber" );
DsError.ThrowExceptionForHR( hr );
// If any of the default config items are set
if (iFrameRate + iHeight + iWidth > 0)
{
SetConfigParms(capGraph, capFilter, iFrameRate, iWidth, iHeight);
}
hr = capGraph.RenderStream( PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt );
DsError.ThrowExceptionForHR( hr );
SaveSizeInfo(sampGrabber);
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (sampGrabber != null)
{
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
if (capGraph != null)
{
Marshal.ReleaseComObject(capGraph);
capGraph = null;
}
}
}
开发者ID:eaglezhao,项目名称:tracnghiemweb,代码行数:65,代码来源:Capture.cs
示例10: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(DsDevice dev, AMMediaType media)
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
// Get the graphbuilder object
m_FilterGraph = (IFilterGraph2) new FilterGraph();
m_mediaCtrl = m_FilterGraph as IMediaControl;
try
{
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
// Get the SampleGrabber interface
sampGrabber = (ISampleGrabber) new SampleGrabber();
// Start building the graph
hr = capGraph.SetFiltergraph( m_FilterGraph );
DsError.ThrowExceptionForHR( hr );
// Add the video device
hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
DsError.ThrowExceptionForHR( hr );
// add video crossbar
// thanks to Andrew Fernie - this is to get tv tuner cards working
IAMCrossbar crossbar = null;
object o;
hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMCrossbar).GUID, out o);
if (hr >= 0)
{
crossbar = (IAMCrossbar)o;
int oPin, iPin;
int ovLink, ivLink;
ovLink = ivLink = 0;
crossbar.get_PinCounts(out oPin, out iPin);
int pIdxRel;
PhysicalConnectorType tp;
for (int i = 0; i < iPin; i++)
{
crossbar.get_CrossbarPinInfo(true, i, out pIdxRel, out tp);
if (tp == PhysicalConnectorType.Video_Composite) ivLink = i;
}
for (int i = 0; i < oPin; i++)
{
crossbar.get_CrossbarPinInfo(false, i, out pIdxRel, out tp);
if (tp == PhysicalConnectorType.Video_VideoDecoder) ovLink = i;
}
try
{
crossbar.Route(ovLink, ivLink);
o = null;
}
catch
{
throw new Exception("Failed to get IAMCrossbar");
}
}
//add AVI Decompressor
IBaseFilter pAVIDecompressor = (IBaseFilter)new AVIDec();
hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
DsError.ThrowExceptionForHR(hr);
//
IBaseFilter baseGrabFlt = (IBaseFilter) sampGrabber;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter( baseGrabFlt, "Ds.NET Grabber" );
DsError.ThrowExceptionForHR( hr );
SetConfigParms(capGraph, capFilter, media);
hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, pAVIDecompressor, baseGrabFlt);
if (hr < 0)
{
hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt);
}
DsError.ThrowExceptionForHR( hr );
SaveSizeInfo(sampGrabber);
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
//.........这里部分代码省略.........
开发者ID:kaldpils,项目名称:ardupilotone,代码行数:101,代码来源:Capture.cs
示例11: InitInterfaces
private void InitInterfaces()
{
try
{
// initialise the graph and get the graph builder and media control from it
_graph = new FilterGraph();
_mediaEvent = (IMediaEventEx)_graph;
_graphBuilder = (IGraphBuilder)_graph;
_mediaControl = (IMediaControl)_graph;
}
catch (Exception ex)
{
throw new ApplicationException("Couldn't initialise filter graph: " + ex.Message);
}
}
开发者ID:Nanook,项目名称:TheGHOST,代码行数:15,代码来源:WindowsAudio.cs
示例12: SetupGraph
// Build the capture graph for grabber and renderer.</summary>
// (Control to show video in, Filename to play)
private void SetupGraph(string FileName)
{
int hr;
// Get the graphbuilder object
m_FilterGraph = new FilterGraph() as IFilterGraph2;
// Get a ICaptureGraphBuilder2 to help build the graph
ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
try
{
// Link the ICaptureGraphBuilder2 to the IFilterGraph2
hr = icgb2.SetFiltergraph(m_FilterGraph);
DsError.ThrowExceptionForHR(hr);
// Add the filters necessary to render the file. This function will
// work with a number of different file types.
IBaseFilter sourceFilter = null;
hr = m_FilterGraph.AddSourceFilter(FileName, FileName, out sourceFilter);
DsError.ThrowExceptionForHR(hr);
// Get the SampleGrabber interface
m_sampGrabber = (ISampleGrabber)new SampleGrabber();
IBaseFilter baseGrabFlt = (IBaseFilter)m_sampGrabber;
// Configure the Sample Grabber
ConfigureSampleGrabber(m_sampGrabber);
// Add it to the filter
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
// Add the null renderer to the graph
IBaseFilter nullrenderer = new NullRenderer() as IBaseFilter;
hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
DsError.ThrowExceptionForHR(hr);
// Connect the pieces together, use the default renderer
hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, nullrenderer);
DsError.ThrowExceptionForHR(hr);
// Now that the graph is built, read the dimensions of the bitmaps we'll be getting
SaveSizeInfo(m_sampGrabber);
// Grab some other interfaces
m_mediaEvent = m_FilterGraph as IMediaEvent;
m_mediaCtrl = m_FilterGraph as IMediaControl;
}
finally
{
if (icgb2 != null)
{
Marshal.ReleaseComObject(icgb2);
icgb2 = null;
}
}
#if DEBUG
// Double check to make sure we aren't releasing something
// important.
GC.Collect();
GC.WaitForPendingFinalizers();
#endif
}
开发者ID:hpavlov,项目名称:occurec,代码行数:66,代码来源:DxPlayer.cs
示例13: InitGraph
private void InitGraph(string filename)
{
int hr = 0;
//IntPtr hEvent;
if (filename == string.Empty)
return;
this.filterGraph = new FilterGraph() as IFilterGraph2;
#if DEBUG
//rot = new DsROTEntry(this.filterGraph);
#endif
// Have the graph builder construct its the appropriate graph automatically
hr = this.filterGraph.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
// QueryInterface for DirectShow interfaces
this.mediaControl = this.filterGraph as IMediaControl;
this.mediaSeeking = this.filterGraph as IMediaSeeking;
//this.mediaEvent = this.graphBuilder as IMediaEvent;
// Query for audio interfaces, which may not be relevant for video-only files
this.basicAudio = this.filterGraph as IBasicAudio;
// Complete window initialization
this.currentPlaybackRate = 1.0;
}
开发者ID:DeSciL,项目名称:Ogama,代码行数:29,代码来源:AudioPlayer.cs
示例14: Run
protected override void Run()
{
#if !DEBUG
WindowsNamedPipe pipe1 = new WindowsNamedPipe("hdpvr.ts", true);
WindowsNamedPipe pipe2 = new WindowsNamedPipe("hdpvr.ts", true);
#endif
try
{
#if !DEBUG
if (!File.Exists(filterGraphFile))
throw new System.Exception("Filter graph file doesn't exist: " + filterGraphFile);
graphBuilder = (IGraphBuilder)new FilterGraph();
FilterGraphTools.LoadGraphFile(graphBuilder, filterGraphFile);
SetSaveFile(SAVEFILEPIPE);
setFiltProp(graphBuilder, "Hauppauge HD PVR Encoder", HDPVRAvgBitrate, 0, 3000000);
setFiltProp(graphBuilder, "Hauppauge HD PVR Encoder", HDPVRPeakBitrate, 0, 3000000);
setFiltProp(graphBuilder, "Hauppauge HD PVR Encoder", HDPVRBitrateMode, 0, 0);
mediaControl = (IMediaControl)this.graphBuilder;
mediaControl.Run();
#endif
}
catch (Exception e)
{
Log.WriteLine(e.ToString());
return;
}
#if !DEBUG
new Thread(new ThreadStart(delegate
{
byte[] tmp = new byte[188];
pipe1._connected.WaitOne();
while (true)
{
int readcount = pipe1.Read(tmp);
Log.WriteLine(readcount.ToString());
if (readcount > 0)
{
Log.WriteLine("pipe1 read " + readcount + " bytes, this is not normal");
}
else if (readcount == -1)
{
Log.WriteLine("pipe1 disconnected, do not worry, this is normal");
pipe1.Close();
break;
}
}
})).Start();
#endif
byte[] readbuffer = new byte[188 * 20 * 1024];
int loopcount = 0;
DateTime noneReceiverFrom = DateTime.Now;
try
{
while (true)
{
#if !DEBUG
int readcount = pipe2.Read(readbuffer);
if (readcount == -1)
{
if (loopcount < 10)
{
Thread.Sleep(1000);
loopcount++;
continue;
}
Log.WriteLine("pipe2 disconnected");
pipe2.Close();
return;
}
Thread.Sleep(1000);
#else
FileStream fs = new FileStream("c:\\0.ts", FileMode.Open, FileAccess.Read);
int readcount = fs.Read(readbuffer, 0, readbuffer.Length);
#endif
loopcount = 0;
lock (this.receiveStreams)
{
if (receiveStreams.Count > 0)
noneReceiverFrom = DateTime.Now;
else if ((DateTime.Now - noneReceiverFrom).TotalSeconds > 60 && this.working)
{
//关闭
new Thread(new ThreadStart(delegate {
this.Stop();
})).Start();
return;
}
foreach (Stream s in receiveStreams)
{
s.Write(readbuffer, 0, readcount);
Log.WriteLine("写入" + readcount + "字节");
}
//.........这里部分代码省略.........
开发者ID:jorgeantwan18,项目名称:rokumedia,代码行数:101,代码来源:HDPVR.cs
示例15: Transcode
//.........这里部分代码省略.........
{
Log.Warn("DVR2MPG: FAILED:unable to get pins of muxer&source");
Cleanup();
return false;
}
bool usingAc3 = false;
AMMediaType amAudio = new AMMediaType();
amAudio.majorType = MediaType.Audio;
amAudio.subType = MediaSubType.Mpeg2Audio;
hr = pinOut0.Connect(pinIn1, amAudio);
if (hr != 0)
{
amAudio.subType = MediaSubType.DolbyAC3;
hr = pinOut0.Connect(pinIn1, amAudio);
usingAc3 = true;
}
if (hr != 0)
{
Log.Warn("DVR2MPG: FAILED: unable to connect audio pins: 0x{0:X}", hr);
Cleanup();
return false;
}
if (usingAc3)
Log.Info("DVR2MPG: using AC3 audio");
else
Log.Info("DVR2MPG: using MPEG audio");
AMMediaType amVideo = new AMMediaType();
amVideo.majorType = MediaType.Video;
amVideo.subType = MediaSubType.Mpeg2Video;
hr = pinOut1.Connect(pinIn0, amVideo);
if (hr != 0)
{
Log.Warn("DVR2MPG: FAILED: unable to connect video pins: 0x{0:X}", hr);
Cleanup();
return false;
}
//connect output of powerdvd muxer->input of filewriter
Log.Info("DVR2MPG: connect multiplexer->filewriter");
IPin pinOut, pinIn;
pinOut = DsFindPin.ByDirection(powerDvdMuxer, PinDirection.Output, 0);
if (pinOut == null)
{
Log.Warn("DVR2MPG: FAILED:cannot get output pin of Cyberlink MPEG muxer :0x{0:X}", hr);
Cleanup();
return false;
}
pinIn = DsFindPin.ByDirection(fileWriterbase, PinDirection.Input, 0);
if (pinIn == null)
{
Log.Warn("DVR2MPG: FAILED:cannot get input pin of Filewriter :0x{0:X}", hr);
Cleanup();
return false;
}
AMMediaType mt = new AMMediaType();
hr = pinOut.Connect(pinIn, mt);
if (hr != 0)
{
Log.Warn("DVR2MPG: FAILED:connect muxer->filewriter :0x{0:X}", hr);
Cleanup();
return false;
}
//set output filename
string outputFileName = System.IO.Path.ChangeExtension(info.file, ".mpg");
Log.Info("DVR2MPG: set output file to :{0}", outputFileName);
mt.majorType = MediaType.Stream;
mt.subType = MediaSubTypeEx.MPEG2;
hr = fileWriterFilter.SetFileName(outputFileName, mt);
if (hr != 0)
{
Log.Warn("DVR2MPG: FAILED:unable to set filename for filewriter :0x{0:X}", hr);
Cleanup();
return false;
}
mediaControl = graphBuilder as IMediaControl;
mediaSeeking = graphBuilder as IMediaSeeking;
mediaEvt = graphBuilder as IMediaEventEx;
Log.Info("DVR2MPG: start transcoding");
hr = mediaControl.Run();
if (hr != 0)
{
Log.Warn("DVR2MPG: FAILED:unable to start graph :0x{0:X}", hr);
Cleanup();
return false;
}
}
catch (Exception ex)
{
Log.Error("DVR2MPG: Unable create graph: {0}", ex.Message);
Cleanup();
return false;
}
return true;
}
开发者ID:npcomplete111,项目名称:MediaPortal-1,代码行数:101,代码来源:Dvrms2Mpeg.cs
示例16: StartCapture
private void StartCapture()
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
if (System.IO.File.Exists(txtAviFileName.Text))
{
// Get the graphbuilder object
m_FilterGraph = (IFilterGraph2) new FilterGraph();
m_mediaCtrl = m_FilterGraph as IMediaControl;
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
// Get the SampleGrabber interface
sampGrabber = (ISampleGrabber) new SampleGrabber();
// Start building the graph
hr = capGraph.SetFiltergraph(m_FilterGraph);
DsError.ThrowExceptionForHR(hr);
// Add the video source
hr = m_FilterGraph.AddSourceFilter(txtAviFileName.Text, "File Source (Async.)", out capFilter);
DsError.ThrowExceptionForHR(hr);
//add AVI Decompressor
IBaseFilter pAVIDecompressor = (IBaseFilter) new AVIDec();
hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
DsError.ThrowExceptionForHR(hr);
IBaseFilter ffdshow;
try
{
// Create Decoder filter COM object (ffdshow video decoder)
Type comtype = Type.GetTypeFromCLSID(new Guid("{04FE9017-F873-410E-871E-AB91661A4EF7}"));
if (comtype == null)
throw new NotSupportedException("Creating ffdshow video decoder COM object fails.");
object comobj = Activator.CreateInstance(comtype);
ffdshow = (IBaseFilter) comobj; // error ocurrs! raised exception
comobj = null;
}
catch
{
CustomMessageBox.Show("Please install/reinstall ffdshow");
return;
}
hr = m_FilterGraph.AddFilter(ffdshow, "ffdshow");
DsError.ThrowExceptionForHR(hr);
//
IBaseFilter baseGrabFlt = (IBaseFilter) sampGrabber;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
IBaseFilter vidrender = (IBaseFilter) new VideoRenderer();
hr = m_FilterGraph.AddFilter(vidrender, "Render");
DsError.ThrowExceptionForHR(hr);
IPin captpin = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);
IPin ffdpinin = DsFindPin.ByName(ffdshow, "In");
IPin ffdpinout = DsFindPin.ByName(ffdshow, "Out");
IPin samppin = DsFindPin.ByName(baseGrabFlt, "Input");
hr = m_FilterGraph.Connect(captpin, ffdpinin);
DsError.ThrowExceptionForHR(hr);
hr = m_FilterGraph.Connect(ffdpinout, samppin);
DsError.ThrowExceptionForHR(hr);
FileWriter filewritter = new FileWriter();
IFileSinkFilter filemux = (IFileSinkFilter) filewritter;
//filemux.SetFileName("test.avi",);
//hr = capGraph.RenderStream(null, MediaType.Video, capFilter, null, vidrender);
// DsError.ThrowExceptionForHR(hr);
SaveSizeInfo(sampGrabber);
// setup buffer
if (m_handle == IntPtr.Zero)
m_handle = Marshal.AllocCoTaskMem(m_stride*m_videoHeight);
// tell the callback to ignore new images
m_PictureReady = new ManualResetEvent(false);
m_bGotOne = false;
m_bRunning = false;
timer1 = new Thread(timer);
timer1.IsBackground = true;
//.........这里部分代码省略.........
开发者ID:duyisu,项目名称:MissionPlanner,代码行数:101,代码来源:OSDVideo.cs
示例17: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(string FileName)
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter baseGrabFlt = null;
IBaseFilter capFilter = null;
IBaseFilter nullrenderer = null;
// Get the graphbuilder object
m_FilterGraph = new FilterGraph() as IFilterGraph2;
m_mediaCtrl = m_FilterGraph as IMediaControl;
m_MediaEvent = m_FilterGraph as IMediaEvent;
IMediaFilter mediaFilt = m_FilterGraph as IMediaFilter;
try
{
#if DEBUG
m_rot = new DsROTEntry(m_FilterGraph);
#endif
// Add the video source
hr = m_FilterGraph.AddSourceFilter(FileName, "Ds.NET FileFilter", out capFilter);
DsError.ThrowExceptionForHR(hr);
// Get the SampleGrabber interface
sampGrabber = new SampleGrabber() as ISampleGrabber;
baseGrabFlt = sampGrabber as IBaseFilter;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
// ---------------------------------
// Connect the file filter to the sample grabber
// Hopefully this will be the video pin, we could check by reading it's mediatype
IPin iPinOut = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);
// Get the input pin from the sample grabber
IPin iPinIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
hr = m_FilterGraph.Connect(iPinOut, iPinIn);
DsError.ThrowExceptionForHR(hr);
// Add the null renderer to the graph
nullrenderer = new NullRenderer() as IBaseFilter;
hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
DsError.ThrowExceptionForHR(hr);
// ---------------------------------
// Connect the sample grabber to the null renderer
iPinOut = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);
iPinIn = DsFindPin.ByDirection(nullrenderer, PinDirection.Input, 0);
hr = m_FilterGraph.Connect(iPinOut, iPinIn);
DsError.ThrowExceptionForHR(hr);
// Turn off the clock. This causes the frames to be sent
// thru the graph as fast as possible
hr = mediaFilt.SetSyncSource(null);
DsError.ThrowExceptionForHR(hr);
// Read and cache the image sizes
SaveSizeInfo(sampGrabber);
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (sampGrabber != null)
{
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
if (nullrenderer != null)
{
Marshal.ReleaseComObject(nullrenderer);
nullrenderer = null;
}
}
}
开发者ID:nikolasbe,项目名称:ugent-dma-videoshotdetection,代码行数:90,代码来源:Capture.cs
示例18: PlayMovieInWindow
private void PlayMovieInWindow(string filename)
{
int hr = 0;
if (filename == string.Empty)
return;
this.graphBuilder = (IGraphBuilder) new FilterGraph();
// Have the graph builder construct its the appropriate graph automatically
hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
// QueryInterface for DirectShow interfaces
this.mediaControl = (IMediaControl) this.graphBuilder;
this.mediaEventEx = (IMediaEventEx) this.graphBuilder;
this.mediaSeeking = (IMediaSeeking) this.graphBuilder;
this.mediaPosition = (IMediaPosition) this.graphBuilder;
// Query for video interfaces, which may not be relevant for audio files
this.videoWindow = this.graphBuilder as IVideoWindow;
this.basi
|
请发表评论