📄 main.c
字号:
FreeImage(prev_recon); if ( (!scalability_mode) || (scalability_mode && (prev_image != prev_enhancement_image) ) ) { FreeImage(prev_image); } } prev_image = curr_image; prev_recon = curr_recon; } /* Frame Layer Rate Control */ frameskip = FrameLayerRC(pic); prev_I_P_quant = pic->QUANT; /* Update frameskip for true B frames */ True_B_frameskip = P_frameskip / (successive_B_frames + 1); break; case PCT_PB: case PCT_IPB: bframes ++; pframes ++; frames += 2; pels = base_pels; lines = base_lines; cpels = base_pels/2; /* Set QP to pic->QUANT from previous encoded picture */ QP = prev_I_P_quant; pic->DQUANT = 0; if (EPTYPE) { /* Alternate picture rounding type */ pic->RTYPE = rtype[0] % 2; rtype[0]++; } image = ReadImage(seqfilename,frame_no,headerlength); curr_image = FillImage(image); B_image = curr_image; image = ReadImage(seqfilename,frame_no + P_frameskip,headerlength); curr_image = FillImage(image); pic->TRB = P_frameskip * orig_frameskip; frame_no += P_frameskip; if (pic->TRB>7) pic->TRB=7; /* Code two frames as a PB-frame */ B_recon = InitImage(pels*lines); fprintf(stdout,"Coding PB frames %d and %d... ", frame_no - P_frameskip, frame_no); fflush(stdout); curr_recon = InitImage(pels*lines); /* Code PP or PB pictures. */ CodeOneOrTwo( curr_image, B_image, prev_image, prev_recon, QP, 2*P_frameskip*orig_frameskip, bits, pic, B_recon, curr_recon); if (NULL != prev_recon) { FreeImage(prev_recon); if ( (!scalability_mode) || (scalability_mode && (prev_image != prev_enhancement_image) ) ) { FreeImage(prev_image); } } prev_image = curr_image; prev_recon = curr_recon; CalculateStatistics(curr_image,curr_recon,B_image, B_recon, bits, pic->BQUANT, pic); /* Frame Layer Rate Control */ frameskip = FrameLayerRC(pic); prev_I_P_quant = pic->QUANT; break; case PCT_B: Bframes ++; /* frames++;*/ pels = base_pels; lines = base_lines; cpels = base_pels/2; image = ReadImage(seqfilename,frame_no,headerlength); curr_image = FillImage(image); fprintf(stdout,"Coding B frame %d... ", frame_no); fflush(stdout); /* Set QP to b_picture_quant, no rate control for true B yet */ QP = b_picture_quant; pic->DQUANT = 0; rtype[0]++; /* Code the next frame as true-B. */ curr_recon = InitImage(pels*lines); mv_outside_frame_old = mv_outside_frame; mv_outside_frame = ON; /* Code the current B picture. */ CodeOneTrueB( next_P_image, curr_image, prev_P_image, prev_P_recon, QP, True_B_frameskip * orig_frameskip, bits, pic, curr_recon, next_P_recon); CalculateStatistics(curr_image, curr_recon, NULL, NULL, bits, QP, pic); mv_outside_frame = mv_outside_frame_old; break; case PCT_EI: EIframes ++; pels = enhancement_pels; lines = enhancement_lines; cpels = enhancement_pels/2; fprintf(stdout,"Coding EI frame %d... ", frame_no); fflush(stdout); /* QP fixed for enhancement layer */ QP = enhancement_layer_quant; pic->DQUANT = 0; pic->UFEP = 1; pic->RLNUM = BASE_LAYER_NUM; pic->ELNUM = ENHANCEMENT_LAYER_NUM; /* Alternate picture rounding type */ pic->RTYPE = rtype[pic->ELNUM-1] % 2; rtype[pic->ELNUM-1]++; /* For all possible spatial scalings */ if (scalability_mode >= 3) { /* No MVs from reference layer, so don't need to frame recon */ curr_reference_recon = UpsampleReferenceLayerPicture(prev_recon); /* Enhancement layer image is temporally simultaneous, same image as was * just coded in reference layer, i.e. stored as prev_image */ if (enhance_seqfilename[0] == '\0') { curr_image = UpsampleReferenceLayerPicture(prev_image); } else { image = ReadImage(enhance_seqfilename,frame_no,headerlength); curr_image = FillImage(image); } source_format_old = pic->source_format; pic->source_format = (scalability_mode>=7) ? source_format_old+1 : SF_CUSTOM; } else { curr_reference_recon = prev_recon; curr_image = prev_image; } mv_outside_frame_old = mv_outside_frame; mv_outside_frame = ON; curr_enhancement_recon = InitImage(pels*lines); CodeOneEI(curr_image, curr_reference_recon, QP, bits, pic, curr_enhancement_recon); /* Must apply DF here, as only now do we have fully reconstructed, enhanced picture */ if (deblocking_filter) { EdgeFilter(curr_enhancement_recon,pic); } CalculateStatistics(curr_image, curr_enhancement_recon, NULL, NULL, bits, QP, pic); mv_outside_frame = mv_outside_frame_old; /* Free the past prev_enhancement_image and prev_enhancement_recon, * no longer needed */ if (NULL != prev_enhancement_image) { FreeImage(prev_enhancement_image); FreeImage(prev_enhancement_recon); } /* Set new prev_enhancement_image and prev_enhancement_recon to old * next_P_image and next_P_recon respectively */ prev_enhancement_image = curr_image; prev_enhancement_recon = curr_enhancement_recon; if (scalability_mode >= 3) { pic->source_format = source_format_old; } break; case PCT_EP: EPframes++; pels = enhancement_pels; lines = enhancement_lines; cpels = enhancement_pels/2; fprintf(stdout,"Coding EP frame %d... ", frame_no); fflush(stdout); /* QP fixed for enhancement layer */ QP = enhancement_layer_quant; pic->DQUANT = 0; pic->UFEP = 1; pic->RLNUM = BASE_LAYER_NUM; pic->ELNUM = ENHANCEMENT_LAYER_NUM; /* Alternate picture rounding type */ pic->RTYPE = rtype[pic->ELNUM-1] % 2; rtype[pic->ELNUM-1]++; /* For all possible spatial scalings */ if (scalability_mode >= 3) { /* No MVs from reference layer, so don't need to frame recon */ curr_reference_recon = UpsampleReferenceLayerPicture(prev_recon); /* Enhancement layer image is temporally simultaneous, same image as was * just coded in reference layer, i.e. stored as prev_image */ if (enhance_seqfilename[0] == '\0') { curr_image = UpsampleReferenceLayerPicture(prev_image); } else { image = ReadImage(enhance_seqfilename,frame_no,headerlength); curr_image = FillImage(image); } source_format_old = pic->source_format; pic->source_format = (scalability_mode>=7) ? source_format_old+1 : SF_CUSTOM; } else { curr_reference_recon = prev_recon; curr_image = prev_image; } curr_enhancement_recon = InitImage(pels*lines); mv_outside_frame_old = mv_outside_frame; mv_outside_frame = ON; /* Code the current EP picture. */ CodeOneEP( curr_image, prev_enhancement_image, prev_enhancement_recon, QP, P_frameskip*orig_frameskip, bits, pic, curr_reference_recon, curr_enhancement_recon); if (deblocking_filter) { EdgeFilter(curr_enhancement_recon,pic); } CalculateStatistics(curr_image, curr_enhancement_recon, NULL, NULL, bits, QP, pic); if (NULL != prev_enhancement_image) { FreeImage(prev_enhancement_image); FreeImage(prev_enhancement_recon); } prev_enhancement_image = curr_image; prev_enhancement_recon = curr_enhancement_recon; mv_outside_frame = mv_outside_frame_old; if (scalability_mode >= 3) { pic->source_format = source_format_old; } break; default: break; } /* Store frame and update Thread counter and image counter for VRC */ if (pic->reference_picture_selection) { if (!pic->sync) { /* for sync frames, only store the first thread */ StorePicture(pic->TR, prev_image, prev_recon); } /* store the TRP for the next picture */ thread[thread_count][(frame_in_thread+1)%frames_per_thread]->TRP = pic->TR; ++thread_count; if (thread_count == number_of_threads || pic->picture_coding_type == PCT_INTRA) { /* If this frame is a sync Intra frame or all threads or coded we increment the picture in all threads */ /* The TRP of remaining threads for I reference pictures should be updated */ for (j=thread_count;j<number_of_threads;j++) thread[j][(frame_in_thread+1)%frames_per_thread]->TRP = pic->TR; thread_count = 0; frame_in_thread = ++frame_in_thread % frames_per_thread; } } /* Update full extended PTYPE */ if (EPTYPE) { /* UFEP is set once every 5 sec or once every five pictures * * whichever is a larger time interval */ if ((frames % 5 && (TR_old - TR_new) / pic->src_frame_rate >= 5) || (TR_old - TR_new) / pic->src_frame_rate >= 5) { TR_new = pic->TRB; pic->UFEP = ON; } else { pic->UFEP = OFF; } TR_old = pic->TRB; } if (pic->PB) { if (write_repeated) wcopies = P_frameskip; for (j = 0; j < wcopies; j++) WriteImage(B_recon,outputfile); /* write wcopies frames to disk */ } if (write_repeated) { wcopies = (pb_frames ? P_frameskip : frameskip); if (wcopies + frame_no > end) wcopies = end - frame_no + 1; } for (j = 0; j < wcopies; j++) if (PCT_EI == pic->picture_coding_type || PCT_EP == pic->picture_coding_type) { /* write wcopies frames to disk */ WriteImage(curr_enhancement_recon,outputfile_enhance); } else { /* write wcopies frames to disk */ if (successive_B_frames && PCT_INTRA != pic->picture_coding_type) { /* Write P picture */ if (B_pictures_to_code != successive_B_frames) { if (B_pictures_to_code == 0) { WriteImage(curr_recon,outputfile); WriteImage(next_P_recon,outputfile); } else { WriteImage(curr_recon,outputfile); } } } else { WriteImage(curr_recon,outputfile); } } /* Can immediately free true B images, as the are never used for prediction */ if (successive_B_frames && PCT_B == pic->picture_coding_type) { FreeImage(curr_image); FreeImage(curr_recon); } if (pic->PB) { FreeImage(B_image); FreeImage(B_recon); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -