这是x264中的函数,请对每一行代码做注释static int encode( x264paramt *param, clioptt *opt ) { x264_t *h =…
- User
这是x264中的函数,请对每一行代码做注释static int encode( x264_param_t *param, cli_opt_t *opt ) { x264_t *h = NULL; x264_picture_t pic; cli_pic_t cli_pic; const cli_pulldown_t *pulldown = NULL; // shut up gcc
int i_frame = 0; int i_frame_output = 0; int64_t i_end, i_previous = 0, i_start = 0; int64_t i_file = 0; int i_frame_size; int64_t last_dts = 0; int64_t prev_dts = 0; int64_t first_dts = 0;define MAX_PTS_WARNING 3 /* arbitrary */
int pts_warning_cnt = 0; int64_t largest_pts = -1; int64_t second_largest_pts = -1; int64_t ticks_per_frame; double duration; double pulldown_pts = 0; int retval = 0; opt->b_progress &= param->i_log_level < X264_LOG_DEBUG; /* set up pulldown */ // 设置了pulldown并且没有设置变帧率 if( opt->i_pulldown && !param->b_vfr_input ) { param->b_pulldown = 1; param->b_pic_struct = 1; pulldown = &pulldown_values[opt->i_pulldown]; param->i_timebase_num = param->i_fps_den; FAIL_IF_ERROR2( fmod( param->i_fps_num * pulldown->fps_factor, 1 ), "unsupported framerate for chosen pulldown\n" ); param->i_timebase_den = param->i_fps_num * pulldown->fps_factor; } h = x264_encoder_open( param ); FAIL_IF_ERROR2( !h, "x264_encoder_open failed\n" ); x264_encoder_parameters( h, param ); FAIL_IF_ERROR2( cli_output.set_param( opt->hout, param ), "can't set outfile param\n" ); i_start = x264_mdate(); /* ticks/frame = ticks/second / frames/second */ ticks_per_frame = (int64_t)param->i_timebase_den * param->i_fps_den / param->i_timebase_num / param->i_fps_num; FAIL_IF_ERROR2( ticks_per_frame < 1 && !param->b_vfr_input, "ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame ); ticks_per_frame = X264_MAX( ticks_per_frame, 1 ); if( !param->b_repeat_headers ) { // Write SPS/PPS/SEI x264_nal_t *headers; int i_nal; FAIL_IF_ERROR2( x264_encoder_headers( h, &headers, &i_nal ) < 0, "x264_encoder_headers failed\n" ); FAIL_IF_ERROR2( (i_file = cli_output.write_headers( opt->hout, headers )) < 0, "error writing headers to output file\n" ); } if( opt->tcfile_out ) fprintf( opt->tcfile_out, "# timecode format v2\n" ); /* Encode frames */ for( ; !b_ctrl_c && (i_frame < param->i_frame_total || !param->i_frame_total); i_frame++ ) { if( filter.get_frame( opt->hin, &cli_pic, i_frame + opt->i_seek ) ) break; x264_picture_init( &pic ); convert_cli_to_lib_pic( &pic, &cli_pic ); if( !param->b_vfr_input ) pic.i_pts = i_frame; if( opt->i_pulldown && !param->b_vfr_input ) { pic.i_pic_struct = pulldown->pattern[ i_frame % pulldown->mod ]; pic.i_pts = (int64_t)( pulldown_pts + 0.5 ); pulldown_pts += pulldown_frame_duration[pic.i_pic_struct]; } else if( opt->timebase_convert_multiplier ) pic.i_pts = (int64_t)( pic.i_pts * opt->timebase_convert_multiplier + 0.5 ); if( pic.i_pts <= largest_pts ) { if( cli_log_level >= X264_LOG_DEBUG || pts_warning_cnt < MAX_PTS_WARNING ) x264_cli_log( "x264", X264_LOG_WARNING, "non-strictly-monotonic pts at frame %d (%"PRId64" <= %"PRId64")\n", i_frame, pic.i_pts, largest_pts ); else if( pts_warning_cnt == MAX_PTS_WARNING ) x264_cli_log( "x264", X264_LOG_WARNING, "too many nonmonotonic pts warnings, suppressing further ones\n" ); pts_warning_cnt++; pic.i_pts = largest_pts + ticks_per_frame; } second_largest_pts = largest_pts; largest_pts = pic.i_pts; if( opt->tcfile_out ) fprintf( opt->tcfile_out, "%.6f\n", pic.i_pts * ((double)param->i_timebase_num / param->i_timebase_den) * 1e3 ); if( opt->qpfile ) parse_qpfile( opt, &pic, i_frame + opt->i_seek ); prev_dts = last_dts; i_frame_size = encode_frame( h, opt->hout, &pic, &last_dts ); if( i_frame_size < 0 ) { b_ctrl_c = 1; /* lie to exit the loop */ retval = -1; } else if( i_frame_size ) { i_file += i_frame_size; i_frame_output++; if( i_frame_output == 1 ) first_dts = prev_dts = last_dts; } if( filter.release_frame( opt->hin, &cli_pic, i_frame + opt->i_seek ) ) break; /* update status line (up to 1000 times per input file) */ if( opt->b_progress && i_frame_output ) i_previous = print_status( i_start, i_previous, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts ); } /* Flush delayed frames */ while( !b_ctrl_c && x264_encoder_delayed_frames( h ) ) { prev_dts = last_dts; i_frame_size = encode_frame( h, opt->hout, NULL, &last_dts ); if( i_frame_size < 0 ) { b_ctrl_c = 1; /* lie to exit the loop */ retval = -1; } else if( i_frame_size ) { i_file += i_frame_size; i_frame_output++; if( i_frame_output == 1 ) first_dts = prev_dts = last_dts; } if( opt->b_progress && i_frame_output ) i_previous = print_status( i_start, i_previous, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts ); } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.