From 152cabeebf37e9f45c49769e8abe64cd5867ad86 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 9 Jan 2015 21:15:46 +0000 Subject: WinGui: Further API tidyup in the interop library. Moving some filesize calculation code into HandBrakeUtils. It's now the responsibility of the consumer to provide a valid title. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6705 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrakeInterop/HandBrakeInstance.cs | 269 +++++------------ .../HandBrakeInterop/HandBrakeUtils.cs | 324 +++++++++++++++++---- .../HandBrakeInterop/Helpers/Utilities.cs | 15 - .../Interfaces/IHandBrakeInstance.cs | 37 --- win/CS/HandBrake10.sln.DotSettings | 1 + 5 files changed, 335 insertions(+), 311 deletions(-) (limited to 'win/CS') diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index 1e6fe8506..9962eca4d 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -14,12 +14,10 @@ namespace HandBrake.Interop using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; - using System.Globalization; using System.IO; using System.Linq; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; - using System.Text; using System.Timers; using System.Windows.Media.Imaging; @@ -37,7 +35,7 @@ namespace HandBrake.Interop using Newtonsoft.Json; - using Size = HandBrake.Interop.Model.Size; + using Geometry = HandBrake.Interop.Json.Anamorphic.Geometry; /// /// A wrapper for a HandBrake instance. @@ -59,11 +57,6 @@ namespace HandBrake.Interop /// private IntPtr hbHandle; - /// - /// The number of previews created during scan. - /// - private int previewCount; - /// /// The timer to poll for scan status. /// @@ -89,11 +82,6 @@ namespace HandBrake.Interop /// private bool disposed; - /// - /// The last scan. - /// - private JsonScanObject lastScan; - /// /// Finalizes an instance of the HandBrakeInstance class. /// @@ -133,17 +121,6 @@ namespace HandBrake.Interop } } - /// - /// Gets the number of previews created during scan. - /// - public int PreviewCount - { - get - { - return this.previewCount; - } - } - /// /// Gets the index of the default title. /// @@ -181,7 +158,9 @@ namespace HandBrake.Interop /// /// Initializes this instance. /// - /// The code for the logging verbosity to use. + /// + /// The code for the logging verbosity to use. + /// public void Initialize(int verbosity) { HandBrakeUtils.EnsureGlobalInit(); @@ -193,9 +172,15 @@ namespace HandBrake.Interop /// /// Starts scanning the given path. /// - /// The path to the video to scan. - /// The number of preview images to make. - /// The minimum duration of a title to show up on the scan. + /// + /// The path to the video to scan. + /// + /// + /// The number of preview images to make. + /// + /// + /// The minimum duration of a title to show up on the scan. + /// public void StartScan(string path, int previewCount, TimeSpan minDuration) { this.StartScan(path, previewCount, minDuration, 0); @@ -204,8 +189,12 @@ namespace HandBrake.Interop /// /// Starts a scan for the given input path. /// - /// The path of the video to scan. - /// The number of preview images to generate for each title while scanning. + /// + /// The path of the video to scan. + /// + /// + /// The number of preview images to generate for each title while scanning. + /// public void StartScan(string path, int previewCount) { this.StartScan(path, previewCount, TimeSpan.FromSeconds(10), 0); @@ -214,9 +203,15 @@ namespace HandBrake.Interop /// /// Starts a scan of the given path. /// - /// The path of the video to scan. - /// The number of preview images to generate for each title while scanning. - /// The title index to scan (1-based, 0 for all titles). + /// + /// The path of the video to scan. + /// + /// + /// The number of preview images to generate for each title while scanning. + /// + /// + /// The title index to scan (1-based, 0 for all titles). + /// public void StartScan(string path, int previewCount, int titleIndex) { this.StartScan(path, previewCount, TimeSpan.Zero, titleIndex); @@ -225,14 +220,20 @@ namespace HandBrake.Interop /// /// Starts a scan of the given path. /// - /// The path of the video to scan. - /// The number of previews to make on each title. - /// The minimum duration of a title to show up on the scan. - /// The title index to scan (1-based, 0 for all titles). + /// + /// The path of the video to scan. + /// + /// + /// The number of previews to make on each title. + /// + /// + /// The minimum duration of a title to show up on the scan. + /// + /// + /// The title index to scan (1-based, 0 for all titles). + /// public void StartScan(string path, int previewCount, TimeSpan minDuration, int titleIndex) { - this.previewCount = previewCount; - IntPtr pathPtr = InteropUtilities.ToUtf8PtrFromString(path); HBFunctions.hb_scan(this.hbHandle, pathPtr, titleIndex, previewCount, 1, (ulong)(minDuration.TotalSeconds * 90000)); Marshal.FreeHGlobal(pathPtr); @@ -262,9 +263,15 @@ namespace HandBrake.Interop /// /// Only incorporates sizing and aspect ratio into preview image. /// - /// The encode job to preview. - /// The index of the preview to get (0-based). - /// An image with the requested preview. + /// + /// The encode job to preview. + /// + /// + /// The index of the preview to get (0-based). + /// + /// + /// An image with the requested preview. + /// [HandleProcessCorruptedStateExceptions] public BitmapImage GetPreview(EncodeJob job, int previewNumber) { @@ -274,17 +281,17 @@ namespace HandBrake.Interop // Creat the Expected Output Geometry details for libhb. hb_geometry_settings_s uiGeometry = new hb_geometry_settings_s { - crop = new[] { job.EncodingProfile.Cropping.Top, job.EncodingProfile.Cropping.Bottom, job.EncodingProfile.Cropping.Left, job.EncodingProfile.Cropping.Right }, - itu_par = 0, + crop = new[] { job.EncodingProfile.Cropping.Top, job.EncodingProfile.Cropping.Bottom, job.EncodingProfile.Cropping.Left, job.EncodingProfile.Cropping.Right }, + itu_par = 0, keep = (int)AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH + (job.EncodingProfile.KeepDisplayAspect ? 0x04 : 0), // TODO Keep Width? - maxWidth = job.EncodingProfile.MaxWidth, - maxHeight = job.EncodingProfile.MaxHeight, - mode = (int)(hb_anamorphic_mode_t)job.EncodingProfile.Anamorphic, - modulus = job.EncodingProfile.Modulus, + maxWidth = job.EncodingProfile.MaxWidth, + maxHeight = job.EncodingProfile.MaxHeight, + mode = (int)(hb_anamorphic_mode_t)job.EncodingProfile.Anamorphic, + modulus = job.EncodingProfile.Modulus, geometry = new hb_geometry_s { - height = job.EncodingProfile.Height, - width = job.EncodingProfile.Width, + height = job.EncodingProfile.Height, + width = job.EncodingProfile.Width, par = job.EncodingProfile.Anamorphic != Anamorphic.Custom ? new hb_rational_t { den = title.ParVal.Height, num = title.ParVal.Width } : new hb_rational_t { den = job.EncodingProfile.PixelAspectY, num = job.EncodingProfile.PixelAspectX } @@ -292,7 +299,7 @@ namespace HandBrake.Interop }; // Sanatise the input. - Json.Anamorphic.Geometry resultGeometry = AnamorphicFactory.CreateGeometry(job, title, AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH); // TODO this keep isn't right. + Geometry resultGeometry = AnamorphicFactory.CreateGeometry(job, title, AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH); // TODO this keep isn't right. int width = resultGeometry.Width * resultGeometry.PAR.Num / resultGeometry.PAR.Den; int height = resultGeometry.Height; uiGeometry.geometry.height = resultGeometry.Height; // Prased the height now. @@ -353,91 +360,7 @@ namespace HandBrake.Interop } } - /// - /// Calculates the video bitrate for the given job and target size. - /// - /// The encode job. - /// 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 int CalculateBitrate(EncodeJob job, int sizeMB, double overallSelectedLengthSeconds = 0) - { - long availableBytes = ((long)sizeMB) * 1024 * 1024; - - EncodingProfile profile = job.EncodingProfile; - Title title = this.GetTitle(job.Title); - - double lengthSeconds = overallSelectedLengthSeconds > 0 ? overallSelectedLengthSeconds : HandBrakeUtils.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 * HandBrakeUtils.ContainerOverheadPerFrame; - List> outputTrackList = this.GetOutputTracks(job, title); - availableBytes -= HandBrakeUtils.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 video bitrate to be used (kbps). - /// The estimated file size (in MB) of the given job and video bitrate. - public double CalculateFileSize(EncodeJob job, int videoBitrate) - { - long totalBytes = 0; - - EncodingProfile profile = job.EncodingProfile; - Title title = this.GetTitle(job.Title); - - double lengthSeconds = HandBrakeUtils.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 * HandBrakeUtils.ContainerOverheadPerFrame; - - List> outputTrackList = this.GetOutputTracks(job, title); - totalBytes += HandBrakeUtils.GetAudioSize(job, lengthSeconds, title, outputTrackList); - - return (double)totalBytes / 1024 / 1024; - } /// /// Starts an encode with the given job. @@ -482,8 +405,6 @@ namespace HandBrake.Interop /// public void StartEncode(EncodeJob job, Title title, bool preview, int previewNumber, int previewSeconds, double overallSelectedLengthSeconds, int scanPreviewCount) { - this.previewCount = scanPreviewCount; - JsonEncodeObject encodeObject = EncodeFactory.Create(job, title); JsonSerializerSettings settings = new JsonSerializerSettings @@ -495,7 +416,7 @@ namespace HandBrake.Interop HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encode)); HBFunctions.hb_start(this.hbHandle); - this.encodePollTimer = new System.Timers.Timer(); + this.encodePollTimer = new Timer(); this.encodePollTimer.Interval = EncodePollIntervalMs; this.encodePollTimer.Elapsed += (o, e) => @@ -560,7 +481,9 @@ namespace HandBrake.Interop /// /// Frees any resources associated with this object. /// - /// True if managed objects as well as unmanaged should be disposed. + /// + /// True if managed objects as well as unmanaged should be disposed. + /// protected virtual void Dispose(bool disposing) { if (disposing) @@ -592,10 +515,10 @@ namespace HandBrake.Interop { this.ScanProgress(this, new ScanProgressEventArgs { - Progress = state.Scanning.Progress, - CurrentPreview = state.Scanning.Preview, - Previews = state.Scanning.PreviewCount, - CurrentTitle = state.Scanning.Title, + Progress = state.Scanning.Progress, + CurrentPreview = state.Scanning.Preview, + Previews = state.Scanning.PreviewCount, + CurrentTitle = state.Scanning.Title, Titles = state.Scanning.TitleCount }); } @@ -609,7 +532,6 @@ namespace HandBrake.Interop string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg); JsonScanObject scanObject = JsonConvert.DeserializeObject(scanJson); - lastScan = scanObject; foreach (Title title in ScanFactory.CreateTitleSet(scanObject)) { @@ -646,10 +568,10 @@ namespace HandBrake.Interop { var progressEventArgs = new EncodeProgressEventArgs { - FractionComplete = state.Working.Progress, - CurrentFrameRate = state.Working.Rate, - AverageFrameRate = state.Working.RateAvg, - EstimatedTimeLeft = new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds), + FractionComplete = state.Working.Progress, + CurrentFrameRate = state.Working.Rate, + AverageFrameRate = state.Working.RateAvg, + EstimatedTimeLeft = new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds), Pass = 1, // TODO }; @@ -670,56 +592,5 @@ namespace HandBrake.Interop } } - /// - /// 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 List> GetOutputTracks(EncodeJob job, Title title) - { - var list = new List>(); - - foreach (AudioEncoding encoding in job.EncodingProfile.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; - } - - /// - /// Gets the title, given the 1-based title number. - /// - /// The number of the title (1-based). - /// The requested Title. - private Title GetTitle(int titleNumber) - { - return this.Titles.SingleOrDefault(title => title.TitleNumber == titleNumber); - } } } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs index fb92c3783..c1f5a5cad 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs @@ -11,19 +11,15 @@ namespace HandBrake.Interop { using System; using System.Collections.Generic; - using System.Linq; + using System.Diagnostics; using System.Runtime.InteropServices; using HandBrake.Interop.EventArgs; using HandBrake.Interop.HbLib; - using HandBrake.Interop.Json.Anamorphic; - using HandBrake.Interop.Json.Scan; using HandBrake.Interop.Model; using HandBrake.Interop.Model.Encoding; using HandBrake.Interop.Model.Scan; - using Newtonsoft.Json; - /// /// HandBrake Interop Utilities /// @@ -109,7 +105,9 @@ namespace HandBrake.Interop /// /// Enables or disables LibDVDNav. If disabled libdvdread will be used instead. /// - /// True to enable LibDVDNav. + /// + /// True to enable LibDVDNav. + /// public static void SetDvdNav(bool enableDvdNav) { HBFunctions.hb_dvd_set_dvdnav(enableDvdNav ? 1 : 0); @@ -142,7 +140,9 @@ namespace HandBrake.Interop /// /// Handles log messages from HandBrake. /// - /// The log message (including newline). + /// + /// The log message (including newline). + /// public static void LoggingHandler(string message) { if (!string.IsNullOrEmpty(message)) @@ -160,7 +160,9 @@ namespace HandBrake.Interop /// /// Handles errors from HandBrake. /// - /// The error message. + /// + /// The error message. + /// public static void ErrorHandler(string message) { if (!string.IsNullOrEmpty(message)) @@ -196,44 +198,76 @@ namespace HandBrake.Interop /// /// Checks to see if the given H.264 level is valid given the inputs. /// - /// The level to check. - /// The output picture width. - /// The output picture height. - /// The rate numerator. - /// The rate denominator. - /// True if x264 interlaced output is enabled. - /// True if x264 fake interlacing is enabled. - /// True if the level is valid. + /// + /// The level to check. + /// + /// + /// The output picture width. + /// + /// + /// The output picture height. + /// + /// + /// The rate numerator. + /// + /// + /// The rate denominator. + /// + /// + /// True if x264 interlaced output is enabled. + /// + /// + /// True if x264 fake interlacing is enabled. + /// + /// + /// True if the level is valid. + /// public static bool IsH264LevelValid(string level, int width, int height, int fpsNumerator, int fpsDenominator, bool interlaced, bool fakeInterlaced) { return HBFunctions.hb_check_h264_level( - level, - width, - height, - fpsNumerator, - fpsDenominator, - interlaced ? 1 : 0, + level, + width, + height, + fpsNumerator, + fpsDenominator, + interlaced ? 1 : 0, fakeInterlaced ? 1 : 0) == 0; } /// /// Creates an X264 options string from the given settings. /// - /// The x264 preset. - /// The x264 tunes being used. - /// The extra options string. - /// The H.264 profile. - /// The H.264 level. - /// The width of the final picture. - /// The height of the final picture. - /// The full x264 options string from the given inputs. + /// + /// The x264 preset. + /// + /// + /// The x264 tunes being used. + /// + /// + /// The extra options string. + /// + /// + /// The H.264 profile. + /// + /// + /// The H.264 level. + /// + /// + /// The width of the final picture. + /// + /// + /// The height of the final picture. + /// + /// + /// The full x264 options string from the given inputs. + /// public static string CreateX264OptionsString( - string preset, - IList tunes, - string extraOptions, - string profile, - string level, - int width, + string preset, + IList tunes, + string extraOptions, + string profile, + string level, + int width, int height) { if (width <= 0) @@ -247,12 +281,12 @@ namespace HandBrake.Interop } IntPtr ptr = HBFunctions.hb_x264_param_unparse( - preset, - string.Join(",", tunes), - extraOptions, - profile, - level, - width, + preset, + string.Join(",", tunes), + extraOptions, + profile, + level, + width, height); string x264Settings = Marshal.PtrToStringAnsi(ptr); @@ -263,9 +297,15 @@ namespace HandBrake.Interop /// /// 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. + /// + /// 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) @@ -292,9 +332,13 @@ namespace HandBrake.Interop /// /// 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. + /// + /// 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) @@ -322,11 +366,21 @@ namespace HandBrake.Interop /// /// 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. + /// + /// 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; @@ -336,7 +390,7 @@ namespace HandBrake.Interop AudioEncoding encoding = outputTrack.Item1; AudioTrack track = title.AudioTracks[outputTrack.Item2 - 1]; - int samplesPerFrame = HandBrakeUtils.GetAudioSamplesPerFrame(encoding.Encoder); + int samplesPerFrame = GetAudioSamplesPerFrame(encoding.Encoder); int audioBitrate; HBAudioEncoder audioEncoder = Encoders.GetAudioEncoder(encoding.Encoder); @@ -361,8 +415,8 @@ namespace HandBrake.Interop else { outputBitrate = Encoders.GetDefaultBitrate( - audioEncoder, - encoding.SampleRateRaw == 0 ? track.SampleRate : encoding.SampleRateRaw, + audioEncoder, + encoding.SampleRateRaw == 0 ? track.SampleRate : encoding.SampleRateRaw, Encoders.SanitizeMixdown(Encoders.GetMixdown(encoding.Mixdown), audioEncoder, track.ChannelLayout)); } @@ -379,10 +433,116 @@ namespace HandBrake.Interop 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; + + EncodingProfile profile = job.EncodingProfile; + + 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; + + EncodingProfile profile = job.EncodingProfile; + + 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. /// - /// The message to send. + /// + /// The message to send. + /// private static void SendMessageEvent(string message) { if (MessageLogged != null) @@ -390,13 +550,15 @@ namespace HandBrake.Interop MessageLogged(null, new MessageLoggedEventArgs { Message = message }); } - System.Diagnostics.Debug.WriteLine(message); + Debug.WriteLine(message); } /// /// Sends the error logged event to any registered listeners. /// - /// The message to send + /// + /// The message to send + /// private static void SendErrorEvent(string message) { if (ErrorLogged != null) @@ -404,7 +566,49 @@ namespace HandBrake.Interop ErrorLogged(null, new MessageLoggedEventArgs { Message = message }); } - System.Diagnostics.Debug.WriteLine("ERROR: " + message); + 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.EncodingProfile.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/Helpers/Utilities.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Utilities.cs index 77106f72d..ef450c62d 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Utilities.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Utilities.cs @@ -47,20 +47,5 @@ namespace HandBrake.Interop.Helpers return GreatestCommonFactor(a, b % a); } - - /// - /// Determines if the given audio encoder is a passthrough encoder choice. - /// - /// The audio encoder to examine. - /// True if the encoder is passthrough. - public static bool IsPassthrough(AudioEncoder encoder) - { - return encoder == AudioEncoder.Ac3Passthrough || - encoder == AudioEncoder.DtsHDPassthrough || - encoder == AudioEncoder.DtsPassthrough || - encoder == AudioEncoder.Mp3Passthru || - encoder == AudioEncoder.AacPassthru || - encoder == AudioEncoder.Passthrough; - } } } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Interfaces/IHandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Interfaces/IHandBrakeInstance.cs index e6eeae943..40dd3de11 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Interfaces/IHandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Interfaces/IHandBrakeInstance.cs @@ -53,11 +53,6 @@ namespace HandBrake.Interop.Interfaces /// int FeatureTitle { get; } - /// - /// Gets the number of previews created during scan. - /// - int PreviewCount { get; } - /// /// Gets the list of titles on this instance. /// @@ -73,38 +68,6 @@ namespace HandBrake.Interop.Interfaces /// The code for the logging verbosity to use. void Initialize(int verbosity); - /// - /// Calculates the video bitrate for the given job and target size. - /// - /// - /// The encode job. - /// - /// - /// 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. - /// - int CalculateBitrate(EncodeJob job, int sizeMB, double overallSelectedLengthSeconds = 0); - - /// - /// Gives estimated file size (in MB) of the given job and video bitrate. - /// - /// - /// The encode job. - /// - /// - /// The video bitrate to be used (kbps). - /// - /// - /// The estimated file size (in MB) of the given job and video bitrate. - /// - double CalculateFileSize(EncodeJob job, int videoBitrate); - /// /// Frees any resources associated with this object. /// diff --git a/win/CS/HandBrake10.sln.DotSettings b/win/CS/HandBrake10.sln.DotSettings index 0f6feff62..7df7d44b1 100644 --- a/win/CS/HandBrake10.sln.DotSettings +++ b/win/CS/HandBrake10.sln.DotSettings @@ -7,6 +7,7 @@ HINT HINT DO_NOT_SHOW + HINT DO_NOT_SHOW HINT DO_NOT_SHOW -- cgit v1.2.3