1 /*******************************************************************************
2 * File Name : h264enc_test.c
5 * Created Time : Sat 31 Oct 2009 04:26:05 PM CST
7 ******************************************************************************/
10 /*******************************************************************************
11 * Desc : Includes Files
12 ******************************************************************************/
14 #include "mfc/common.h"
21 /*******************************************************************************
22 * Desc : Macro Definations
23 ******************************************************************************/
26 /*******************************************************************************
27 * Desc : Type Definations
28 ******************************************************************************/
31 /*******************************************************************************
32 * Desc : Global Variables
33 ******************************************************************************/
36 /*******************************************************************************
37 * Desc : File Variables
38 ******************************************************************************/
46 unsigned int measureTime(struct timeval
*start
, struct timeval
*stop
)
48 unsigned int sec
, usec
, time
;
50 sec
= stop
->tv_sec
- start
->tv_sec
;
51 if(stop
->tv_usec
>= start
->tv_usec
)
53 usec
= stop
->tv_usec
- start
->tv_usec
;
57 usec
= stop
->tv_usec
+ 1000000 - start
->tv_usec
;
60 time
= sec
*1000 + usec
/1000;
77 int Test_H264_Encoder(int argc
, char **argv
)
98 // int para_change[2];
102 H264Encoder zheEncoder
;
105 struct timeval start
;
107 unsigned int time
= 0;
113 printf("Usage : mfc <YUV file name> <output filename> <width> <height> ");
114 printf("<frame rate> <bitrate> <GOP number>\n");
119 in_fd
= open(argv
[1], O_RDONLY
);
120 out_fd
= open(argv
[2], O_RDWR
| O_CREAT
| O_TRUNC
, 0644);
122 if( (in_fd
< 0) || (out_fd
< 0) ) {
123 printf("input/output file open error\n");
127 // get input file size
129 file_size
= s
.st_size
;
131 // mapping input file to memory
132 in_addr
= (char *)mmap(0, file_size
, PROT_READ
, MAP_SHARED
, in_fd
, 0);
133 if(in_addr
== NULL
) {
134 printf("input file memory mapping failed\n");
138 width
= atoi(argv
[3]);
139 height
= atoi(argv
[4]);
140 frame_rate
= atoi(argv
[5]);
141 bitrate
= atoi(argv
[6]);
142 gop_num
= atoi(argv
[7]);
144 frame_size
= (width
* height
* 3) >> 1;
145 frame_count
= file_size
/ frame_size
;
147 printf("file_size : %d, frame_size : %d, frame count : %d\n", file_size
, frame_size
, frame_count
);
150 nRetVal
= zheEncoder
.Create (width
, height
, frame_rate
, bitrate
, gop_num
);
152 LOG_MSG(LOG_ERROR
, "Test_Encoder", "create encoder failed\n");
156 backup_frame_cnt
= frame_count
;
158 while (frame_count
> 0)
160 printf ("frame count : %d\n", frame_count
);
162 // copy YUV data into input buffer
163 gettimeofday(&start
, NULL
);
165 p_outbuf
= zheEncoder
.Encode (in_addr
, frame_size
, size
);
166 if (frame_count
== backup_frame_cnt
) {
167 zheEncoder
.GetConfig(H264_ENC_GETCONF_HEADER_SIZE
, &hdr_size
);
168 printf("Header Size : %d\n", hdr_size
);
170 in_addr
+= frame_size
;
172 gettimeofday (&stop
, NULL
);
173 time
+= measureTime (&start
, &stop
);
177 write(out_fd
, p_outbuf
, size
);
182 printf("Decoding Time : %u, Frame Count : %d, FPS : %f\n", time
, frame_cnt
, (float)frame_cnt
*1000/time
);
184 zheEncoder
.Destroy ();
186 munmap(in_addr
, file_size
);
196 int main ( int argc
, char *argv
[] )
198 Test_H264_Encoder(argc
, argv
);
200 } /* ---------- end of function main ---------- */