コード例 #1
0
        public string GetDuration(String file)
        {
            var inputFile = new MediaToolkit.Model.MediaFile {
                Filename = file
            };

            using (var engine = new MediaToolkit.Engine(System.Web.Hosting.HostingEnvironment.MapPath("~/App_data/ffmpeg/ffmpeg.exe")))
            {
                engine.GetMetadata(inputFile);
            }

            TimeSpan ts = new TimeSpan(inputFile.Metadata.Duration.Ticks);

            return(ts.ToString(@"hh\:mm\:ss"));
        }
コード例 #2
0
        public void laconversion2(string titulo)
        {
            if (cancelado == false)
            {
                this.Invoke((MethodInvoker) delegate
                {
                    this.pictureBox2.Visible = false;
                });

                var inputfile = new MediaToolkit.Model.MediaFile {
                    Filename = Path.Combine(direccion, titulo.Replace(".mp3", ".mp4"))
                };
                var outputfile = new MediaToolkit.Model.MediaFile {
                    Filename = Path.Combine(direccion, titulo)
                };
                MediaToolkit.Options.ConversionOptions prro = new MediaToolkit.Options.ConversionOptions();
                prro.VideoFps         = 0;
                prro.CustomHeight     = 0;
                prro.CustomWidth      = 0;
                prro.VideoAspectRatio = MediaToolkit.Options.VideoAspectRatio.R3_2;
                using (var engine = new MediaToolkit.Engine())
                {
                    engine.CustomCommand("-threads 1");
                    engine.GetMetadata(inputfile);
                    engine.Convert(inputfile, outputfile);
                }
                File.Delete(Path.Combine(direccion, titulo.Replace(".mp3", ".mp4")));
                //  var aaa = new NReco.VideoConverter.FFMpegConverter();
                //   aaa.ConvertMedia(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title) ) + ".mp3", Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title) ) + ".mp33", "mp3");

                //   File.Delete(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title) ) + ".mp3");
                // File.Move(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title)) + ".mp33", Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title)) + ".mp3");

                //    File.Delete(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title)) + ".mp33");


                this.Invoke((MethodInvoker) delegate
                {
                    this.pictureBox2.Visible  = true;
                    this.pictureBox2.Location = new Point(37, 114);
                    this.pictureBox3.Visible  = true;
                    this.pictureBox3.Location = new Point(7, 114);
                });
            }
        }
コード例 #3
0
        /// <summary>
        /// Scans all the videos for its format. Resolution, framerate
        /// </summary>
        private void ScanFormat()
        {
            Log("");
            foreach (var video in Videos)
            {
                try
                {
                    if (video.FrameRate == 0)
                    {
                        if (System.IO.File.Exists((video.FileName)))
                        {
                            var inputFile = new MediaFile {
                                Filename = video.FileName
                            };

                            try
                            {
                                using (var engine = new MediaToolkit.Engine())
                                {
                                    engine.GetMetadata(inputFile);
                                    video.Format    = inputFile.Metadata.VideoData.FrameSize;
                                    video.FrameRate = inputFile.Metadata.VideoData.Fps;
                                    video.Duration  = inputFile.Metadata.Duration.Duration();
                                    engine.Dispose();
                                }
                            }
                            catch (Exception ex) { Log(ex.Message, Prism.Logging.Category.Exception); }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log(ex.Message, Prism.Logging.Category.Exception);
                }
            }
        }
コード例 #4
0
		public static void Remux( string targetName, string sourceName, string tempName ) {
			Directory.CreateDirectory( Path.GetDirectoryName( targetName ) );
			Console.WriteLine( "Remuxing to " + targetName + "..." );
			var inputFile = new MediaToolkit.Model.MediaFile( sourceName );
			var outputFile = new MediaToolkit.Model.MediaFile( tempName );
			using ( var engine = new MediaToolkit.Engine( "ffmpeg.exe" ) ) {
				MediaToolkit.Options.ConversionOptions options = new MediaToolkit.Options.ConversionOptions();
				options.AdditionalOptions = "-codec copy -bsf:a aac_adtstoasc";
				engine.Convert( inputFile, outputFile, options );
			}
			Util.MoveFileOverwrite( tempName, targetName );
			Console.WriteLine( "Created " + targetName + "!" );
		}