Ejemplo n.º 1
0
 public TranscodeAction(TranscodePlugin plugin, Preset preset)
 {
     m_Plugin = plugin;
     m_Preset = preset;
 }
Ejemplo n.º 2
0
        private static Size CalculateDimensions(ref Size s, Preset preset, double aspectRatio)
        {
            if (aspectRatio < 1.34 & aspectRatio >= 1.33) {
                aspectRatio = 4.0 / 3.0;
                //....
            } else if (aspectRatio < 1.78 & aspectRatio >= 1.77) {
                aspectRatio = 16.0 / 9.0;
                //....
            } else if (aspectRatio <= 2.4 & aspectRatio >= 2.35) {
                aspectRatio = 2.35;
                //....
            }

            if (s.Width > preset.MaxWidth || s.Height > preset.MaxHeight) {
                if (aspectRatio > (double) preset.MaxWidth / preset.MaxHeight) {
                    s.Height = (int) ((double) preset.MaxWidth / aspectRatio);
                    s.Width = preset.MaxWidth;
                } else {
                    s.Height = preset.MaxHeight;
                    s.Width = (int) ((double) preset.MaxHeight * aspectRatio);
                }
            }

            s.Width += s.Width % 2;
            s.Height += s.Height % 2;

            return s;
        }
Ejemplo n.º 3
0
        private void Transcode(MGFile file, ProgressStatus progress, Preset preset)
        {
            log.InfoFormat("Encoding using preset {0}...", preset.Name);

            var p = new Process();
            p.StartInfo = new ProcessStartInfo(GetEncoderPath(preset.Encoder));

            var outputPath = new Uri(file.FileName + preset.Extension);
            p.StartInfo.Arguments = BuildCommandLine(preset, file, outputPath);
            log.InfoFormat("{0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments);
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;

            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardOutput = true;

            int totalFrames = file.Tags.GetInt(TVShowDataStoreTemplate.FrameCount).Value;
            var statusParser = new EncoderStatusParser(preset.Encoder, totalFrames, progress);
            p.OutputDataReceived += statusParser.OutputHandler;
            p.ErrorDataReceived += statusParser.OutputHandler;

            log.Debug("Starting...");
            p.Start();

            p.BeginErrorReadLine();
            p.BeginOutputReadLine();

            p.WaitForExit();
            log.Debug("Done.");
            if (p.ExitCode != 0)
                log.ErrorFormat("Encoding failed with error code {0}.", p.ExitCode);
            else if (!File.Exists(outputPath.LocalPath))
                log.ErrorFormat("Encoding failed- output file doesn't exist: \"{0}\".", outputPath.LocalPath);
            else {
                MGFile newFile = m_DataStore.AddNewFile(outputPath);
                Mp4TagWriterPlugin.WriteMp4TvShowTags(newFile);
            }
        }
Ejemplo n.º 4
0
        private static string BuildCommandLine(Preset preset, MGFile file, Uri outputPath)
        {
            string cmd = Regex.Replace(preset.CommandLine, "\\s+", " ");
            cmd = cmd.Replace("%input%", file.FileName);
            cmd = cmd.Replace("%output%", outputPath.LocalPath);

            cmd = cmd.Replace("%video-bitrate%", (768 * 1024).ToString());
            cmd = cmd.Replace("%max-video-bitrate%", (1500 * 1024).ToString());
            cmd = cmd.Replace("%audio-bitrate%", (128 * 1024).ToString());

            int width = file.Tags.GetInt(TVShowDataStoreTemplate.VideoWidthPx).Value;
            int height = file.Tags.GetInt(TVShowDataStoreTemplate.VideoHeightPx).Value;
            double aspect = file.Tags.GetDouble(TVShowDataStoreTemplate.VideoDisplayAspectRatio).Value;

            var size = new Size(width, height);
            Size s = CalculateDimensions(ref size, preset, aspect);
            cmd = cmd.Replace("%width%", s.Width.ToString());
            cmd = cmd.Replace("%height%", s.Height.ToString());

            cmd = cmd.Replace("%fps%", CalculateFrameRate(file.Tags.GetDouble(TVShowDataStoreTemplate.FrameRate).Value).ToString());

            return cmd;
        }