diff options
Diffstat (limited to 'win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs')
-rw-r--r-- | win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs | 285 |
1 files changed, 0 insertions, 285 deletions
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 @@ -295,249 +295,6 @@ namespace HandBrake.Interop }
/// <summary>
- /// Gets the total number of seconds on the given encode job.
- /// </summary>
- /// <param name="job">
- /// The encode job to query.
- /// </param>
- /// <param name="title">
- /// The title being encoded.
- /// </param>
- /// <returns>
- /// The total number of seconds of video to encode.
- /// </returns>
- 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;
- }
-
- /// <summary>
- /// Gets the number of audio samples used per frame for the given audio encoder.
- /// </summary>
- /// <param name="encoderName">
- /// The encoder to query.
- /// </param>
- /// <returns>
- /// The number of audio samples used per frame for the given
- /// audio encoder.
- /// </returns>
- 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;
- }
-
- /// <summary>
- /// Gets the size in bytes for the audio with the given parameters.
- /// </summary>
- /// <param name="job">
- /// The encode job.
- /// </param>
- /// <param name="lengthSeconds">
- /// The length of the encode in seconds.
- /// </param>
- /// <param name="title">
- /// The title to encode.
- /// </param>
- /// <param name="outputTrackList">
- /// The list of tracks to encode.
- /// </param>
- /// <returns>
- /// The size in bytes for the audio with the given parameters.
- /// </returns>
- internal static long GetAudioSize(EncodeJob job, double lengthSeconds, Title title, List<Tuple<AudioEncoding, int>> outputTrackList)
- {
- long audioBytes = 0;
-
- foreach (Tuple<AudioEncoding, int> 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;
- }
-
- /// <summary>
- /// Calculates the video bitrate for the given job and target size.
- /// </summary>
- /// <param name="job">
- /// The encode job.
- /// </param>
- /// <param name="title">
- /// The title.
- /// </param>
- /// <param name="sizeMB">
- /// The target size in MB.
- /// </param>
- /// <param name="overallSelectedLengthSeconds">
- /// The currently selected encode length. Used in preview
- /// for calculating bitrate when the target size would be wrong.
- /// </param>
- /// <returns>
- /// The video bitrate in kbps.
- /// </returns>
- 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<Tuple<AudioEncoding, int>> 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));
- }
-
- /// <summary>
- /// Gives estimated file size (in MB) of the given job and video bitrate.
- /// </summary>
- /// <param name="job">
- /// The encode job.
- /// </param>
- /// <param name="title">
- /// The title.
- /// </param>
- /// <param name="videoBitrate">
- /// The video bitrate to be used (kbps).
- /// </param>
- /// <returns>
- /// The estimated file size (in MB) of the given job and video bitrate.
- /// </returns>
- 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<Tuple<AudioEncoding, int>> outputTrackList = GetOutputTracks(job, title);
- totalBytes += GetAudioSize(job, lengthSeconds, title, outputTrackList);
-
- return (double)totalBytes / 1024 / 1024;
- }
-
- /// <summary>
/// Sends the message logged event to any registered listeners.
/// </summary>
/// <param name="message">
@@ -568,47 +325,5 @@ namespace HandBrake.Interop Debug.WriteLine("ERROR: " + message);
}
-
- /// <summary>
- /// Gets a list of encodings and target track indices (1-based).
- /// </summary>
- /// <param name="job">The encode job</param>
- /// <param name="title">The title the job is meant to encode.</param>
- /// <returns>A list of encodings and target track indices (1-based).</returns>
- private static List<Tuple<AudioEncoding, int>> GetOutputTracks(EncodeJob job, Title title)
- {
- var list = new List<Tuple<AudioEncoding, int>>();
-
- 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<AudioEncoding, int>(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<AudioEncoding, int>(encoding, trackNumber));
- }
- }
- }
-
- return list;
- }
}
}
|