胡斌

more code about transcode

... ... @@ -8,7 +8,8 @@ _cur_a_ts_ms(INT64_MAX),
_cur_v_ts_ms(INT64_MAX),
_end_time_ms(0),
_cur_a_frame(NULL),
_cur_v_frame(NULL)
_cur_v_frame(NULL),
_media_role(mr_student)
{
}
... ... @@ -19,6 +20,7 @@ CAVDecoder::~CAVDecoder()
int CAVDecoder::add(media_info &info)
{
_media_role = info.m_role;
if (info.m_type == mt_audio) {
_a_start_time_ms = info.start_time_ms;
_a_end_time_ms = info.end_time_ms;
... ...
... ... @@ -15,7 +15,10 @@ public:
bool get_one_v_frame();
int64_t _cur_a_ts_ms;
int64_t _cur_v_ts_ms;
media_role _media_role;
AVFrame * _cur_a_frame;
AVFrame * _cur_v_frame;
protected:
list<media_info> _video_info;
list<media_info> _audio_info;
... ... @@ -26,8 +29,7 @@ protected:
int64_t _v_start_time_ms;
int64_t _v_end_time_ms;
int64_t _end_time_ms;
AVFrame * _cur_a_frame;
AVFrame * _cur_v_frame;
private:
AVFrame * get_blank_frame();
AVFrame * get_silence_frame();
... ...
... ... @@ -3,8 +3,16 @@
CAVTranscoder::CAVTranscoder():
_start_time(INT64_MAX),
_all_processed(true)
_all_processed(true),
_one2one(false),
_nOutputWidth(320)
{
if (_one2one) {
_nOutputHeight = 480;
}
else {
_nOutputHeight = 240;
}
}
... ... @@ -38,7 +46,7 @@ int CAVTranscoder::add(media_info & info)
int64_t CAVTranscoder::transcode()
{
vector<CAVDecoder *> decoders_got_frame;
vector < CAVDecoder *>::iterator it = _decoders.begin();
vector <CAVDecoder *>::iterator it = _decoders.begin();
for (; it != _decoders.end();) {
if((*it)->get_one_v_frame()){
decoders_got_frame.push_back(*it);
... ... @@ -201,6 +209,16 @@ int CAVTranscoder::open_output_file(const char *filename)
int CAVTranscoder::mix_and_output_vframe(vector<CAVDecoder *> & decoders_got_frame)
{
if (_one2one){
return mix_and_output_one2one_vframe(decoders_got_frame);
}
else {
return mix_and_output_one2many_vframe(decoders_got_frame);
}
}
int CAVTranscoder::mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame)
{
vector < CAVDecoder *>::iterator it = decoders_got_frame.begin();
for (; it != decoders_got_frame.end(); it++) {
(*it)->free_cur_a_frame();
... ... @@ -208,17 +226,37 @@ int CAVTranscoder::open_output_file(const char *filename)
return 0;
}
int CAVTranscoder::mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame)
int CAVTranscoder::mix_and_output_one2many_vframe(vector<CAVDecoder *> & decoders_got_frame)
{
vector < CAVDecoder *>::iterator it = decoders_got_frame.begin();
for (; it != decoders_got_frame.end(); it++) {
(*it)->free_cur_v_frame();
return 0;
}
int CAVTranscoder::fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y)
{
}
int CAVTranscoder::mix_and_output_one2one_vframe(vector<CAVDecoder *> & decoders_got_frame)
{
//prepare one2one base frame
AVFrame *pDstFrame = av_frame_alloc();
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);
if (decoders_got_frame.size() == 2){
fillDestFrame(pDstFrame, decoders_got_frame[0]->_cur_v_frame, 0, decoders_got_frame[0]->_media_role == mr_teacher ? 0 : 240);
fillDestFrame(pDstFrame, decoders_got_frame[1]->_cur_v_frame, 0, decoders_got_frame[1]->_media_role == mr_teacher ? 0 : 240);
}
else {
fillDestFrame(pDstFrame, decoders_got_frame[0]->_cur_v_frame, 0, 0);
}
return 0;
}
int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame) {
int ret;
int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame) {
int ret;
int got_frame_local;
AVPacket enc_pkt;
#if 0
... ...
... ... @@ -23,9 +23,17 @@ protected:
int64_t _start_time;
int64_t _cur_a_time;
int64_t _cur_v_time;
int _nOutputWidth;
int _nOutputHeight;
private:
int mix_and_output_vframe(vector<CAVDecoder *> & decoders_got_frame);
int mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame);
bool _all_processed;
bool _one2one;
int mix_and_output_one2one_vframe(vector<CAVDecoder *> & decoders_got_frame);
int mix_and_output_one2many_vframe(vector<CAVDecoder *> & decoders_got_frame);
int fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y);
};
... ...