Ai
2 Star 0 Fork 0

lidedongsn/H264Decoder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
h264_decoder_test.cpp 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
#include "h264_decoder.h"
#include "h264_file.h"
#include <time.h>
#include<sys/time.h>
#include <unistd.h>
int main(int argc, char **argv) {
uint8_t *data;
int file_size;
uint32_t decode_len = 0;
int data_size = INBUF_SIZE;
int frame_count = 0;
AVFrame *frame;
const char* filename;
struct timeval start;
struct timeval end;
if (argc <= 1) {
fprintf(stderr, "Usage: %s <input 264 file>\n", argv[0]);
exit(-1);
}
filename = argv[1];
H264File file(filename);
file.Open();
data = file.GetData();
file_size = file.GetSize();
if(!data) {
fprintf(stderr, "GetData failed!");
exit(-1);
}
H264Decoder *decoder = new H264Decoder();
decoder->Init();
printf("%s size: %d\n", filename, file_size);
printf("Starting decode ...\n");
gettimeofday(&start, NULL);
while(file_size >= 0) {
if(file_size < INBUF_SIZE) {
data_size = file_size;
}else{
data_size = INBUF_SIZE;
}
while(data_size > 0) {
frame = decoder->Decode(data, data_size, &decode_len);
data += decode_len;
data_size -= decode_len;
// printf("data_size: %d, decode_len: %d\n", data_size, decode_len);
if(frame) {
frame_count++;
// printf("frame_count %d\n", frame_count);
}
}
file_size -= INBUF_SIZE;
// printf("-->%s size: %d\n", filename, file_size);
}
decoder->Flush();
gettimeofday(&end, NULL);
printf("%ld %ld %ld, %ld\n", end.tv_sec , start.tv_sec, end.tv_usec , start.tv_usec);
long duration_sec = end.tv_sec - start.tv_sec;
long duration_usec = 0;
if(duration_sec > 0 && end.tv_usec < start.tv_usec) {
duration_sec -= 1;
duration_usec = 1000000 - start.tv_usec;
duration_usec = duration_usec + end.tv_usec;
}else{
duration_usec = end.tv_usec - start.tv_usec;
}
printf("Decode done! frame_count: %d, %ld s %ld us\n", frame_count, duration_sec, duration_usec);
file.Close();
if(decoder != NULL) {
delete decoder;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lidecoolblue/H264Decoder.git
git@gitee.com:lidecoolblue/H264Decoder.git
lidecoolblue
H264Decoder
H264Decoder
master

搜索帮助