private static decimal GetDurationOfMediaFile(string filePath)
        {
            var inputFile = new MediaFile {Filename = filePath};

            using (var engine = new Engine())
                engine.GetMetadata(inputFile);

            var durationOfMediaFile = inputFile.Metadata.Duration.TotalMilliseconds;

            return Convert.ToDecimal(durationOfMediaFile);
        }
Esempio n. 2
0
        private void OpenVideoFile(string filepath)
        {
            // read data from this file
            var mediafile = new MediaFile(filepath);

            using (var engine = new Engine())
                engine.GetMetadata(mediafile);

            selVideoRange.RangeValue2 = selVideoRange.FrameMax = (int)(mediafile.Metadata.VideoData.Fps * mediafile.Metadata.Duration.TotalSeconds);
            selVideoRange.RangeValue1 = 0;
            VideoFilePath = filepath;
            VideoDuration = TimeSpan.FromSeconds(mediafile.Metadata.Duration.TotalSeconds);

            // and load it in the player
            vlcVideoPlayer.Play(new FileInfo(filepath));
        }
Esempio n. 3
0
        public static void ExtractFrame(string file, int momentFromStartInSeconds, string output)
        {
            var inputFile = new MediaFile { Filename = file };
            var outputFile = new MediaFile { Filename = output };

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);
                var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(momentFromStartInSeconds) };
                try
                {
                    engine.GetThumbnail(inputFile, outputFile, options);
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Failed to extract the image from: {0} because of {1}", inputFile, ex.ToString());
                }
            }
        }
        private void CreateImageButton_Click(object sender, RoutedEventArgs e)
        {
            _imageExt.ToBitmapImage(Screen);

            ImageItem.Source = _imageExt.GetImageSource();

            var time = Screen.Position;

            var foo = new MediaFile {Filename = "Hist.bmp"};

            if (File.Exists("Hist.bmp"))
            {
                File.Delete("Hist.bmp");
            }

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);

                var options = new ConversionOptions {Seek = TimeSpan.FromMilliseconds(time.Milliseconds)};
                engine.GetThumbnail(inputFile, foo, options);
            }
        }
Esempio n. 5
0
 public void genThumb()
 {
     thumbPath = System.IO.Path.Combine( System.IO.Path.GetTempPath(), cutName+index.ToString()+".jpg");
     var inputFile = new MediaFile { Filename = sourcePath };
     var outputFile = new MediaFile { Filename = thumbPath };
     using (var engine = new Engine())
     {
         engine.GetMetadata(inputFile);
         var options = new ConversionOptions { Seek = startTime };
         engine.GetThumbnail(inputFile, outputFile, options);
     }
     var img = System.Drawing.Image.FromFile(thumbPath);
     MemoryStream ms = new MemoryStream();
     img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
     imgThumb = ms.ToArray();
 }
Esempio n. 6
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            var options = new MediaToolkit.Options.ConversionOptions();
            var inputFiled = new MediaFile { Filename = VideoToTrim };
            var outputFile = new MediaFile { Filename = VideoToTrimTo };

            string video2trim = "\"" + VideoToTrim + "\"";
            string video2trim2 = "\"" + VideoToTrimTo + "\"";
            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFiled);
                options.CutMedia(Start, End);
                //fade=in:0:30
                engine.ConvertProgressEvent += ConvertProgressEvent;
                engine.ConversionCompleteEvent += engine_ConversionCompleteEvent;
                engine.Convert(inputFiled, outputFile, options);

                //ffmpeg -i input.mp4 -filter:v 'fade=in:0:50' \ -c:v libx264 -crf 22 -preset veryfast -c:a copy output.mp4
                //engine.CustomCommand("-ss " + Start + " -t " + End + " -i " + video2trim + " " + "\"" + " fade=in:0:03" + "\"" +  " " + video2trim2);
                //engine.CustomCommand("-ss " + Start + " -t " + End + " -i" + " " + video2trim + " -filter:v" + " fade=in=0:130 " + "-c:v libx264 -crf 22 -preset veryfast -c:a copy " + video2trim2);
                //std trim
               // string startTime = Start.Hours + ":" + Start.m
                //engine.CustomCommand("-ss " + Start. + " -t " + End + " -i " + video2trim + " -acodec copy -vcodec copy " + video2trim2);
            }
        }
Esempio n. 7
0
        public void GetProperties(string VideoFile)
        {
            var inputFile = new MediaFile { Filename = VideoFile };
            string GetFrameSize = string.Empty;

            try
            {
                using (var engine = new Engine())
                {
                    engine.GetMetadata(inputFile);
                    this.Format = inputFile.Metadata.VideoData.FrameSize;
                    this.FrameRate = inputFile.Metadata.VideoData.Fps;
                    engine.Dispose();
                }
            }
            catch (Exception)
            {
            }
        }
        public StdResult<TimeSpan> GetVideoLength()
        {
            using (var engine = new Engine())
            {
                engine.GetMetadata(InputFile);
            }

            return StdResult<TimeSpan>.OkResultInstance(InputFile.Metadata.Duration);
        }
        public StdResult<double> GetVideoFrameRate()
        {
            using (var engine = new Engine())
            {
                engine.GetMetadata(InputFile);
            }

            return StdResult<double>.OkResultInstance(InputFile.Metadata.VideoData.Fps);
        }
        public StdResult<List<string>> ExtractFrames(int nbFramesDesired)
        {
            DesiredFramesAmount = nbFramesDesired;
            int nbSeconds = (int)GetVideoLength().ReturnObject.TotalSeconds;
            int framePeriod = nbSeconds / (nbFramesDesired + 1);

            List<MediaFile> outputFiles = new List<MediaFile>();

            using (var engine = new Engine())
            {
                engine.GetMetadata(InputFile);

                for (int i = 0; i < DesiredFramesAmount; i++)
                {
                    outputFiles.Add(new MediaFile { Filename = string.Format(OutputSpriteFramePathTemplate, i) });
                    var options = new ConversionOptions { Seek = TimeSpan.FromSeconds((i + 1) * framePeriod), VideoSize = VideoSize._200par125 };
                    if (File.Exists(outputFiles[i].Filename))
                        File.Delete(outputFiles[i].Filename);
                    engine.GetThumbnail(InputFile, outputFiles[i], options);
                }
            }
            OutputSpriteFrames = outputFiles.Select(of => of.Filename).ToList();
            return StdResult<List<string>>.OkResultInstance(OutputSpriteFrames);
        }
        public StdResult<string> CreateThumbnail(string forceOutputFilePath = null, TimeSpan? forceTimeSpan = null)
        {
            var outputFile = new MediaFile { Filename = OutputImagePath };

            using (var engine = new Engine())
            {
                engine.GetMetadata(InputFile);

                // Saves the frame located on the 15th second of the video.
                var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(15) };
                engine.GetThumbnail(InputFile, outputFile, options);
            }
            return StdResult<string>.OkResultInstance(OutputImagePath);
        }
        private static void TrimFileToNewDuration(string inputFilePath, decimal newDurationInMilliseconds, TrailerClipperOptions clipperOptions)
        {
            var outputFilePath = ComputeOutputFilePath(inputFilePath, clipperOptions.OutputDirectoryPath);

            var inputFile = new MediaFile {Filename = inputFilePath};

            var outputFile = new MediaFile {Filename = outputFilePath};

            var options = InitializeClippingData(newDurationInMilliseconds, clipperOptions);

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);

                engine.Convert(inputFile, outputFile, options);
            }

            if (clipperOptions.OutputToConsole)
                Console.WriteLine("Finished on trimming file, output: " + outputFilePath);
        }
Esempio n. 13
-1
        public IEnumerable<MediaSegment> Segment(FileInfo file, long fileId)
        {
            var source = new MediaFile(file.FullName);
            using (var engine = new Engine())
            {
                engine.GetMetadata(source);
                var progressMs = 0.0;
                while (progressMs < source.Metadata.Duration.TotalMilliseconds)
                {
                    var options = new ConversionOptions();
                    var endMs = Math.Min(progressMs + _segmentLengthMs, source.Metadata.Duration.TotalMilliseconds);

                    options.CutMedia(TimeSpan.FromMilliseconds(progressMs),
                        TimeSpan.FromMilliseconds(endMs));

                    var outputFile = Path.Combine(file.DirectoryName,
                        string.Format("{0}_audio_{1}ms.wav", file.Name, progressMs));

                    engine.Convert(source, new MediaFile(outputFile), options);
                    yield return new MediaSegment
                    {
                        FileId = fileId,
                        File = new FileInfo(outputFile),
                        OffsetMs = progressMs,
                        DurationMs = endMs - progressMs
                    };
                    progressMs = endMs;
                }
            }
        }