胡斌

new feature, if no video in all student and teacher,the output mp4 is also no video

... ... @@ -34,13 +34,14 @@ int g_fps;
#define ensure_no_zero(x, v) if(!x) x = v
CAVTranscoder::CAVTranscoder(bool bOne2One, bool one2one_same_size, bool one2many_inflat, int width_teacher, int height_teacher, int width_student, int height_student, bool has_teacher, int max_audio,int keep_4_3) :
CAVTranscoder::CAVTranscoder(bool bOne2One, bool one2one_same_size, bool one2many_inflat, int width_teacher, int height_teacher, int width_student, int height_student, bool has_teacher, int max_audio, int max_video, int keep_4_3) :
_start_time(INT64_MAX),
_all_processed(true),
_nOutputWidth(320),
_cur_out_v_ts(0),
_cur_out_a_ts(0),
_max_audio(1),
_max_audio(max_audio),
_max_video(max_video),
_sws_ctx_w_h(NULL),
_sws_ctx_h_w(NULL),
_sws_ctx_h_h(NULL),
... ... @@ -133,6 +134,8 @@ _one2one_same_size(one2one_same_size)
init_scale_context(&_sws_ctx_h_h, &_scaled_frame_h_h, _student_height, _student_height, _scaled_height, _scaled_height);
}
RGB2YUV(blank_r, blank_g, blank_b, &_blank_y, &_blank_u, &_blank_v);
_n_streams = max_video > 0 ? 2 : 1;
}
... ... @@ -182,7 +185,9 @@ double CAVTranscoder::transcode()
_all_processed = decoders_got_frame.size() == 0;
mix_and_output_vframe(decoders_got_frame);
if (_max_video > 0) {
mix_and_output_vframe(decoders_got_frame);
}
_cur_v_time += g_vframe_duration;
... ... @@ -214,8 +219,9 @@ bool CAVTranscoder::all_processed()
int CAVTranscoder::close()
{
flush_encoder(0);
flush_encoder(1);
for (int i = 0; i < _n_streams; i++){
flush_encoder(i);
}
av_write_trailer(_ofmt_ctx);
free_scale_context(&_sws_ctx_w_h, &_scaled_frame_w_h);
... ... @@ -238,7 +244,7 @@ int CAVTranscoder::close()
av_bitstream_filter_close(aacbsfc);
#endif
unsigned int i;
for (i = 0; i<2; i++)
for (i = 0; i< _n_streams; i++)
{
if (_ofmt_ctx && _ofmt_ctx->nb_streams > i && _ofmt_ctx->streams[i] && _ofmt_ctx->streams[i]->codec)
avcodec_close(_ofmt_ctx->streams[i]->codec);
... ... @@ -267,7 +273,9 @@ int CAVTranscoder::open_output_file(const char *filename)
return AVERROR_UNKNOWN;
}
for (i = 0; i < 2; i++) {
for (i = 0; i < _n_streams; i++) {
out_stream = avformat_new_stream(_ofmt_ctx, NULL);
if (!out_stream) {
av_log(NULL, AV_LOG_ERROR, "Failed allocating output stream\n");
... ... @@ -279,7 +287,7 @@ int CAVTranscoder::open_output_file(const char *filename)
if (_ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
enc_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
if (0 == i) {
if (1 == i) {
encoder = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!encoder) {
av_log(NULL, AV_LOG_FATAL, "Necessary encoder not found\n");
... ... @@ -449,7 +457,7 @@ int CAVTranscoder::open_output_file(const char *filename)
_cur_out_a_ts += 1024;
int got_frame = 0;
encode_write_frame(pDstFrame, 1, &got_frame);
encode_write_frame(pDstFrame, 0, &got_frame);
return 0;
}
... ... @@ -598,7 +606,7 @@ int CAVTranscoder::open_output_file(const char *filename)
//send to encoder
int got_frame = 0;
encode_write_frame(pDstFrame, 0, &got_frame);
encode_write_frame(pDstFrame, 1, &got_frame);
return 0;
}
... ... @@ -1100,7 +1108,7 @@ int CAVTranscoder::open_output_file(const char *filename)
//send to encoder
int got_frame = 0;
encode_write_frame(pDstFrame, 0, &got_frame);
encode_write_frame(pDstFrame, 1, &got_frame);
return 0;
}
... ... @@ -1111,7 +1119,7 @@ int CAVTranscoder::encode_write_frame(AVFrame *filt_frame, unsigned int stream_i
AVPacket enc_pkt;
int(*enc_func)(AVCodecContext *, AVPacket *, const AVFrame *, int *) =
stream_index == 0 ? avcodec_encode_video2 : avcodec_encode_audio2;
stream_index == 1 ? avcodec_encode_video2 : avcodec_encode_audio2;
if (!got_frame)
got_frame = &got_frame_local;
... ... @@ -1193,8 +1201,3 @@ int CAVTranscoder::free_scale_context(SwsContext ** ctx, AVFrame ** frame)
}
return 0;
}
void CAVTranscoder::set_max_audio(int max_audio)
{
_max_audio = max_audio;
}
... ...
... ... @@ -5,7 +5,7 @@
class CAVTranscoder
{
public:
CAVTranscoder(bool bOne2One, bool one2one_same_size, bool one2many_inflat, int width_teacher, int height_teacher, int student_width, int student_height, bool has_teacher, int max_audio, int keep_4_3= true);
CAVTranscoder(bool bOne2One, bool one2one_same_size, bool one2many_inflat, int width_teacher, int height_teacher, int student_width, int student_height, bool has_teacher, int max_audio, int max_video, int keep_4_3= true);
virtual ~CAVTranscoder();
int add(media_info & info);
... ... @@ -45,6 +45,8 @@ private:
void * _a_frame_pool;
int _max_audio;
int _max_video;
int _n_streams;
int _scaled_width;
int _scaled_height;
int _pip_width;
... ... @@ -75,8 +77,6 @@ private:
int _src_height_student;
uint8_t _blank_y, _blank_u, _blank_v;
public:
void set_max_audio(int max_audio);
private:
int scale_fill_one2one_studentframe(AVFrame * pDstFrame, int y);
int fill_one2one_student_frame(AVFrame * pDstFrame, int y);
... ...
... ... @@ -637,6 +637,8 @@ void add_media_info_with_end(media_info m)
}
list<media_info> audio_files;
list<media_info> video_files;
int count_audio_files(float mid)
{
... ... @@ -655,7 +657,25 @@ int count_audio_files(float mid)
return files;
}
int count_video_files(float mid)
{
int files = 0;
list<media_info>::iterator it = video_files.begin();
for (; it != video_files.end(); it++){
if (it->start_time < mid){
if (it->end_time > mid) {
files++;
}
}
else {
break;
}
}
return files;
}
int max_audio = 1;
int max_video = 0;
int width = 0;
int height = 0;
int width_teacher = 0;
... ... @@ -705,6 +725,9 @@ void add_media_infos()
if (it->m_type == mt_audio) {
audio_files.push_back(*it);
}
else if (it->m_type == mt_video) {
video_files.push_back(*it);
}
}
list<media_info> audio_type_files;
... ... @@ -800,6 +823,38 @@ void add_media_infos()
}
}
}
list<media_info> video_type_files;
it = sorted_media_with_end.begin();
for (; it != sorted_media_with_end.end(); it++){
if (it->m_type == mt_video) {
video_type_files.push_back(*it);
}
}
it = video_type_files.begin();
if (it != video_type_files.end()) {
media_info last = *it;
for (it++; it != video_type_files.end(); it++) {
if (it->t_type == tt_end) {
if (last.t_type == tt_start) {
float mid = (it->type_time + last.type_time) / 2;
int files_with_mid = count_video_files(mid);
if (files_with_mid > max_video) {
max_video = files_with_mid;
}
}
}
else {
last = *it;
}
}
}
}
void unifiy_start_time()
... ... @@ -1097,7 +1152,10 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size, in
{
time_t start, end;
time(&start);
load_record_info(record_info);
if (load_record_info(record_info)){
printf("\nerror open record info file: %s", record_info);
return -1;
}
get_outinfo_file_name(record_info);
... ... @@ -1139,8 +1197,7 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size, in
}
}
CAVTranscoder videoTranscoder(one2one, one2one_same_size, one_to_many_inflat, width_teacher, height_teacher, width_student, height_student, has_teacher, max_audio);
videoTranscoder.set_max_audio(max_audio);
CAVTranscoder videoTranscoder(one2one, one2one_same_size, one_to_many_inflat, width_teacher, height_teacher, width_student, height_student, has_teacher, max_audio, max_video);
int64_t cur_time = 0;
bool has_file = sorted_media.size()!=0;
... ...