Пример #1
0
        public void Test()
        {
            VideoPlayer2  mediaTransformer = new VideoPlayer2();
            OpenVideoArgs openArgs         = new OpenVideoArgs("d:\\b (1).mp4");

            mediaTransformer.enableLibAVLogging(MediaTransformer.LogLevel.LOG_LEVEL_DEBUG);
            mediaTransformer.setLogCallback(logCallback);

            MediaFileSource video = new MediaFileSource(openArgs, "input", mediaTransformer.getFilterGraph(), 0, Double.MaxValue, 1);

            mediaTransformer.addInput(video);

            MediaFileSink output = new MediaFileSink("d:\\masseffect.mp4", "output", mediaTransformer.getFilterGraph(), "libx264",
                                                     1280, 720, 30, null, 48000, 2, null);//"libvo_aacenc",48000,2);

            mediaTransformer.addOutput(output);

            mediaTransformer.start();
        }
Пример #2
0
        public void Test()
        {
            VideoPlayer2 mediaTransformer = new VideoPlayer2();
            OpenVideoArgs openArgs = new OpenVideoArgs("d:\\b (1).mp4");

            mediaTransformer.enableLibAVLogging(MediaTransformer.LogLevel.LOG_LEVEL_DEBUG);
            mediaTransformer.setLogCallback(logCallback);

            MediaFileSource video = new MediaFileSource(openArgs, "input", mediaTransformer.getFilterGraph(), 0, Double.MaxValue, 1);

            mediaTransformer.addInput(video);

            MediaFileSink output = new MediaFileSink("d:\\masseffect.mp4", "output", mediaTransformer.getFilterGraph(), "libx264",
                1280, 720, 30, null, 48000, 2,null);//"libvo_aacenc",48000,2);

            mediaTransformer.addOutput(output);           

            mediaTransformer.start();

        }
        private void downloadAndMuxStreams(string fullpath, YoutubeVideoStreamedItem videoStream,
                                           YoutubeVideoStreamedItem audioStream)
        {
            TotalProgress   = 0;
            ItemProgressMax = 100;

            Dictionary <String, Object> options = new Dictionary <string, object>();

            options.Add("videoStreamMode", StreamOptions.Copy);
            options.Add("audioStreamMode", StreamOptions.Copy);

            ItemProgress = 0;
            ItemInfo     = "Downloading and muxing: " + videoStream.Name;

            try
            {
                OpenVideoArgs openArgs = new OpenVideoArgs(videoStream.Location, null, audioStream.Location, null);

                videoTranscoder.transcode(openArgs, fullpath, CancellationToken, options, muxingProgressCallback);
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error muxing: " + e.Message);

                try
                {
                    File.Delete(fullpath);
                }
                catch (Exception ex)
                {
                    InfoMessages.Add("Error deleting: " + fullpath + " " + ex.Message);
                }

                return;
            }

            ItemProgress = 100;
        }
Пример #4
0
        public async Task openAndPlay(string location,
                                      string inputFormatName = null, string audioLocation            = null,
                                      string audioFormatName = null, List <String> subtitleLocations = null)
        {
            try
            {
                // cancel any previously running open operation
                CancellationTokenSource prevCancelTokenSource = CancelTokenSource;
                Task prevOpenTask = OpenTask;

                CancellationTokenSource newCancelTokenSource = new CancellationTokenSource();
                CancelTokenSource = newCancelTokenSource;

                await close(prevCancelTokenSource, prevOpenTask);

                // open video
                newCancelTokenSource.Token.ThrowIfCancellationRequested();

                VideoLocation = location;

                OpenVideoArgs args = new OpenVideoArgs(location, inputFormatName, audioLocation, audioFormatName);

                OpenTask = Task.Factory.StartNew(() => videoDecoder.open(args, DecodedVideoFormat, newCancelTokenSource.Token), newCancelTokenSource.Token);
                await OpenTask;

                if (videoDecoder.HasVideo)
                {
                    videoRender.initialize(videoDecoder.Width, videoDecoder.Height);

                    Subtitles.clear();
                    Subtitles.findMatchingSubtitleFiles(location);

                    if (subtitleLocations != null)
                    {
                        foreach (String subtitleLocation in subtitleLocations)
                        {
                            Subtitles.addSubtitleFile(subtitleLocation);
                        }
                    }

                    Subtitles.Track = 0;
                }

                DurationSeconds = videoDecoder.DurationSeconds;
                HasAudio        = videoDecoder.HasAudio;

                previousVideoPts   = 0;
                previousVideoDelay = 0.04;
                audioDiffAvgCount  = 0;

                if (videoDecoder.HasAudio)
                {
                    audioPlayer.initialize(videoDecoder.SamplesPerSecond, videoDecoder.BytesPerSample,
                                           Math.Min(videoDecoder.NrChannels, 2), videoDecoder.MaxAudioFrameSize * 2);

                    audioDiffThreshold = 2.0 * 1024 / videoDecoder.SamplesPerSecond;
                }

                VideoState = VideoState.OPEN;

                play();
            }
            catch (VideoLib.VideoLibException)
            {
                VideoState = VideoState.CLOSED;

                //log.Error("Cannot open: " + location, e);

                throw;
            }
        }
Пример #5
0
        public async Task openAndPlay(string location,
            string inputFormatName = null, string audioLocation = null,
            string audioFormatName = null, List<String> subtitleLocations = null)
        {
            try
            {
                // cancel any previously running open operation
                CancellationTokenSource prevCancelTokenSource = CancelTokenSource;
                Task prevOpenTask = OpenTask;

                CancellationTokenSource newCancelTokenSource = new CancellationTokenSource();
                CancelTokenSource = newCancelTokenSource;

                await close(prevCancelTokenSource, prevOpenTask);

                // open video
                newCancelTokenSource.Token.ThrowIfCancellationRequested();

                VideoLocation = location;

                OpenVideoArgs args = new OpenVideoArgs(location, inputFormatName, audioLocation, audioFormatName);

                OpenTask = Task.Factory.StartNew(() => videoDecoder.open(args, DecodedVideoFormat, newCancelTokenSource.Token), newCancelTokenSource.Token);
                await OpenTask;

                if (videoDecoder.HasVideo)
                {
                    videoRender.initialize(videoDecoder.Width, videoDecoder.Height);

                    Subtitles.clear();
                    Subtitles.findMatchingSubtitleFiles(location);

                    if (subtitleLocations != null)
                    {
                        foreach (String subtitleLocation in subtitleLocations)
                        {
                            Subtitles.addSubtitleFile(subtitleLocation);
                        }
                    }

                    Subtitles.Track = 0;
                }

                DurationSeconds = videoDecoder.DurationSeconds;
                HasAudio = videoDecoder.HasAudio;

                previousVideoPts = 0;
                previousVideoDelay = 0.04;
                audioDiffAvgCount = 0;

                if (videoDecoder.HasAudio)
                {
                    audioPlayer.initialize(videoDecoder.SamplesPerSecond, videoDecoder.BytesPerSample,
                        Math.Min(videoDecoder.NrChannels, 2), videoDecoder.MaxAudioFrameSize * 2);

                    audioDiffThreshold = 2.0 * 1024 / videoDecoder.SamplesPerSecond;
                }

                VideoState = VideoState.OPEN;

                play();

            }
            catch (VideoLib.VideoLibException)
            {

                VideoState = VideoState.CLOSED;

                //log.Error("Cannot open: " + location, e);

                throw;

            }

        }
        private void downloadAndMuxStreams(string fullpath, YoutubeVideoStreamedItem videoStream, 
            YoutubeVideoStreamedItem audioStream)
        {                    
            TotalProgress = 0;
            ItemProgressMax = 100;

            Dictionary<String, Object> options = new Dictionary<string, object>();
            options.Add("videoStreamMode", StreamOptions.Copy);
            options.Add("audioStreamMode", StreamOptions.Copy);
                           
            ItemProgress = 0;
            ItemInfo = "Downloading and muxing: " + videoStream.Name;

            try
            {
                OpenVideoArgs openArgs = new OpenVideoArgs(videoStream.Location, null, audioStream.Location, null);

                videoTranscoder.transcode(openArgs, fullpath, CancellationToken, options,muxingProgressCallback);
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error muxing: " + e.Message);

                try
                {
                    File.Delete(fullpath);
                }
                catch (Exception ex)
                {
                    InfoMessages.Add("Error deleting: " + fullpath + " " + ex.Message);
                }
                    
                return;
            }
                    
            ItemProgress = 100;  
        }