예제 #1
0
        public override List<ChapterInfo> GetStreams(string location)
        {
            int titleSetNum = 1;
              List<ChapterInfo> cil = new List<ChapterInfo>();

              if (location.StartsWith("VTS_"))
              {
            titleSetNum = int.Parse(Path.GetFileNameWithoutExtension(location)
             .ToUpper()
             .Replace("VTS_", string.Empty)
             .Replace("_0.IFO", string.Empty));
              }

              ChapterInfo pgc = new ChapterInfo();
              pgc.SourceType = "DVD";
              pgc.SourceName = "PGC " + titleSetNum.ToString("D2");//location;
              pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
              pgc.Title = Path.GetFileNameWithoutExtension(location);
              OnStreamDetected(pgc);

              TimeSpan duration;
              double fps;
              pgc.Chapters = GetChapters(location, titleSetNum, out duration, out fps);
              pgc.Duration = duration;
              pgc.FramesPerSecond = fps;
              OnChaptersLoaded(pgc);

              OnExtractionComplete();
            //  return Enumerable.Repeat(pgc, 1).ToList();
              cil.Add(pgc);
              return cil;
        }
예제 #2
0
 protected void OnStreamDetected(ChapterInfo pgc)
 {
     if (StreamDetected != null)
     {
         StreamDetected(this, new ProgramChainArg()
         {
             ProgramChain = pgc
         });
     }
 }
예제 #3
0
 protected void OnChaptersLoaded(ChapterInfo pgc)
 {
     if (ChaptersLoaded != null)
     {
         ChaptersLoaded(this, new ProgramChainArg()
         {
             ProgramChain = pgc
         });
     }
 }
예제 #4
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            ChapterInfo pgc = new ChapterInfo();

            pgc.Chapters   = new List <Chapter>();
            pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
            pgc.SourceName = location;
            pgc.Title      = Path.GetFileNameWithoutExtension(location);
            pgc.SourceType = "Blu-Ray";

            FileInfo fileInfo = new FileInfo(location);

            OnStreamDetected(pgc);
            TSPlaylistFile mpls = new TSPlaylistFile(fileInfo);

            //Dictionary<string, TSStreamClipFile> clips = new Dictionary<string,TSStreamClipFile>();
            mpls.Scan(); int count = 1;
            foreach (double d in mpls.Chapters)
            {
                pgc.Chapters.Add(new Chapter()
                {
                    Name = "Chapter " + count.ToString("D2"),
                    Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond))
                });
                count++;
            }

            pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond));

            foreach (TSStreamClip clip in mpls.StreamClips)
            {
                clip.StreamClipFile.Scan();
                foreach (TSStream stream in clip.StreamClipFile.Streams.Values)
                {
                    if (stream.IsVideoStream)
                    {
                        pgc.FramesPerSecond = (double)((TSVideoStream)stream).FrameRateEnumerator /
                                              (double)((TSVideoStream)stream).FrameRateDenominator;
                        break;
                    }
                }
                if (pgc.FramesPerSecond != 0)
                {
                    break;
                }
            }

            OnChaptersLoaded(pgc);
            OnExtractionComplete();
            return(new List <ChapterInfo>()
            {
                pgc
            });
        }
예제 #5
0
 public ChapterCreator(MainForm mainForm)
 {
     InitializeComponent();
     intIndex      = 0;
     chapters      = new Chapter[0];
     this.mainForm = mainForm;
     pgc           = new ChapterInfo()
     {
         Chapters        = new List <Chapter>(),
         FramesPerSecond = 0,
         LangCode        = string.Empty
     };
 }
예제 #6
0
        /// <summary>
        /// checks if the input file has chapters
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns>true if the file has chapters</returns>
        public static bool HasChapters(MediaInfoFile iFile)
        {
            if (iFile.HasChapters)
            {
                return(true);
            }

            if (Path.GetExtension(iFile.FileName.ToLowerInvariant()) != ".vob" &&
                Path.GetExtension(iFile.FileName.ToLowerInvariant()) != ".ifo")
            {
                return(false);
            }

            // detect ifo file
            string videoIFO = String.Empty;

            if (Path.GetExtension(iFile.FileName.ToLowerInvariant()) == ".vob")
            {
                // find the main IFO
                if (Path.GetFileName(iFile.FileName).ToUpperInvariant().Substring(0, 4) == "VTS_")
                {
                    videoIFO = iFile.FileName.Substring(0, iFile.FileName.LastIndexOf("_")) + "_0.IFO";
                }
                else
                {
                    videoIFO = Path.ChangeExtension(iFile.FileName, ".IFO");
                }
            }

            if (!File.Exists(videoIFO))
            {
                return(false);
            }

            int iPGCNumber = 1;

            if (iFile.VideoInfo.PGCNumber > 0)
            {
                iPGCNumber = iFile.VideoInfo.PGCNumber;
            }

            IfoExtractor ex  = new IfoExtractor();
            ChapterInfo  pgc = ex.GetChapterInfo(videoIFO, iPGCNumber);

            if (pgc != null && pgc.HasChapters)
            {
                return(true);
            }
            return(false);
        }
예제 #7
0
        public ChapterCreator()
        {
            InitializeComponent();
            pgc = new ChapterInfo();
            pgc.FramesPerSecond = 0;
            chkCounter.Checked  = MainForm.Instance.Settings.ChapterCreatorCounter;
            fpsChooserOut_SelectionChanged(null, null);

            // DPI rescale
            if (MainForm.Instance != null)
            {
                btOutput.Height = output.Height + MainForm.Instance.Settings.DPIRescale(2);
                btInput.Height  = input.Height + MainForm.Instance.Settings.DPIRescale(2);
            }
        }
예제 #8
0
파일: ChapterInfo.cs 프로젝트: pphh77/MeGui
 public ChapterInfo(ChapterInfo oOther)
 {
     Title           = oOther.Title;
     SourceFilePath  = oOther.SourceFilePath;
     SourceType      = oOther.SourceType;
     FramesPerSecond = oOther.FramesPerSecond;
     TitleNumber     = oOther.TitleNumber;
     PGCNumber       = oOther.PGCNumber;
     AngleNumber     = oOther.AngleNumber;
     Chapters        = new List <Chapter>();
     oOther.Chapters.ForEach((item) =>
     {
         Chapters.Add(new Chapter(item));
     });
 }
예제 #9
0
        private void chapters_FileSelected(FileBar sender, FileBarEventArgs args)
        {
            if (!File.Exists(chapters.Filename))
            {
                fileUpdated();
                return;
            }

            ChapterInfo oChapter = new ChapterInfo();

            if (!oChapter.LoadFile(chapters.Filename))
            {
                MessageBox.Show("The selected file is not a valid chapter file", "Invalid Chapter File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            fileUpdated();
        }
예제 #10
0
 public ChapterCreator(MainForm mainForm)
 {
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     intIndex      = 0;
     chapters      = new Chapter[0];
     this.mainForm = mainForm;
     pgc           = new ChapterInfo()
     {
         Chapters        = new List <Chapter>(),
         FramesPerSecond = 25.0,
         LangCode        = string.Empty
     };
 }
예제 #11
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            MediaInfoFile oInfo = new MediaInfoFile(location);
            ChapterInfo   pgc   = oInfo.ChapterInfo;

            if (!String.IsNullOrEmpty(pgc.SourceFilePath))
            {
                OnStreamDetected(pgc);
                OnChaptersLoaded(pgc);
            }
            OnExtractionComplete();
            return(new List <ChapterInfo>()
            {
                pgc
            });
        }
예제 #12
0
 public MuxSettings()
 {
     audioStreams    = new List <MuxStream>();
     subtitleStreams = new List <MuxStream>();
     chapterInfo     = new ChapterInfo();
     attachments     = new List <string>();
     framerate       = null;
     muxedInput      = "";
     videoName       = "";
     videoInput      = "";
     muxedOutput     = "";
     deviceType      = "";
     splitSize       = null;
     muxAll          = false;
     timeStampFile   = String.Empty;
 }
예제 #13
0
        /// <summary>
        /// Checks if the source file if from a DVD/Blu-ray stucture & asks for title list if needed
        /// </summary>
        /// <param name="fileName">input file name</param>
        /// <param name="iFileTemp">reference to the mediainfofile object</param>
        /// <returns>true if DVD/Blu-ray source is found, false if no DVD/Blu-ray source is available</returns>
        private bool GetDVDorBluraySource(string fileName, ref MediaInfoFile iFileTemp)
        {
            iFileTemp = null;
            using (frmStreamSelect frm = new frmStreamSelect(fileName, SelectionMode.One))
            {
                // check if playlists have been found
                if (frm.TitleCount == 0)
                {
                    return(false);
                }

                // only continue if a DVD or Blu-ray structure is found
                if (!frm.IsDVDOrBluraySource)
                {
                    return(false);
                }

                // open the selection window
                DialogResult dr = DialogResult.OK;
                dr = frm.ShowDialog();

                if (dr != DialogResult.OK)
                {
                    return(false);
                }

                ChapterInfo oChapterInfo  = frm.SelectedSingleChapterInfo;
                string      strSourceFile = string.Empty;
                if (frm.IsDVDSource)
                {
                    strSourceFile = Path.Combine(Path.GetDirectoryName(oChapterInfo.SourceFilePath), oChapterInfo.Title + "_0.IFO");
                }
                else
                {
                    strSourceFile = oChapterInfo.SourceFilePath;
                }
                if (!File.Exists(strSourceFile))
                {
                    _oLog.LogEvent(strSourceFile + " cannot be found. skipping...");
                    return(true);
                }
                iFileTemp = new MediaInfoFile(strSourceFile, ref _oLog, oChapterInfo.PGCNumber, oChapterInfo.AngleNumber);
            }
            return(true);
        }
예제 #14
0
        /// <summary>
        /// Checks if the source file if from a DVD stucture & asks for title list if needed
        /// </summary>
        /// <param name="fileName">input file name</param>
        /// <returns>true if DVD source is found, false if no DVD source is available</returns>
        private bool GetDVDSource(ref string fileName)
        {
            iPGC   = 1;
            iAngle = 0;
            using (frmStreamSelect frm = new frmStreamSelect(fileName, SelectionMode.One))
            {
                // check if playlists have been found
                if (frm.TitleCount == 0)
                {
                    return(false);
                }

                // only continue if a DVD or Blu-ray structure is found
                if (!frm.IsDVDSource)
                {
                    return(false);
                }

                // open the selection window if not exactly one title set with the desired minimum length is found
                DialogResult dr = DialogResult.OK;
                if (frm.TitleCountWithRequiredLength != 1)
                {
                    dr = frm.ShowDialog();
                }

                if (dr != DialogResult.OK)
                {
                    return(false);
                }

                ChapterInfo oChapterInfo  = frm.SelectedSingleChapterInfo;
                string      strSourceFile = Path.Combine(Path.GetDirectoryName(oChapterInfo.SourceFilePath), oChapterInfo.Title + "_0.IFO");
                if (!File.Exists(strSourceFile))
                {
                    // cannot be found. skipping...;
                    return(false);
                }
                iPGC     = oChapterInfo.PGCNumber;
                iAngle   = oChapterInfo.AngleNumber;
                fileName = strSourceFile;
            }
            return(true);
        }
예제 #15
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            ChapterInfo oChapterInfo = new ChapterInfo();

            if (!oChapterInfo.LoadFile(location))
            {
                OnExtractionComplete();
                return(new List <ChapterInfo>());
            }

            List <ChapterInfo> pgcs = new List <ChapterInfo>();

            pgcs.Add(oChapterInfo);

            OnStreamDetected(pgcs[0]);
            OnChaptersLoaded(pgcs[0]);
            OnExtractionComplete();
            return(pgcs);
        }
예제 #16
0
 /// <summary>
 /// gets the additionally configured stream configuration from this window
 /// this method is used when the muxwindow is created from the AutoEncodeWindow in order to configure audio languages
 /// add subtitles and chapters
 /// </summary>
 /// <param name="aStreams">the configured audio streams(language assignments)</param>
 /// <param name="sStreams">the newly added subtitle streams</param>
 /// <param name="chapterInfo">the ChapterInfo</param>
 public void getAdditionalStreams(out MuxStream[] aStreams, out MuxStream[] sStreams, out ChapterInfo chapterInfo)
 {
     aStreams    = getStreams(audioTracks);
     sStreams    = getStreams(subtitleTracks);
     chapterInfo = new ChapterInfo();
     if (chapters.Filename.StartsWith("<"))
     {
         MediaInfoFile oInfo = new MediaInfoFile(vInput.Filename);
         chapterInfo = oInfo.ChapterInfo;
     }
     else if (File.Exists(chapters.Filename))
     {
         chapterInfo.LoadFile(chapters.Filename);
         if (chapterInfo.FramesPerSecond == 0)
         {
             MediaInfoFile oInfo = new MediaInfoFile(vInput.Filename);
             chapterInfo.FramesPerSecond = oInfo.VideoInfo.FPS;
         }
     }
 }
예제 #17
0
        public ChapterInfo GetChapterInfo(string location, int titleSetNum)
        {
            if (location.StartsWith("VTS_"))
            {
                titleSetNum = int.Parse(Path.GetFileNameWithoutExtension(location)
                                        .ToUpper(System.Globalization.CultureInfo.InvariantCulture)
                                        .Replace("VTS_", string.Empty)
                                        .Replace("_0.IFO", string.Empty));
            }

            ChapterInfo pgc = new ChapterInfo();

            pgc.SourceType  = "DVD";
            pgc.SourceName  = "PGC " + titleSetNum.ToString("D2");
            pgc.TitleNumber = titleSetNum;
            pgc.SourceHash  = ChapterExtractor.ComputeMD5Sum(location);
            pgc.Title       = Path.GetFileNameWithoutExtension(location);
            if (pgc.Title.Split('_').Length == 3)
            {
                pgc.Title = pgc.Title.Split('_')[0] + "_" + pgc.Title.Split('_')[1];
            }

            TimeSpan duration;
            double   fps;

            pgc.Chapters        = GetChapters(location, titleSetNum, out duration, out fps);
            pgc.Duration        = duration;
            pgc.FramesPerSecond = fps;

            if (pgc.Duration.TotalSeconds > MainForm.Instance.Settings.ChapterCreatorMinimumLength)
            {
                OnStreamDetected(pgc);
            }
            else
            {
                pgc = null;
            }
            OnExtractionComplete();
            return(pgc);
        }
예제 #18
0
        public override List <ChapterInfo> GetStreams(string ifoFile)
        {
            List <ChapterInfo> oList = new List <ChapterInfo>();

            int pgcCount = IFOparser.GetPGCCount(ifoFile);

            for (int i = 1; i <= pgcCount; i++)
            {
                int iAngleCount = IFOparser.GetAngleCount(ifoFile, i);
                for (int a = 0; a <= iAngleCount; a++)
                {
                    if (a == 0 && iAngleCount > 0)
                    {
                        continue;
                    }
                    ChapterInfo oChapterInfo = GetChapterInfo(ifoFile, i);
                    oChapterInfo.AngleNumber = a;
                    oList.Add(oChapterInfo);
                }
            }
            return(oList);
        }
예제 #19
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            ChapterInfo pgc = new ChapterInfo();

            pgc.Chapters   = new List <Chapter>();
            pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
            pgc.SourceName = location;
            pgc.Title      = Path.GetFileNameWithoutExtension(location);
            pgc.SourceType = "Blu-Ray";

            DirectoryInfo DirectoryBDMV = GetDirectoryBDMV(location);

            if (DirectoryBDMV == null)
            {
                throw new Exception("Unable to locate BD structure.");
            }

            DirectoryInfo DirectoryRoot =
                DirectoryBDMV.Parent;
            DirectoryInfo DirectoryBDJO =
                GetDirectory("BDJO", DirectoryBDMV, 0);
            DirectoryInfo DirectoryCLIPINF =
                GetDirectory("CLIPINF", DirectoryBDMV, 0);
            DirectoryInfo DirectoryPLAYLIST =
                GetDirectory("PLAYLIST", DirectoryBDMV, 0);
            DirectoryInfo DirectorySNP =
                GetDirectory("SNP", DirectoryRoot, 0);
            DirectoryInfo DirectorySTREAM =
                GetDirectory("STREAM", DirectoryBDMV, 0);
            DirectoryInfo DirectorySSIF =
                GetDirectory("SSIF", DirectorySTREAM, 0);

            Dictionary <string, TSStreamClipFile> StreamClipFiles = new Dictionary <string, TSStreamClipFile>();
            Dictionary <string, TSStreamFile>     StreamFiles     = new Dictionary <string, TSStreamFile>();

            if (DirectorySTREAM != null)
            {
                FileInfo[] files = DirectorySTREAM.GetFiles("*.m2ts");
                if (files.Length == 0)
                {
                    files = DirectoryPLAYLIST.GetFiles("*.M2TS");
                }
                foreach (FileInfo file in files)
                {
                    StreamFiles.Add(file.Name.ToUpper(), new TSStreamFile(file));
                }
            }

            if (DirectoryCLIPINF != null)
            {
                FileInfo[] files = DirectoryCLIPINF.GetFiles("*.clpi");
                if (files.Length == 0)
                {
                    files = DirectoryPLAYLIST.GetFiles("*.CLPI");
                }
                foreach (FileInfo file in files)
                {
                    StreamClipFiles.Add(file.Name.ToUpper(), new TSStreamClipFile(file));
                }
            }

            FileInfo       fileInfo = new FileInfo(location);
            TSPlaylistFile mpls     = new TSPlaylistFile(fileInfo);

            mpls.Scan(StreamFiles, StreamClipFiles);

            int count = 1;

            foreach (double d in mpls.Chapters)
            {
                pgc.Chapters.Add(new Chapter()
                {
                    Name = "Chapter " + count.ToString("D2"),
                    Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond))
                });
                count++;
            }

            pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond));

            foreach (TSStreamClip clip in mpls.StreamClips)
            {
                clip.StreamClipFile.Scan();
                foreach (TSStream stream in clip.StreamClipFile.Streams.Values)
                {
                    if (stream.IsVideoStream)
                    {
                        pgc.FramesPerSecond = VideoUtil.ConvertFPSFractionToDouble(((TSVideoStream)stream).FrameRateEnumerator, ((TSVideoStream)stream).FrameRateDenominator);
                        break;
                    }
                }
                if (pgc.FramesPerSecond != 0)
                {
                    break;
                }
            }

            if (pgc.Duration.TotalSeconds > MainForm.Instance.Settings.ChapterCreatorMinimumLength)
            {
                OnStreamDetected(pgc);
                OnChaptersLoaded(pgc);
            }
            else
            {
                pgc = null;
            }
            OnExtractionComplete();
            return(new List <ChapterInfo>()
            {
                pgc
            });
        }
예제 #20
0
        public override List<ChapterInfo> GetStreams(string location)
        {
            ChapterInfo pgc = new ChapterInfo();
              List<Chapter> chapters = new List<Chapter>();
              pgc.SourceName = location;
              pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
              pgc.SourceType = "Blu-Ray";
              pgc.Title = Path.GetFileNameWithoutExtension(location);

              FileInfo fileInfo = new FileInfo(location);
              byte[] data = File.ReadAllBytes(location);

              string fileType = ASCIIEncoding.ASCII.GetString(data, 0, 8);

              if ((fileType != "MPLS0100" && fileType != "MPLS0200")
            /*|| data[45] != 1*/)
              {
            throw new Exception(string.Format(
            "Playlist {0} has an unknown file type {1}.",
            fileInfo.Name, fileType));
              }

              List<Clip> chapterClips = GetClips(data);
              pgc.Duration = new TimeSpan((long)(chapterClips.Sum(c => c.Length) * (double)TimeSpan.TicksPerSecond));
              OnStreamDetected(pgc);

              int chaptersIndex =
              ((int)data[12] << 24) +
              ((int)data[13] << 16) +
              ((int)data[14] << 8) +
              ((int)data[15]);

              int chaptersLength =
              ((int)data[chaptersIndex] << 24) +
              ((int)data[chaptersIndex + 1] << 16) +
              ((int)data[chaptersIndex + 2] << 8) +
              ((int)data[chaptersIndex + 3]);

              byte[] chapterData = new byte[chaptersLength];
              Array.Copy(data, chaptersIndex + 4, chapterData, 0, chaptersLength);

              int chapterCount = ((int)chapterData[0] << 8) + chapterData[1];
              int chapterOffset = 2;
              for (int chapterIndex = 0; chapterIndex < chapterCount; chapterIndex++)
              {
            if (chapterData[chapterOffset + 1] == 1)
            {
              int streamFileIndex =
              ((int)chapterData[chapterOffset + 2] << 8) +
              chapterData[chapterOffset + 3];

              Clip streamClip = chapterClips[streamFileIndex];

              long chapterTime =
              ((long)chapterData[chapterOffset + 4] << 24) +
              ((long)chapterData[chapterOffset + 5] << 16) +
              ((long)chapterData[chapterOffset + 6] << 8) +
              ((long)chapterData[chapterOffset + 7]);

              double chapterSeconds = (double)chapterTime / 45000D;
              double relativeSeconds = chapterSeconds - streamClip.TimeIn + streamClip.RelativeTimeIn;
              chapters.Add(new Chapter()
              {
              Name = "Chapter " + (chapterIndex + 1).ToString("D2"),//string.Empty,
            Time = new TimeSpan((long)(relativeSeconds * (double)TimeSpan.TicksPerSecond))
              });
            }
            chapterOffset += 14;
              }
              pgc.Chapters = chapters;

              //TODO: get real FPS
              pgc.FramesPerSecond = 25.0;

              OnChaptersLoaded(pgc);
              OnExtractionComplete();
              return new List<ChapterInfo>() { pgc };
        }
예제 #21
0
        /// <summary>
        /// handles the go button for automated encoding
        /// checks if we're in automated 2 pass video mode
        /// then the video and audio configuration is checked, and if it checks out
        /// the audio job, video jobs and muxing job are generated, audio and video job are linked
        /// and encoding is started
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void queueButton_Click(object sender, System.EventArgs e)
        {
            if (String.IsNullOrEmpty(this.muxedOutput.Filename))
            {
                return;
            }

            FileSize?desiredSize = targetSize.Value;
            FileSize?splitSize   = splitting.Value;
            LogItem  log         = new LogItem(this.muxedOutput.Filename);

            MainForm.Instance.AutoEncodeLog.Add(log);

            if (FileSizeRadio.Checked)
            {
                log.LogValue("Desired Size", desiredSize);
            }
            else if (averageBitrateRadio.Checked)
            {
                log.LogValue("Projected Bitrate", string.Format("{0}kbps", projectedBitrateKBits.Text));
            }
            else
            {
                log.LogEvent("No Target Size (use profile settings)");
            }

            log.LogValue("Split Size", splitSize);

            MuxStream[]        audio;
            AudioJob[]         aStreams;
            AudioEncoderType[] muxTypes;
            separateEncodableAndMuxableAudioStreams(out aStreams, out audio, out muxTypes);
            MuxStream[]   subtitles   = new MuxStream[0];
            ChapterInfo   chapters    = new ChapterInfo();
            string        videoInput  = vInfo.VideoInput;
            string        videoOutput = vInfo.VideoOutput;
            string        muxedOutput = this.muxedOutput.Filename;
            ContainerType cot         = this.container.SelectedItem as ContainerType;

            // determine audio language
            foreach (MuxStream stream in audio)
            {
                string strLanguage = LanguageSelectionContainer.GetLanguageFromFileName(Path.GetFileNameWithoutExtension(stream.path));
                if (!String.IsNullOrEmpty(strLanguage))
                {
                    stream.language = strLanguage;
                }
            }

            if (addSubsNChapters.Checked)
            {
                AdaptiveMuxWindow amw = new AdaptiveMuxWindow();
                amw.setMinimizedMode(videoOutput, "", videoStream.Settings.EncoderType, JobUtil.getFramerate(videoInput), audio,
                                     muxTypes, muxedOutput, splitSize, cot);
                if (amw.ShowDialog() == DialogResult.OK)
                {
                    amw.getAdditionalStreams(out audio, out subtitles, out chapters, out muxedOutput, out cot);
                }
                else // user aborted, abort the whole process
                {
                    return;
                }
            }
            removeStreamsToBeEncoded(ref audio, aStreams);
            MainForm.Instance.Jobs.AddJobsWithDependencies(VideoUtil.GenerateJobSeries(videoStream, muxedOutput, aStreams, subtitles, new List <string>(), String.Empty, chapters,
                                                                                       desiredSize, splitSize, cot, prerender, audio, log, device.Text, vInfo.Zones, null, null, false), true);
            this.Close();
        }
예제 #22
0
        public static JobChain GenerateMuxJobs(VideoStream video, decimal?framerate, MuxStream[] audioStreamsArray,
                                               MuxableType[] audioTypes, MuxStream[] subtitleStreamsArray, MuxableType[] subTypes, List <string> attachments,
                                               ChapterInfo chapterInfo, MuxableType chapterInputType, ContainerType container, string output, string timeStampFile,
                                               FileSize?splitSize, List <string> inputsToDelete, string deviceType, MuxableType deviceOutputType, bool alwaysMuxOutput)
        {
            Debug.Assert(splitSize == null || splitSize.Value != FileSize.Empty);

            MuxProvider        prov           = MainForm.Instance.MuxProvider;
            List <MuxableType> allTypes       = new List <MuxableType>();
            List <MuxableType> tempTypes      = new List <MuxableType>();
            List <MuxableType> duplicateTypes = new List <MuxableType>();

            tempTypes.AddRange(audioTypes);
            tempTypes.AddRange(subTypes);
            allTypes.Add(video.VideoType);

            // remove duplicate entries to speed up the process
            foreach (MuxableType oType in tempTypes)
            {
                bool bFound = false;
                foreach (MuxableType oAllType in allTypes)
                {
                    if (oType.outputType.ID.Equals(oAllType.outputType.ID))
                    {
                        bFound = true;
                        break;
                    }
                }
                if (!bFound)
                {
                    allTypes.Add(oType);
                }
                else
                {
                    duplicateTypes.Add(oType);
                }
            }
            if (chapterInputType != null)
            {
                allTypes.Add(chapterInputType);
            }
            if (deviceOutputType != null)
            {
                allTypes.Add(deviceOutputType);
            }

            // get mux path
            MuxPath muxPath = prov.GetMuxPath(container, alwaysMuxOutput || splitSize.HasValue, allTypes.ToArray());

            // add duplicate entries back into the mux path
            muxPath.InitialInputTypes.AddRange(duplicateTypes);
            while (duplicateTypes.Count > 0)
            {
                int iPath = 0;
                for (int i = 0; i < muxPath.Length; i++)
                {
                    foreach (MuxableType oType in muxPath[i].handledInputTypes)
                    {
                        if (oType.outputType.ID.Equals(duplicateTypes[0].outputType.ID))
                        {
                            iPath = i;
                        }
                    }
                }
                muxPath[iPath].handledInputTypes.Add(duplicateTypes[0]);
                duplicateTypes.RemoveAt(0);
            }

            List <MuxJob>    jobs            = new List <MuxJob>();
            List <MuxStream> subtitleStreams = new List <MuxStream>(subtitleStreamsArray);
            List <MuxStream> audioStreams    = new List <MuxStream>(audioStreamsArray);
            int    index          = 0;
            int    tempNumber     = 1;
            string previousOutput = null;

            foreach (MuxPathLeg mpl in muxPath)
            {
                List <string> filesToDeleteThisJob = new List <string>();

                MuxJob mjob = new MuxJob();

                if (previousOutput != null)
                {
                    mjob.Settings.MuxedInput = previousOutput;
                    filesToDeleteThisJob.Add(previousOutput);
                }

                if (video.Settings != null)
                {
                    mjob.NbOfBFrames        = video.Settings.NbBframes;
                    mjob.Codec              = video.Settings.Codec.ToString();
                    mjob.Settings.VideoName = video.Settings.VideoName;
                }
                mjob.NbOfFrames = video.NumberOfFrames;
                if (framerate != null)
                {
                    string fpsFormated = String.Format("{0:##.###}", framerate); // this formating is required for mkvmerge at least to avoid fps rounding error
                    mjob.Settings.Framerate = Convert.ToDecimal(fpsFormated);
                }

                string tempOutputName = Path.Combine(Path.GetDirectoryName(output),
                                                     Path.GetFileNameWithoutExtension(output) + tempNumber + ".");
                tempNumber++;
                foreach (MuxableType o in mpl.handledInputTypes)
                {
                    if (o.outputType is VideoType)
                    {
                        mjob.Settings.VideoInput = video.Output;
                        if (inputsToDelete.Contains(video.Output))
                        {
                            filesToDeleteThisJob.Add(video.Output);
                        }
                        mjob.Settings.DAR = video.DAR;
                    }
                    else if (o.outputType is AudioType)
                    {
                        MuxStream stream = audioStreams.Find(delegate(MuxStream m)
                        {
                            return(VideoUtil.guessAudioType(m.path) == o.outputType);
                        });

                        if (stream != null)
                        {
                            mjob.Settings.AudioStreams.Add(stream);
                            audioStreams.Remove(stream);

                            if (inputsToDelete.Contains(stream.path))
                            {
                                filesToDeleteThisJob.Add(stream.path);
                            }
                        }
                    }
                    else if (o.outputType is SubtitleType)
                    {
                        MuxStream stream = subtitleStreams.Find(delegate(MuxStream m)
                        {
                            return(VideoUtil.guessSubtitleType(m.path) == o.outputType);
                        });

                        if (stream != null)
                        {
                            mjob.Settings.SubtitleStreams.Add(stream);
                            subtitleStreams.Remove(stream);

                            if (inputsToDelete.Contains(stream.path))
                            {
                                filesToDeleteThisJob.Add(stream.path);
                            }
                        }
                    }
                    else if (o.outputType is ChapterType)
                    {
                        mjob.Settings.ChapterInfo = chapterInfo;
                    }
                    else if (o.outputType is DeviceType)
                    {
                        if ((VideoUtil.guessDeviceType(deviceType) == o.outputType))
                        {
                            mjob.Settings.DeviceType = deviceType;
                        }
                    }
                }
                foreach (MuxStream s in mjob.Settings.AudioStreams)
                {
                    audioStreams.Remove(s);
                }
                foreach (MuxStream s in mjob.Settings.SubtitleStreams)
                {
                    subtitleStreams.Remove(s);
                }
                mjob.FilesToDelete.AddRange(filesToDeleteThisJob);
                if (index == muxPath.Length - 1)
                {
                    mjob.Settings.MuxedOutput = output;
                    mjob.Settings.SplitSize   = splitSize;
                    mjob.Settings.DAR         = video.DAR;
                    mjob.ContainerType        = container;
                }
                else
                {
                    ContainerType cot = mpl.muxerInterface.GetContainersInCommon(muxPath[index + 1].muxerInterface)[0];
                    mjob.Settings.MuxedOutput = tempOutputName + cot.Extension;
                    mjob.ContainerType        = cot;
                }
                previousOutput = mjob.Settings.MuxedOutput;
                index++;
                mjob.Settings.Attachments   = attachments;
                mjob.Settings.TimeStampFile = timeStampFile;
                jobs.Add(mjob);
                if (string.IsNullOrEmpty(mjob.Settings.VideoInput))
                {
                    mjob.Input = mjob.Settings.MuxedInput;
                }
                else
                {
                    mjob.Input = mjob.Settings.VideoInput;
                }
                mjob.Output  = mjob.Settings.MuxedOutput;
                mjob.MuxType = mpl.muxerInterface.MuxerType;
            }

            return(new SequentialChain(jobs.ToArray()));
        }
예제 #23
0
        public static JobChain GenerateJobSeries(VideoStream video, string muxedOutput, AudioJob[] audioStreams,
                                                 MuxStream[] subtitles, List <string> attachments, string timeStampFile, ChapterInfo chapterInfo, FileSize?desiredSize, FileSize?splitSize,
                                                 ContainerType container, bool prerender, MuxStream[] muxOnlyAudio, LogItem log, string deviceType,
                                                 Zone[] zones, string videoFileToMux, OneClickAudioTrack[] audioTracks, bool alwaysMuxOutput)
        {
            if (desiredSize.HasValue && String.IsNullOrEmpty(videoFileToMux))
            {
                if (video.Settings.VideoEncodingType != VideoCodecSettings.VideoEncodingMode.twopassAutomated &&
                    video.Settings.VideoEncodingType != VideoCodecSettings.VideoEncodingMode.threepassAutomated)    // no automated 2/3 pass
                {
                    if (MainForm.Instance.Settings.NbPasses == 2)
                    {
                        video.Settings.VideoEncodingType = VideoCodecSettings.VideoEncodingMode.twopassAutomated; // automated 2 pass
                    }
                    else if (video.Settings.MaxNumberOfPasses == 3)
                    {
                        video.Settings.VideoEncodingType = VideoCodecSettings.VideoEncodingMode.threepassAutomated;
                    }
                }
            }

            fixFileNameExtensions(video, audioStreams, container);
            string videoOutput = video.Output;

            log.Add(eliminatedDuplicateFilenames(ref videoOutput, ref muxedOutput, audioStreams));

            JobChain vjobs = null;

            if (!String.IsNullOrEmpty(videoFileToMux))
            {
                video.Output = videoFileToMux;
            }
            else
            {
                video.Output = videoOutput;
                vjobs        = JobUtil.prepareVideoJob(video.Input, video.Output, video.Settings, video.DAR, prerender, zones);
                if (vjobs == null)
                {
                    return(null);
                }
            }

            /* Here, we guess the types of the files based on extension.
             * This is guaranteed to work with MeGUI-encoded files, because
             * the extension will always be recognised. For non-MeGUI files,
             * we can only ever hope.*/
            List <MuxStream>   allAudioToMux      = new List <MuxStream>();
            List <MuxableType> allInputAudioTypes = new List <MuxableType>();

            if (audioTracks != null)
            {
                // OneClick mode
                foreach (OneClickAudioTrack ocAudioTrack in audioTracks)
                {
                    if (ocAudioTrack.DirectMuxAudio != null)
                    {
                        if (VideoUtil.guessAudioMuxableType(ocAudioTrack.DirectMuxAudio.path, true) != null)
                        {
                            allInputAudioTypes.Add(VideoUtil.guessAudioMuxableType(ocAudioTrack.DirectMuxAudio.path, true));
                            allAudioToMux.Add(ocAudioTrack.DirectMuxAudio);
                        }
                    }
                    if (ocAudioTrack.AudioJob != null && !String.IsNullOrEmpty(ocAudioTrack.AudioJob.Input))
                    {
                        allAudioToMux.Add(ocAudioTrack.AudioJob.ToMuxStream());
                        allInputAudioTypes.Add(ocAudioTrack.AudioJob.ToMuxableType());
                    }
                }
            }
            else
            {
                // AutoEncode mode
                foreach (AudioJob stream in audioStreams)
                {
                    allAudioToMux.Add(stream.ToMuxStream());
                    allInputAudioTypes.Add(stream.ToMuxableType());
                }

                foreach (MuxStream muxStream in muxOnlyAudio)
                {
                    if (VideoUtil.guessAudioMuxableType(muxStream.path, true) != null)
                    {
                        allInputAudioTypes.Add(VideoUtil.guessAudioMuxableType(muxStream.path, true));
                        allAudioToMux.Add(muxStream);
                    }
                }
            }

            List <MuxableType> allInputSubtitleTypes = new List <MuxableType>();

            foreach (MuxStream muxStream in subtitles)
            {
                if (VideoUtil.guessSubtitleType(muxStream.path) != null)
                {
                    allInputSubtitleTypes.Add(new MuxableType(VideoUtil.guessSubtitleType(muxStream.path), null));
                }
            }

            MuxableType chapterInputType = null;

            if (chapterInfo.HasChapters)
            {
                chapterInputType = new MuxableType(ChapterType.OGG_TXT, null);
            }

            MuxableType deviceOutputType = null;

            if (!String.IsNullOrEmpty(deviceType))
            {
                DeviceType type = VideoUtil.guessDeviceType(deviceType);
                if (type != null)
                {
                    deviceOutputType = new MuxableType(type, null);
                }
            }

            List <string> inputsToDelete = new List <string>();

            if (String.IsNullOrEmpty(videoFileToMux))
            {
                inputsToDelete.Add(video.Output);
            }
            inputsToDelete.AddRange(Array.ConvertAll <AudioJob, string>(audioStreams, delegate(AudioJob a) { return(a.Output); }));

            JobChain muxJobs = JobUtil.GenerateMuxJobs(video, null, allAudioToMux.ToArray(), allInputAudioTypes.ToArray(),
                                                       subtitles, allInputSubtitleTypes.ToArray(), attachments, chapterInfo, chapterInputType, container, muxedOutput, timeStampFile,
                                                       splitSize, inputsToDelete, deviceType, deviceOutputType, alwaysMuxOutput);

            if (desiredSize.HasValue && String.IsNullOrEmpty(videoFileToMux))
            {
                BitrateCalculationInfo b = new BitrateCalculationInfo();

                List <string> audiofiles = new List <string>();
                foreach (MuxStream s in allAudioToMux)
                {
                    audiofiles.Add(s.path);
                }
                b.AudioFiles = audiofiles;

                b.Container   = container;
                b.VideoJobs   = new List <TaggedJob>(vjobs.Jobs);
                b.DesiredSize = desiredSize.Value;
                ((VideoJob)vjobs.Jobs[0].Job).BitrateCalculationInfo = b;
            }

            if (!String.IsNullOrEmpty(videoFileToMux))
            {
                return(new SequentialChain(new SequentialChain((Job[])audioStreams), new SequentialChain(muxJobs)));
            }
            else
            {
                return(new SequentialChain(
                           new SequentialChain((Job[])audioStreams),
                           new SequentialChain(vjobs),
                           new SequentialChain(muxJobs)));
            }
        }
예제 #24
0
        private void btInput_Click(object sender, EventArgs e)
        {
            if (rbFromFile.Checked)
            {
                openFileDialog.Filter      = "IFO Files (*.ifo)|*.ifo|MPLS Files (*.mpls)|*.mpls|Text Files (*.txt)|*.txt|All Files supported (*.ifo,*.mpls,*.txt)|*.ifo;*.mpls;*.txt";
                openFileDialog.FilterIndex = 4;

                if (this.openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    input.Text = openFileDialog.FileName;

                    if (input.Text.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith("ifo"))
                    {
                        ChapterExtractor ex = new DvdExtractor();
                        using (frmStreamSelect frm = new frmStreamSelect(ex))
                        {
                            if (ex is DvdExtractor)
                            {
                                frm.Text = "Select your PGC";
                            }
                            else
                            {
                                frm.Text = "Select your Playlist";
                            }
                            ex.GetStreams(input.Text);
                            if (frm.ChapterCount == 1 || frm.ShowDialog(this) == DialogResult.OK)
                            {
                                pgc = frm.SelectedSingleChapterInfo;
                                if (pgc.FramesPerSecond == 0)
                                {
                                    pgc.FramesPerSecond = 25.0;
                                }
                                if (String.IsNullOrEmpty(pgc.LangCode))
                                {
                                    pgc.LangCode = "und";
                                }
                            }
                        }
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith("mpls"))
                    {
                        ChapterExtractor ex = new MplsExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else
                    {
                        ChapterExtractor ex = new TextExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                }
            }
            else
            {
                using (FolderBrowserDialog d = new FolderBrowserDialog())
                {
                    d.ShowNewFolderButton = false;
                    d.Description         = "Select DVD, BluRay disc, or folder.";
                    if (d.ShowDialog() == DialogResult.OK)
                    {
                        input.Text = d.SelectedPath;
                        try
                        {
                            ChapterExtractor ex =
                                Directory.Exists(Path.Combine(input.Text, "VIDEO_TS")) ?
                                new DvdExtractor() as ChapterExtractor :
                                File.Exists(Path.Combine(input.Text, "VIDEO_TS.IFO")) ?
                                new DvdExtractor() as ChapterExtractor :
                                Directory.Exists(Path.Combine(Path.Combine(input.Text, "BDMV"), "PLAYLIST")) ?
                                new BlurayExtractor() as ChapterExtractor :
                                null;

                            if (ex == null)
                            {
                                throw new Exception("The location was not detected as DVD, or Blu-Ray.");
                            }

                            using (frmStreamSelect frm = new frmStreamSelect(ex))
                            {
                                if (ex is DvdExtractor)
                                {
                                    frm.Text = "Select your Title";
                                }
                                else
                                {
                                    frm.Text = "Select your Playlist";
                                }
                                ex.GetStreams(input.Text);
                                if (frm.ChapterCount == 1 || frm.ShowDialog(this) == DialogResult.OK)
                                {
                                    pgc = frm.SelectedSingleChapterInfo;
                                    if (pgc.FramesPerSecond == 0)
                                    {
                                        pgc.FramesPerSecond = 25.0;
                                    }
                                    if (String.IsNullOrEmpty(pgc.LangCode))
                                    {
                                        pgc.LangCode = "und";
                                    }
                                }
                            }
                            FreshChapterView();
                            updateTimeLine();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }

            if (chapterListView.Items.Count != 0)
            {
                chapterListView.Items[0].Selected = true;
            }
        }
예제 #25
0
 public ChapterCreator(MainForm mainForm)
 {
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     intIndex = 0;
     chapters = new Chapter[0];
     this.mainForm = mainForm;
     pgc = new ChapterInfo()
     {
         Chapters = new List<Chapter>(),
         FramesPerSecond = 25.0,
         LangCode = string.Empty
     };
 }
예제 #26
0
        private void btInput_Click(object sender, EventArgs e)
        {
            if (rbFromFile.Checked)
            {
                openFileDialog.Filter = "IFO Files (*.ifo)|*.ifo|MPLS Files (*.mpls)|*.mpls|Text Files (*.txt)|*.txt|All Files supported (*.ifo,*.mpls,*.txt)|*.ifo;*.mpls;*.txt";
                openFileDialog.FilterIndex = 4;

               if (this.openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    input.Text = openFileDialog.FileName;

                    if (input.Text.ToLower().EndsWith("ifo"))
                    {
                        ChapterExtractor ex = new IfoExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLower().EndsWith("mpls"))
                    {
                        ChapterExtractor ex = new MplsExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else
                    {
                        ChapterExtractor ex = new TextExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                }
            }
            else
            {
                using (FolderBrowserDialog d = new FolderBrowserDialog())
                {
                    d.ShowNewFolderButton = false;
                    d.Description = "Select DVD, BluRay disc, or folder.";
                    if (d.ShowDialog() == DialogResult.OK)
                    {
                        input.Text = d.SelectedPath;
                        try
                        {
                            ChapterExtractor ex =
                              Directory.Exists(Path.Combine(input.Text, "VIDEO_TS")) ?
                              new DvdExtractor() as ChapterExtractor :
                              Directory.Exists(Path.Combine(Path.Combine(input.Text, "BDMV"), "PLAYLIST")) ?
                              new BlurayExtractor() as ChapterExtractor :
                              null;

                            if (ex == null)
                                throw new Exception("The location was not detected as DVD, or Blu-Ray.");

                            using (frmStreamSelect frm = new frmStreamSelect(ex))
                            {
                                if (ex is DvdExtractor)
                                    frm.Text = "Select your PGC";
                                else
                                    frm.Text = "Select your Playlist";
                                ex.GetStreams(input.Text);
                                if (frm.ShowDialog(this) == DialogResult.OK)
                                {
                                    pgc = frm.ProgramChain;
                                    if (pgc.FramesPerSecond == 0) pgc.FramesPerSecond = 25.0;
                                    if (pgc.LangCode == null) pgc.LangCode = "und";
                                }
                            }
                            FreshChapterView();
                            updateTimeLine();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }

            if (chapterListView.Items.Count != 0)
                chapterListView.Items[0].Selected = true;
        }
예제 #27
0
        /// <summary>
        /// sets the configuration of the GUI
        /// used when a job is loaded (jobs have everything already filled out)
        /// </summary>
        /// <param name="videoInput">the video input file</param>
        /// <param name="videoName">the name of the video track</param>
        /// <param name="framerate">framerate of the input</param>
        /// <param name="audioStreams">the audio streams</param>
        /// <param name="subtitleStreams">the subtitle streams</param>
        /// <param name="chapterInfo">the chapterinfo information</param>
        /// <param name="output">name of the output file</param>
        /// <param name="splitSize">split size of the output</param>
        /// <param name="dar">the DAR of the file</param>
        /// <param name="deviceType">the device type (e.g. for AVI, M2TS, MP4)</param>
        public void setConfig(string videoInput, string videoName, decimal?framerate, MuxStream[] audioStreams, MuxStream[] subtitleStreams, ChapterInfo chapterInfo, string output, FileSize?splitSize, Dar?dar, string deviceType)
        {
            this.dar            = dar;
            vInput.Filename     = videoInput;
            fps.Value           = framerate;
            this.videoName.Text = videoName;

            int index = 0;

            foreach (MuxStream stream in audioStreams)
            {
                if (audioTracks.Count == index)
                {
                    AudioAddTrack();
                }
                audioTracks[index].Stream = stream;
                index++;
            }

            index = 0;
            foreach (MuxStream stream in subtitleStreams)
            {
                if (subtitleTracks.Count == index)
                {
                    SubtitleAddTrack();
                }
                subtitleTracks[index].Stream = stream;
                index++;
            }

            chapters.Filename            = chapterInfo.SourceFilePath;
            this.output.Filename         = output;
            this.splitting.Value         = splitSize;
            this.muxButton.Text          = "Update";
            this.chkCloseOnQueue.Visible = false;
            this.cbType.Text             = deviceType;
            checkIO();
        }
예제 #28
0
        private void saveButton_Click(object sender, System.EventArgs e)
        {
            if (String.IsNullOrEmpty(output.Text))
            {
                btOutput_Click(null, null);
                if (String.IsNullOrEmpty(output.Text))
                {
                    MessageBox.Show("Please select the output file first", "Configuration Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            if (!Directory.Exists(Path.GetDirectoryName(output.Text)))
            {
                btOutput_Click(null, null);
                if (!Directory.Exists(Path.GetDirectoryName(output.Text)))
                {
                    return;
                }
            }

            if (rbQPF.Checked && fpsChooserIn.Value == null)
            {
                MessageBox.Show("The FPS value for the input file is unknown.\nPlease make sure that the correct value for the input is selected.", "FPS unknown", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (rbQPF.Checked && fpsChooserOut.Value == null)
            {
                MessageBox.Show("The FPS value for the output file is unknown.\nPlease make sure that the correct value for the output is selected.", "FPS unknown", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!FileUtil.IsDirWriteable(Path.GetDirectoryName(output.Text)))
            {
                MessageBox.Show("MeGUI cannot write to the path " + Path.GetDirectoryName(output.Text) + "\n" +
                                "Please select another output path to save your file.", "Configuration Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!pgc.HasChapters)
            {
                MessageBox.Show("Please add at least one chapter.", "Missing Chapter", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ChapterInfo oChapterSave = new ChapterInfo(pgc);

            if (fpsChooserOut.Value != null)
            {
                oChapterSave.ChangeFps((double)fpsChooserOut.Value);
            }
            if (rbQPF.Checked)
            {
                oChapterSave.SaveQpfile(output.Text);
            }
            else if (rbXML.Checked)
            {
                oChapterSave.SaveXml(output.Text);
            }
            else
            {
                oChapterSave.SaveText(output.Text);
            }

            if (this.closeOnQueue.Checked)
            {
                this.Close();
            }
        }
예제 #29
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            List <ChapterInfo> pgcs = new List <ChapterInfo>();
            XDocument          doc  = XDocument.Load(location);
            XNamespace         ns   = "http://www.dvdforum.org/2005/HDDVDVideo/Playlist";

            foreach (XElement ts in doc.Element(ns + "Playlist").Elements(ns + "TitleSet"))
            {
                float timeBase = GetFps((string)ts.Attribute("timeBase"));
                float tickBase = GetFps((string)ts.Attribute("tickBase"));
                foreach (XElement title in ts.Elements(ns + "Title").Where(t => t.Element(ns + "ChapterList") != null))
                {
                    ChapterInfo    pgc      = new ChapterInfo();
                    List <Chapter> chapters = new List <Chapter>();
                    pgc.SourceName      = location;
                    pgc.SourceHash      = ChapterExtractor.ComputeMD5Sum(location);
                    pgc.SourceType      = "HD-DVD";
                    pgc.FramesPerSecond = 24D;
                    OnStreamDetected(pgc);

                    int tickBaseDivisor = (int?)title.Attribute("tickBaseDivisor") ?? 1;
                    pgc.Duration = GetTimeSpan((string)title.Attribute("titleDuration"), timeBase, tickBase, tickBaseDivisor);
                    string titleName = Path.GetFileNameWithoutExtension(location);
                    if (title.Attribute("id") != null)
                    {
                        titleName = (string)title.Attribute("id");
                    }
                    if (title.Attribute("displayName") != null)
                    {
                        titleName = (string)title.Attribute("displayName");
                    }
                    pgc.Title = titleName;
                    int count = 0;
                    foreach (XElement chapter in title.Element(ns + "ChapterList").Elements(ns + "Chapter"))
                    {
                        if (string.IsNullOrEmpty((string)chapter.Attribute("displayName")))
                        {
                            chapters.Add(new Chapter()
                            {
                                Name = "Chapter " + (count + 1).ToString("D2"),
                                Time = GetTimeSpan((string)chapter.Attribute("titleTimeBegin"), timeBase, tickBase, tickBaseDivisor)
                            });
                        }
                        else
                        {
                            chapters.Add(new Chapter()
                            {
                                Name = (string)chapter.Attribute("displayName"),
                                Time = GetTimeSpan((string)chapter.Attribute("titleTimeBegin"), timeBase, tickBase, tickBaseDivisor)
                            });
                        }
                        count++;
                    }
                    pgc.Chapters = chapters;
                    OnChaptersLoaded(pgc);
                    //pgc.ChangeFps(24D / 1.001D);
                    pgcs.Add(pgc);
                }
            }
            pgcs = pgcs.OrderByDescending(p => p.Duration).ToList();
            OnExtractionComplete();
            return(pgcs);
        }
예제 #30
0
 public void getAdditionalStreams(out MuxStream[] audio, out MuxStream[] subtitles, out ChapterInfo chapters, out string output, out ContainerType cot)
 {
     cot    = (cbContainer.SelectedItem as ContainerType);
     output = this.output.Filename;
     base.getAdditionalStreams(out audio, out subtitles, out chapters);
 }
예제 #31
0
        private void btInput_Click(object sender, EventArgs e)
        {
            if (rbFromFile.Checked)
            {
                openFileDialog.Filter      = "IFO files (*.ifo)|*.ifo|Container files (*.mkv,*.mp4)|*.mkv;*.mp4|MPLS files (*.mpls)|*.mpls|Chapter files (*.txt,*.xml)|*.txt;*.xml|All supported files (*.ifo,*.mkv,*.mp4,*.mpls,*.txt,*.xml)|*.ifo;*.mkv;*.mp4;*.mpls;*.txt;*.xml";
                openFileDialog.FilterIndex = 5;

                if (this.openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                input.Text = openFileDialog.FileName;
            }
            else
            {
                using (FolderBrowserDialog d = new FolderBrowserDialog())
                {
                    d.ShowNewFolderButton = false;
                    d.Description         = "Select DVD/BluRay disc or folder";
                    if (d.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    input.Text = d.SelectedPath;
                }
            }

            using (frmStreamSelect frm = new frmStreamSelect(input.Text))
            {
                if (frm.TitleCount == 0)
                {
                    MessageBox.Show("No chapters found");
                    return;
                }

                DialogResult dr = DialogResult.OK;
                if (frm.TitleCountWithRequiredLength != 1)
                {
                    dr = frm.ShowDialog();
                }

                if (dr != DialogResult.OK)
                {
                    return;
                }

                pgc = frm.SelectedSingleChapterInfo;
            }

            bNoUpdates = true;
            if (pgc.FramesPerSecond > 0)
            {
                fpsChooserIn.Value = (decimal)pgc.FramesPerSecond;
                bInputFPSKnown     = true;
                if (fpsChooserOut.Value == null)
                {
                    fpsChooserOut.Value = (decimal)pgc.FramesPerSecond;
                }
            }
            else
            {
                fpsChooserIn.Value  = null;
                bInputFPSKnown      = false;
                pgc.FramesPerSecond = 0;
            }
            bNoUpdates = false;

            ResetChapterView(-1);

            chaptersGroupbox.Text = " Chapters ";
            if (chapterListView.Items.Count != 0)
            {
                chapterListView.Items[0].Selected = true;
            }

            string fileName = Path.GetFileNameWithoutExtension(input.Text);

            if (this.pgc.PGCNumber > 0)
            {
                chaptersGroupbox.Text += "- VTS " + pgc.TitleNumber.ToString("D2") + " - PGC " + pgc.PGCNumber.ToString("D2") + " ";
                if (FileUtil.RegExMatch(fileName, @"_\d{1,2}\z", false))
                {
                    // file ends with e.g. _1 as in VTS_01_1
                    fileName  = fileName.Substring(0, fileName.LastIndexOf('_'));
                    fileName += "_" + this.pgc.PGCNumber;
                }
            }

            fileName = FileUtil.GetOutputFilePrefix(input.Text) + fileName + " - Chapter Information.txt";
            if (rbXML.Checked)
            {
                fileName = Path.ChangeExtension(fileName, "xml");
            }
            else if (rbQPF.Checked)
            {
                fileName = Path.ChangeExtension(fileName, "qpf");
            }

            output.Text = Path.Combine(FileUtil.GetOutputFolder(input.Text), fileName);
        }
예제 #32
0
 protected void OnStreamDetected(ChapterInfo pgc)
 {
     if (StreamDetected != null) StreamDetected(this, new ProgramChainArg() { ProgramChain = pgc });
 }
예제 #33
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            ChapterInfo    pgc      = new ChapterInfo();
            List <Chapter> chapters = new List <Chapter>();

            pgc.SourceName = location;
            pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
            pgc.SourceType = "Blu-Ray";
            pgc.Title      = Path.GetFileNameWithoutExtension(location);

            FileInfo fileInfo = new FileInfo(location);

            byte[] data = File.ReadAllBytes(location);

            string fileType = ASCIIEncoding.ASCII.GetString(data, 0, 8);

            if ((fileType != "MPLS0100" && fileType != "MPLS0200")
                /*|| data[45] != 1*/)
            {
                throw new Exception(string.Format(
                                        "Playlist {0} has an unknown file type {1}.",
                                        fileInfo.Name, fileType));
            }

            List <Clip> chapterClips = GetClips(data);

            pgc.Duration = new TimeSpan((long)(chapterClips.Sum(c => c.Length) * (double)TimeSpan.TicksPerSecond));

            int chaptersIndex =
                ((int)data[12] << 24) +
                ((int)data[13] << 16) +
                ((int)data[14] << 8) +
                ((int)data[15]);

            int chaptersLength =
                ((int)data[chaptersIndex] << 24) +
                ((int)data[chaptersIndex + 1] << 16) +
                ((int)data[chaptersIndex + 2] << 8) +
                ((int)data[chaptersIndex + 3]);

            byte[] chapterData = new byte[chaptersLength];
            Array.Copy(data, chaptersIndex + 4, chapterData, 0, chaptersLength);

            int chapterCount  = ((int)chapterData[0] << 8) + chapterData[1];
            int chapterOffset = 2;

            for (int chapterIndex = 0; chapterIndex < chapterCount; chapterIndex++)
            {
                if (chapterData[chapterOffset + 1] == 1)
                {
                    int streamFileIndex =
                        ((int)chapterData[chapterOffset + 2] << 8) +
                        chapterData[chapterOffset + 3];

                    Clip streamClip = chapterClips[streamFileIndex];

                    long chapterTime =
                        ((long)chapterData[chapterOffset + 4] << 24) +
                        ((long)chapterData[chapterOffset + 5] << 16) +
                        ((long)chapterData[chapterOffset + 6] << 8) +
                        ((long)chapterData[chapterOffset + 7]);

                    double chapterSeconds  = (double)chapterTime / 45000D;
                    double relativeSeconds = chapterSeconds - streamClip.TimeIn + streamClip.RelativeTimeIn;
                    chapters.Add(new Chapter()
                    {
                        Name = "Chapter " + (chapterIndex + 1).ToString("D2"),//string.Empty,
                        Time = new TimeSpan((long)(relativeSeconds * (double)TimeSpan.TicksPerSecond))
                    });
                }
                chapterOffset += 14;
            }
            pgc.Chapters = chapters;

            MediaInfoFile oInfo = new MediaInfoFile(pgc.SourceName);

            pgc.FramesPerSecond = oInfo.VideoInfo.FPS;

            OnStreamDetected(pgc);
            OnChaptersLoaded(pgc);
            OnExtractionComplete();
            return(new List <ChapterInfo>()
            {
                pgc
            });
        }
예제 #34
0
        private void btInput_Click(object sender, EventArgs e)
        {
            if (rbFromFile.Checked)
            {
                openFileDialog.Filter      = "IFO files (*.ifo)|*.ifo|MKV files (*.mkv)|*.mkv|MPLS files (*.mpls)|*.mpls|Text files (*.txt)|*.txt|All supported files (*.ifo,*.mkv,*.mpls,*.txt)|*.ifo;*.mkv;*.mpls;*.txt";
                openFileDialog.FilterIndex = 5;

                if (this.openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    input.Text = openFileDialog.FileName;

                    if (input.Text.ToLowerInvariant().EndsWith("ifo"))
                    {
                        ChapterExtractor ex = new DvdExtractor();
                        using (frmStreamSelect frm = new frmStreamSelect(ex))
                        {
                            if (ex is DvdExtractor)
                            {
                                frm.Text = "Select your PGC";
                            }
                            else
                            {
                                frm.Text = "Select your Playlist";
                            }
                            ex.GetStreams(input.Text);
                            if (frm.ChapterCount <= 1 || frm.ShowDialog(this) == DialogResult.OK)
                            {
                                if (frm.ChapterCount == 0)
                                {
                                    if (MainForm.Instance.Settings.ChapterCreatorMinimumLength > 0)
                                    {
                                        MessageBox.Show("No titles found. Please try to reduce the \"Minimum title length\"");
                                    }
                                    else
                                    {
                                        MessageBox.Show("No titles found.");
                                    }
                                    return;
                                }
                                else
                                {
                                    pgc = frm.SelectedSingleChapterInfo;
                                    if (pgc.FramesPerSecond == 0)
                                    {
                                        MediaInfoFile oInfo = new MediaInfoFile(input.Text);
                                        pgc.FramesPerSecond = oInfo.VideoInfo.FPS;
                                    }
                                    if (String.IsNullOrEmpty(pgc.LangCode))
                                    {
                                        pgc.LangCode = "und";
                                    }
                                }
                            }
                        }
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLowerInvariant().EndsWith("mpls"))
                    {
                        ChapterExtractor ex = new MplsExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLowerInvariant().EndsWith("txt"))
                    {
                        ChapterExtractor ex = new TextExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLowerInvariant().EndsWith("mkv"))
                    {
                        ChapterExtractor ex = new MkvExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else
                    {
                        MessageBox.Show("The input file is not supported.");
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                using (FolderBrowserDialog d = new FolderBrowserDialog())
                {
                    d.ShowNewFolderButton = false;
                    d.Description         = "Select DVD, BluRay disc or folder.";
                    if (d.ShowDialog() == DialogResult.OK)
                    {
                        input.Text = d.SelectedPath;
                        try
                        {
                            ChapterExtractor ex =
                                Directory.Exists(Path.Combine(input.Text, "VIDEO_TS")) ?
                                new DvdExtractor() as ChapterExtractor :
                                File.Exists(Path.Combine(input.Text, "VIDEO_TS.IFO")) ?
                                new DvdExtractor() as ChapterExtractor :
                                Directory.Exists(Path.Combine(Path.Combine(input.Text, "BDMV"), "PLAYLIST")) ?
                                new BlurayExtractor() as ChapterExtractor :
                                null;

                            if (ex == null)
                            {
                                MessageBox.Show("The input folder is not supported.");
                                return;
                            }

                            using (frmStreamSelect frm = new frmStreamSelect(ex))
                            {
                                if (ex is DvdExtractor)
                                {
                                    frm.Text = "Select your Title";
                                }
                                else
                                {
                                    frm.Text = "Select your Playlist";
                                }
                                ex.GetStreams(input.Text);
                                if (frm.ChapterCount <= 1 || frm.ShowDialog(this) == DialogResult.OK)
                                {
                                    if (frm.ChapterCount == 0)
                                    {
                                        if (MainForm.Instance.Settings.ChapterCreatorMinimumLength > 0)
                                        {
                                            MessageBox.Show("No titles found. Please try to reduce the \"Minimum title length\"");
                                        }
                                        else
                                        {
                                            MessageBox.Show("No titles found.");
                                        }
                                        return;
                                    }
                                    else
                                    {
                                        pgc = frm.SelectedSingleChapterInfo;
                                        if (pgc.FramesPerSecond == 0)
                                        {
                                            MediaInfoFile oInfo = new MediaInfoFile(input.Text);
                                            pgc.FramesPerSecond = oInfo.VideoInfo.FPS;
                                        }
                                        if (String.IsNullOrEmpty(pgc.LangCode))
                                        {
                                            pgc.LangCode = "und";
                                        }
                                    }
                                }
                            }
                            FreshChapterView();
                            updateTimeLine();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (chapterListView.Items.Count != 0)
            {
                chapterListView.Items[0].Selected = true;
            }

            if (pgc.FramesPerSecond > 0)
            {
                fpsChooser.Value = (decimal)pgc.FramesPerSecond;
                bFPSKnown        = true;
            }
            else
            {
                bFPSKnown = false;
            }

            string path = String.Empty;

            if (Directory.Exists(MainForm.Instance.Settings.DefaultOutputDir) && FileUtil.IsDirWriteable(MainForm.Instance.Settings.DefaultOutputDir))
            {
                path = MainForm.Instance.Settings.DefaultOutputDir;
            }
            else if (!String.IsNullOrEmpty(input.Text) && Directory.Exists(Path.GetDirectoryName(input.Text)) && FileUtil.IsDirWriteable(Path.GetDirectoryName(input.Text)))
            {
                path = Path.GetDirectoryName(input.Text);
            }

            string file = String.Empty;

            if (String.IsNullOrEmpty(Path.GetFileNameWithoutExtension(input.Text)))
            {
                file = "Chapter Information.txt";
            }
            else
            {
                file = Path.GetFileNameWithoutExtension(input.Text) + " - Chapter Information.txt";
            }
            if (rbXML.Checked)
            {
                Path.ChangeExtension(file, "xml");
            }
            else if (rbQPF.Checked)
            {
                Path.ChangeExtension(file, "qpf");
            }

            if (String.IsNullOrEmpty(path))
            {
                output.Text = file;
            }
            else
            {
                output.Text = Path.Combine(path, file);
            }
        }
예제 #35
0
        public ChapterInfo GetChapterInfo(string strMplsFile, double iFPS)
        {
            ChapterInfo pgc = new ChapterInfo();

            byte[] data     = File.ReadAllBytes(strMplsFile);
            string fileType = ASCIIEncoding.ASCII.GetString(data, 0, 8);

            if (fileType != "MPLS0100" && fileType != "MPLS0200" && fileType != "MPLS0300")
            {
                // playlist has an unknown file type
                return(pgc);
            }

            List <Chapter> chapters = new List <Chapter>();

            pgc.SourceFilePath = strMplsFile;
            pgc.SourceType     = "Blu-Ray";
            pgc.Title          = Path.GetFileNameWithoutExtension(strMplsFile);

            List <Clip> chapterClips = GetClips(data);

            pgc.Duration = new TimeSpan((long)(chapterClips.Sum(c => c.Length) * (double)TimeSpan.TicksPerSecond));

            int chaptersIndex =
                ((int)data[12] << 24) +
                ((int)data[13] << 16) +
                ((int)data[14] << 8) +
                ((int)data[15]);

            int chaptersLength =
                ((int)data[chaptersIndex] << 24) +
                ((int)data[chaptersIndex + 1] << 16) +
                ((int)data[chaptersIndex + 2] << 8) +
                ((int)data[chaptersIndex + 3]);

            byte[] chapterData = new byte[chaptersLength];
            Array.Copy(data, chaptersIndex + 4, chapterData, 0, chaptersLength);

            int chapterCount  = ((int)chapterData[0] << 8) + chapterData[1];
            int chapterOffset = 2;

            for (int chapterIndex = 0; chapterIndex < chapterCount; chapterIndex++)
            {
                if (chapterData[chapterOffset + 1] == 1)
                {
                    int streamFileIndex =
                        ((int)chapterData[chapterOffset + 2] << 8) +
                        chapterData[chapterOffset + 3];

                    Clip streamClip = chapterClips[streamFileIndex];

                    long chapterTime =
                        ((long)chapterData[chapterOffset + 4] << 24) +
                        ((long)chapterData[chapterOffset + 5] << 16) +
                        ((long)chapterData[chapterOffset + 6] << 8) +
                        ((long)chapterData[chapterOffset + 7]);

                    double chapterSeconds  = (double)chapterTime / 45000D;
                    double relativeSeconds = chapterSeconds - streamClip.TimeIn + streamClip.RelativeTimeIn;
                    chapters.Add(new Chapter()
                    {
                        Name = "Chapter " + (chapterIndex + 1).ToString("D2"),//string.Empty,
                        Time = new TimeSpan((long)(relativeSeconds * (double)TimeSpan.TicksPerSecond))
                    });
                }
                chapterOffset += 14;
            }
            pgc.Chapters        = chapters;
            pgc.FramesPerSecond = iFPS;

            return(pgc);
        }
예제 #36
0
 protected void OnChaptersLoaded(ChapterInfo pgc)
 {
     if (ChaptersLoaded != null) ChaptersLoaded(this, new ProgramChainArg() { ProgramChain = pgc });
 }