From fcf8255c2e1c6c646e1fa184cca8c2cd9d2fc5b6 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 18 Jan 2015 18:10:12 +0000 Subject: [PATCH] WinGui: Removing some redundant code from the interop library. Fixed the libdvdnav option for the libhb based encoding. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6768 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Services/Encode/LibEncode.cs | 2 + .../Utilities/InteropModelCreator.cs | 6 - .../HandBrakeInterop/HandBrakeInterop.csproj | 1 - .../HandBrakeInterop/HandBrakeUtils.cs | 285 ------------------ .../HandBrakeInterop/Model/EncodeJob.cs | 12 - .../Model/Encoding/CroppingType.cs | 21 -- .../Model/Encoding/PictureRotation.cs | 5 +- 7 files changed, 6 insertions(+), 326 deletions(-) delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs index 0fbc7dbfe..215b05e02 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs @@ -134,6 +134,8 @@ namespace HandBrake.ApplicationServices.Services.Encode this.ScanCompleted(job, this.instance); }; + HandBrakeUtils.SetDvdNav(!job.Configuration.IsDvdNavDisabled); + this.instance.StartScan(job.Task.Source, job.Configuration.PreviewScanCount, job.Task.Title); } catch (Exception exc) diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs index 2ffc766b5..50388fc0d 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs @@ -68,7 +68,6 @@ namespace HandBrake.ApplicationServices.Utilities // Audio Settings job.AudioEncodings = new List(); - job.ChosenAudioTracks = new List(); foreach (AudioTrack track in work.AudioTracks) { AudioEncoding newTrack = new AudioEncoding @@ -86,10 +85,6 @@ namespace HandBrake.ApplicationServices.Utilities }; job.AudioEncodings.Add(newTrack); - if (track.Track != null) - { - job.ChosenAudioTracks.Add(track.Track.Value); - } } // Title Settings @@ -155,7 +150,6 @@ namespace HandBrake.ApplicationServices.Utilities // Picture Settings job.Anamorphic = work.Anamorphic; job.Cropping = new Cropping { Top = work.Cropping.Top, Bottom = work.Cropping.Bottom, Left = work.Cropping.Left, Right = work.Cropping.Right }; - job.CroppingType = CroppingType.Custom; // TODO deal with this better job.DisplayWidth = work.DisplayWidth.HasValue ? int.Parse(Math.Round(work.DisplayWidth.Value, 0).ToString()) : 0; job.PixelAspectX = work.PixelAspectX; job.PixelAspectY = work.PixelAspectY; diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj index 52939e219..7d5c59f0d 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj @@ -233,7 +233,6 @@ - diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs index 1d7042ab3..1726ea635 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs @@ -294,249 +294,6 @@ namespace HandBrake.Interop return x264Settings; } - /// - /// Gets the total number of seconds on the given encode job. - /// - /// - /// The encode job to query. - /// - /// - /// The title being encoded. - /// - /// - /// The total number of seconds of video to encode. - /// - internal static double GetJobLengthSeconds(EncodeJob job, Title title) - { - switch (job.RangeType) - { - // case VideoRangeType.All: - // return title.Duration.TotalSeconds; - case VideoRangeType.Chapters: - TimeSpan duration = TimeSpan.Zero; - for (int i = job.ChapterStart; i <= job.ChapterEnd; i++) - { - duration += title.Chapters[i - 1].Duration; - } - - return duration.TotalSeconds; - case VideoRangeType.Seconds: - return job.SecondsEnd - job.SecondsStart; - case VideoRangeType.Frames: - return (job.FramesEnd - job.FramesStart) / title.Framerate; - } - - return 0; - } - - /// - /// Gets the number of audio samples used per frame for the given audio encoder. - /// - /// - /// The encoder to query. - /// - /// - /// The number of audio samples used per frame for the given - /// audio encoder. - /// - internal static int GetAudioSamplesPerFrame(string encoderName) - { - switch (encoderName) - { - case "faac": - case "ffaac": - case "copy:aac": - case "vorbis": - return 1024; - case "lame": - case "copy:mp3": - return 1152; - case "ffac3": - case "copy": - case "copy:ac3": - case "copy:dts": - case "copy:dtshd": - return 1536; - } - - // Unknown encoder; make a guess. - return 1536; - } - - /// - /// Gets the size in bytes for the audio with the given parameters. - /// - /// - /// The encode job. - /// - /// - /// The length of the encode in seconds. - /// - /// - /// The title to encode. - /// - /// - /// The list of tracks to encode. - /// - /// - /// The size in bytes for the audio with the given parameters. - /// - internal static long GetAudioSize(EncodeJob job, double lengthSeconds, Title title, List> outputTrackList) - { - long audioBytes = 0; - - foreach (Tuple outputTrack in outputTrackList) - { - AudioEncoding encoding = outputTrack.Item1; - AudioTrack track = title.AudioTracks[outputTrack.Item2 - 1]; - - int samplesPerFrame = GetAudioSamplesPerFrame(encoding.Encoder); - int audioBitrate; - - HBAudioEncoder audioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(encoding.Encoder); - - if (audioEncoder.IsPassthrough) - { - // Input bitrate is in bits/second. - audioBitrate = track.Bitrate / 8; - } - else if (encoding.EncodeRateType == AudioEncodeRateType.Quality) - { - // Can't predict size of quality targeted audio encoding. - audioBitrate = 0; - } - else - { - int outputBitrate; - if (encoding.Bitrate > 0) - { - outputBitrate = encoding.Bitrate; - } - else - { - outputBitrate = HandBrakeEncoderHelpers.GetDefaultBitrate( - audioEncoder, - encoding.SampleRateRaw == 0 ? track.SampleRate : encoding.SampleRateRaw, - HandBrakeEncoderHelpers.SanitizeMixdown(HandBrakeEncoderHelpers.GetMixdown(encoding.Mixdown), audioEncoder, track.ChannelLayout)); - } - - // Output bitrate is in kbps. - audioBitrate = outputBitrate * 1000 / 8; - } - - audioBytes += (long)(lengthSeconds * audioBitrate); - - // Audio overhead - audioBytes += encoding.SampleRateRaw * ContainerOverheadPerFrame / samplesPerFrame; - } - - return audioBytes; - } - - /// - /// Calculates the video bitrate for the given job and target size. - /// - /// - /// The encode job. - /// - /// - /// The title. - /// - /// - /// The target size in MB. - /// - /// - /// The currently selected encode length. Used in preview - /// for calculating bitrate when the target size would be wrong. - /// - /// - /// The video bitrate in kbps. - /// - public static int CalculateBitrate(EncodeJob job, Title title, int sizeMB, double overallSelectedLengthSeconds = 0) - { - long availableBytes = ((long)sizeMB) * 1024 * 1024; - - EncodeJob profile = job; - - double lengthSeconds = overallSelectedLengthSeconds > 0 ? overallSelectedLengthSeconds : GetJobLengthSeconds(job, title); - lengthSeconds += 1.5; - - double outputFramerate; - if (profile.Framerate == 0) - { - outputFramerate = title.Framerate; - } - else - { - // Not sure what to do for VFR here hb_calc_bitrate never handled it... - // just use the peak for now. - outputFramerate = profile.Framerate; - } - - long frames = (long)(lengthSeconds * outputFramerate); - - availableBytes -= frames * ContainerOverheadPerFrame; - - List> outputTrackList = GetOutputTracks(job, title); - availableBytes -= GetAudioSize(job, lengthSeconds, title, outputTrackList); - - if (availableBytes < 0) - { - return 0; - } - - // Video bitrate is in kilobits per second, or where 1 kbps is 1000 bits per second. - // So 1 kbps is 125 bytes per second. - return (int)(availableBytes / (125 * lengthSeconds)); - } - - /// - /// Gives estimated file size (in MB) of the given job and video bitrate. - /// - /// - /// The encode job. - /// - /// - /// The title. - /// - /// - /// The video bitrate to be used (kbps). - /// - /// - /// The estimated file size (in MB) of the given job and video bitrate. - /// - public static double CalculateFileSize(EncodeJob job, Title title, int videoBitrate) - { - long totalBytes = 0; - - EncodeJob profile = job; - - double lengthSeconds = GetJobLengthSeconds(job, title); - lengthSeconds += 1.5; - - double outputFramerate; - if (profile.Framerate == 0) - { - outputFramerate = title.Framerate; - } - else - { - // Not sure what to do for VFR here hb_calc_bitrate never handled it... - // just use the peak for now. - outputFramerate = profile.Framerate; - } - - long frames = (long)(lengthSeconds * outputFramerate); - - totalBytes += (long)(lengthSeconds * videoBitrate * 125); - totalBytes += frames * ContainerOverheadPerFrame; - - List> outputTrackList = GetOutputTracks(job, title); - totalBytes += GetAudioSize(job, lengthSeconds, title, outputTrackList); - - return (double)totalBytes / 1024 / 1024; - } - /// /// Sends the message logged event to any registered listeners. /// @@ -568,47 +325,5 @@ namespace HandBrake.Interop Debug.WriteLine("ERROR: " + message); } - - /// - /// Gets a list of encodings and target track indices (1-based). - /// - /// The encode job - /// The title the job is meant to encode. - /// A list of encodings and target track indices (1-based). - private static List> GetOutputTracks(EncodeJob job, Title title) - { - var list = new List>(); - - foreach (AudioEncoding encoding in job.AudioEncodings) - { - if (encoding.InputNumber == 0) - { - // Add this encoding for all chosen tracks - foreach (int chosenTrack in job.ChosenAudioTracks) - { - // In normal cases we'll never have a chosen audio track that doesn't exist but when batch encoding - // we just choose the first audio track without checking if it exists. - if (chosenTrack <= title.AudioTracks.Count) - { - list.Add(new Tuple(encoding, chosenTrack)); - } - } - } - else if (encoding.InputNumber <= job.ChosenAudioTracks.Count) - { - // Add this encoding for the specified track, if it exists - int trackNumber = job.ChosenAudioTracks[encoding.InputNumber - 1]; - - // In normal cases we'll never have a chosen audio track that doesn't exist but when batch encoding - // we just choose the first audio track without checking if it exists. - if (trackNumber <= title.AudioTracks.Count) - { - list.Add(new Tuple(encoding, trackNumber)); - } - } - } - - return list; - } } } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs index ce7209948..f231073f4 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs @@ -156,11 +156,6 @@ namespace HandBrake.Interop.Model /// public ScaleMethod ScaleMethod { get; set; } - /// - /// Gets or sets the cropping type. - /// - public CroppingType CroppingType { get; set; } - /// /// Gets or sets the cropping. /// @@ -376,11 +371,6 @@ namespace HandBrake.Interop.Model /// public List AudioEncodings { get; set; } - /// - /// Gets or sets the list of chosen audio tracks (1-based) - /// - public List ChosenAudioTracks { get; set; } - /// /// Gets or sets the audio encoder fallback. /// @@ -439,7 +429,6 @@ namespace HandBrake.Interop.Model SecondsEnd = this.SecondsEnd, FramesStart = this.FramesStart, FramesEnd = this.FramesEnd, - ChosenAudioTracks = new List(this.ChosenAudioTracks), Subtitles = this.Subtitles, UseDefaultChapterNames = this.UseDefaultChapterNames, DxvaDecoding = this.DxvaDecoding, @@ -456,7 +445,6 @@ namespace HandBrake.Interop.Model MaxWidth = this.MaxWidth, MaxHeight = this.MaxHeight, ScaleMethod = this.ScaleMethod, - CroppingType = this.CroppingType, Cropping = this.Cropping.Clone(), Anamorphic = this.Anamorphic, UseDisplayWidth = this.UseDisplayWidth, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs deleted file mode 100644 index e7c8da445..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// The type of cropping to apply. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop.Model.Encoding -{ - /// - /// The type of cropping to apply. - /// - public enum CroppingType - { - Automatic, - None, - Custom - } -} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/PictureRotation.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/PictureRotation.cs index 0476b1673..716d65402 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/PictureRotation.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/PictureRotation.cs @@ -1,7 +1,10 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // +// +// Possible picture rotations. +// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.Interop.Model.Encoding -- 2.40.0