胡斌

print the run time and speed ratio for encoding

fix the bug for RGB2YUV
#include "AVTranscoder.h"
#include "tools.h"
extern "C" {
#include <libswscale/swscale.h>
}
... ... @@ -10,6 +12,9 @@ extern "C" {
#define SCALED_H 60
#define SRC_W 320
#define SRC_H 240
uint8_t blank_r = 0x16;
uint8_t blank_g = 0x5a;
uint8_t blank_b = 0x82;
CAVTranscoder::CAVTranscoder(bool bOne2One):
_start_time(INT64_MAX),
... ... @@ -43,6 +48,7 @@ _last_videos_got(-1)
printf("Error alloc frame buffer for scaling video frame");
}
}
RGB2YUV(blank_r, blank_g, blank_b, &_blank_y, &_blank_u, &_blank_v);
}
... ... @@ -342,9 +348,9 @@ int CAVTranscoder::open_output_file(const char *filename)
}
}
if(fill_pure_color){//fill with pure color
memset(pDstFrame->data[0], 0, _nOutputWidth * _nOutputHeight);
memset(pDstFrame->data[1], 0x80, _nOutputWidth *_nOutputHeight / 4);
memset(pDstFrame->data[2], 0x80, _nOutputWidth * _nOutputHeight / 4);
memset(pDstFrame->data[0], _blank_y, _nOutputWidth * _nOutputHeight);
memset(pDstFrame->data[1], _blank_u, _nOutputWidth *_nOutputHeight / 4);
memset(pDstFrame->data[2], _blank_v, _nOutputWidth * _nOutputHeight / 4);
}
int imageIdx = 0;
... ... @@ -422,7 +428,10 @@ int CAVTranscoder::open_output_file(const char *filename)
int nDstSize = avpicture_get_size(AV_PIX_FMT_YUV420P,_nOutputWidth, _nOutputHeight);
uint8_t *dstbuf = new uint8_t[nDstSize];
avpicture_fill((AVPicture*)pDstFrame, dstbuf, AV_PIX_FMT_YUV420P, _nOutputWidth, _nOutputHeight);
memset(dstbuf, 0x80, nDstSize);
memset(pDstFrame->data[0], _blank_y, _nOutputWidth * _nOutputHeight);
memset(pDstFrame->data[1], _blank_u, _nOutputWidth *_nOutputHeight / 4);
memset(pDstFrame->data[2], _blank_v, _nOutputWidth * _nOutputHeight / 4);
if (decoders_got_frame.size() == 2){
if (_last_videos_got != 2) {
... ...
... ... @@ -44,6 +44,8 @@ private:
struct SwsContext * _swsCtx;
AVFrame * _scaledFrame;
int _last_videos_got;
uint8_t _blank_y, _blank_u, _blank_v;
public:
void set_max_audio(int max_audio);
};
... ...
... ... @@ -961,6 +961,8 @@ int load_record_info(char * record_info)
int process_av_files(char * record_info)
{
time_t start, end;
time(&start);
load_record_info(record_info);
get_outinfo_file_name(record_info);
... ... @@ -1014,6 +1016,10 @@ int process_av_files(char * record_info)
save_out_info(((double)cur_time)/1000.0, out_media_file.c_str());
time(&end);
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));
return 0;
}
... ...
... ... @@ -93,6 +93,7 @@
<ClInclude Include="AudioDecoder.h" />
<ClInclude Include="AVDecoder.h" />
<ClInclude Include="media_info.h" />
<ClInclude Include="tools.h" />
<ClInclude Include="VideoDecoder.h" />
<ClInclude Include="AVTranscoder.h" />
</ItemGroup>
... ...
... ... @@ -53,5 +53,8 @@
<ClInclude Include="AVTranscoder.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="tools.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
... ...
... ... @@ -39,6 +39,6 @@ time_t calc_sec1970(int Y, int M, int D, int h, int m, int s)
void RGB2YUV(unsigned char r, unsigned char g, unsigned char b, unsigned char *y, unsigned char * u, unsigned char * v){
*y = (unsigned char)(0.30*r + 0.59*g + 0.11*b);
*u = (unsigned char)(0.493*(b - (*y)));
*v = (unsigned char)(0.877*(r - (*y)));
*u = (unsigned char)(0.493*(b - (*y)) + 128);
*v = (unsigned char)(0.877*(r - (*y)) + 128);
}
... ...