C# Playing Video From A Memory Stream Using DirectShow (quartz.dll).

I have a C# Visual Studio WinForms app that plays video using the QuartzTypeLib (quartz.dll). With the code I've written, I can play any video file from the hard drive. Here's the code at the top that executes when the app starts:
        public const int WS_CHILD = 0x40000000;
        public const int WS_CLIPCHILDREN = 0x2000000;
        public QuartzTypeLib.IMediaControl mc;
        public QuartzTypeLib.IVideoWindow videoWindow = null;
        IMediaPosition mp = null;
And here's the code that opens the video file:
        private void openMediaToolStripMenuItem_Click(object sender, EventArgs e)
            // Open a media file.
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Video Files|*.mpg;*.avi;*;*.wmv;*.mov";
            ofd.FilterIndex = 1;
            if (DialogResult.OK == ofd.ShowDialog())
                // Stop the playback for the current movie if a video is currently playing.
                if (mc != null)
                    mc.Stop();
                if (pbVideoDisplay.Image != null)
                    pbVideoDisplay.Image = null;
                // Load the movie file.
                FilgraphManager graphManager = new FilgraphManager();
                graphManager.RenderFile(ofd.FileName);
                mp = graphManager as IMediaPosition;
                mc = (IMediaControl)graphManager;
                tsbtnPlay.Enabled = tsbtnPause.Enabled = tsbtnStop.Enabled = true;
                // Attach the view to the picture box (pbVideoDisplay) on frmMain.
                try
                    videoWindow = (IVideoWindow)graphManager;
                    videoWindow.Owner = (int)pbVideoDisplay.Handle;
                    videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                    videoWindow.SetWindowPosition(
                    pbVideoDisplay.ClientRectangle.Left,
                    pbVideoDisplay.ClientRectangle.Top,
                    pbVideoDisplay.ClientRectangle.Width,
                    pbVideoDisplay.ClientRectangle.Height);
                catch //(Exception Ex)
                    // I'll write code for this when I have a need to.
                // Now we convert the video to a byte array.
                FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
                try
                    // Here we convert the video to Base 64.
                    VideoInBytes = new byte[fs.Length];
                    VideoInBytes = System.Text.Encoding.UTF8.GetBytes(ofd.FileName);
                    VideoInBase64 = Convert.ToBase64String(VideoInBytes);
                catch //(Exception Ex)
                    //throw new Exception("Error in base64Encode" + Ex.Message); Worry about this later.
Notice that I have code that converts the video to a Base64 string. I'd like to add code that will allow me to play a video from a memory stream or any other type of stream that might work better. Is that even possible and if so, what code would I need to add
and where would I put it?

You should be able to do it by developing a plug-in for the existing DShow filter. For instance, wmv files are being opened/read with the "WM ASF Reader" filter. You can register your own protocol and implement your own plug-in for that protocol
(e.g. you could name it 'memory', and your URL would look like
memory://something.wmv). You can register your protocol under the [HKEY_CLASSES_ROOT\memory\Extensions] by creating a new string value with the file extension as a name (.wmv). The value is the WM ASF Readers's
GUID ({187463A0-5BB7-11D3-ACBE-0080C75E246E}).
You also need to register your plugin that will be used for a wmv file when used with the 'memory' protocol.
In [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Media\WMSDK\sources] create a new string value with the protocol name and the value is a path to you DLL plug-in. Your plug-in must implement the IStream interface. The plugin DLL exports a single function:
HRESULT WMCreateStreamForURL( LPCWSTR pwszURL, BOOL *pfCorrectSource, IStream **ppStream )
MSDN can provide more info on WMCreateStreamForURL() and plugins in general.
Once you do that, what will happen is this: each time you open a file like "memory://myfile.wmv", the WM ASF Reader filter will load your plugin, call WMCreateStreamForURL() and it will use your custom IStream object for all read/write operations.

Similar Messages

  • Playing videos from within the application using Phonegap.

    I am trying to get videos to play videos from within a PhoneGap app across IOS/Android/WP8 that will play videos contained within the phonegap app.  I have accomplished getting videos on Android and IOS but getting it working on WP8 has left me stumped
    as I have not been able to find anyone even attempting to getting videos to play from within a phonegap application on WP8.   So if anyone knows how to do this, or any suggestions of what direction I should look for a solution (I'm assuming it doesn't
    work as because of how IE treats videos on WP8 and will not load off the device)
    (Yes I know this is probably not the first place to look for solutions,and its not I've been looking elsewhere as well, but there is very few people supporting phone gap on WP8 elsewhere so this seems like the best place to maybe get some help/ideas)

    Hi Mwengil,
    You are asking questions about third-party library. It’s out of our support range.
    Please refer to check the API documentation.
    http://docs.phonegap.com/en/4.0.0/index.html or try to contact library official site.
    http://phonegap.com/about/contact/.
    Thank you for understanding. If you have any questions about windows phone development, you are always welcome posting here.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate
    the survey.

  • Playing video from a flash streaming server

    Hi I've been trying to insert a video in a flash project that is hosted on a flash media server. I put the address wich by the way is rtmp://p8bezucu.rtmphost.com/testevideo/portfolio.flv and it doesn't work, I'm pretty sure that the address is right, am I misssing something? Thanks a lot

    Have you tried dropping the .flv from the source url string? I think if the FLVPlayback component sees .flv it thinks it is a progressive download instead of a stream.

  • How do I play video from photostream on apple TV?

    PhotoStream is now available on my applet TV and the notes on the upgrade said I could play video from my Photo Stream.  However the Photo Stream on the apple TV only presents photos for viewing.  Any idea on how to get it to show my videos?

    Welcome to the Apple Community.
    Unfortunately that's not possible.

  • Playing video from a capture device - Out of memory for video buffers?

    Hello guys, I'm having problems playing video from a video capture device when not using JMStudio. When I use JMStudio, the video plays real time with no problems, but when I use code taken from a java book which is a simple Media Player, I get the following error:
    "Error is Error: Out of memory for video buffers."
    My capture device is working and I don't know why i get this error when trying to watch the video feed from a program other than JMStudio. I also tried different code that has worked in the past with the same exact capture device and I still get the same error. Please help, I have no clue at this point. The code for the simple media player is below, it's taken out of the book "Java: How to Program (4th edition)":
    Thanks in advance, I am very greatful
    Miguel
    device info: vfw:Microsoft WDM Image Capture (Win32):0
    When I type the locator, I am typing vfw://0, I also tried just vfw://
    and I get the same error.
    // Fig. 22.1: SimplePlayer.java
    // Opens and plays a media file from
    // local computer, public URL, or an RTP session
    // Java core packages
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    // Java extension packages
    import javax.swing.*;
    import javax.media.*;
    public class SimplePlayer extends JFrame {
         // Java media player
         private Player player;
    // visual content component
    private Component visualMedia;
    // controls component for media
    private Component mediaControl;
    // main container
    private Container container;
    // media file and media locations
    private File mediaFile;
    private URL fileURL;
    // constructor for SimplePlayer
    public SimplePlayer()
    super( "Simple Java Media Player" );
    container = getContentPane();
    // panel containing buttons
    JPanel buttonPanel = new JPanel();
    container.add( buttonPanel, BorderLayout.NORTH );
    // opening file from directory button
    JButton openFile = new JButton( "Open File" );
    buttonPanel.add( openFile );
    // register an ActionListener for openFile events
    openFile.addActionListener(
    // anonymous inner class to handle openFile events
    new ActionListener() {
    // open and create player for file
    public void actionPerformed( ActionEvent event )
    mediaFile = getFile();
    if ( mediaFile != null ) {
    // obtain URL from file
    try {
    fileURL = mediaFile.toURL();
    // file path unresolvable
    catch ( MalformedURLException badURL ) {
    badURL.printStackTrace();
    showErrorMessage( "Bad URL" );
    makePlayer( fileURL.toString() );
    } // end actionPerformed
    } // end ActionListener
    ); // end call to method addActionListener
    // URL opening button
    JButton openURL = new JButton( "Open Locator" );
    buttonPanel.add( openURL );
    // register an ActionListener for openURL events
    openURL.addActionListener(
    // anonymous inner class to handle openURL events
    new ActionListener() {
    // open and create player for media locator
    public void actionPerformed( ActionEvent event )
    String addressName = getMediaLocation();
    if ( addressName != null )
    makePlayer( addressName );
    } // end ActionListener
    ); // end call to method addActionListener
    // turn on lightweight rendering on players to enable
    // better compatibility with lightweight GUI components
    Manager.setHint( Manager.LIGHTWEIGHT_RENDERER,
    Boolean.TRUE );
    } // end SimplePlayer constructor
    // utility method for pop-up error messages
    public void showErrorMessage( String error )
    JOptionPane.showMessageDialog( this, error, "Error",
    JOptionPane.ERROR_MESSAGE );
    // get file from computer
    public File getFile()
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(
    JFileChooser.FILES_ONLY );
    int result = fileChooser.showOpenDialog( this );
    if ( result == JFileChooser.CANCEL_OPTION )
    return null;
    else
    return fileChooser.getSelectedFile();
    // get media location from user input
    public String getMediaLocation()
    String input = JOptionPane.showInputDialog(
    this, "Enter URL" );
    // if user presses OK with no input
    if ( input != null && input.length() == 0 )
    return null;
    return input;
    // create player using media's location
    public void makePlayer( String mediaLocation )
    // reset player and window if previous player exists
    if ( player != null )
    removePlayerComponents();
    // location of media source
    MediaLocator mediaLocator =
    new MediaLocator( mediaLocation );
    if ( mediaLocator == null ) {
    showErrorMessage( "Error opening file" );
    return;
    // create a player from MediaLocator
    try {
    player = Manager.createPlayer( mediaLocator );
    // register ControllerListener to handle Player events
    player.addControllerListener(
    new PlayerEventHandler() );
    // call realize to enable rendering of player's media
    player.realize();
    // no player exists or format is unsupported
    catch ( NoPlayerException noPlayerException ) {
    noPlayerException.printStackTrace();
    // file input error
    catch ( IOException ioException ) {
    ioException.printStackTrace();
    } // end makePlayer method
    // return player to system resources and
    // reset media and controls
    public void removePlayerComponents()
    // remove previous video component if there is one
    if ( visualMedia != null )
    container.remove( visualMedia );
    // remove previous media control if there is one
    if ( mediaControl != null )
    container.remove( mediaControl );
    // stop player and return allocated resources
    player.close();
    // obtain visual media and player controls
    public void getMediaComponents()
    // get visual component from player
    visualMedia = player.getVisualComponent();
    // add visual component if present
    if ( visualMedia != null )
    container.add( visualMedia, BorderLayout.CENTER );
    // get player control GUI
    mediaControl = player.getControlPanelComponent();
    // add controls component if present
    if ( mediaControl != null )
    container.add( mediaControl, BorderLayout.SOUTH );
    } // end method getMediaComponents
    // handler for player's ControllerEvents
    private class PlayerEventHandler extends ControllerAdapter {
    // prefetch media feed once player is realized
    public void realizeComplete(
    RealizeCompleteEvent realizeDoneEvent )
    player.prefetch();
    // player can start showing media after prefetching
    public void prefetchComplete(
    PrefetchCompleteEvent prefetchDoneEvent )
    getMediaComponents();
    // ensure valid layout of frame
    validate();
    // start playing media
    player.start();
    } // end prefetchComplete method
    // if end of media, reset to beginning, stop play
    public void endOfMedia( EndOfMediaEvent mediaEndEvent )
    player.setMediaTime( new Time( 0 ) );
    player.stop();
    } // end PlayerEventHandler inner class
    // execute application
    public static void main( String args[] )
    SimplePlayer testPlayer = new SimplePlayer();
    testPlayer.setSize( 300, 300 );
    testPlayer.setLocation( 300, 300 );
    testPlayer.setDefaultCloseOperation( EXIT_ON_CLOSE );
    testPlayer.setVisible( true );
    } // end class SimplePlayer

    somebody? anybody? I know there are some JMF professionals in here, any ideas?
    I was reading the Sun documentation and it said something about increasing the JVM memory buffer or something? Well, i'm just clueless at this point.
    Help a brotha out!

  • Can I stream live video from mobile to fms using flashlite?

    Can I stream live video from mobile to fms using flashlite?
    I Know flash lite 4 also not access the mobile camera.  But, I need to develop a application it captures the mobile camera and stream the vedio to fms server and display the live event to other mobile users.
    Is it possible? 
    If possible what are the technologies i can use?
    Thanks for the help in adavance
    Prasad

    i have made a few test with Flash Lite 3.0 and Flash Media Server 3  and I have to say that it is pretty easy to stream FLV Video files and  Live Video from local web camera to mobile phone. Here are a quick  instructions how to do it in Windows (I will publish Linux version  later).
    Play FLV-video from Flash Media Server 3:
    Install Flash Media Server 3 (download developer version)
    There are a few sample FLV files in applications/vod/media folder, so you can use one of them for testing
    Create a new Flash Lite 3.0 file in Flash
    Add a new Video symbol to library
    Drag this Video symbol to Stage and give instance name to it: video
    Type following programming to timeline:
    // make a new video-object
    var video:Video;
    // make a new NetConnection-object
    var nc:NetConnection = new NetConnection();
    // check connection status from server
    nc.onStatus = function(info:Object):Void {
      status_txt.text=info.code;
      if (info.code == "NetConnection.Connect.Success") {
        startStreaming();
    // start streaming video to phone
    function startStreaming() {
      ns = new NetStream(nc);
      ns.setBufferTime(5);
      video.attachVideo(ns);
      // play sample.flv from server
      ns.play("sample",0);
    // show info to user
    status_txt.text = "Connecting server...";
    // connect FMS 3 video on demand service (default port 1935)
    nc.connect("rtmp://your.server.ip.here:1935/vod");
    Go to Publish Settings...
    Set Local playback security: Access network only
    Publish your SWF-file
    Send your SWF-file to your phone
    Test and you should see FLV-video playing in your phone
    Play live video from Flash Media Server 3:
    Install Flash Media Server 3 (download developer version)
    Install Flash Media Encoder 2 (Windows only)
    Start Flash Media Encoder 2
    You should see your live camera in Input screen
    Press Start-button to start sending live video to Flash Media Server 3
    Create a new Flash Lite 3.0 file in Flash
    Add Video symbol and programming as you did earlier
    Modify your programming:
    // in startStreaming()-function
    // Flash Media Encoder 2 publish stream name is "livestream"
    ns.play("livestream",-1,-1,true);
    // start connection to Flash Media Server 3
    // Flash Media Encoder 2 publishes Flash Media Server's default
    // live publishing point, so connect it
    nc.connect("rtmp://your.server.ip.here:1935/live");
    Publish, test and enjoy
    box office movies

  • Play video from memory/cache

    Hi All,
    Is it possible to play video from memory or cache? I trying to build a video player. And I am using NetStream.play(). It can play a local file,  but how can I load the a file into memory first, do some modification, and then play it?
    Thanks a lot!

    If you mean "can I play a video file's video part via AppleTV and the audio part via the Macbook" then the answer is no.
    You could probably play the video on AppleTv and also play it on the Macbook and output the audio, but you would have to do this manually, and 2 applications accessing the same video file might cause stuttering playback issues. Additionally you'd have to manually sync the audio and lip sync problems are annoying at the best of times.
    If you mean "can I watch a video from AppleTV and play separate music via iTunes on the Macbook", then the answer is yes.
    AC

  • Play video from input stream

    urgent
    i need to play an mpg file from a jar file but the Manager.createPlayer now only Url object
    is there any other way to play video from InputStream?

    You may want to take a look at this:
    http://www.extollit.com/isdsjmf.php
    I developed a similar implementation of this for a client and it works fine. It's based on using a sequential InputStream as a DataSource for the media player. As you may already know, the Java Media Framework does not seem to support URLDataSource and/or sequential InputStreams.
    This code allows you to play media from nothing more than an InputStream without downloading it all into memory or to a local file. It uses a ringbuffer as a compromise along with some other enhancements.

  • I want to use my I Pad mini to play videos from my Gopro Hero HD camera and also to use as a monitor if possible?

    I want to use my I Pad mini to play videos from my Gopro Hero HD camera and also to use as a monitor if possible? What software would i need to use ? I movie is what i use with my I Mac not sure if this will work on I Pad Mini?

    At first I thought that this solved my problem, but alas it didn't. It does appear to add display area for your computer or to suplement it. But it is not a view screen for your Mini. I guess I will just have to live on with my monitor and use my Ipad and the "remote" app to run Itunes.
    Once I have the system all set up, I could use the display but I don't know why I would. Thanks for your help.

  • I am not able to play videos from YoyTube, or videow posted on my blog. That does not happens with explorer, where videos are playing normal

    I am not able to play videos from YouTube, or videow posted on my blog, when I use Fire Fox. That did not happened before the 3.6.14 and allthouhg you informed us that with the 3.6.15 the problem will dissapear, it does not happen. Take into consideration that, with explorer, everything is running fine. I am a long time user o firefox and I donnot want to change. Please give me advise how to solve thiw problem. Tanhks in advance

    Hi, My computer shuts down when I try to do any thing with graphics, ie, watching streamed video or looking at my photo's. this is a recent problem, anyone got any idea's

  • Play video from video capture device

    I tried fixing my running of out memory for the video buffers problem but could find a fix. I have tried code from a book and it doesn't work. I can only get the video feed to display the video from the capture device using JMStudio, so the device works fine. Maybe my coding methodology/process is incorrect.
    Is there anyone out there that knows of some working code that plays live video in a window from a video capture device. Any other help regarding to displaying capture video would help. Please help.
    Thanks in advance.

    I am using the Belkin USB VideoBus II and it uses the video for windows drivers (vfw), so yet it is supported. And it works when I use JMStudio to play the live feed from the capture device. Thanks for the suggestion.
    I also ran the code suggested above and I still get the same errors. Thanks for your suggestions. Any other help or suggestions would be appreciated.

  • How do I play video from my macbook pro to my tv?

    How do I play video from my macbook pro to my tv?

    What model MacBook Pro do you have? On my late 2011, I used to use a Mini DisplayPort/Thunderbolt to HDMI adapter to get video and audio from my Mac to my television. I used this adapter from Monoprice. Worked great - I just no longer use it because I bought a 27" monitor.
    You can also use AirPlay mirroring if you've the right MBP and an Apple TV - but the wired method works, too.
    Clinton

  • Is there a software like flash player for ipad.what software do I exactly need in order to play videos from websites?

    Is there a software like flash player for ipad.what software do I exactly need in order to play videos from websites?

    NKafafi88-
    There may be a couple Apps that may help, but I understand they don't work very well.  The best solution would be to contact the owners of the websites and let them know they need to update their site.
    The alternative I use, is to download the problem video onto my computer, and convert it to M4V or MP4 format using a program like HandBrake <HandBrake>.  Then it can be added to iTunes and synced with the iPad.
    Fred

  • Easy fix to play video from itunes on PC

    OK Everyone who has the same problem of playing videos on a PC, and after a couple of seconds, your computer either crashes, or freezes/plays choppy, here is a very easy fix. I actually found it by reading other posts, and I can not remember who tried it first, so sorry to who it is that I can't give you credit, but thank you very much. All you need to do is have an external hard drive like what I am using (WD 160gig Passport). Copy your movie/tv shows files from your itunes file folder in your music folder on your computer harddrive to the external harddrive. Then just play it FROM your external harddrive using Quicktime, and it will work flawlessly! I don't know why it will not play from your computer, but it works with all videos from the external drive. Now go watch some movies!

    Buy yourself a small set of speakers that plug into the headset jack of your iPod. Lots of options out there. It's simple and straightforward.

  • I canon play video from my ipad through my Apple TV after downloading ios7 any idea why?

    Is there any reason I can't play video from my ipad through Apple TV after downloading ios7?

    Home sharing isn't working either
    Which is why you can not use the remote app.  Did you turn on home sharing on your computer and on ATV?
    eve though they have the same Apple ID.
    Did you enter the ApplieID in the home sharing login though?  Or just in for the iTunes store, or iCloud, or photo sharing, or something else?
    Home sharing isn't working either, I can't play or transmit any video from my iPad to the Apple TV because it doesn't recognize it
    That would be AirPlay, not homesharing.  THey are not related.  Did you enable air play on all the devices?
    Have you run the network test tools on ATV?  Can ATV access the iTunes store, Netflix, etc?

Maybe you are looking for

  • Transfer documents b/w iPad and borrowed laptop

    I am travelling soon for work and can only take my iPad. I will need to transfer files between my iPad and a borrowed MacBook. Can I do this without transferring all of my data and apps?

  • Stock Account Valuation

    Dear Guru, User wants to post FX gains or loss when difference arises between Good receipt and Good issue. AS-IS now, (1) Good receipt comes in Euro (local currnecy CZK, 1st March 2011 Rate : 25: 1 ) Stock 100 Euro ( 2500 CZK ) / GRIR 100 Euro ( 2500

  • Saving a modified word document without user intervention

    Dear Reader, I have successfully opened a template (MS Word document), and modified the bookmarks using DDE; however, now in attempting to save the document without the user having to respond I am having problems. I have attempted to use DDE.EXECUTE(

  • Unable to exit program from menu

    Hi, I have written a test program to experiment and learn about some codes. Been using Sun Java Studio Enterprise 8.1 Designed the interface and added a menu. It is supposed to exit the program from the File > Exit menu path. For some reason, the pro

  • Cat changed screen orientation from vertical to horizontal

    What key combination will reorient my display from horizontal back to vertical? Do you know someone who is looking for a cat. Ours is now looking for a new home.