Exemple #1
0
 /// <summary>
 /// reads the d2v file, which is essentially a text file
 /// the first few lines contain the video properties in plain text and the
 /// last line contains the film percentage
 /// this method reads all this information and stores it internally, then
 /// closes the d2v file again
 /// </summary>
 private void readFileProperties()
 {
     info = reader.VideoInfo.Clone();
     using (StreamReader sr = new StreamReader(fileName))
     {
         int    iLineCount = 0;
         string line       = null;
         while ((line = sr.ReadLine()) != null)
         {
             iLineCount++;
             if (iLineCount == 3)
             {
                 string strSourceFile = line;
                 if (File.Exists(strSourceFile))
                 {
                     MediaInfoFile oInfo = new MediaInfoFile(strSourceFile);
                     info.DAR = oInfo.VideoInfo.DAR;
                 }
             }
             if (line.IndexOf("Field_Operation") != -1)
             {
                 string fieldOp = line.Substring(16, 1);
                 this.fieldOperation = Int32.Parse(fieldOp);
             }
             else if (line.IndexOf("FINISHED") != -1 && line.IndexOf("FILM") != -1)                     // dgindex now reports VIDEO % if it's > 50%
             {
                 int    end        = line.IndexOf("%");
                 string percentage = line.Substring(10, end - 10);
                 this.filmPercentage = Double.Parse(percentage, System.Globalization.CultureInfo.InvariantCulture);
             }
         }
     }
 }
Exemple #2
0
        public static MuxableType guessVideoMuxableType(string p, bool useMediaInfo)
        {
            if (string.IsNullOrEmpty(p))
            {
                return(null);
            }
            if (useMediaInfo)
            {
                MediaInfoFile info = new MediaInfoFile(p);
                if (info.Info.HasVideo)
                {
                    return(new MuxableType(info.VideoType, info.VCodec));
                }
                // otherwise we may as well try the other route too
            }
            VideoType vType = guessVideoType(p);

            if (vType != null)
            {
                if (vType.SupportedCodecs.Length == 1)
                {
                    return(new MuxableType(vType, vType.SupportedCodecs[0]));
                }
                else
                {
                    return(new MuxableType(vType, null));
                }
            }
            return(null);
        }
Exemple #3
0
        public static MuxableType guessAudioMuxableType(string p, bool useMediaInfo)
        {
            if (string.IsNullOrEmpty(p))
            {
                return(null);
            }
            if (useMediaInfo)
            {
                MediaInfoFile info = new MediaInfoFile(p);
                if (info.AudioType != null)
                {
                    return(new MuxableType(info.AudioType, info.ACodecs[0]));
                }
            }
            AudioType aType = guessAudioType(p);

            if (aType != null)
            {
                if (aType.SupportedCodecs.Length == 1)
                {
                    return(new MuxableType(aType, aType.SupportedCodecs[0]));
                }
                else
                {
                    return(new MuxableType(aType, null));
                }
            }
            return(null);
        }
Exemple #4
0
        /// <summary>
        /// initializes the ffms reader
        /// </summary>
        /// <param name="fileName">the FFMSIndex source file file that this reader will process</param>
        /// <param name="indexFile">the FFMSIndex index file that this reader will process</param>
        public ffmsFile(string fileName, string indexFile)
        {
            string strScript = "";

            if (!String.IsNullOrEmpty(indexFile) && String.IsNullOrEmpty(fileName))
            {
                this.fileName = indexFile.Substring(0, indexFile.Length - 8);
                indexFile     = null;
            }
            else
            {
                this.fileName = fileName;
            }

            string strDLL = Path.Combine(Path.GetDirectoryName(MainForm.Instance.Settings.FFMSIndexPath), "ffms2.dll");

            strScript = "LoadPlugin(\"" + strDLL + "\")\r\nFFVideoSource(\"" + this.fileName + "\""
                        + (!string.IsNullOrEmpty(indexFile) ? ", cachefile=\"" + indexFile + "\"" : String.Empty)
                        + (MainForm.Instance.Settings.FFMSThreads > 0 ? ", threads=" + MainForm.Instance.Settings.FFMSThreads : String.Empty) + ")";
            reader = AvsFile.ParseScript(strScript);
            info   = reader.VideoInfo.Clone();
            if (File.Exists(this.fileName))
            {
                MediaInfoFile oInfo = new MediaInfoFile(this.fileName);
                info.DAR = oInfo.VideoInfo.DAR;
            }
        }
        protected virtual void doExitConfig()
        {
            if (su.HasError || su.WasAborted)
            {
                return;
            }

            if (String.IsNullOrEmpty(job.Output))
            {
                return;
            }

            if (File.Exists(job.Output))
            {
                MediaInfoFile oInfo = new MediaInfoFile(job.Output, ref log);
            }
            else if (Path.GetExtension(job.Output).ToLower().Equals(".avi"))
            {
                string strFile = Path.GetFileNameWithoutExtension(job.Output) + " (1).avi";
                strFile = Path.Combine(Path.GetDirectoryName(job.Output), strFile);
                if (File.Exists(strFile))
                {
                    MediaInfoFile oInfo = new MediaInfoFile(strFile, ref log);
                }
            }
        }
        public void openVideoFile(string fileName, MediaInfoFile oNewInfo)
        {
            if (oNewInfo == null)
            {
                oInfo = new MediaInfoFile(fileName);
            }
            else
            {
                oInfo = oNewInfo;
            }

            info.CreditsStartFrame = -1;
            info.IntroEndFrame     = -1;
            info.VideoInput        = fileName;
            info.DAR   = oInfo.VideoInfo.DAR;
            info.Zones = null;

            if (MainForm.Instance.Settings.AutoOpenScript)
            {
                openAvisynthScript(fileName);
            }

            string filePath            = FileUtil.GetOutputFolder(fileName);
            string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);

            this.VideoOutput = Path.Combine(filePath, fileNameNoExtension) + MainForm.Instance.Settings.VideoExtension + ".extension";
            this.VideoOutput = Path.ChangeExtension(this.VideoOutput, this.CurrentVideoOutputType.Extension);
            updateIOConfig();
        }
Exemple #7
0
        /// <summary>
        /// initializes the ffms reader
        /// </summary>
        /// <param name="fileName">the FFMSIndex source file file that this reader will process</param>
        /// <param name="indexFile">the FFMSIndex index file that this reader will process</param>
        public ffmsFile(string fileName, string indexFile)
        {
            if (!String.IsNullOrEmpty(indexFile) && String.IsNullOrEmpty(fileName))
            {
                this.fileName = indexFile.Substring(0, indexFile.Length - 8);
                indexFile     = null;
            }
            else
            {
                this.fileName = fileName;
            }

            double        fps   = 0;
            MediaInfoFile oInfo = null;

            if (File.Exists(this.fileName))
            {
                oInfo = new MediaInfoFile(this.fileName);
                if (oInfo.VideoInfo.HasVideo && oInfo.VideoInfo.FPS > 0)
                {
                    fps = oInfo.VideoInfo.FPS;
                }
            }

            reader = AvsFile.ParseScript(VideoUtil.getFFMSVideoInputLine(this.fileName, indexFile, fps), true);
            info   = reader.VideoInfo.Clone();
            if (oInfo != null)
            {
                info.DAR = oInfo.VideoInfo.DAR;
            }
        }
Exemple #8
0
        public static string getAssumeFPS(double fps, string strInput)
        {
            if (fps <= 0)
            {
                if (!File.Exists(strInput))
                {
                    return(String.Empty);
                }
                if (strInput.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ffindex"))
                {
                    strInput = strInput.Substring(0, strInput.Length - 8);
                }
                if (Path.GetExtension(strInput).ToLower(System.Globalization.CultureInfo.InvariantCulture).Equals(".avs"))
                {
                    fps = GetFPSFromAVSFile(strInput);
                    if (fps <= 0)
                    {
                        return(String.Empty);
                    }
                }
                else
                {
                    MediaInfoFile oInfo = new MediaInfoFile(strInput);
                    if (oInfo.VideoInfo.HasVideo && oInfo.VideoInfo.FPS > 0)
                    {
                        fps = oInfo.VideoInfo.FPS;
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
            }

            string strAssumeFPS = ".AssumeFPS(";
            string strFPS       = Math.Round(fps, 3).ToString("F3", System.Globalization.CultureInfo.InvariantCulture);

            switch (strFPS)
            {
            case "23.976": strAssumeFPS += "24000,1001"; break;

            case "29.970": strAssumeFPS += "30000,1001"; break;

            case "59.940": strAssumeFPS += "60000,1001"; break;

            case "119.880": strAssumeFPS += "120000,1001"; break;

            case "24.000": strAssumeFPS += "24,1"; break;

            case "25.000": strAssumeFPS += "25,1"; break;

            case "50.000": strAssumeFPS += "50,1"; break;

            case "100.000": strAssumeFPS += "100,1"; break;

            default: strAssumeFPS += strFPS; break;
            }
            return(strAssumeFPS + ")");
        }
Exemple #9
0
        /// <summary>
        /// initializes the lsmash reader
        /// </summary>
        /// <param name="fileName">the LSMASHIndex source file file that this reader will process</param>
        /// <param name="indexFile">the LSMASHIndex index file that this reader will process</param>
        public lsmashFile(string fileName, string indexFile)
        {
            MediaInfoFile oInfo = null;

            reader = AvsFile.ParseScript(VideoUtil.getLSMASHVideoInputLine(fileName, indexFile, 0, ref oInfo), true);
            info   = reader.VideoInfo.Clone();
            if (oInfo != null)
            {
                info.DAR = oInfo.VideoInfo.DAR;
            }
        }
Exemple #10
0
        protected virtual void doExitConfig()
        {
            if (su.HasError || su.WasAborted)
            {
                return;
            }

            if (!String.IsNullOrEmpty(job.Output) && File.Exists(job.Output))
            {
                MediaInfoFile oInfo = new MediaInfoFile(job.Output, ref log);
            }
        }
 private void initVideoInfo()
 {
     oInfo = null;
     info  = new VideoInfo();
     info.VideoInputChanged += new StringChanged(delegate(object _, string val)
     {
         videoInput.Filename = val;
     });
     info.VideoOutputChanged += new StringChanged(delegate(object _, string val)
     {
         videoOutput.Filename = val;
     });
 }
Exemple #12
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);
        }
Exemple #13
0
        public static string getLSMASHVideoInputLine(string inputFile, string indexFile, double fps, ref MediaInfoFile oInfo)
        {
            UpdateCacher.CheckPackage("lsmash");

            int iVideoBits = 8;

            if (!String.IsNullOrEmpty(indexFile) && String.IsNullOrEmpty(inputFile))
            {
                using (StreamReader sr = new StreamReader(indexFile, System.Text.Encoding.Default))
                {
                    string line = null;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("<InputFilePath>"))
                        {
                            string strSourceFile = line.Substring(15, line.LastIndexOf("</InputFilePath>") - 15);
                            if (File.Exists(strSourceFile))
                            {
                                inputFile = strSourceFile;
                            }
                            break;
                        }
                    }
                }
            }
            if (File.Exists(inputFile) && oInfo == null)
            {
                oInfo = new MediaInfoFile(inputFile);
            }
            if (oInfo != null)
            {
                if (oInfo.VideoInfo.HasVideo)
                {
                    if (fps == 0 && oInfo.VideoInfo.FPS > 0)
                    {
                        fps = oInfo.VideoInfo.FPS;
                    }
                    iVideoBits = oInfo.VideoInfo.BitDepth;
                }
                if (String.IsNullOrEmpty(indexFile) && !oInfo.FileName.Equals(inputFile))
                {
                    indexFile = inputFile;
                    inputFile = oInfo.FileName;
                }
            }

            GetFPSDetails(fps, inputFile, out int fpsnum, out int fpsden);
            return(getLSMASHBasicInputLine(inputFile, indexFile, -1, 0, fpsnum, fpsden, true, iVideoBits));
        }
Exemple #14
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
            });
        }
Exemple #15
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);
        }
Exemple #16
0
        /// <summary>
        /// initializes the lsmash reader
        /// </summary>
        /// <param name="fileName">the LSMASHIndex source file file that this reader will process</param>
        /// <param name="indexFile">the LSMASHIndex index file that this reader will process</param>
        public lsmashFile(string fileName, string indexFile)
        {
            if (!String.IsNullOrEmpty(indexFile) && String.IsNullOrEmpty(fileName))
            {
                using (StreamReader sr = new StreamReader(indexFile, System.Text.Encoding.Default))
                {
                    string line = null;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("<InputFilePath>"))
                        {
                            string strSourceFile = line.Substring(15, line.LastIndexOf("</InputFilePath>") - 15);
                            if (File.Exists(strSourceFile))
                            {
                                this.fileName = strSourceFile;
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                this.fileName = fileName;
            }

            double        fps   = 0;
            MediaInfoFile oInfo = null;

            if (File.Exists(this.fileName))
            {
                oInfo = new MediaInfoFile(this.fileName);
                if (oInfo.VideoInfo.HasVideo && oInfo.VideoInfo.FPS > 0)
                {
                    fps = oInfo.VideoInfo.FPS;
                }
            }

            reader = AvsFile.ParseScript(VideoUtil.getLSMASHVideoInputLine(this.fileName, indexFile, fps));
            info   = reader.VideoInfo.Clone();
            if (oInfo != null)
            {
                info.DAR = oInfo.VideoInfo.DAR;
            }
        }
Exemple #17
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            List <ChapterInfo> pgcs = new List <ChapterInfo>();

            MediaInfoFile oInfo = new MediaInfoFile(location);

            if (!oInfo.HasChapters)
            {
                OnExtractionComplete();
                return(pgcs);
            }

            pgcs.Add(oInfo.ChapterInfo);
            OnStreamDetected(oInfo.ChapterInfo);
            OnChaptersLoaded(oInfo.ChapterInfo);
            OnExtractionComplete();
            return(pgcs);
        }
Exemple #18
0
        protected override void RunInThread()
        {
            try
            {
                // job output file in case of LWLibavVideoSource()
                base.jobOutputFile = job.Input + ".lwi";

                // generate the avs script
                StringBuilder strAVSScript = new StringBuilder();
                MediaInfoFile oInfo        = null;
                strAVSScript.Append(VideoUtil.getLSMASHVideoInputLine(job.Input, job.Output, 0, ref oInfo));
                if (oInfo != null)
                {
                    oInfo.Dispose();
                }
                base.log.LogValue("AviSynth script", strAVSScript.ToString(), ImageType.Information);

                // check if the script has a video track, also this call will create the index file if there is one
                string strErrorText = "no video track found";
                bool   openSuccess  = false;
                try
                {
                    strErrorText = String.Empty;
                    using (AviSynthScriptEnvironment env = new AviSynthScriptEnvironment())
                        using (AviSynthClip a = env.ParseScript(strAVSScript.ToString(), false, false))
                            openSuccess = a.HasVideo;
                }
                catch (Exception ex)
                {
                    strErrorText = ex.Message;
                }
                if (!openSuccess)
                {
                    // avs script has no video track or an error has been thrown
                    base.log.LogEvent(strErrorText, ImageType.Error);
                    su.HasError = true;
                }
            }
            catch (Exception ex)
            {
                base.log.LogValue("Error: ", ex.Message, ImageType.Error);
                su.HasError = true;
            }
        }
Exemple #19
0
        private void vInput_FileSelected(FileBar sender, FileBarEventArgs args)
        {
            MediaInfoFile oInfo = new MediaInfoFile(vInput.Filename);

            fps.Value = (decimal)oInfo.VideoInfo.FPS;

            if (string.IsNullOrEmpty(output.Filename))
            {
                chooseOutputFilename();
            }

            if (String.IsNullOrEmpty(chapters.Filename) && oInfo.HasChapters)
            {
                chapters.Filename = "<internal chapters>";
            }

            fileUpdated();
            checkIO();
        }
Exemple #20
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;
         }
     }
 }
Exemple #21
0
 /// <summary>
 /// reads the dga file, which is essentially a text file
 /// </summary>
 private void readFileProperties()
 {
     info = reader.VideoInfo.Clone();
     using (StreamReader sr = new StreamReader(fileName))
     {
         int    iLineCount = 0;
         string line       = null;
         while ((line = sr.ReadLine()) != null)
         {
             iLineCount++;
             if (iLineCount == 3)
             {
                 string strSourceFile = line;
                 if (File.Exists(strSourceFile))
                 {
                     MediaInfoFile oInfo = new MediaInfoFile(strSourceFile);
                     info.DAR = oInfo.VideoInfo.DAR;
                 }
                 break;
             }
         }
     }
 }
Exemple #22
0
        public int AVSCreatorOpen(string videoInput)
        {
            int           iResult = -1;
            MediaInfoFile iFile   = new MediaInfoFile(videoInput);

            FileIndexerWindow.IndexType oIndexer;

            if (!iFile.recommendIndexer(out oIndexer, true))
            {
                return(iResult);
            }

            if (oIndexer != FileIndexerWindow.IndexType.D2V && oIndexer != FileIndexerWindow.IndexType.DGA &&
                oIndexer != FileIndexerWindow.IndexType.DGI && oIndexer != FileIndexerWindow.IndexType.FFMS &&
                oIndexer != FileIndexerWindow.IndexType.LSMASH)
            {
                return(iResult);
            }

            if (iFile.ContainerFileTypeString.ToUpperInvariant().Equals("AVI"))
            {
                iResult = askAbout3("Do you want to open this file with\r\n" +
                                    "- One Click Encoder (fully automated, easy to use) or\r\n" +
                                    "- File Indexer (manual, advanced) or \r\n" +
                                    "- AviSource (manual, expert, may cause problems)?", "Please choose your prefered way to open this file",
                                    "One Click Encoder", "File Indexer", "AviSource", MessageBoxIcon.Question);
            }
            else
            {
                iResult = askAbout3("Do you want to open this file with\r\n" +
                                    "- One Click Encoder (fully automated, easy to use) or\r\n" +
                                    "- File Indexer (manual, advanced) or \r\n" +
                                    "- DirectShowSource (manual, expert, may cause problems)?", "Please choose your prefered way to open this file",
                                    "One Click Encoder", "File Indexer", "DirectShowSource", MessageBoxIcon.Question);
            }
            return(iResult);
        }
Exemple #23
0
 /// <summary>
 /// reads the dgi file, which is essentially a text file
 /// </summary>
 private void readFileProperties()
 {
     info = reader.VideoInfo.Clone();
     using (StreamReader sr = new StreamReader(fileName))
     {
         string line       = null;
         int    iLineCount = 0;
         while ((line = sr.ReadLine()) != null)
         {
             if (iLineCount == 3)
             {
                 string strSourceFile = line.Substring(0, line.LastIndexOf(" "));
                 strSourceFile = Path.Combine(Path.GetDirectoryName(fileName), strSourceFile);
                 if (File.Exists(strSourceFile))
                 {
                     MediaInfoFile oInfo = new MediaInfoFile(strSourceFile);
                     info.DAR = oInfo.VideoInfo.DAR;
                 }
                 break;
             }
             iLineCount++;
         }
     }
 }
Exemple #24
0
        public bool LoadFile(string strFileName)
        {
            ResetChapterInfo();

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

            // try to get the chapter information from plain chapter files
            FileInfo oFileInfo = new FileInfo(strFileName);

            if (oFileInfo.Length < 20971520) // max 20 MB files are supported to avoid reading large files
            {
                if (LoadText(strFileName) || LoadText2(strFileName) || LoadXML(strFileName))
                {
                    return(true);
                }
            }

            // now try mediainfo
            MediaInfoFile oInfo = new MediaInfoFile(strFileName);

            if (!oInfo.HasChapters)
            {
                return(false);
            }

            Chapters        = oInfo.ChapterInfo.Chapters;
            SourceFilePath  = oInfo.ChapterInfo.SourceFilePath;
            SourceType      = oInfo.ChapterInfo.SourceType;
            FramesPerSecond = oInfo.ChapterInfo.FramesPerSecond;
            Title           = oInfo.ChapterInfo.Title;
            Duration        = oInfo.ChapterInfo.Duration;
            return(true);
        }
Exemple #25
0
        private void generateMetaFile()
        {
            metaFile = Path.ChangeExtension(job.Output, ".meta");
            MuxSettings settings = job.Settings;
            CultureInfo ci       = new CultureInfo("en-us");

            using (StreamWriter sw = new StreamWriter(metaFile, false, Encoding.Default))
            {
                string        vcodecID   = "";
                string        extra      = "";
                string        trackID    = "";
                MediaInfoFile oVideoInfo = null;

                sw.Write("MUXOPT --no-pcr-on-video-pid --new-audio-pes"); // mux options
                if (!string.IsNullOrEmpty(settings.DeviceType) && settings.DeviceType != "Standard")
                {
                    switch (settings.DeviceType)
                    {
                    case "Blu-ray": sw.Write(" --blu-ray"); break;

                    case "AVCHD": sw.Write(" --avchd"); break;
                    }

                    if (settings.ChapterInfo.HasChapters) // chapters are defined
                    {
                        sw.Write(" --custom-chapters" + settings.ChapterInfo.GetChapterTimeLine());
                    }

                    job.Output = Path.GetDirectoryName(job.Output) + "\\" + Path.GetFileNameWithoutExtension(job.Output); // remove m2ts file extension - use folder name only with this mode
                }
                sw.Write(" --vbr --vbv-len=500");                                                                         // mux options
                if (settings.SplitSize.HasValue)
                {
                    sw.Write(" --split-size=" + settings.SplitSize.Value.MB + "MB");
                }

                string fpsString = null;
                string videoFile = null;
                if (!string.IsNullOrEmpty(settings.VideoInput))
                {
                    videoFile = settings.VideoInput;
                }
                else if (!string.IsNullOrEmpty(settings.MuxedInput))
                {
                    videoFile = settings.MuxedInput;
                }
                if (!String.IsNullOrEmpty(videoFile))
                {
                    oVideoInfo = new MediaInfoFile(videoFile, ref log);
                    if (oVideoInfo.HasVideo)
                    {
                        if (oVideoInfo.VideoInfo.Codec == VideoCodec.AVC)
                        {
                            vcodecID = "V_MPEG4/ISO/AVC";
                            extra    = "insertSEI, contSPS";
                        }
                        else if (oVideoInfo.VideoInfo.Codec == VideoCodec.HEVC)
                        {
                            vcodecID = "V_MPEGH/ISO/HEVC";
                        }
                        else if (oVideoInfo.VideoInfo.Codec == VideoCodec.MPEG2)
                        {
                            vcodecID = "V_MPEG-2";
                        }
                        else if (oVideoInfo.VideoInfo.Codec == VideoCodec.VC1)
                        {
                            vcodecID = "V_MS/VFW/WVC1";
                        }

                        if (oVideoInfo.ContainerFileType == ContainerType.MP4)
                        {
                            trackID = "track=1";
                        }
                        else if (oVideoInfo.ContainerFileType == ContainerType.MKV || oVideoInfo.ContainerFileType == ContainerType.M2TS)
                        {
                            trackID = "track=" + oVideoInfo.VideoInfo.Track.TrackID;
                        }

                        sw.Write("\n" + vcodecID + ", ");
                        sw.Write("\"" + videoFile + "\"");

                        if (settings.DAR.HasValue)
                        {
                            sw.Write(", ar=" + settings.DAR.Value.X + ":" + settings.DAR.Value.Y);
                        }

                        fpsString = oVideoInfo.VideoInfo.FPS.ToString(ci);
                        if (settings.Framerate.HasValue)
                        {
                            fpsString = settings.Framerate.Value.ToString(ci);
                        }
                        sw.Write(", fps=" + fpsString);

                        if (!String.IsNullOrEmpty(extra))
                        {
                            sw.Write(", " + extra);
                        }

                        if (!String.IsNullOrEmpty(trackID))
                        {
                            sw.Write(", " + trackID);
                        }
                    }
                    else
                    {
                        log.Error("No video track found: " + videoFile);
                    }
                }

                foreach (object o in settings.AudioStreams)
                {
                    MuxStream stream   = (MuxStream)o;
                    string    acodecID = "";

                    MediaInfoFile oInfo = new MediaInfoFile(stream.path, ref log);

                    if (!oInfo.HasAudio)
                    {
                        log.Error("No audio track found: " + stream.path);
                        continue;
                    }

                    if (oInfo.AudioInfo.Tracks[0].AudioCodec == AudioCodec.AC3 || oInfo.AudioInfo.Tracks[0].AudioCodec == AudioCodec.EAC3 ||
                        oInfo.AudioInfo.Tracks[0].AudioCodec == AudioCodec.THDAC3)
                    {
                        acodecID = "A_AC3";
                    }
                    else if (oInfo.AudioInfo.Tracks[0].AudioCodec == AudioCodec.AAC)
                    {
                        acodecID = "A_AAC";
                    }
                    else if (oInfo.AudioInfo.Tracks[0].AudioCodec == AudioCodec.DTS)
                    {
                        acodecID = "A_DTS";
                    }
                    else if (oInfo.AudioInfo.Tracks[0].AudioCodec == AudioCodec.PCM)
                    {
                        acodecID = "A_LPCM";
                    }
                    else
                    {
                        log.Error("Audio Codec not supported: " + oInfo.AudioInfo.Tracks[0].Codec);
                        continue;
                    }

                    sw.Write("\n" + acodecID + ", ");
                    sw.Write("\"" + stream.path + "\"");

                    if (stream.delay != 0)
                    {
                        sw.Write(", timeshift={0}ms", stream.delay);
                    }

                    if (!String.IsNullOrEmpty(stream.language))
                    {
                        foreach (KeyValuePair <string, string> strLanguage in LanguageSelectionContainer.Languages)
                        {
                            if (stream.language.ToLowerInvariant().Equals(strLanguage.Key.ToLowerInvariant()))
                            {
                                sw.Write(", lang=" + strLanguage.Value);
                                break;
                            }
                        }
                    }
                }

                foreach (object o in settings.SubtitleStreams)
                {
                    MuxStream stream   = (MuxStream)o;
                    string    scodecID = "";

                    if (stream.path.ToLowerInvariant().EndsWith(".srt"))
                    {
                        scodecID = "S_TEXT/UTF8";
                    }
                    else
                    {
                        scodecID = "S_HDMV/PGS"; // sup files
                    }
                    sw.Write("\n" + scodecID + ", ");
                    sw.Write("\"" + stream.path + "\"");

                    if (stream.delay != 0)
                    {
                        sw.Write(", timeshift={0}ms", stream.delay);
                    }

                    if (stream.path.ToLowerInvariant().EndsWith(".srt") && oVideoInfo != null && !String.IsNullOrEmpty(fpsString))
                    {
                        sw.Write(", video-width={0}, video-height={1}, fps={2}", oVideoInfo.VideoInfo.Width, oVideoInfo.VideoInfo.Height, fpsString);
                    }

                    if (!String.IsNullOrEmpty(stream.language))
                    {
                        foreach (KeyValuePair <string, string> strLanguage in LanguageSelectionContainer.Languages)
                        {
                            if (stream.language.ToLowerInvariant().Equals(strLanguage.Key.ToLowerInvariant()))
                            {
                                sw.Write(", lang=" + strLanguage.Value);
                                break;
                            }
                        }
                    }
                }
            }

            job.FilesToDelete.Add(metaFile);
            if (File.Exists(metaFile))
            {
                string strMuxFile = String.Empty;
                try
                {
                    StreamReader sr = new StreamReader(metaFile);
                    strMuxFile = sr.ReadToEnd();
                    sr.Close();
                }
                catch (Exception)
                {
                }
                log.LogValue("mux script", strMuxFile);
            }
        }
        private void StartPostProcessing()
        {
            Thread t = null;

            try
            {
                _log.LogEvent("Processing thread started");
                raiseEvent("Preprocessing...   ***PLEASE WAIT***");
                _start = DateTime.Now;
                t      = new Thread(new ThreadStart(delegate
                {
                    while (true)
                    {
                        updateTime();
                        Thread.Sleep(1000);
                    }
                }));
                t.Start();

                List <string> arrAudioFilesDelete = new List <string>();
                audioFiles = new Dictionary <int, string>();
                List <AudioTrackInfo> arrAudioTracks    = new List <AudioTrackInfo>();
                List <AudioJob>       arrAudioJobs      = new List <AudioJob>();
                List <MuxStream>      arrMuxStreams     = new List <MuxStream>();
                List <string>         intermediateFiles = new List <string>();

                FileUtil.ensureDirectoryExists(job.PostprocessingProperties.WorkingDirectory);
                foreach (OneClickAudioTrack oAudioTrack in job.PostprocessingProperties.AudioTracks)
                {
                    if (oAudioTrack.ExtractMKVTrack)
                    {
                        audioFiles.Add(oAudioTrack.AudioTrackInfo.TrackID, job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName);
                        arrAudioFilesDelete.Add(job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName);
                    }
                    else if (oAudioTrack.AudioTrackInfo != null)
                    {
                        arrAudioTracks.Add(oAudioTrack.AudioTrackInfo);
                    }
                    if (oAudioTrack.AudioJob != null)
                    {
                        if (job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.NONE &&
                            String.IsNullOrEmpty(oAudioTrack.AudioJob.Input))
                        {
                            oAudioTrack.AudioJob.Input = job.Input;
                        }
                        arrAudioJobs.Add(oAudioTrack.AudioJob);
                    }
                    if (oAudioTrack.DirectMuxAudio != null)
                    {
                        arrMuxStreams.Add(oAudioTrack.DirectMuxAudio);
                    }
                }
                if (audioFiles.Count == 0 && job.PostprocessingProperties.IndexType != FileIndexerWindow.IndexType.NONE && !job.PostprocessingProperties.Eac3toDemux)
                {
                    audioFiles = vUtil.getAllDemuxedAudio(arrAudioTracks, new List <AudioTrackInfo>(), out arrAudioFilesDelete, job.IndexFile, _log);
                }

                fillInAudioInformation(arrAudioJobs, arrMuxStreams);

                if (!String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux))
                {
                    _log.LogEvent("Don't encode video: True");
                }
                else
                {
                    _log.LogEvent("Desired size: " + job.PostprocessingProperties.OutputSize);
                }
                _log.LogEvent("Split size: " + job.PostprocessingProperties.Splitting);


                // chapter file handling
                if (String.IsNullOrEmpty(job.PostprocessingProperties.ChapterFile))
                {
                    job.PostprocessingProperties.ChapterFile = null;
                }
                else if (job.PostprocessingProperties.Container == ContainerType.AVI)
                {
                    _log.LogEvent("Chapter handling disabled because of the AVI target container");
                    job.PostprocessingProperties.ChapterFile = null;
                }
                else if (!File.Exists(job.PostprocessingProperties.ChapterFile))
                {
                    if (job.PostprocessingProperties.ChapterFile.StartsWith("<") || job.PostprocessingProperties.ChapterExtracted)
                    {
                        // internal chapter file
                        string strTempFile = job.PostprocessingProperties.ChapterFile;
                        if (Path.GetExtension(job.PostprocessingProperties.VideoInput).ToLower(System.Globalization.CultureInfo.InvariantCulture).Equals(".mkv"))
                        {
                            MediaInfoFile oInfo = new MediaInfoFile(job.PostprocessingProperties.VideoInput, ref _log);
                            if (oInfo.hasMKVChapters())
                            {
                                job.PostprocessingProperties.ChapterFile = Path.Combine(job.PostprocessingProperties.WorkingDirectory, Path.GetFileNameWithoutExtension(job.IndexFile) + " - Chapter Information.txt");
                                if (oInfo.extractMKVChapters(job.PostprocessingProperties.ChapterFile))
                                {
                                    intermediateFiles.Add(job.PostprocessingProperties.ChapterFile);
                                    job.PostprocessingProperties.ChapterExtracted = true;
                                }
                                else
                                {
                                    job.PostprocessingProperties.ChapterFile = strTempFile;
                                }
                            }
                        }
                        else if (File.Exists(job.PostprocessingProperties.IFOInput))
                        {
                            job.PostprocessingProperties.ChapterFile = VideoUtil.getChaptersFromIFO(job.PostprocessingProperties.IFOInput, false, job.PostprocessingProperties.WorkingDirectory, job.PostprocessingProperties.TitleNumberToProcess);
                            if (!String.IsNullOrEmpty(job.PostprocessingProperties.ChapterFile))
                            {
                                intermediateFiles.Add(job.PostprocessingProperties.ChapterFile);
                                job.PostprocessingProperties.ChapterExtracted = true;
                            }
                            else
                            {
                                job.PostprocessingProperties.ChapterFile = strTempFile;
                            }
                        }
                    }
                    if (!File.Exists(job.PostprocessingProperties.ChapterFile))
                    {
                        _log.LogEvent("File not found: " + job.PostprocessingProperties.ChapterFile, ImageType.Error);
                        job.PostprocessingProperties.ChapterFile = null;
                    }
                }
                else if (job.PostprocessingProperties.ChapterExtracted)
                {
                    intermediateFiles.Add(job.PostprocessingProperties.ChapterFile);
                }

                string             avsFile       = String.Empty;
                VideoStream        myVideo       = new VideoStream();
                VideoCodecSettings videoSettings = job.PostprocessingProperties.VideoSettings;
                if (String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux))
                {
                    //Open the video
                    Dar?dar;
                    avsFile = createAVSFile(job.IndexFile, job.Input, job.PostprocessingProperties.DAR,
                                            job.PostprocessingProperties.HorizontalOutputResolution, job.PostprocessingProperties.SignalAR, _log,
                                            job.PostprocessingProperties.AvsSettings, job.PostprocessingProperties.AutoDeinterlace, videoSettings, out dar,
                                            job.PostprocessingProperties.AutoCrop, job.PostprocessingProperties.KeepInputResolution,
                                            job.PostprocessingProperties.UseChaptersMarks);

                    ulong  length;
                    double framerate;
                    JobUtil.getInputProperties(out length, out framerate, avsFile);
                    myVideo.Input  = avsFile;
                    myVideo.Output = Path.Combine(job.PostprocessingProperties.WorkingDirectory,
                                                  Path.GetFileNameWithoutExtension(job.Input) + "_Video");
                    myVideo.NumberOfFrames = length;
                    myVideo.Framerate      = (decimal)framerate;
                    myVideo.DAR            = dar;
                    myVideo.VideoType      = new MuxableType((new VideoEncoderProvider().GetSupportedOutput(videoSettings.EncoderType))[0], videoSettings.Codec);
                    myVideo.Settings       = videoSettings;
                }
                else
                {
                    myVideo.Output   = job.PostprocessingProperties.VideoFileToMux;
                    myVideo.Settings = videoSettings;

                    MediaInfoFile oInfo = new MediaInfoFile(myVideo.Output, ref _log);
                    videoSettings.VideoName = oInfo.VideoInfo.Track.Name;
                    myVideo.Framerate       = (decimal)oInfo.VideoInfo.FPS;
                }

                intermediateFiles.Add(avsFile);
                intermediateFiles.Add(job.IndexFile);
                intermediateFiles.AddRange(audioFiles.Values);
                if (!string.IsNullOrEmpty(qpfile))
                {
                    intermediateFiles.Add(qpfile);
                }
                foreach (string file in arrAudioFilesDelete)
                {
                    intermediateFiles.Add(file);
                }
                if (File.Exists(Path.Combine(Path.GetDirectoryName(job.Input), Path.GetFileNameWithoutExtension(job.Input) + "._log")))
                {
                    intermediateFiles.Add(Path.Combine(Path.GetDirectoryName(job.Input), Path.GetFileNameWithoutExtension(job.Input) + "._log"));
                }
                foreach (string file in job.PostprocessingProperties.FilesToDelete)
                {
                    intermediateFiles.Add(file);
                }

                if (!string.IsNullOrEmpty(avsFile) || !String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux))
                {
                    MuxStream[] subtitles;
                    if (job.PostprocessingProperties.SubtitleTracks.Count == 0)
                    {
                        //Create empty subtitles for muxing
                        subtitles = new MuxStream[0];
                    }
                    else
                    {
                        subtitles = new MuxStream[job.PostprocessingProperties.SubtitleTracks.Count];
                        int i = 0;
                        foreach (OneClickStream oTrack in job.PostprocessingProperties.SubtitleTracks)
                        {
                            if (oTrack.TrackInfo.IsMKVContainer())
                            {
                                //demuxed MKV
                                string trackFile = Path.GetDirectoryName(job.IndexFile) + "\\" + oTrack.TrackInfo.DemuxFileName;
                                if (File.Exists(trackFile))
                                {
                                    intermediateFiles.Add(trackFile);
                                    if (Path.GetExtension(trackFile).ToLower(System.Globalization.CultureInfo.InvariantCulture).Equals(".idx"))
                                    {
                                        intermediateFiles.Add(FileUtil.GetPathWithoutExtension(trackFile) + ".sub");
                                    }

                                    subtitles[i] = new MuxStream(trackFile, oTrack.Language, oTrack.Name, oTrack.Delay, oTrack.DefaultStream, oTrack.ForcedStream, null);
                                }
                                else
                                {
                                    _log.LogEvent("File not found: " + trackFile, ImageType.Error);
                                }
                            }
                            else
                            {
                                subtitles[i] = new MuxStream(oTrack.DemuxFilePath, oTrack.Language, oTrack.Name, oTrack.Delay, oTrack.DefaultStream, oTrack.ForcedStream, null);
                            }
                            i++;
                        }
                    }

                    JobChain c = vUtil.GenerateJobSeries(myVideo, job.PostprocessingProperties.FinalOutput, arrAudioJobs.ToArray(),
                                                         subtitles, job.PostprocessingProperties.ChapterFile, job.PostprocessingProperties.OutputSize,
                                                         job.PostprocessingProperties.Splitting, job.PostprocessingProperties.Container,
                                                         job.PostprocessingProperties.PrerenderJob, arrMuxStreams.ToArray(),
                                                         _log, job.PostprocessingProperties.DeviceOutputType, null, job.PostprocessingProperties.VideoFileToMux, job.PostprocessingProperties.AudioTracks.ToArray());
                    if (c == null)
                    {
                        _log.Warn("Job creation aborted");
                        return;
                    }

                    c = CleanupJob.AddAfter(c, intermediateFiles, job.PostprocessingProperties.FinalOutput);
                    mainForm.Jobs.addJobsWithDependencies(c);

                    // batch processing other input files if necessary
                    if (job.PostprocessingProperties.FilesToProcess.Count > 0)
                    {
                        OneClickWindow ocw = new OneClickWindow(mainForm);
                        ocw.setBatchProcessing(job.PostprocessingProperties.FilesToProcess, job.PostprocessingProperties.OneClickSetting);
                    }
                }
            }
            catch (Exception e)
            {
                t.Abort();
                if (e is ThreadAbortException)
                {
                    _log.LogEvent("Aborting...");
                    su.WasAborted = true;
                    su.IsComplete = true;
                    raiseEvent();
                }
                else
                {
                    _log.LogValue("An error occurred", e, ImageType.Error);
                    su.HasError   = true;
                    su.IsComplete = true;
                    raiseEvent();
                }
                return;
            }
            t.Abort();
            su.IsComplete = true;
            raiseEvent();
        }
Exemple #27
0
        private void openVideo(string fileName)
        {
            setControlState(true);

            this._oLog = MainForm.Instance.FileIndexerLog;
            if (_oLog == null)
            {
                _oLog = MainForm.Instance.Log.Info("FileIndexer");
                MainForm.Instance.FileIndexerLog = _oLog;
            }

            gbFileInformation.Text = " File Information ";
            iFile = null;
            if (GetDVDorBluraySource(fileName, ref iFile))
            {
                if (iFile != null)
                {
                    fileName = iFile.FileName;
                    string strText = (iFile.VideoInfo.PGCNumber > 1 ? " - PGC " + iFile.VideoInfo.PGCNumber.ToString("D2") : string.Empty) + (iFile.VideoInfo.AngleNumber > 0 ? " - Angle " + iFile.VideoInfo.AngleNumber + " " : string.Empty);
                    if (strText.Trim().Length > 0)
                    {
                        gbFileInformation.Text += strText.Trim() + " ";
                    }
                }
            }
            else
            {
                iFile = new MediaInfoFile(fileName, ref _oLog);
            }

            if (iFile != null && iFile.HasVideo)
            {
                strVideoCodec      = iFile.VideoInfo.Track.Codec;
                strVideoScanType   = iFile.VideoInfo.ScanType;
                strContainerFormat = iFile.ContainerFileTypeString;
            }
            else
            {
                strVideoCodec = strVideoScanType = strContainerFormat = string.Empty;
            }

            if (String.IsNullOrEmpty(strVideoCodec))
            {
                txtCodecInformation.Text = " unknown";
            }
            else
            {
                txtCodecInformation.Text = " " + strVideoCodec;
            }
            if (String.IsNullOrEmpty(strContainerFormat))
            {
                txtContainerInformation.Text = " unknown";
            }
            else
            {
                txtContainerInformation.Text = " " + strContainerFormat;
            }
            if (String.IsNullOrEmpty(strVideoScanType))
            {
                txtScanTypeInformation.Text = " unknown";
            }
            else
            {
                txtScanTypeInformation.Text = " " + strVideoScanType;
            }

            if (iFile != null && iFile.HasAudio)
            {
                audioTracks = iFile.AudioInfo.Tracks;
            }
            else
            {
                audioTracks = new List <AudioTrackInfo>();
            }

            if (input.Filename != fileName)
            {
                input.Filename = fileName;
            }

            generateAudioList();

            if (iFile != null)
            {
                IndexType newType = IndexType.NONE;
                iFile.recommendIndexer(out newType);
                if (newType == IndexType.D2V || newType == IndexType.DGM ||
                    newType == IndexType.DGI || newType == IndexType.FFMS ||
                    newType == IndexType.LSMASH)
                {
                    btnD2V.Enabled    = iFile.isD2VIndexable();
                    btnDGM.Enabled    = iFile.isDGMIndexable();
                    btnDGI.Enabled    = iFile.isDGIIndexable();
                    btnFFMS.Enabled   = iFile.isFFMSIndexable();
                    btnLSMASH.Enabled = iFile.isLSMASHIndexable();

                    gbIndexer.Enabled = gbAudio.Enabled = gbOutput.Enabled = true;
                    changeIndexer(newType);
                    setControlState(false);
                    return;
                }
            }

            // source file not supported
            btnD2V.Enabled             = btnDGM.Enabled = btnDGI.Enabled = btnFFMS.Enabled = btnLSMASH.Enabled = false;
            gbIndexer.Enabled          = gbAudio.Enabled = gbOutput.Enabled = false;
            btnFFMS.Checked            = btnD2V.Checked = btnDGM.Checked = btnDGI.Checked = btnLSMASH.Checked = false;
            output.Filename            = "";
            demuxNoAudiotracks.Checked = true;
            setControlState(false);
            MessageBox.Show("No indexer for this file found!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
Exemple #28
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            List <ChapterInfo> pgcs            = new List <ChapterInfo>();
            List <Chapter>     list            = new List <Chapter>();
            string             tempChapterFile = String.Empty;

            do
            {
                tempChapterFile = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), Path.GetRandomFileName());
            }while (File.Exists(tempChapterFile));

            MediaInfoFile oInfo = new MediaInfoFile(location);

            if (!oInfo.hasMKVChapters() || !oInfo.extractMKVChapters(tempChapterFile))
            {
                OnExtractionComplete();
                return(pgcs);
            }

            int      num    = 0;
            TimeSpan ts     = new TimeSpan(0);
            string   time   = String.Empty;
            string   name   = String.Empty;
            bool     onTime = true;

            string[] lines = File.ReadAllLines(tempChapterFile);
            foreach (string line in lines)
            {
                if (onTime)
                {
                    num++;
                    //read time
                    time = line.Replace("CHAPTER" + num.ToString("00") + "=", "");
                    ts   = TimeSpan.Parse(time);
                }
                else
                {
                    //read name
                    name = line.Replace("CHAPTER" + num.ToString("00") + "NAME=", "");
                    //add it to list
                    list.Add(new Chapter()
                    {
                        Name = name, Time = ts
                    });
                }
                onTime = !onTime;
            }

            pgcs.Add(new ChapterInfo()
            {
                Chapters        = list,
                SourceName      = location,
                SourceHash      = ChapterExtractor.ComputeMD5Sum(tempChapterFile),
                FramesPerSecond = oInfo.VideoInfo.FPS,
                Title           = Path.GetFileNameWithoutExtension(location)
            });

            try { File.Delete(tempChapterFile); } catch {}

            OnStreamDetected(pgcs[0]);
            OnChaptersLoaded(pgcs[0]);
            OnExtractionComplete();
            return(pgcs);
        }
Exemple #29
0
        protected override void RunInThread()
        {
            JobChain      c = null;
            List <string> intermediateFiles = new List <string>();
            bool          bError            = false;

            try
            {
                log.LogEvent("Processing thread started");
                su.Status = "Preprocessing...   ***PLEASE WAIT***";
                su.ResetTime();

                List <string> arrAudioFilesDelete = new List <string>();
                audioFiles = new Dictionary <int, string>();
                List <AudioTrackInfo> arrAudioTracks = new List <AudioTrackInfo>();
                List <AudioJob>       arrAudioJobs   = new List <AudioJob>();
                List <MuxStream>      arrMuxStreams  = new List <MuxStream>();
                FileUtil.ensureDirectoryExists(job.PostprocessingProperties.WorkingDirectory);

                // audio handling
                foreach (OneClickAudioTrack oAudioTrack in job.PostprocessingProperties.AudioTracks)
                {
                    if (IsJobStopped())
                    {
                        return;
                    }

                    if (oAudioTrack.AudioTrackInfo != null)
                    {
                        if (oAudioTrack.AudioTrackInfo.ExtractMKVTrack)
                        {
                            if (job.PostprocessingProperties.ApplyDelayCorrection && File.Exists(job.PostprocessingProperties.IntermediateMKVFile))
                            {
                                MediaInfoFile oFile  = new MediaInfoFile(job.PostprocessingProperties.IntermediateMKVFile, ref log);
                                bool          bFound = false;
                                foreach (AudioTrackInfo oAudioInfo in oFile.AudioInfo.Tracks)
                                {
                                    if (oAudioInfo.MMGTrackID == oAudioTrack.AudioTrackInfo.MMGTrackID)
                                    {
                                        bFound = true;
                                    }
                                }
                                int mmgTrackID = 0;
                                if (!bFound)
                                {
                                    mmgTrackID = oFile.AudioInfo.Tracks[oAudioTrack.AudioTrackInfo.TrackIndex].MMGTrackID;
                                }
                                else
                                {
                                    mmgTrackID = oAudioTrack.AudioTrackInfo.MMGTrackID;
                                }
                                foreach (AudioTrackInfo oAudioInfo in oFile.AudioInfo.Tracks)
                                {
                                    if (oAudioInfo.MMGTrackID == mmgTrackID)
                                    {
                                        if (oAudioTrack.DirectMuxAudio != null)
                                        {
                                            oAudioTrack.DirectMuxAudio.delay = oAudioInfo.Delay;
                                        }
                                        if (oAudioTrack.AudioJob != null)
                                        {
                                            oAudioTrack.AudioJob.Delay = oAudioInfo.Delay;
                                        }
                                        break;
                                    }
                                }
                            }
                            if (!audioFiles.ContainsKey(oAudioTrack.AudioTrackInfo.TrackID))
                            {
                                audioFiles.Add(oAudioTrack.AudioTrackInfo.TrackID, job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName);
                                arrAudioFilesDelete.Add(job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName);
                            }
                        }
                        else
                        {
                            arrAudioTracks.Add(oAudioTrack.AudioTrackInfo);
                        }
                    }
                    if (oAudioTrack.AudioJob != null)
                    {
                        if (job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.NONE &&
                            String.IsNullOrEmpty(oAudioTrack.AudioJob.Input))
                        {
                            oAudioTrack.AudioJob.Input = job.Input;
                        }
                        arrAudioJobs.Add(oAudioTrack.AudioJob);
                    }
                    if (oAudioTrack.DirectMuxAudio != null)
                    {
                        arrMuxStreams.Add(oAudioTrack.DirectMuxAudio);
                    }
                }
                if (audioFiles.Count == 0 && !job.PostprocessingProperties.Eac3toDemux &&
                    job.PostprocessingProperties.IndexType != FileIndexerWindow.IndexType.NONE &&
                    job.PostprocessingProperties.IndexType != FileIndexerWindow.IndexType.AVISOURCE)
                {
                    if ((job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.DGI || job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.DGM) &&
                        File.Exists(Path.ChangeExtension(job.IndexFile, ".log")))
                    {
                        job.PostprocessingProperties.FilesToDelete.Add(Path.ChangeExtension(job.IndexFile, ".log"));
                        audioFiles = AudioUtil.GetAllDemuxedAudioFromDGI(arrAudioTracks, out arrAudioFilesDelete, job.IndexFile, log);
                    }
                    else
                    {
                        audioFiles = VideoUtil.getAllDemuxedAudio(arrAudioTracks, new List <AudioTrackInfo>(), out arrAudioFilesDelete, job.IndexFile, log);
                    }
                }

                FillInAudioInformation(ref arrAudioJobs, arrMuxStreams);

                if (!String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux))
                {
                    log.LogEvent("Don't encode video: True");
                }
                else
                {
                    log.LogEvent("Desired size: " + job.PostprocessingProperties.OutputSize);
                }
                log.LogEvent("Split size: " + job.PostprocessingProperties.Splitting);

                if (IsJobStopped())
                {
                    return;
                }

                // video file handling
                string             avsFile       = String.Empty;
                VideoStream        myVideo       = new VideoStream();
                VideoCodecSettings videoSettings = job.PostprocessingProperties.VideoSettings;
                if (String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux))
                {
                    //Open the video
                    try
                    {
                        avsFile = CreateAVSFile(job.IndexFile, job.Input, job.PostprocessingProperties.DAR,
                                                job.PostprocessingProperties.HorizontalOutputResolution, log,
                                                job.PostprocessingProperties.AvsSettings, job.PostprocessingProperties.AutoDeinterlace, videoSettings,
                                                job.PostprocessingProperties.AutoCrop, job.PostprocessingProperties.KeepInputResolution,
                                                job.PostprocessingProperties.UseChaptersMarks);
                    }
                    catch (Exception ex)
                    {
                        log.LogValue("An error occurred creating the AVS file", ex, ImageType.Error);
                    }

                    if (IsJobStopped())
                    {
                        return;
                    }

                    if (!String.IsNullOrEmpty(avsFile))
                    {
                        // check AVS file
                        JobUtil.GetInputProperties(avsFile, out ulong frameCount, out double frameRate);

                        myVideo.Input          = avsFile;
                        myVideo.Output         = Path.Combine(job.PostprocessingProperties.WorkingDirectory, Path.GetFileNameWithoutExtension(job.Input) + "_Video");
                        myVideo.NumberOfFrames = frameCount;
                        myVideo.Framerate      = (decimal)frameRate;
                        myVideo.VideoType      = new MuxableType((new VideoEncoderProvider().GetSupportedOutput(videoSettings.EncoderType))[0], videoSettings.Codec);
                        myVideo.Settings       = videoSettings;
                    }
                    else
                    {
                        bError = true;
                    }
                }
                else
                {
                    myVideo.DAR    = job.PostprocessingProperties.ForcedDAR;
                    myVideo.Output = job.PostprocessingProperties.VideoFileToMux;
                    MediaInfoFile oInfo = new MediaInfoFile(myVideo.Output, ref log);
                    if (Path.GetExtension(job.PostprocessingProperties.VideoFileToMux).Equals(".unknown") && !String.IsNullOrEmpty(oInfo.ContainerFileTypeString))
                    {
                        job.PostprocessingProperties.VideoFileToMux = Path.ChangeExtension(job.PostprocessingProperties.VideoFileToMux, oInfo.ContainerFileTypeString.ToLowerInvariant());
                        File.Move(myVideo.Output, job.PostprocessingProperties.VideoFileToMux);
                        myVideo.Output = job.PostprocessingProperties.VideoFileToMux;
                        job.PostprocessingProperties.FilesToDelete.Add(myVideo.Output);
                    }

                    myVideo.Settings       = videoSettings;
                    myVideo.Framerate      = (decimal)oInfo.VideoInfo.FPS;
                    myVideo.NumberOfFrames = oInfo.VideoInfo.FrameCount;
                }

                if (IsJobStopped())
                {
                    return;
                }

                intermediateFiles.Add(avsFile);
                intermediateFiles.Add(job.IndexFile);
                intermediateFiles.AddRange(audioFiles.Values);
                foreach (string file in arrAudioFilesDelete)
                {
                    intermediateFiles.Add(file);
                }
                intermediateFiles.Add(Path.ChangeExtension(job.Input, ".log"));
                foreach (string file in job.PostprocessingProperties.FilesToDelete)
                {
                    intermediateFiles.Add(file);
                }

                // subtitle handling
                List <MuxStream> subtitles = new List <MuxStream>();
                if (job.PostprocessingProperties.SubtitleTracks.Count > 0)
                {
                    foreach (OneClickStream oTrack in job.PostprocessingProperties.SubtitleTracks)
                    {
                        if (oTrack.TrackInfo.ExtractMKVTrack)
                        {
                            //demuxed MKV
                            string trackFile = Path.GetDirectoryName(job.IndexFile) + "\\" + oTrack.TrackInfo.DemuxFileName;
                            if (File.Exists(trackFile))
                            {
                                intermediateFiles.Add(trackFile);
                                if (Path.GetExtension(trackFile).ToLowerInvariant().Equals(".idx"))
                                {
                                    intermediateFiles.Add(FileUtil.GetPathWithoutExtension(trackFile) + ".sub");
                                }

                                subtitles.Add(new MuxStream(trackFile, oTrack.Language, oTrack.Name, oTrack.Delay, oTrack.DefaultStream, oTrack.ForcedStream, null));
                            }
                            else
                            {
                                log.LogEvent("Ignoring subtitle as the it cannot be found: " + trackFile, ImageType.Warning);
                            }
                        }
                        else
                        {
                            // sometimes the language is detected differently by vsrip and the IFO parser. Therefore search also for other files
                            string strDemuxFile = oTrack.DemuxFilePath;
                            if (!File.Exists(strDemuxFile) && Path.GetFileNameWithoutExtension(strDemuxFile).Contains("_"))
                            {
                                string strDemuxFileName = Path.GetFileNameWithoutExtension(strDemuxFile);
                                strDemuxFileName = strDemuxFileName.Substring(0, strDemuxFileName.LastIndexOf("_")) + "_*" + Path.GetExtension(strDemuxFile);
                                foreach (string strFileName in Directory.GetFiles(Path.GetDirectoryName(strDemuxFile), strDemuxFileName))
                                {
                                    strDemuxFile = Path.Combine(Path.GetDirectoryName(strDemuxFile), strFileName);
                                    intermediateFiles.Add(strDemuxFile);
                                    intermediateFiles.Add(Path.ChangeExtension(strDemuxFile, ".sub"));
                                    log.LogEvent("Subtitle + " + oTrack.DemuxFilePath + " cannot be found. " + strFileName + " will be used instead", ImageType.Information);
                                    break;
                                }
                            }
                            if (File.Exists(strDemuxFile))
                            {
                                string strTrackName = oTrack.Name;

                                // check if a forced stream is available
                                string strForcedFile = Path.Combine(Path.GetDirectoryName(strDemuxFile), Path.GetFileNameWithoutExtension(strDemuxFile) + "_forced.idx");
                                if (File.Exists(strForcedFile))
                                {
                                    subtitles.Add(new MuxStream(strForcedFile, oTrack.Language, SubtitleUtil.ApplyForcedStringToTrackName(true, oTrack.Name), oTrack.Delay, oTrack.DefaultStream, true, null));
                                    intermediateFiles.Add(strForcedFile);
                                    intermediateFiles.Add(Path.ChangeExtension(strForcedFile, ".sub"));
                                }
                                subtitles.Add(new MuxStream(strDemuxFile, oTrack.Language, SubtitleUtil.ApplyForcedStringToTrackName(false, oTrack.Name), oTrack.Delay, oTrack.DefaultStream, (File.Exists(strForcedFile) ? false : oTrack.ForcedStream), null));
                            }
                            else
                            {
                                log.LogEvent("Ignoring subtitle as the it cannot be found: " + oTrack.DemuxFilePath, ImageType.Warning);
                            }
                        }
                    }
                }

                if (IsJobStopped())
                {
                    return;
                }

                if (!bError)
                {
                    c = VideoUtil.GenerateJobSeries(myVideo, job.PostprocessingProperties.FinalOutput, arrAudioJobs.ToArray(),
                                                    subtitles.ToArray(), job.PostprocessingProperties.Attachments, job.PostprocessingProperties.TimeStampFile,
                                                    job.PostprocessingProperties.ChapterInfo, job.PostprocessingProperties.OutputSize,
                                                    job.PostprocessingProperties.Splitting, job.PostprocessingProperties.Container,
                                                    job.PostprocessingProperties.PrerenderJob, arrMuxStreams.ToArray(),
                                                    log, job.PostprocessingProperties.DeviceOutputType, null, job.PostprocessingProperties.VideoFileToMux,
                                                    job.PostprocessingProperties.AudioTracks.ToArray(), true);
                }

                if (c != null && !String.IsNullOrEmpty(job.PostprocessingProperties.TimeStampFile) &&
                    c.Jobs[c.Jobs.Length - 1].Job is MuxJob && (c.Jobs[c.Jobs.Length - 1].Job as MuxJob).MuxType == MuxerType.MP4BOX)
                {
                    // last job is a mp4box job and vfr timecode data has to be applied
                    MP4FpsModJob mp4FpsMod = new MP4FpsModJob(((MuxJob)c.Jobs[c.Jobs.Length - 1].Job).Output, job.PostprocessingProperties.TimeStampFile);
                    c = new SequentialChain(c, new SequentialChain(mp4FpsMod));
                }
            }
            catch (Exception e)
            {
                log.LogValue("An error occurred", e, ImageType.Error);
                bError = true;
            }

            if (c == null || bError)
            {
                log.Error("Job creation aborted");
                su.HasError = true;
            }

            // add cleanup job also in case of an error
            c = CleanupJob.AddAfter(c, intermediateFiles, job.PostprocessingProperties.FinalOutput);
            MainForm.Instance.Jobs.AddJobsWithDependencies(c, false);

            // batch processing other input files if necessary
            if (job.PostprocessingProperties.FilesToProcess.Count > 0)
            {
                OneClickWindow ocw = new OneClickWindow();
                ocw.setBatchProcessing(job.PostprocessingProperties.FilesToProcess, job.PostprocessingProperties.OneClickSetting);
            }

            su.IsComplete = true;
        }
Exemple #30
0
        /// <summary>
        /// Gets the information how the file can be opened
        /// </summary>
        /// <param name="videoInput"></param>
        /// <returns>
        /// -1 file cannot be opened
        ///  0 OneClick Encoder
        ///  1 File Indexer
        ///  2 AviSource
        ///  3 DirectShowSource
        /// </returns>
        public int AVSCreatorOpen(string videoInput)
        {
            int           iResult = -1;
            MediaInfoFile iFile   = new MediaInfoFile(videoInput);

            FileIndexerWindow.IndexType oIndexer = FileIndexerWindow.IndexType.NONE;

            // check if OCE or FileIndexer can be used
            if (!iFile.recommendIndexer(out oIndexer))
            {
                // they cannot be used
                if (iFile.isAVISourceIndexable(false))
                {
                    iResult = 2;
                }
                else if (iFile.isDirectShowSourceIndexable())
                {
                    iResult = 3;
                }
                return(iResult);
            }

            // OCE or File Indexer can be used - should DirectShowSource/AVISource be tried as well?

            if (MainForm.Instance.Settings.EnableDirectShowSource)
            {
                if (iFile.isAVISourceIndexable(false))
                {
                    iResult = askAbout3("Do you want to open this file with\r\n" +
                                        "- One Click Encoder (fully automated, easy to use) or\r\n" +
                                        "- File Indexer (manual, advanced) or \r\n" +
                                        "- AviSource (manual, expert, may cause problems)?", "Please choose your prefered way to open this file",
                                        "One Click Encoder", "File Indexer", "AviSource", MessageBoxIcon.Question);
                    return(iResult);
                }
                else if (iFile.isDirectShowSourceIndexable())
                {
                    iResult = askAbout3("Do you want to open this file with\r\n" +
                                        "- One Click Encoder (fully automated, easy to use) or\r\n" +
                                        "- File Indexer (manual, advanced) or \r\n" +
                                        "- DirectShowSource (manual, expert, may cause problems)?", "Please choose your prefered way to open this file",
                                        "One Click Encoder", "File Indexer", "DirectShowSource", MessageBoxIcon.Question);
                    if (iResult == 2)
                    {
                        iResult = 3;
                    }
                    return(iResult);
                }
            }

            string strText = string.Empty;

            if (MainForm.Instance.Settings.EnableDirectShowSource)
            {
                strText = "\r\n\r\nDirectShowSource or AVISource is not supported.";
            }
            else
            {
                strText = "\r\n\r\nDirectShowSource or AVISource is not recommended\r\nand has to be enabled in the settings if required.";
            }

            iResult = askAbout2("Do you want to open this file with\r\n" +
                                "- One Click Encoder (fully automated, easy to use) or\r\n" +
                                "- File Indexer (manual, advanced)?" + strText, "Please choose your preferred tool",
                                "One Click Encoder", "File Indexer", MessageBoxIcon.Question);
            return(iResult);
        }