/*--------------------------------------------------------------------------- * * Course: SoC design * * File: main.c * * Purpose: This is main code of H.263 video encoder * * Group: 22 * * Authors: 205441 Petteri Aimonen * * * Notes: This encoder code implements only a part of H.263 features. * As you know, H.263 standard defines only the decoder - not * the encoder. Thus, this encoder code produces bitstream that * any H.263 compliant decoder is able to decode. * * This implementation is an extremely simplified version * H.263 video encoder. For instance, parallel execution and * motion estimation is not applied at all in these codes. * Limitations: * - Only INTRA coding mode is supported * - Only QCIF picture format supported * - None of the optional coding modes supported * *--------------------------------------------------------------------------- */ #include "headers.h" #include #define MACROBLOCKS_Y 9 #define MACROBLOCKS_X 11 #define MACROBLOCK_SIZE (8*8*6) #define FRAME_SIZE (MACROBLOCK_SIZE * MACROBLOCKS_X * MACROBLOCKS_Y) #define QUANTIZER 20 vbool main(){ sint32 frame_count, frame_index; uint8 frame[FRAME_SIZE]; BitStreamType bitstream; bitstreamInitBuffer(&bitstream); bitstream.file = fopen("output.h263", "wb"); if (bitstream.file == NULL) { perror("output.h263"); return 1; } FILE *input = yuvOpenInputFile("carphone.qcif", &frame_count); if (input == NULL) { perror("carphone.qcif"); return 1; } for (frame_index = 0; frame_index < frame_count; frame_index++) { int x, y; uint8 input_macroblock[MACROBLOCK_SIZE]; sint16 dct_macroblock[MACROBLOCK_SIZE]; MBType macroblock = {0, dct_macroblock}; PictureType picturehdr = {frame_index, QUANTIZER}; if (!yuvReadFrame(input, frame)) { perror("yuvReadFrame"); return 1; } bitstreamAlign(&bitstream); codePictureHeader(&picturehdr, &bitstream); for (y = 0; y < MACROBLOCKS_Y; y++) { for (x = 0; x < MACROBLOCKS_X; x++) { memoryLoadMB(y, x, frame, input_macroblock); fdct_8x8(input_macroblock, dct_macroblock, 6); quantizeIntraMB(QUANTIZER, ¯oblock); codeIntraMB(¯oblock, &bitstream); } } } bitstreamFlushBufferToFile(&bitstream); fclose(bitstream.file); fclose(input); return 0; }