コード例 #1
0
ファイル: vlcrender.cs プロジェクト: duyisu/MissionPlanner
        public void Start(int Width, int Height)
        {
            if (store.Count > 0)
                store[0].Stop();

            store.Add(this);

            this.Width = Width;
            this.Height = Height;

            library = LibVLCLibrary.Load(null);
            
            inst = library.m_libvlc_new(4,
                new string[] {":sout-udp-caching=0", ":udp-caching=0", ":rtsp-caching=0", ":tcp-caching=0"});
                //libvlc_new()                                    // Load the VLC engine 
            m = library.libvlc_media_new_location(inst, playurl);
                // Create a new item 
            mp = library.libvlc_media_player_new_from_media(m); // Create a media player playing environement 
            library.libvlc_media_release(m); // No need to keep the media now 

            vlc_lock_delegate = new LibVLCLibrary.libvlc_video_lock_cb(vlc_lock);
            vlc_unlock_delegate = new LibVLCLibrary.libvlc_video_unlock_cb(vlc_unlock);
            vlc_picture_delegate = new LibVLCLibrary.libvlc_video_display_cb(vlc_picture);

            library.libvlc_video_set_callbacks(mp,
                vlc_lock_delegate,
                vlc_unlock_delegate,
                vlc_picture_delegate);

            library.libvlc_video_set_format(mp, "RV24", (uint)Width, (uint)Height, (uint)Width*4);

            library.libvlc_media_player_play(mp); // play the media_player 
        }
コード例 #2
0
        private void GenerateImpl(int thumbnailWidth, int secondStep, string thumbnailDir, string filepath, NamedPipeClient<string> mediaScribeServer)
        {
            //TODO - ensure that these don't get wrapped in quotes, so we don't have to strip them out.
            filepath = filepath.Substring(1, filepath.Length - 2);
            thumbnailDir = thumbnailDir.Substring(1, thumbnailDir.Length - 2);

            if (false == Directory.Exists(thumbnailDir))
                Directory.CreateDirectory(thumbnailDir);

            if (null == library)
            {
                #region start VLC
                string[] vlcargs = {
                   "--intf", "dummy",                  /* no interface                   */
                   "--vout", "dummy",                  /* we don't want video (output)   */
                   "--no-audio",                       /* we don't want audio (decoding) */
                   "--no-video-title-show",            /* nor the filename displayed     */
                   "--no-stats",                       /* no stats                       */
                   "--no-sub-autodetect-file",         /* we don't want subtitles        */
                   "--no-spu",
                   "--no-osd",

             //      "--no-inhibit",                     /* we don't want interfaces       */
                   "--no-disable-screensaver",         /* we don't want interfaces       */
                   "--no-snapshot-preview",            /* no blending in dummy vout      */
                                      };
                library = LibVLCLibrary.Load(null);
                IntPtr m;

                /* Load the VLC engine */
                inst = library.libvlc_new(vlcargs);

                /* Create a new item */
                m = library.libvlc_media_new_path(inst, filepath);

                /* Create a media player playing environement */
                mp = library.libvlc_media_player_new_from_media(m);

                //hook up the libvlc event listening
                int event_index = 0;
                IntPtr media_player_event_manager = library.libvlc_media_player_event_manager(mp);
                LibVLCLibrary.libvlc_callback_t m_EventManagerEventCallback = EventManager_Event;
                while (event_index < m_Events.Length)
                    if (library.libvlc_event_attach(media_player_event_manager, m_Events[event_index++], m_EventManagerEventCallback, IntPtr.Zero) != 0)
                        throw new LibVLCException(library);

                #endregion
            }
            else
            {
                library.libvlc_media_player_release(mp);
                IntPtr m = library.libvlc_media_new_path(inst, filepath);
                mp = library.libvlc_media_player_new_from_media(m);
                //hook up the libvlc event listening
                int event_index = 0;
                IntPtr media_player_event_manager = library.libvlc_media_player_event_manager(mp);
                LibVLCLibrary.libvlc_callback_t m_EventManagerEventCallback = EventManager_Event;
                while (event_index < m_Events.Length)
                    if (library.libvlc_event_attach(media_player_event_manager, m_Events[event_index++], m_EventManagerEventCallback, IntPtr.Zero) != 0)
                        throw new LibVLCException(library);
            }
            //configure time tracking
            TimeSpan time = new TimeSpan(0, 0, 0);
            TimeSpan step = new TimeSpan(0, 0, secondStep);

            //wait until VLC is playing
            signalPlaying = new SemaphoreSlim(0, 1);
            /* play the media_player */
            int successCode = library.libvlc_media_player_play(mp);
            signalPlaying.Wait();
            if (errorOccured)
            {
                string errormsg = library.libvlc_errmsg();
                throw new Exception("libvlc_MediaPlayerEncounteredError error: " + errormsg ?? "unknown error... ah crap.");
            }

            endReached = false;
            stopped = false;

            int thumbnailHeight = -1;

            long trackLength = library.libvlc_media_player_get_length(mp);

            //while there's still video left, collect screenshots
            while (endReached != true && stopped != true)
            {
                //if we're flagged to cancel, exit out.
                if (State == GeneratorState.Cancelling)
                    return;

                //take screenshot
                string fileName = time.TotalSeconds + ".jpg";
                string thumbnailFullPath = Path.Combine(thumbnailDir, fileName);

                int result = -1;
                do
                {
                    if (endReached)
                        break;
                    //if we're flagged to cancel, exit out.
                    if (State == GeneratorState.Cancelling)
                        return;

                    int tryCount = 3;
                    bool successfulSnapshot = false;
                    Exception error = null;
                    do
                    {
                        try
                        {
                            //if we're flagged to cancel, exit out.
                            if (State == GeneratorState.Cancelling)
                                return;
                            successfulSnapshot = false;
                            result = library.libvlc_video_take_snapshot(mp, 0, thumbnailFullPath, (uint)thumbnailWidth, 0);
                            successfulSnapshot = true;
                        }
                        catch (Exception ex)
                        {
                            tryCount--;
                            error = ex;
                        }
                    }
                    while (!successfulSnapshot && tryCount > 0);
                    if (null != error && tryCount == 0)
                    {
                        throw error;
                    }
                }
                while (false == File.Exists(thumbnailFullPath));

                if (result == 0)
                {
                    mediaScribeServer.PushMessage(time.TotalSeconds.ToString().PadLeft(6, '0') + " " + fileName);
                    //Thread.Sleep(70);
                }

                //increment the time
                time += step;
                //signalPosChanged.Reset();
                library.libvlc_media_player_set_time(mp, (long)time.TotalMilliseconds);
                if (library.libvlc_media_player_get_state(mp) == LibVLCLibrary.libvlc_state_t.libvlc_Playing)
                    library.libvlc_media_player_pause(mp);

                if (library.libvlc_media_player_get_time(mp) > trackLength)
                    return;

                if (endReached)
                    return;
            }
        }