/// <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 = HandBrakeUtils.GetAudioSamplesPerFrame(encoding.Encoder); int audioBitrate; HBAudioEncoder audioEncoder = Encoders.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 = Encoders.GetDefaultBitrate( audioEncoder, encoding.SampleRateRaw == 0 ? track.SampleRate : encoding.SampleRateRaw, Encoders.SanitizeMixdown(Encoders.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); }
public AudioEncodingViewModel(AudioEncoding audioEncoding, Title selectedTitle, List <int> chosenAudioTracks, string containerName, AudioPanelViewModel audioPanelVM) { this.initializing = true; this.audioPanelVM = audioPanelVM; this.targetStreams = new ObservableCollection <TargetStreamViewModel>(); this.targetStreamIndex = audioEncoding.InputNumber; this.SetChosenTracks(chosenAudioTracks, selectedTitle); this.audioEncoders = new List <AudioEncoderViewModel>(); this.mixdownChoices = new List <MixdownViewModel>(); this.containerName = containerName; this.RefreshEncoderChoices(); HBAudioEncoder hbAudioEncoder = Encoders.GetAudioEncoder(audioEncoding.Encoder); if (hbAudioEncoder.IsPassthrough) { this.selectedAudioEncoder = this.audioEncoders[0]; this.selectedPassthrough = audioEncoding.Encoder; } else { this.selectedAudioEncoder = this.audioEncoders.Skip(1).FirstOrDefault(e => e.Encoder.ShortName == audioEncoding.Encoder); this.selectedPassthrough = "copy"; } if (this.selectedAudioEncoder == null) { this.selectedAudioEncoder = this.audioEncoders[1]; } this.RefreshMixdownChoices(); this.RefreshBitrateChoices(); this.RefreshSampleRateChoices(); this.SelectMixdown(Encoders.GetMixdown(audioEncoding.Mixdown)); this.sampleRate = audioEncoding.SampleRateRaw; if (!this.HBAudioEncoder.SupportsQuality) { this.encodeRateType = AudioEncodeRateType.Bitrate; } else { this.encodeRateType = audioEncoding.EncodeRateType; } this.audioQuality = audioEncoding.Quality; if (audioEncoding.Compression >= 0) { this.audioCompression = audioEncoding.Compression; } else { this.audioCompression = this.HBAudioEncoder.DefaultCompression; } this.selectedBitrate = this.BitrateChoices.SingleOrDefault(b => b.Bitrate == audioEncoding.Bitrate); if (this.selectedBitrate == null) { this.selectedBitrate = this.BitrateChoices.First(); } this.gain = audioEncoding.Gain; this.drc = audioEncoding.Drc; this.passthroughIfPossible = audioEncoding.PassthroughIfPossible; this.name = audioEncoding.Name; Messenger.Default.Register <SelectedTitleChangedMessage>( this, message => { this.RefreshMixdownChoices(); this.RefreshBitrateChoices(); this.RefreshDrc(); }); Messenger.Default.Register <AudioInputChangedMessage>( this, message => { this.RefreshMixdownChoices(); this.RefreshBitrateChoices(); this.RefreshDrc(); }); Messenger.Default.Register <OptionsChangedMessage>( this, message => { this.RaisePropertyChanged(() => this.NameVisible); }); Messenger.Default.Register <ContainerChangedMessage>( this, message => { this.containerName = message.ContainerName; this.RefreshEncoderChoices(); }); this.initializing = false; }