private MemoryStream GetThumbnailInternal(FileInfo file, ref int width, ref int height) { if (file.Extension == ".mkv" && MKVTools.Loaded) { var thumbIdx = MKVTools.FindThumbnail(file.FullName); if (thumbIdx != MKVTools.NoThumbnail) { var origThumb = MKVTools.ExtractThumbnail(file.FullName, thumbIdx); var origImage = Image.FromStream(origThumb); var scaled = ThumbnailMaker.ResizeImage(origImage, width, height, ThumbnailMakerBorder.Bordered); var rv = new MemoryStream(); scaled.Save(rv, ImageFormat.Jpeg); return(rv); } } Exception last = null; for (var best = IdentifyBestCapturePosition(file); best >= 0; best -= Math.Max(best / 2, 5)) { try { using (var p = new Process()) { var sti = p.StartInfo; #if !DEBUG sti.CreateNoWindow = true; #endif sti.UseShellExecute = false; sti.FileName = FFmpeg.FFmpegExecutable; sti.Arguments = $"-v quiet -ss {best} -i \"{file.FullName}\" -an -frames:v 1 -f image2 pipe:"; sti.LoadUserProfile = false; sti.RedirectStandardOutput = true; p.Start(); DebugFormat("Running: {0} {1}", sti.FileName, sti.Arguments); return(GetThumbnailFromProcess(p, ref width, ref height)); } } catch (Exception ex) { last = ex; } } throw last ?? new Exception("Not reached"); }
private static void Main(string[] args) { Console.WriteLine(); var options = new Options(); try { Console.TreatControlCAsInput = false; Console.CancelKeyPress += CancelKeyPressed; options.Parse(args); MKVTools.Initialise(options.MKVTools.DirectoryName); if (options.ShowHelp) { options.PrintUsage(); return; } if (options.ShowVersion) { ShowVersion(); return; } if (options.ShowLicense) { ShowLicense(); return; } if (options.ListViews) { ListViews(); return; } if (options.ListOrders) { ListOrders(); return; } if (options.Directories.Length == 0) { throw new GetOptException("No directories specified"); } options.SetupLogging(); using (new ProgramIcon()) { var server = new HttpServer(options.Port); try { using (var authorizer = new HttpAuthorizer(server)) { if (options.Ips.Length != 0) { authorizer.AddMethod(new IPAddressAuthorizer(options.Ips)); } if (options.Macs.Length != 0) { authorizer.AddMethod(new MacAuthorizer(options.Macs)); } if (options.UserAgents.Length != 0) { authorizer.AddMethod( new UserAgentAuthorizer(options.UserAgents)); } Console.Title = "SimpleDLNA - starting ..."; var types = options.Types[0]; foreach (var t in options.Types) { types = types | t; server.InfoFormat("Enabled type {0}", t); } var friendlyName = "sdlna"; if (options.Seperate) { foreach (var d in options.Directories) { server.InfoFormat("Mounting FileServer for {0}", d.FullName); var fs = SetupFileServer( options, types, new[] { d }); friendlyName = fs.FriendlyName; server.RegisterMediaServer(fs); server.NoticeFormat("{0} mounted", d.FullName); } } else { server.InfoFormat( "Mounting FileServer for {0} ({1})", options.Directories[0], options.Directories.Length); var fs = SetupFileServer(options, types, options.Directories); friendlyName = fs.FriendlyName; server.RegisterMediaServer(fs); server.NoticeFormat( "{0} ({1}) mounted", options.Directories[0], options.Directories.Length); } Console.Title = $"{friendlyName} - running ..."; Run(server); } } finally { server.Dispose(); } } } catch (GetOptException ex) { Console.Error.WriteLine("Error: {0}\n\n", ex.Message); options.PrintUsage(); } #if !DEBUG catch (Exception ex) { LogManager.GetLogger(typeof(Program)).Fatal("Failed to run", ex); } #endif }