V2.0.7
1.修改bug: 在V2.0.4开放了设置视频编码参数,由于修改不完整,其中fps设置如果不是默认的参数20,会导致音视频不同步。
正在显示
8 个修改的文件
包含
32 行增加
和
16 行删除
| @@ -67,6 +67,9 @@ unsigned int CAVDecoder::getuid() | @@ -67,6 +67,9 @@ unsigned int CAVDecoder::getuid() | ||
| 67 | return _uid; | 67 | return _uid; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | +extern double g_vframe_duration; | ||
| 71 | + | ||
| 72 | + | ||
| 70 | bool CAVDecoder::get_one_v_frame() | 73 | bool CAVDecoder::get_one_v_frame() |
| 71 | { | 74 | { |
| 72 | int64_t ts; | 75 | int64_t ts; |
| @@ -79,12 +82,12 @@ bool CAVDecoder::get_one_v_frame() | @@ -79,12 +82,12 @@ bool CAVDecoder::get_one_v_frame() | ||
| 79 | free_cur_v_frame(); | 82 | free_cur_v_frame(); |
| 80 | _cur_v_frame = pFrame; | 83 | _cur_v_frame = pFrame; |
| 81 | } | 84 | } |
| 82 | - _cur_v_ts_ms += VFRAME_DURATION_MS; | 85 | + _cur_v_ts_ms += g_vframe_duration; |
| 83 | } | 86 | } |
| 84 | else { | 87 | else { |
| 85 | _video_info.pop_front(); | 88 | _video_info.pop_front(); |
| 86 | if (_cur_v_ts_ms < _end_time_ms) { | 89 | if (_cur_v_ts_ms < _end_time_ms) { |
| 87 | - _cur_v_ts_ms += VFRAME_DURATION_MS;//return last v frame | 90 | + _cur_v_ts_ms += g_vframe_duration;//return last v frame |
| 88 | ret = 0; | 91 | ret = 0; |
| 89 | } | 92 | } |
| 90 | } | 93 | } |
| @@ -92,7 +95,7 @@ bool CAVDecoder::get_one_v_frame() | @@ -92,7 +95,7 @@ bool CAVDecoder::get_one_v_frame() | ||
| 92 | 95 | ||
| 93 | if (ret) {//no video decoded | 96 | if (ret) {//no video decoded |
| 94 | if (_cur_v_ts_ms < _end_time_ms) {//should have as video frame | 97 | if (_cur_v_ts_ms < _end_time_ms) {//should have as video frame |
| 95 | - _cur_v_ts_ms += VFRAME_DURATION_MS;//return last v frame | 98 | + _cur_v_ts_ms += g_vframe_duration;//return last v frame |
| 96 | ret = 0; | 99 | ret = 0; |
| 97 | } | 100 | } |
| 98 | } | 101 | } |
| @@ -16,7 +16,7 @@ public: | @@ -16,7 +16,7 @@ public: | ||
| 16 | std::string get_cur_vfile(); | 16 | std::string get_cur_vfile(); |
| 17 | std::string get_cur_afile(); | 17 | std::string get_cur_afile(); |
| 18 | double _cur_a_ts_ms; | 18 | double _cur_a_ts_ms; |
| 19 | - int64_t _cur_v_ts_ms; | 19 | + double _cur_v_ts_ms; |
| 20 | media_role _media_role; | 20 | media_role _media_role; |
| 21 | 21 | ||
| 22 | AVFrame * _cur_a_frame; | 22 | AVFrame * _cur_a_frame; |
| @@ -29,6 +29,9 @@ int pip_x_reduce = 3; | @@ -29,6 +29,9 @@ int pip_x_reduce = 3; | ||
| 29 | int pip_y_reduce = 3; | 29 | int pip_y_reduce = 3; |
| 30 | int pip_x_border = 4; | 30 | int pip_x_border = 4; |
| 31 | 31 | ||
| 32 | +double g_vframe_duration; | ||
| 33 | +int g_fps; | ||
| 34 | + | ||
| 32 | #define ensure_no_zero(x, v) if(!x) x = v | 35 | #define ensure_no_zero(x, v) if(!x) x = v |
| 33 | 36 | ||
| 34 | CAVTranscoder::CAVTranscoder(bool bOne2One, bool one2one_same_size, int width_teacher, int height_teacher, int width_student, int height_student, bool has_teacher, int max_audio) : | 37 | CAVTranscoder::CAVTranscoder(bool bOne2One, bool one2one_same_size, int width_teacher, int height_teacher, int width_student, int height_student, bool has_teacher, int max_audio) : |
| @@ -72,6 +75,9 @@ _one2one_same_size(one2one_same_size) | @@ -72,6 +75,9 @@ _one2one_same_size(one2one_same_size) | ||
| 72 | _scaled_width = _teacher_width * 10 / 32; | 75 | _scaled_width = _teacher_width * 10 / 32; |
| 73 | _scaled_height = _teacher_height * 10 / 32; | 76 | _scaled_height = _teacher_height * 10 / 32; |
| 74 | 77 | ||
| 78 | + g_fps = _codec_config.get_int("fps", 20); | ||
| 79 | + g_vframe_duration = 1000.0 / (double)g_fps; | ||
| 80 | + | ||
| 75 | _one2one = bOne2One; | 81 | _one2one = bOne2One; |
| 76 | if (_one2one) { | 82 | if (_one2one) { |
| 77 | _nOutputWidth = max(_teacher_width, _student_width); | 83 | _nOutputWidth = max(_teacher_width, _student_width); |
| @@ -141,7 +147,7 @@ int CAVTranscoder::add(media_info & info) | @@ -141,7 +147,7 @@ int CAVTranscoder::add(media_info & info) | ||
| 141 | _all_processed = false; | 147 | _all_processed = false; |
| 142 | if (_start_time == INT64_MAX) { | 148 | if (_start_time == INT64_MAX) { |
| 143 | _start_time = info.start_time_ms; | 149 | _start_time = info.start_time_ms; |
| 144 | - _cur_v_time = _start_time; | 150 | + _cur_v_time = (double)_start_time; |
| 145 | _cur_a_time = (double)_start_time; | 151 | _cur_a_time = (double)_start_time; |
| 146 | } | 152 | } |
| 147 | vector < CAVDecoder *>::iterator it = _decoders.begin(); | 153 | vector < CAVDecoder *>::iterator it = _decoders.begin(); |
| @@ -159,7 +165,7 @@ int CAVTranscoder::add(media_info & info) | @@ -159,7 +165,7 @@ int CAVTranscoder::add(media_info & info) | ||
| 159 | return 0; | 165 | return 0; |
| 160 | } | 166 | } |
| 161 | 167 | ||
| 162 | -int64_t CAVTranscoder::transcode() | 168 | +double CAVTranscoder::transcode() |
| 163 | { | 169 | { |
| 164 | vector<CAVDecoder *> decoders_got_frame; | 170 | vector<CAVDecoder *> decoders_got_frame; |
| 165 | vector <CAVDecoder *>::iterator it = _decoders.begin(); | 171 | vector <CAVDecoder *>::iterator it = _decoders.begin(); |
| @@ -177,7 +183,7 @@ int64_t CAVTranscoder::transcode() | @@ -177,7 +183,7 @@ int64_t CAVTranscoder::transcode() | ||
| 177 | _all_processed = decoders_got_frame.size() == 0; | 183 | _all_processed = decoders_got_frame.size() == 0; |
| 178 | mix_and_output_vframe(decoders_got_frame); | 184 | mix_and_output_vframe(decoders_got_frame); |
| 179 | 185 | ||
| 180 | - _cur_v_time += VFRAME_DURATION_MS; | 186 | + _cur_v_time += g_vframe_duration; |
| 181 | 187 | ||
| 182 | while (_cur_a_time < _cur_v_time) | 188 | while (_cur_a_time < _cur_v_time) |
| 183 | { | 189 | { |
| @@ -289,7 +295,7 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -289,7 +295,7 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 289 | enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P; | 295 | enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P; |
| 290 | /* video time_base can be set to whatever is handy and supported by encoder */ | 296 | /* video time_base can be set to whatever is handy and supported by encoder */ |
| 291 | enc_ctx->time_base.num = 1; | 297 | enc_ctx->time_base.num = 1; |
| 292 | - enc_ctx->time_base.den = _codec_config.get_int("fps", 20); | 298 | + enc_ctx->time_base.den = g_fps; |
| 293 | printf("\n fps: %d", enc_ctx->time_base.den); | 299 | printf("\n fps: %d", enc_ctx->time_base.den); |
| 294 | enc_ctx->gop_size = _codec_config.get_int("gop_size", enc_ctx->time_base.den); | 300 | enc_ctx->gop_size = _codec_config.get_int("gop_size", enc_ctx->time_base.den); |
| 295 | printf("\n gop_size: %d", enc_ctx->gop_size); | 301 | printf("\n gop_size: %d", enc_ctx->gop_size); |
| @@ -9,7 +9,7 @@ public: | @@ -9,7 +9,7 @@ public: | ||
| 9 | virtual ~CAVTranscoder(); | 9 | virtual ~CAVTranscoder(); |
| 10 | 10 | ||
| 11 | int add(media_info & info); | 11 | int add(media_info & info); |
| 12 | - int64_t transcode(); | 12 | + double transcode(); |
| 13 | bool all_processed(); | 13 | bool all_processed(); |
| 14 | int close(); | 14 | int close(); |
| 15 | int open_output_file(const char *filename); | 15 | int open_output_file(const char *filename); |
| @@ -20,7 +20,7 @@ protected: | @@ -20,7 +20,7 @@ protected: | ||
| 20 | AVFormatContext * _ofmt_ctx; | 20 | AVFormatContext * _ofmt_ctx; |
| 21 | int64_t _start_time; | 21 | int64_t _start_time; |
| 22 | double _cur_a_time; | 22 | double _cur_a_time; |
| 23 | - int64_t _cur_v_time; | 23 | + double _cur_v_time; |
| 24 | int _nOutputWidth; | 24 | int _nOutputWidth; |
| 25 | int _nOutputHeight; | 25 | int _nOutputHeight; |
| 26 | int64_t _cur_out_v_ts; | 26 | int64_t _cur_out_v_ts; |
| @@ -79,4 +79,7 @@ V2.0.5 | @@ -79,4 +79,7 @@ V2.0.5 | ||
| 79 | V2.0.6 | 79 | V2.0.6 |
| 80 | 1. 命令行添加-s可选参数,在一对一布局下起作用。缺省为1 | 80 | 1. 命令行添加-s可选参数,在一对一布局下起作用。缺省为1 |
| 81 | 1 如果老师和学生的视频大小不一致,会放大较小的视频使得老师和学生视频大小相同。 | 81 | 1 如果老师和学生的视频大小不一致,会放大较小的视频使得老师和学生视频大小相同。 |
| 82 | - 0 保持原有视频大小 | ||
| 82 | + 0 保持原有视频大小 | ||
| 83 | + | ||
| 84 | +V2.0.7 | ||
| 85 | +1.修改bug: 在V2.0.4开放了设置视频编码参数,由于修改不完整,其中fps设置如果不是默认的参数20,会导致音视频不同步。 |
| @@ -203,11 +203,15 @@ end: | @@ -203,11 +203,15 @@ end: | ||
| 203 | return ret; | 203 | return ret; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | +extern int g_fps; | ||
| 207 | + | ||
| 206 | int CVideoDecoder::init_filters(void) | 208 | int CVideoDecoder::init_filters(void) |
| 207 | { | 209 | { |
| 208 | const char *filter_spec; | 210 | const char *filter_spec; |
| 209 | unsigned int i; | 211 | unsigned int i; |
| 210 | int ret; | 212 | int ret; |
| 213 | + char fps_filter_spec[128]; | ||
| 214 | + | ||
| 211 | filter_ctx = (FilteringContext *)av_malloc_array(ifmt_ctx->nb_streams, sizeof(*filter_ctx)); | 215 | filter_ctx = (FilteringContext *)av_malloc_array(ifmt_ctx->nb_streams, sizeof(*filter_ctx)); |
| 212 | if (!filter_ctx) | 216 | if (!filter_ctx) |
| 213 | return AVERROR(ENOMEM); | 217 | return AVERROR(ENOMEM); |
| @@ -222,9 +226,10 @@ int CVideoDecoder::init_filters(void) | @@ -222,9 +226,10 @@ int CVideoDecoder::init_filters(void) | ||
| 222 | 226 | ||
| 223 | 227 | ||
| 224 | if (ifmt_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { | 228 | if (ifmt_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 225 | - filter_spec = "fps=fps=20"; /* passthrough (dummy) filter for video */ | 229 | + sprintf(fps_filter_spec, "fps=fps=%d", g_fps); |
| 230 | + filter_spec = fps_filter_spec; /* passthrough (dummy) filter for video */ | ||
| 226 | _codec_timebase.num = 1; | 231 | _codec_timebase.num = 1; |
| 227 | - _codec_timebase.den = 20; | 232 | + _codec_timebase.den = g_fps; |
| 228 | } | 233 | } |
| 229 | else | 234 | else |
| 230 | filter_spec = "anull"; /* passthrough (dummy) filter for audio */ | 235 | filter_spec = "anull"; /* passthrough (dummy) filter for audio */ |
| @@ -83,7 +83,6 @@ typedef struct FilteringContext { | @@ -83,7 +83,6 @@ typedef struct FilteringContext { | ||
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | #define AFRAME_DURATION_MS 21.333333 | 85 | #define AFRAME_DURATION_MS 21.333333 |
| 86 | -#define VFRAME_DURATION_MS 50 | ||
| 87 | 86 | ||
| 88 | #if LIBAVCODEC_VERSION_MAJOR < 57 | 87 | #if LIBAVCODEC_VERSION_MAJOR < 57 |
| 89 | #define PCM_USING_FLTP_FOR_AAC_ENCODE | 88 | #define PCM_USING_FLTP_FOR_AAC_ENCODE |
| @@ -1170,7 +1170,7 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size) | @@ -1170,7 +1170,7 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size) | ||
| 1170 | } | 1170 | } |
| 1171 | } | 1171 | } |
| 1172 | 1172 | ||
| 1173 | - cur_time = videoTranscoder.transcode(); | 1173 | + cur_time = (int64_t) videoTranscoder.transcode(); |
| 1174 | 1174 | ||
| 1175 | encode_loop_count++; | 1175 | encode_loop_count++; |
| 1176 | if (encode_loop_count == 1200) { | 1176 | if (encode_loop_count == 1200) { |
| @@ -1202,7 +1202,7 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size) | @@ -1202,7 +1202,7 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size) | ||
| 1202 | int main(int argc, char * argv[]) | 1202 | int main(int argc, char * argv[]) |
| 1203 | { | 1203 | { |
| 1204 | if (argc < 2) { | 1204 | if (argc < 2) { |
| 1205 | - printf(" merge_pip 2.0.6\n"); | 1205 | + printf(" merge_pip 2.0.7\n"); |
| 1206 | printf(" merge video files to one pip video according to record info file,\nusage:"); | 1206 | printf(" merge video files to one pip video according to record info file,\nusage:"); |
| 1207 | printf("\n %s record_info_filename [-t {0,1,2}] [-c codec.cfg] [-s {1,0}]", argv[0]); | 1207 | printf("\n %s record_info_filename [-t {0,1,2}] [-c codec.cfg] [-s {1,0}]", argv[0]); |
| 1208 | printf("\n\n"); | 1208 | printf("\n\n"); |
-
请 注册 或 登录 后发表评论