📄 mp4dmain.c
字号:
/******************************************************************************// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright (c) 2003 Intel Corporation. All Rights Reserved.//// Description: Decoder main entry function of MPEG-4 video decoder sample// code for Intel(R) Integrated Performance Primitives.// Functions List:// main()// output_frame_mpeg4()******************************************************************************/#include "sampmp4.h"/******************************************************************************// Name: output_frame_mpeg4// Description: Dump the decoded yuv plane to the appointed output file//// Input Parameters:// picture Pointer to the decoded yuv plane// fpout Output file handle// Output Parameters:// fpout The updated output file handle//// Note:// the fpout handle shouldn't be NULL.//******************************************************************************/void output_frame_mpeg4 (FILE *fpout, sample_picture *picture) { int i, step; Ipp8u *dst_y, *dst_u, *dst_v; dst_y = picture->pic_plane[0]; dst_u = picture->pic_plane[1]; dst_v = picture->pic_plane[2]; /* Y plane */ step = picture->pic_plane_step[0]; for(i = 0; i<picture->pic_height; i++) { fwrite(dst_y, sizeof(char), picture->pic_width, fpout); dst_y += step; } /* U plane */ step = picture->pic_plane_step[1]; for(i = 0; i<picture->pic_height/2; i++) { fwrite(dst_u, sizeof(char), picture->pic_width/2, fpout); dst_u += step; } /* V plane */ step = picture->pic_plane_step[2]; for(i = 0; i<picture->pic_height/2; i++) { fwrite(dst_v, sizeof(char), picture->pic_width/2, fpout); dst_v += step; } }/*****************************************************************************// Name: main// Description: Entry function for MPEG4 simple profile decoder//// Returns: 0: decoding okay// others: decoding fail*****************************************************************************/int main (int argc, char *argv[]){ FILE *fpin = NULL, *fpout = NULL; sample_picture pic; sample_bitstream stream_buf; mp4_dec_state dec_state; sample_status ret_code; /* return value */ int end_flag = 0, last_frame_flag = 0; /* argument check */ if (3 > argc) { printf("Usage: MPEG4Decoder.exe infile outfile!\n" " infile : .cmp input filename\n" " outfile: .yuv output filename\n"); return -1; } /* open input .cmp file handle */ fpin = fopen(argv[1], "rb"); if (!fpin) { printf("Can't open input cmp file!\n"); return -1; } /* open output .yuv file handle */ fpout = fopen(argv[2], "wb"); if (!fpout) { printf("Can't open output yuv file!\n"); return -1; } /* init input video bitstream buffer */ ret_code = init_input_video_buffer(&stream_buf); if (ret_code != SAMPLE_STATUS_NOERR) { printf("Init input video bitstream buffer error!\n"); return -1; } /* load bitstream into buffer for the 1st time */ ret_code = load_video_buffer(&stream_buf, fpin); if (ret_code != SAMPLE_STATUS_NOERR) { release_input_video_buffer(&stream_buf); printf ("Empty buffer error!\n"); return -1; } /* init decoder state struct */ ret_code = decoder_init_alloc_mpeg4(&stream_buf, &dec_state); if (ret_code != SAMPLE_STATUS_NOERR) { release_input_video_buffer(&stream_buf); printf ("Init decoder state error!\n"); return -1; } /* decoding loop */ while (!end_flag) { /* decode video stream frame by frame */ ret_code = decode_mpeg4(&stream_buf, &pic, &dec_state); switch (ret_code) { /* one frame has been decoded successfully */ case SAMPLE_STATUS_NOERR: output_frame_mpeg4(fpout, &pic); /* if it's the last frame, exit the decoding loop */ if (1 == last_frame_flag) { end_flag = 1; } break; /* next sync code is not found in the buffer */ case SAMPLE_STATUS_SYNCNOTFOUND_ERR: /* not end of input .cmp file stream */ if (!feof(fpin)) { /* load bitstream into buffer to fill it up */ if (SAMPLE_STATUS_NOERR != load_video_buffer(&stream_buf, fpin)) { /* no new bits loaded, this could happen if the buffer // length is less than one frame of raw stream or the // sync code is missing at all */ end_flag = 1; }; } else { /* to decode the last frame in buffer */ last_frame_flag = 1; /* insert sync code in the end of the stream to provide error // protection boundary for the last frame */ insert_sc_mpeg4 (&stream_buf); } break; default: /* exceptions */ end_flag = 1; } } /* print the final decoding state */ switch (ret_code) { case SAMPLE_STATUS_NOERR: printf("Everything is okay!\n"); break; case SAMPLE_STATUS_ERR: printf("Unknown/Unspecified error!\n"); break; case SAMPLE_STATUS_NOMEM_ERR: printf("Memory allocation failed!\n"); break; case SAMPLE_STATUS_BADARG_ERR: printf("Bad argument error!\n"); break; case SAMPLE_STATUS_SYNCNOTFOUND_ERR: printf("Miss synchronize code!\n"); break; case SAMPLE_STATUS_INPUT_ERR: printf("Wrong input parameter!\n"); break; case SAMPLE_STATUS_NOTSUPPORTED_ERR: printf("Not support in current version yet!\n"); break; default: printf("Out of control!\n"); break; } /* free decoder state struct working buffer */ decoder_free_mpeg4(&dec_state); /* free input video bitstream buffer */ release_input_video_buffer(&stream_buf); /* close the input and output file handle */ fclose (fpout); fclose (fpin); return (SAMPLE_STATUS_NOERR == ret_code) ? 0 : -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -