Example #1
0
        public void openVideoFile(string fileName)
        {
            if (AudioUtil.AVSFileHasAudio(fileName))
            {
                mainForm.Audio.openAudioFile(fileName);
            }

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

            if (mainForm.Settings.AutoOpenScript)
            {
                openAvisynthScript(fileName);
            }
            else
            {
                using (AvsFile avi = AvsFile.OpenScriptFile(fileName))
                {
                    info.DAR = avi.VideoInfo.DAR;
                }
            }
            string filePath;

            if (string.IsNullOrEmpty(filePath = mainForm.Settings.DefaultOutputDir))
            {
                filePath = Path.GetDirectoryName(fileName);
            }
            string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);

            this.VideoOutput = Path.Combine(filePath, fileNameNoExtension) + mainForm.Settings.VideoExtension + ".extension";
            this.VideoOutput = Path.ChangeExtension(this.VideoOutput, this.CurrentVideoOutputType.Extension);
            updateIOConfig();
        }
Example #2
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;
        }
Example #3
0
        protected override void doExitConfig()
        {
            if (su.HasError || su.WasAborted || job.DemuxMode == 0 || job.AudioTracks.Count == 0)
            {
                base.doExitConfig();
                return;
            }

            bool bFound = File.Exists(job.Input + ".lwi");

            int iTracksFound       = 0;
            int iCurrentAudioTrack = -1;

            for (int iCurrentTrack = 0; iCurrentTrack <= 29; iCurrentTrack++) // hard limit to max. 30 tracks
            {
                StringBuilder strAVSScript = new StringBuilder();
                strAVSScript.Append(VideoUtil.getLSMASHAudioInputLine(job.Input, job.Output, iCurrentTrack));

                // is this an audio track?
                string strErrorText;
                if (AudioUtil.AVSScriptHasAudio(strAVSScript.ToString(), out strErrorText) == false)
                {
                    continue;
                }
                iCurrentAudioTrack++;

                foreach (AudioTrackInfo oAudioTrack in job.AudioTracks)
                {
                    if (oAudioTrack.TrackIndex != iCurrentAudioTrack)
                    {
                        continue;
                    }

                    // write avs file
                    string strAudioAVSFile;
                    strAudioAVSFile = Path.GetFileNameWithoutExtension(job.Output) + "_track_" + (oAudioTrack.TrackIndex + 1) + "_" + oAudioTrack.Language.ToLower(System.Globalization.CultureInfo.InvariantCulture) + ".avs";
                    strAudioAVSFile = Path.Combine(Path.GetDirectoryName(job.Output), Path.GetFileName(strAudioAVSFile));
                    try
                    {
                        strAVSScript.AppendLine(@"# detected channels: " + oAudioTrack.NbChannels);
                        strAVSScript.Append(@"# detected channel positions: " + oAudioTrack.ChannelPositions);
                        StreamWriter oAVSWriter = new StreamWriter(strAudioAVSFile, false, Encoding.Default);
                        oAVSWriter.Write(strAVSScript);
                        oAVSWriter.Close();
                    }
                    catch (IOException ex)
                    {
                        log.LogValue("Error creating audio AVS file", ex);
                    }
                    break;
                }
                if (++iTracksFound == job.AudioTracks.Count)
                {
                    break;
                }
            }

            if (!bFound && File.Exists(job.Input + ".lwi"))
            {
                File.Delete(job.Input + ".lwi");
            }

            base.doExitConfig();
        }
Example #4
0
        protected override void doExitConfig()
        {
            // no further action if job failed or was aborted
            if (su.HasError || su.WasAborted)
            {
                job.FilesToDelete.Add(job.Input + ".lwi");
                base.doExitConfig();
                return;
            }

            if (job.DemuxMode == 0 || job.AudioTracks.Count == 0 || su.HasError)
            {
                // no audio processing
                base.doExitConfig();
                return;
            }

            int iTracksFound       = 0;
            int iCurrentAudioTrack = -1;

            for (int iCurrentTrack = 0; iCurrentTrack <= 29; iCurrentTrack++) // hard limit to max. 30 tracks
            {
                StringBuilder strAVSScript = new StringBuilder();
                strAVSScript.Append(VideoUtil.getLSMASHAudioInputLine(job.Input, job.Output, iCurrentTrack));

                // is this an audio track?
                string strErrorText;
                if (AudioUtil.AVSScriptHasAudio(strAVSScript.ToString(), out strErrorText) == false)
                {
                    continue;
                }
                iCurrentAudioTrack++;

                foreach (AudioTrackInfo oAudioTrack in job.AudioTracks)
                {
                    if (oAudioTrack.TrackIndex != iCurrentAudioTrack)
                    {
                        continue;
                    }

                    // write avs file
                    string strAudioAVSFile;
                    strAudioAVSFile = Path.GetFileNameWithoutExtension(job.Output) + "_track_" + (oAudioTrack.TrackIndex + 1) + "_" + oAudioTrack.Language.ToLowerInvariant() + ".avs";
                    strAudioAVSFile = Path.Combine(Path.GetDirectoryName(job.Output), Path.GetFileName(strAudioAVSFile));
                    try
                    {
                        strAVSScript.AppendLine(@"# detected channels: " + oAudioTrack.NbChannels);
                        strAVSScript.Append(@"# detected channel positions: " + oAudioTrack.ChannelPositions);
                        StreamWriter oAVSWriter = new StreamWriter(strAudioAVSFile, false, Encoding.Default);
                        oAVSWriter.Write(strAVSScript);
                        oAVSWriter.Close();
                    }
                    catch (Exception ex)
                    {
                        base.log.LogEvent("Error creating audio AVS file: " + ex.Message, ImageType.Error);
                    }
                    break;
                }
                if (++iTracksFound == job.AudioTracks.Count)
                {
                    break;
                }
            }

            base.doExitConfig();
        }