print the run time and speed ratio for encoding
fix the bug for RGB2YUV
正在显示
6 个修改的文件
包含
27 行增加
和
6 行删除
| 1 | #include "AVTranscoder.h" | 1 | #include "AVTranscoder.h" |
| 2 | +#include "tools.h" | ||
| 3 | + | ||
| 2 | extern "C" { | 4 | extern "C" { |
| 3 | #include <libswscale/swscale.h> | 5 | #include <libswscale/swscale.h> |
| 4 | } | 6 | } |
| @@ -10,6 +12,9 @@ extern "C" { | @@ -10,6 +12,9 @@ extern "C" { | ||
| 10 | #define SCALED_H 60 | 12 | #define SCALED_H 60 |
| 11 | #define SRC_W 320 | 13 | #define SRC_W 320 |
| 12 | #define SRC_H 240 | 14 | #define SRC_H 240 |
| 15 | +uint8_t blank_r = 0x16; | ||
| 16 | +uint8_t blank_g = 0x5a; | ||
| 17 | +uint8_t blank_b = 0x82; | ||
| 13 | 18 | ||
| 14 | CAVTranscoder::CAVTranscoder(bool bOne2One): | 19 | CAVTranscoder::CAVTranscoder(bool bOne2One): |
| 15 | _start_time(INT64_MAX), | 20 | _start_time(INT64_MAX), |
| @@ -43,6 +48,7 @@ _last_videos_got(-1) | @@ -43,6 +48,7 @@ _last_videos_got(-1) | ||
| 43 | printf("Error alloc frame buffer for scaling video frame"); | 48 | printf("Error alloc frame buffer for scaling video frame"); |
| 44 | } | 49 | } |
| 45 | } | 50 | } |
| 51 | + RGB2YUV(blank_r, blank_g, blank_b, &_blank_y, &_blank_u, &_blank_v); | ||
| 46 | } | 52 | } |
| 47 | 53 | ||
| 48 | 54 | ||
| @@ -342,9 +348,9 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -342,9 +348,9 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 342 | } | 348 | } |
| 343 | } | 349 | } |
| 344 | if(fill_pure_color){//fill with pure color | 350 | if(fill_pure_color){//fill with pure color |
| 345 | - memset(pDstFrame->data[0], 0, _nOutputWidth * _nOutputHeight); | ||
| 346 | - memset(pDstFrame->data[1], 0x80, _nOutputWidth *_nOutputHeight / 4); | ||
| 347 | - memset(pDstFrame->data[2], 0x80, _nOutputWidth * _nOutputHeight / 4); | 351 | + memset(pDstFrame->data[0], _blank_y, _nOutputWidth * _nOutputHeight); |
| 352 | + memset(pDstFrame->data[1], _blank_u, _nOutputWidth *_nOutputHeight / 4); | ||
| 353 | + memset(pDstFrame->data[2], _blank_v, _nOutputWidth * _nOutputHeight / 4); | ||
| 348 | } | 354 | } |
| 349 | 355 | ||
| 350 | int imageIdx = 0; | 356 | int imageIdx = 0; |
| @@ -422,7 +428,10 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -422,7 +428,10 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 422 | int nDstSize = avpicture_get_size(AV_PIX_FMT_YUV420P,_nOutputWidth, _nOutputHeight); | 428 | int nDstSize = avpicture_get_size(AV_PIX_FMT_YUV420P,_nOutputWidth, _nOutputHeight); |
| 423 | uint8_t *dstbuf = new uint8_t[nDstSize]; | 429 | uint8_t *dstbuf = new uint8_t[nDstSize]; |
| 424 | avpicture_fill((AVPicture*)pDstFrame, dstbuf, AV_PIX_FMT_YUV420P, _nOutputWidth, _nOutputHeight); | 430 | avpicture_fill((AVPicture*)pDstFrame, dstbuf, AV_PIX_FMT_YUV420P, _nOutputWidth, _nOutputHeight); |
| 425 | - memset(dstbuf, 0x80, nDstSize); | 431 | + |
| 432 | + memset(pDstFrame->data[0], _blank_y, _nOutputWidth * _nOutputHeight); | ||
| 433 | + memset(pDstFrame->data[1], _blank_u, _nOutputWidth *_nOutputHeight / 4); | ||
| 434 | + memset(pDstFrame->data[2], _blank_v, _nOutputWidth * _nOutputHeight / 4); | ||
| 426 | 435 | ||
| 427 | if (decoders_got_frame.size() == 2){ | 436 | if (decoders_got_frame.size() == 2){ |
| 428 | if (_last_videos_got != 2) { | 437 | if (_last_videos_got != 2) { |
| @@ -44,6 +44,8 @@ private: | @@ -44,6 +44,8 @@ private: | ||
| 44 | struct SwsContext * _swsCtx; | 44 | struct SwsContext * _swsCtx; |
| 45 | AVFrame * _scaledFrame; | 45 | AVFrame * _scaledFrame; |
| 46 | int _last_videos_got; | 46 | int _last_videos_got; |
| 47 | + | ||
| 48 | + uint8_t _blank_y, _blank_u, _blank_v; | ||
| 47 | public: | 49 | public: |
| 48 | void set_max_audio(int max_audio); | 50 | void set_max_audio(int max_audio); |
| 49 | }; | 51 | }; |
| @@ -961,6 +961,8 @@ int load_record_info(char * record_info) | @@ -961,6 +961,8 @@ int load_record_info(char * record_info) | ||
| 961 | 961 | ||
| 962 | int process_av_files(char * record_info) | 962 | int process_av_files(char * record_info) |
| 963 | { | 963 | { |
| 964 | + time_t start, end; | ||
| 965 | + time(&start); | ||
| 964 | load_record_info(record_info); | 966 | load_record_info(record_info); |
| 965 | 967 | ||
| 966 | get_outinfo_file_name(record_info); | 968 | get_outinfo_file_name(record_info); |
| @@ -1014,6 +1016,10 @@ int process_av_files(char * record_info) | @@ -1014,6 +1016,10 @@ int process_av_files(char * record_info) | ||
| 1014 | 1016 | ||
| 1015 | save_out_info(((double)cur_time)/1000.0, out_media_file.c_str()); | 1017 | save_out_info(((double)cur_time)/1000.0, out_media_file.c_str()); |
| 1016 | 1018 | ||
| 1019 | + time(&end); | ||
| 1020 | + | ||
| 1021 | + printf("\nfinished,used %"PRIu64" second,encoded %.0lf second, the speed ratio is %.3lfX\n", end - start, (double)cur_time / 1000, cur_time / 1000.0 / (end - start)); | ||
| 1022 | + | ||
| 1017 | return 0; | 1023 | return 0; |
| 1018 | } | 1024 | } |
| 1019 | 1025 |
| @@ -93,6 +93,7 @@ | @@ -93,6 +93,7 @@ | ||
| 93 | <ClInclude Include="AudioDecoder.h" /> | 93 | <ClInclude Include="AudioDecoder.h" /> |
| 94 | <ClInclude Include="AVDecoder.h" /> | 94 | <ClInclude Include="AVDecoder.h" /> |
| 95 | <ClInclude Include="media_info.h" /> | 95 | <ClInclude Include="media_info.h" /> |
| 96 | + <ClInclude Include="tools.h" /> | ||
| 96 | <ClInclude Include="VideoDecoder.h" /> | 97 | <ClInclude Include="VideoDecoder.h" /> |
| 97 | <ClInclude Include="AVTranscoder.h" /> | 98 | <ClInclude Include="AVTranscoder.h" /> |
| 98 | </ItemGroup> | 99 | </ItemGroup> |
| @@ -53,5 +53,8 @@ | @@ -53,5 +53,8 @@ | ||
| 53 | <ClInclude Include="AVTranscoder.h"> | 53 | <ClInclude Include="AVTranscoder.h"> |
| 54 | <Filter>头文件</Filter> | 54 | <Filter>头文件</Filter> |
| 55 | </ClInclude> | 55 | </ClInclude> |
| 56 | + <ClInclude Include="tools.h"> | ||
| 57 | + <Filter>头文件</Filter> | ||
| 58 | + </ClInclude> | ||
| 56 | </ItemGroup> | 59 | </ItemGroup> |
| 57 | </Project> | 60 | </Project> |
| @@ -39,6 +39,6 @@ time_t calc_sec1970(int Y, int M, int D, int h, int m, int s) | @@ -39,6 +39,6 @@ time_t calc_sec1970(int Y, int M, int D, int h, int m, int s) | ||
| 39 | 39 | ||
| 40 | void RGB2YUV(unsigned char r, unsigned char g, unsigned char b, unsigned char *y, unsigned char * u, unsigned char * v){ | 40 | void RGB2YUV(unsigned char r, unsigned char g, unsigned char b, unsigned char *y, unsigned char * u, unsigned char * v){ |
| 41 | *y = (unsigned char)(0.30*r + 0.59*g + 0.11*b); | 41 | *y = (unsigned char)(0.30*r + 0.59*g + 0.11*b); |
| 42 | - *u = (unsigned char)(0.493*(b - (*y))); | ||
| 43 | - *v = (unsigned char)(0.877*(r - (*y))); | 42 | + *u = (unsigned char)(0.493*(b - (*y)) + 128); |
| 43 | + *v = (unsigned char)(0.877*(r - (*y)) + 128); | ||
| 44 | } | 44 | } |
-
请 注册 或 登录 后发表评论