示例#1
0
 public static T UseFFMpeg <T>(this AppBuilderBase <T> b, FFOptions fFMpegOptions)
     where T : AppBuilderBase <T>, new()
 {
     return(b.AfterSetup(_ =>
     {
         GlobalFFOptions.Configure(fFMpegOptions);
         FFMpegHelper.VerifyFFMpegExists(fFMpegOptions);
     }));
 }
 public MediaService(IConfiguration configuration, IMediaToolkitService mediaToolkitService, IFileSystem fileSystem)
 {
     _fileSystem         = fileSystem;
     MediaToolkitService = mediaToolkitService;
     FfmpegPath          = configuration["ffpmegPath"];
     GlobalFFOptions.Configure(new FFOptions
     {
         BinaryFolder         = Path.GetDirectoryName(FfmpegPath),
         TemporaryFilesFolder = "/tmp"
     });
 }
示例#3
0
        public Scribo(String fileName)
        {
            InitializeComponent();
            GlobalFFOptions.Configure(new FFOptions {
                BinaryFolder = "./bin", TemporaryFilesFolder = "./tmp"
            });
            SetText(fileName);
            String file = fileName;

            button1.Click += delegate(object sender, EventArgs e) { button_Click(sender, e, file); };
        }
示例#4
0
 public static void VerifyFFProbeExists(FFOptions ffMpegOptions)
 {
     if (_ffprobeVerified)
     {
         return;
     }
     var(exitCode, _) = Instance.Finish(GlobalFFOptions.GetFFProbeBinaryPath(ffMpegOptions), "-version");
     _ffprobeVerified = exitCode == 0;
     if (!_ffprobeVerified)
     {
         throw new FFMpegException(FFMpegExceptionType.Operation, "ffprobe was not found on your system");
     }
 }
示例#5
0
        private static void Main(string[] args)
        {
            try
            {
                var task = UpdateCheck();
                task.Wait();
            }
            catch (Exception e)
            {
            }

            if (Update)
            {
                Console.WriteLine("A Newer Version is available! would you like to update? y/n");
                var answer = Console.ReadKey(true);
                if (answer.Key == ConsoleKey.Y)
                {
                    OpenBrowser("http://www.github.com/RinLovesYou/Flipnote-Encoder/releases/latest");
                    return;
                }
            }


            Running = true;

            GlobalFFOptions.Configure(new FFOptions {
                BinaryFolder = "ffmpeg/bin"
            });

            while (Running)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Clear();

                Console.WriteLine("What would you like to do?");
                Console.WriteLine("1: Encode a video to Flipnote");
                Console.WriteLine("2: Decode a Flipnote");
                var Selection = Console.ReadKey(true);

                switch (Selection.Key)
                {
                case ConsoleKey.D1: EncodeFlipnote(); break;

                case ConsoleKey.D2: DecodeFlipnote(); break;

                default: break;
                }
            }
        }
示例#6
0
        ///// <summary>
        ///// Delete written scripts to prevent versioning issues
        ///// </summary>
        //private static void DeleteResourcesFromDisk()
        //{
        //    File.Delete(Resources.analyze_transcript_pt);
        //    File.Delete(Resources.transcribe_audio_pt);

        //    Directory.Delete(Resources.script_dir);
        //}

        ///// <summary>
        ///// Write scripts to disk at predetermined locations so they can be run later
        ///// </summary>
        //private static void WriteResourcesToDisk()
        //{
        //    Directory.CreateDirectory(Resources.script_dir);
        //    using (var sw = File.CreateText(Path.Combine(Resources.script_dir, Resources.analyze_transcript_pt)))
        //        sw.Write(Encoding.UTF8.GetString(Resources.analyze_transcript));

        //    using (var sw = File.CreateText(Path.Combine(Resources.script_dir, Resources.transcribe_audio_pt)))
        //        sw.Write(Encoding.UTF8.GetString(Resources.transcribe_audio));

        //}

        private static void CreateDbIfNotExists(IHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var logger   = services.GetRequiredService <ILogger <Program> >();

                try
                {
                    var userRolesContext = services.GetRequiredService <UsersRolesDbContext>();
                    var montageContext   = services.GetRequiredService <MontageDbContext>();
                    var manager          = services.GetRequiredService <UserManager <IdentityUser> >();
                    var roleManager      = services.GetRequiredService <RoleManager <IdentityRole> >();

                    UsersRolesDbInitializer.Initialize(userRolesContext, manager, roleManager, services.GetRequiredService <ILogger <UsersRolesDbInitializer> >()).Wait();
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "An error occurred while seeding the Users portion of the database.");
                }

                try
                {
                    var montageContext = services.GetRequiredService <MontageDbContext>();
                    MontageDbInitializer.Initialize(montageContext, services.GetRequiredService <ILogger <MontageDbInitializer> >());
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "An error occurred creating the Montage DB.");
                }

                try
                {
                    // configure FFMpegCore options
                    GlobalFFOptions.Configure(options =>
                    {
                        options.BinaryFolder         = Environment.GetEnvironmentVariable("FFMPEG_PATH");
                        options.TemporaryFilesFolder = Environment.GetEnvironmentVariable("FFMPEG_TMP");
                    });
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "An error occurred configuring FFMpegCore");
                }
            }
        }
示例#7
0
        public VideoFileInfoReader(IDiskProvider diskProvider, Logger logger)
        {
            _diskProvider = diskProvider;
            _logger       = logger;

            // We bundle ffprobe for all platforms
            GlobalFFOptions.Configure(options => options.BinaryFolder = AppDomain.CurrentDomain.BaseDirectory);

            try
            {
                _pixelFormats = FFProbe.GetPixelFormats();
            }
            catch (Exception e)
            {
                _logger.Error(e, "Failed to get supported pixel formats from ffprobe");
                _pixelFormats = new List <FFProbePixelFormat>();
            }
        }
示例#8
0
        public void Options_Set_Programmatically()
        {
            var original = GlobalFFOptions.Current;

            try
            {
                GlobalFFOptions.Configure(new FFOptions {
                    BinaryFolder = "Whatever"
                });
                Assert.AreEqual(
                    GlobalFFOptions.Current.BinaryFolder,
                    "Whatever"
                    );
            }
            finally
            {
                GlobalFFOptions.Configure(original);
            }
        }
示例#9
0
        public void Video_OutputsData()
        {
            var outputFile   = new TemporaryFile("out.mp4");
            var dataReceived = false;

            GlobalFFOptions.Configure(opt => opt.Encoding = Encoding.UTF8);
            var success = FFMpegArguments
                          .FromFileInput(TestResources.Mp4Video)
                          .WithGlobalOptions(options => options
                                             .WithVerbosityLevel(VerbosityLevel.Info))
                          .OutputToFile(outputFile, false, opt => opt
                                        .WithDuration(TimeSpan.FromSeconds(2)))
                          .NotifyOnOutput((_, _) => dataReceived = true)
                          .ProcessSynchronously();

            Assert.IsTrue(dataReceived);
            Assert.IsTrue(success);
            Assert.IsTrue(File.Exists(outputFile));
        }
示例#10
0
        /// <summary>
        /// A task for recording a video
        /// </summary>
        /// <param name="graph">Optional graph to record</param>
        async public void Go(PlottedGraph?graph)
        {
            if (!File.Exists(GlobalConfig.GetSettingPath(CONSTANTS.PathKey.FFmpegPath)))
            {
                StopRecording(processQueue: false, error: $"Unable to start recording: Path to ffmpeg.exe not configured");
                Loaded      = false;
                Initialised = false;
                return;
            }

            try
            {
                string?dirname = Path.GetDirectoryName(GlobalConfig.GetSettingPath(CONSTANTS.PathKey.FFmpegPath));
                if (dirname is not null)
                {
                    GlobalFFOptions.Configure(new FFOptions {
                        BinaryFolder = dirname
                    });
                }
                else
                {
                    StopRecording(processQueue: false, error: $"Unable to start recording: FFMpeg not found");
                    Loaded = false;
                    return;
                }
            }
            catch (Exception e)
            {
                StopRecording(processQueue: false, error: $"Unable to start recording: Exception '{e.Message}' configuring recorder");
                Loaded = false;
                return;
            }

            Initialised          = true;
            CurrentRecordingFile = GenerateVideoFilepath(graph);
            _recordedFrameCount  = 0;
            Logging.RecordLogEvent("Recording video to " + CurrentRecordingFile);
            var videoFramesSource = new RawVideoPipeSource(GetNextFrame());

            try
            {
                //https://trac.ffmpeg.org/wiki/Encode/H.264
                await FFMpegArguments
                .FromPipeInput(videoFramesSource)
                .OutputToFile(CurrentRecordingFile, false, opt => opt
                              .WithFramerate(GlobalConfig.Settings.Media.VideoCodec_FPS)
                              .WithConstantRateFactor(28 - GlobalConfig.Settings.Media.VideoCodec_Quality)
                              .WithSpeedPreset(GetVideoSpeed())
                              .WithVideoCodec(VideoCodec.LibX264)
                              )
                .ProcessAsynchronously();
            }
            catch (Exception e)
            {
                Logging.RecordException("FFMpeg Record Error: " + e.Message, e);
            }


            Initialised = false;
            StopRecording();
            CapturePaused = false;
            _bmpQueue.Clear();

            Logging.RecordLogEvent($"Recorded {_recordedFrameCount} x {CurrentVideoWidth}*{CurrentVideoHeight} frames of video to " + CurrentRecordingFile);
            CurrentRecordingFile = "";
            _capturedContent     = CaptureContent.Invalid;
        }