示例#1
0
 private CalcData GetCalcData()
 {
     CalcData data = new CalcData((long)videoStream.NumberOfFrames, videoStream.Framerate, (ContainerType)container.SelectedItem,
         videoStream.Settings.Codec, videoStream.Settings.NbBframes > 0, getAudioStreamsForBitrate());
     return data;
 }
        /// <summary>
        /// postprocesses an audio job followed by a video job
        /// this constellation happens in automated or one click encoding where we have an audio job linked
        /// to a video job
        /// first, any audio jobs previous to the audio job in question will be located
        /// then we get the size of all audio tracks
        /// from the desired final output size stored in the first video job, we calculate the video bitrate
        /// we have to use to obtain the final file size, taking container overhead into account
        /// the calculated bitrate is then applied to all video jobs
        /// </summary>
        /// <param name="firstAudio">the audio job that is linked to a video job</param>
        /// <param name="firstpass">the video job to which the audio job is linked</param>
        public static LogItem calculateBitrate(MainForm mainForm, Job ajob)
        {
            if (!(ajob is VideoJob)) return null;
            VideoJob job = (VideoJob)ajob;
            if (job.BitrateCalculationInfo == null) return null;

            BitrateCalculationInfo b = job.BitrateCalculationInfo;
            LogItem log = new LogItem("Bitrate calculation for video");

            List<AudioBitrateCalculationStream> audioStreams = new List<AudioBitrateCalculationStream>();
            foreach (string s in b.AudioFiles)
                audioStreams.Add(new AudioBitrateCalculationStream(s));

            double framerate;
            ulong framecount;
            JobUtil.getInputProperties(out framecount, out framerate, job.Input);

            CalcData data = new CalcData((long)framecount, (decimal)framerate, b.Container, job.Settings.Codec,
                job.Settings.NbBframes > 0, audioStreams.ToArray());
            data.TotalSize = b.DesiredSize;

            try
            {
                data.CalcByTotalSize();
            }
            catch (Exception e)
            {
                log.LogValue("Calculation failed", e, ImageType.Error);
                return log;
            }

            log.LogValue("Desired size after subtracting audio", data.VideoSize.KBExact + "KBs");
            log.LogValue("Calculated desired bitrate", data.VideoBitrate + "kbit/s");

            foreach (TaggedJob t in b.VideoJobs)
                ((VideoJob)t.Job).Settings.BitrateQuantizer = (int)data.VideoBitrate;

            return log;
        }
示例#3
0
        /// <summary>
        /// Calculates by the selected method
        /// </summary>
        protected void Calculate()
        {
            if (calculating) return;
            calculating = true;
            try
            {

                CalcData data = new CalcData((long)nbFrames.Value, fpsChooser.Value ?? 0);
                data.FrameSize = new Size((int)width.Value, (int)height.Value);
                data.ExtraSize = GetTotalExtraSize();
                data.AudioStreams = GetAudioStreams().ToArray();
                data.ContainerType = containerFormat.SelectedItem as ContainerType;
                data.HasBFrames = bframes.Checked;
                data.VideoCodec = SelectedVCodec.VCodec;
                data.QualityCoeffient = (float)complexity.Value / 100F;

                if (fileSizeRadio.Checked) // get video, bpp, qest
                {
                    data.TotalSize = new FileSize(targetSize.Value.Value.Bytes);
                    data.CalcByTotalSize();
                }
                else if (this.bppRadio.Checked) // get video, quest, total
                {
                    data.BitsPerPixel = (float)bpp.Value;
                    data.CalcByBitsPerPixel();
                }
                else if (this.qEstRadio.Checked) // get video, bpp, total
                {
                    data.QualityEstimate = (float)qest.Value;
                    data.CalcByQualityEstimate();
                }
                else // given video size, get total, bpp, quest
                {
                    data.VideoBitrate = projectedBitrate.Value;
                    data.CalcByVideoSize();
                }

                targetSize.Value = new FileSize(Unit.KB, data.TotalSize.KB);
                projectedBitrate.Value = data.VideoBitrate;
                videoSize.Text = new FileSize(Unit.KB, data.VideoSize.KB).ToString();
                bpp.Value = (decimal)data.BitsPerPixel;
                qest.Value = (decimal)data.QualityEstimate;
                applyButton.Enabled = true;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                applyButton.Enabled = false;
                videoSize.Text = "";
                if (fileSizeRadio.Checked)
                {
                    bpp.Value = 0;
                    qest.Value = 0;
                    projectedBitrate.Value = 0;
                }
                else if (this.bppRadio.Checked)
                {
                    qest.Value = 0;
                    projectedBitrate.Value = 0;
                    targetSize.Value = null;
                }
                else if (this.qEstRadio.Checked)
                {
                    bpp.Value = 0;
                    projectedBitrate.Value = 0;
                    targetSize.Value = null;
                }
                else
                {
                    bpp.Value = 0;
                    qest.Value = 0;
                    targetSize.Value = null;
                }
            }
            calculating = false;
        }