ParseParamsByteIO::ParseParamsByteIO( const ByteIO& stream_data, ParseParams &parse_params, EncoderParams &enc_params): ByteIO(stream_data), m_parse_params(parse_params) { if (enc_params.NumL1() == 0) { if (!enc_params.UsingAC()) { // Simple Profile m_parse_params.SetProfile(1); } else { // Main (Intra) profile m_parse_params.SetProfile(2); } } else { // Main (Long GOP) profile m_parse_params.SetProfile(8); } // FIXME - no support for Low Delay Profile }
SequenceCompressor::SequenceCompressor( StreamPicInput* pin , EncoderParams& encp, DiracByteStream& dirac_byte_stream): m_all_done(false), m_just_finished(true), m_srcparams(pin->GetSourceParams()), m_encparams(encp), m_predparams(encp.GetPicPredParams()), m_L1_sep(encp.L1Sep()), m_pparams(m_srcparams.CFormat(), m_encparams.Xl(), m_encparams.Yl(), m_encparams.LumaDepth(), m_encparams.ChromaDepth() ), m_pic_in(pin), m_current_display_pnum(-1), m_current_code_pnum(0), m_show_pnum(-1),m_last_picture_read(-1), m_gop_start_num(0), m_delay(1), m_qmonitor( m_encparams ), m_pcoder( m_encparams ), m_dirac_byte_stream(dirac_byte_stream), m_eos_signalled(false) { // Set up the compression of the sequence //TBD: put into the constructor for EncoderParams m_encparams.SetEntropyFactors( new EntropyCorrector(m_encparams.TransformDepth()) ); // Set up generic picture parameters m_pparams.SetUsingAC(m_encparams.UsingAC() ); // Set up a rate controller if rate control being used if (m_encparams.TargetRate() != 0) m_ratecontrol = new RateController(m_encparams.TargetRate(), m_pic_in->GetSourceParams(), encp); // Copy in the block parameters in case we want to change them dynamically m_basic_olb_params2 = &m_predparams.LumaBParams(2); m_basic_olb_params1 = new OLBParams( 2*m_predparams.LumaBParams(2).Xblen(), 2*m_predparams.LumaBParams(2).Yblen(), 2*m_predparams.LumaBParams(2).Xbsep(), 2*m_predparams.LumaBParams(2).Ybsep() ); m_basic_olb_params0 = new OLBParams( 4*m_predparams.LumaBParams(2).Xblen(), 4*m_predparams.LumaBParams(2).Yblen(), 4*m_predparams.LumaBParams(2).Xbsep(), 4*m_predparams.LumaBParams(2).Ybsep() ); m_intra_olbp = new OLBParams( 2*m_basic_olb_params2->Xbsep() , 2*m_basic_olb_params2->Ybsep() , m_basic_olb_params2->Xbsep() , m_basic_olb_params2->Ybsep() ); SetMotionParameters(); }
void CoeffArray::SetBandWeights (const EncoderParams& encparams, const PictureParams& pparams, const CompSort csort) { const WltFilter wltfilter = encparams.TransformFilter(); const bool field_coding = encparams.FieldCoding(); const ChromaFormat cformat = pparams.CFormat(); const float cpd = encparams.CPD(); const PictureSort psort = pparams.PicSort(); int xlen, ylen, xl, yl, xp, yp; float xfreq, yfreq; float temp(0.0); // Compensate for chroma subsampling float chroma_xfac(1.0); float chroma_yfac(1.0); if( csort != Y_COMP) { if( cformat == format422) { chroma_xfac = 2.0; chroma_yfac = 1.0; } else if( cformat == format420 ) { chroma_xfac = 2.0; chroma_yfac = 2.0; } } xlen = 2 * m_band_list(1).Xl(); ylen = 2 * m_band_list(1).Yl(); if (cpd != 0.0) { for( int i = 1; i<=m_band_list.Length() ; i++ ) { xp = m_band_list(i).Xp(); yp = m_band_list(i).Yp(); xl = m_band_list(i).Xl(); yl = m_band_list(i).Yl(); xfreq = cpd * ( float(xp) + (float(xl)/2.0) ) / float(xlen); yfreq = cpd * ( float(yp) + (float(yl)/2.0) ) / float(ylen); if ( psort.IsInter() ) { xfreq /= 8.0; yfreq /= 8.0; } if(field_coding) yfreq/=2.0; temp = PerceptualWeight( xfreq/chroma_xfac , yfreq/chroma_yfac , csort ); m_band_list(i).SetWt(temp); }// i // Make sure dc is always the lowest weight float min_weight=m_band_list(m_band_list.Length()).Wt(); for( int b=1 ; b<=m_band_list.Length()-1 ; b++ ) min_weight = ((min_weight>m_band_list(b).Wt()) ? m_band_list(b).Wt() : min_weight); m_band_list( m_band_list.Length() ).SetWt( min_weight ); // Now normalize weights so that white noise is always weighted the same // Overall factor to ensure that white noise ends up with the same RMS, whatever the weight double overall_factor=0.0; //fraction of the total number of samples belonging to each subband double subband_fraction; for( int i=1 ; i<=m_band_list.Length() ; i++ ) { subband_fraction = 1.0/((double) m_band_list(i).Scale() * m_band_list(i).Scale()); overall_factor += subband_fraction/( m_band_list(i).Wt() * m_band_list(i).Wt() ); } overall_factor = std::sqrt( overall_factor ); //go through and normalise for( int i=m_band_list.Length() ; i>0 ; i-- ) m_band_list(i).SetWt( m_band_list(i).Wt() * overall_factor ); } else {//cpd=0 so set all weights to 1 for( int i=1 ; i<=m_band_list.Length() ; i++ ) m_band_list(i).SetWt( 1.0 ); } //Finally, adjust to compensate for the absence of scaling in the transform //Factor used to compensate: double lfac; double hfac; int filt_shift; switch (wltfilter){ case DD9_7 : lfac = 1.218660804;; hfac = 0.780720058; filt_shift = 1; break; case LEGALL5_3 : lfac = 1.179535649; hfac = 0.81649658; filt_shift = 1; break; case DD13_7 : lfac = 1.235705971; hfac = 0.780719354; filt_shift = 1; break; case HAAR0 : lfac = 1.414213562; hfac = 0.707106781; filt_shift = 0; break; case HAAR1 : lfac = 1.414213562; hfac = 0.707106781; filt_shift = 1; break; case DAUB9_7 : lfac = 1.149604398; hfac = 0.869864452; filt_shift = 1; break; default: lfac = 1.0; hfac = 1.0; filt_shift = 0; } int idx; int shift; int depth = (m_band_list.Length()-1)/3; // Do the DC subband idx = m_band_list.Length(); double cf = (1<<(depth*filt_shift)) / std::pow(lfac,2*depth ) ; m_band_list(idx).SetWt( m_band_list(idx).Wt()*cf); // Do the non-DC subbands for (int level=1; level<=depth; level++) { shift = (depth-level+1)*filt_shift; for ( int orient=3;orient>=1; --orient ) { idx = 3*(depth-level)+orient; // index into the subband list idx = 3*(depth-level)+orient; // Divide through by the weight for the LF subband that was decomposed // to create this level cf = 1.0/ std::pow(lfac,2*(depth-level) ); if ( m_band_list(idx).Xp() != 0 && m_band_list(idx).Yp() != 0) // HH subband cf /= (hfac * hfac); else // LH or HL subband cf /= (lfac * hfac); cf *= double(1<<shift); m_band_list(idx).SetWt( m_band_list(idx).Wt()*cf ); }// orient }//level }
void SetDefaultEncoderParameters(EncoderParams& encparams) { encparams.SetLossless(false); encparams.SetQf(5.5f); encparams.GetPicPredParams().SetMVPrecision(MV_PRECISION_HALF_PIXEL); encparams.SetUsingAC(true); switch (encparams.GetVideoFormat()) { case VIDEO_FORMAT_4SIF525: case VIDEO_FORMAT_4CIF: case VIDEO_FORMAT_SD_480I60: case VIDEO_FORMAT_SD_576I50: encparams.SetL1Sep(3); encparams.SetNumL1(7); encparams.SetCPD(32.0f); break; case VIDEO_FORMAT_HD_720P60: case VIDEO_FORMAT_HD_720P50: encparams.SetL1Sep(3); encparams.SetNumL1(15); encparams.SetCPD(20.0f); break; case VIDEO_FORMAT_HD_1080I60: case VIDEO_FORMAT_HD_1080I50: case VIDEO_FORMAT_HD_1080P60: case VIDEO_FORMAT_HD_1080P50: encparams.SetL1Sep(3); encparams.SetNumL1(7); encparams.SetCPD(32.0f); break; case VIDEO_FORMAT_UHDTV_4K60: case VIDEO_FORMAT_UHDTV_4K50: case VIDEO_FORMAT_UHDTV_8K60: case VIDEO_FORMAT_UHDTV_8K50: encparams.SetL1Sep(6); encparams.SetNumL1(7); encparams.SetCPD(48.0f); break; case VIDEO_FORMAT_CIF: default: encparams.SetL1Sep(3); encparams.SetNumL1(19); encparams.SetCPD(20.0f); break; } }