time0 = time1 = 0;
input_file = fopen(input_filename, "rb");
if (input_file == NULL)
{
printf("Could not open input file '%s' \n", input_filename);
goto lb_exit;
}
if (argc>5)
{
output_filename = argv[5];
output_file = fopen(output_filename, "wb");
if (output_file == NULL)
{
printf("Could not open output file '%s' \n", output_filename);
goto lb_exit;
}
}
/// Decoder initialization
vsm2dec_options.decode_type =
VSM2DEC_DECODE_I_FRAMES | VSM2DEC_DECODE_P_FRAMES |
VSM2DEC_DECODE_B_FRAMES | VSM2DEC_DECODE_D_FRAMES;
decoder = vsm2dec_create(&vsm2dec_options);
if (decoder==NULL)
{
printf("Could not initializate decoder\n");
goto lb_exit;
}
/// Title initialization
title = title_init(title_filename, title_width, title_height);
if (title==NULL)
{
printf("Could not initializate title\n");
goto lb_exit;
}
/// Encoder initialization
encoder = vsm2tenc_create();
if (encoder==NULL)
{
printf("Could not initializate encoder\n");
goto lb_exit;
}
/// Allocating memory for buffers
decoder_coded_data = malloc(DECODER_BUFFER_SIZE);
if (decoder_coded_data==NULL)
{
printf("Could not allocate memory for decoder video buffer\n");
goto lb_exit;
}
encoder_coded_data = malloc(ENCODER_BUFFER_SIZE);
if (encoder_coded_data==NULL)
{
printf("Could not allocate memory for encoder video buffer\n");
goto lb_exit;
}
frame_number = 0;
time0 = time(0);
perf_init();
perf_start();
//////////////////////////////////////////////////////////////////////////
/// main cycle
while (1)
{
/// Reading MPEG2 video stream from the file
bytes_read = fread(decoder_coded_data, 1, DECODER_BUFFER_SIZE, input_file);
/// Send MPEG2 video stream to decoder
vsm2dec_send_data(decoder, decoder_coded_data, bytes_read, 0);
while (1)
{
vsm2dec_decode(decoder, &vsm2dec_output);
if (vsm2dec_output.error_log)
report_decoder_errors(vsm2dec_output.error_log);
if (vsm2dec_output.frame_decoded)
{
frame_number++;
#ifdef DUMP_DECODER_OUTPUT
dump_vsm2dec_output(&vsm2dec_output);
#endif
/// Process titling (edit frame)
title_status = title_process(title, &vsm2dec_output, &vsm2tenc_input);
/// Check for frame overflow
if (title_status==TITLE_NO_FREE_BUFFERS)
{
printf("No free buffers in title module, increment MAX_YUV_BUFFER_SIZE\n");
goto lb_exit;
}
/// Check for decoder compability
if (title_status==TITLE_MISSING_MACROBLOCK_INFO)
{
printf("Decoder doesn't return macroblock info. Please, recompile decoder.\n");
goto lb_exit;
}
#ifdef DUMP_TITLE_OUTPUT
else
dump_title_output(&vsm2tenc_input);
#endif
/// Sending frame to the encoder
vsm2tenc_send_frame(encoder, &vsm2tenc_input);
/// Encode cycle
while (1)
{
frame_id = vsm2tenc_get_frame(encoder);
if (frame_id!=VSM2ENC_FRAME_ID_NO_FRAME)
{
title_status = title_free_buffer(title, frame_id);
}
encoder_status = vsm2tenc_encode_frame(encoder, encoder_coded_data, ENCODER_BUFFER_SIZE);
if (encoder_status!=VSM2ENC_NO_INPUT)
{
bytes_encoded = vsm2tenc_get_encoded_data_size(encoder, NULL);
if (output_file)
fwrite(encoder_coded_data, 1, bytes_encoded, output_file);
}
else
break;
} /// Encode cycle
}
else
break;
}
if (bytes_read==0) break;
} /// Main cycle
/// Putting SEQUENCE_END_START_CODE
bytes_encoded = vsm2tenc_finalize_sequence(encoder, encoder_coded_data, ENCODER_BUFFER_SIZE);
if (output_file)
fwrite(encoder_coded_data, 1, bytes_encoded, output_file);
lb_exit:
perf_end();
time1 = time(0);
lTicks += (lEnd-lStart);
/// Deallocating memory for buffers
if (decoder_coded_data!=NULL) free(decoder_coded_data);
if (encoder_coded_data!=NULL) free(encoder_coded_data);
/// Decoder finalization
vsm2dec_release(decoder);
/// Title finalization
title_done(title);
/// Encoder finalization
vsm2tenc_release(encoder);
/// Closing input and output files
if (input_file!=NULL) fclose(input_file);
if (output_file!=NULL) fclose(output_file);
perf_report(frame_number, time1-time0);
return 0;
}
////////////////////////////////////////////////////////////////////////// EOF
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.