Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
merge_av
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
胡斌
2019-05-25 09:51:09 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0bc119d143c7f1914585002022d1341306a47be0
0bc119d1
1 parent
a0c88ba2
V2.0.7
1.修改bug: 在V2.0.4开放了设置视频编码参数,由于修改不完整,其中fps设置如果不是默认的参数20,会导致音视频不同步。
隐藏空白字符变更
内嵌
并排对比
正在显示
8 个修改的文件
包含
32 行增加
和
16 行删除
pip/AVDecoder.cpp
pip/AVDecoder.h
pip/AVTranscoder.cpp
pip/AVTranscoder.h
pip/ReadMe.txt
pip/VideoDecoder.cpp
pip/media_info.h
pip/merge_pip.cpp
pip/AVDecoder.cpp
查看文件 @
0bc119d
...
...
@@ -67,6 +67,9 @@ unsigned int CAVDecoder::getuid()
return
_uid
;
}
extern
double
g_vframe_duration
;
bool
CAVDecoder
::
get_one_v_frame
()
{
int64_t
ts
;
...
...
@@ -79,12 +82,12 @@ bool CAVDecoder::get_one_v_frame()
free_cur_v_frame
();
_cur_v_frame
=
pFrame
;
}
_cur_v_ts_ms
+=
VFRAME_DURATION_MS
;
_cur_v_ts_ms
+=
g_vframe_duration
;
}
else
{
_video_info
.
pop_front
();
if
(
_cur_v_ts_ms
<
_end_time_ms
)
{
_cur_v_ts_ms
+=
VFRAME_DURATION_MS
;
//return last v frame
_cur_v_ts_ms
+=
g_vframe_duration
;
//return last v frame
ret
=
0
;
}
}
...
...
@@ -92,7 +95,7 @@ bool CAVDecoder::get_one_v_frame()
if
(
ret
)
{
//no video decoded
if
(
_cur_v_ts_ms
<
_end_time_ms
)
{
//should have as video frame
_cur_v_ts_ms
+=
VFRAME_DURATION_MS
;
//return last v frame
_cur_v_ts_ms
+=
g_vframe_duration
;
//return last v frame
ret
=
0
;
}
}
...
...
pip/AVDecoder.h
查看文件 @
0bc119d
...
...
@@ -16,7 +16,7 @@ public:
std
::
string
get_cur_vfile
();
std
::
string
get_cur_afile
();
double
_cur_a_ts_ms
;
int64_t
_cur_v_ts_ms
;
double
_cur_v_ts_ms
;
media_role
_media_role
;
AVFrame
*
_cur_a_frame
;
...
...
pip/AVTranscoder.cpp
查看文件 @
0bc119d
...
...
@@ -29,6 +29,9 @@ int pip_x_reduce = 3;
int
pip_y_reduce
=
3
;
int
pip_x_border
=
4
;
double
g_vframe_duration
;
int
g_fps
;
#define ensure_no_zero(x, v) if(!x) x = v
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)
_scaled_width
=
_teacher_width
*
10
/
32
;
_scaled_height
=
_teacher_height
*
10
/
32
;
g_fps
=
_codec_config
.
get_int
(
"fps"
,
20
);
g_vframe_duration
=
1000.0
/
(
double
)
g_fps
;
_one2one
=
bOne2One
;
if
(
_one2one
)
{
_nOutputWidth
=
max
(
_teacher_width
,
_student_width
);
...
...
@@ -141,7 +147,7 @@ int CAVTranscoder::add(media_info & info)
_all_processed
=
false
;
if
(
_start_time
==
INT64_MAX
)
{
_start_time
=
info
.
start_time_ms
;
_cur_v_time
=
_start_time
;
_cur_v_time
=
(
double
)
_start_time
;
_cur_a_time
=
(
double
)
_start_time
;
}
vector
<
CAVDecoder
*>::
iterator
it
=
_decoders
.
begin
();
...
...
@@ -159,7 +165,7 @@ int CAVTranscoder::add(media_info & info)
return
0
;
}
int64_t
CAVTranscoder
::
transcode
()
double
CAVTranscoder
::
transcode
()
{
vector
<
CAVDecoder
*>
decoders_got_frame
;
vector
<
CAVDecoder
*>::
iterator
it
=
_decoders
.
begin
();
...
...
@@ -177,7 +183,7 @@ int64_t CAVTranscoder::transcode()
_all_processed
=
decoders_got_frame
.
size
()
==
0
;
mix_and_output_vframe
(
decoders_got_frame
);
_cur_v_time
+=
VFRAME_DURATION_MS
;
_cur_v_time
+=
g_vframe_duration
;
while
(
_cur_a_time
<
_cur_v_time
)
{
...
...
@@ -289,7 +295,7 @@ int CAVTranscoder::open_output_file(const char *filename)
enc_ctx
->
pix_fmt
=
AV_PIX_FMT_YUV420P
;
/* video time_base can be set to whatever is handy and supported by encoder */
enc_ctx
->
time_base
.
num
=
1
;
enc_ctx
->
time_base
.
den
=
_codec_config
.
get_int
(
"fps"
,
20
)
;
enc_ctx
->
time_base
.
den
=
g_fps
;
printf
(
"
\n
fps: %d"
,
enc_ctx
->
time_base
.
den
);
enc_ctx
->
gop_size
=
_codec_config
.
get_int
(
"gop_size"
,
enc_ctx
->
time_base
.
den
);
printf
(
"
\n
gop_size: %d"
,
enc_ctx
->
gop_size
);
...
...
pip/AVTranscoder.h
查看文件 @
0bc119d
...
...
@@ -9,7 +9,7 @@ public:
virtual
~
CAVTranscoder
();
int
add
(
media_info
&
info
);
int64_t
transcode
();
double
transcode
();
bool
all_processed
();
int
close
();
int
open_output_file
(
const
char
*
filename
);
...
...
@@ -20,7 +20,7 @@ protected:
AVFormatContext
*
_ofmt_ctx
;
int64_t
_start_time
;
double
_cur_a_time
;
int64_t
_cur_v_time
;
double
_cur_v_time
;
int
_nOutputWidth
;
int
_nOutputHeight
;
int64_t
_cur_out_v_ts
;
...
...
pip/ReadMe.txt
查看文件 @
0bc119d
...
...
@@ -79,4 +79,7 @@ V2.0.5
V2.0.6
1. 命令行添加-s可选参数,在一对一布局下起作用。缺省为1
1 如果老师和学生的视频大小不一致,会放大较小的视频使得老师和学生视频大小相同。
0 保持原有视频大小
\ No newline at end of file
0 保持原有视频大小
V2.0.7
1.修改bug: 在V2.0.4开放了设置视频编码参数,由于修改不完整,其中fps设置如果不是默认的参数20,会导致音视频不同步。
\ No newline at end of file
...
...
pip/VideoDecoder.cpp
查看文件 @
0bc119d
...
...
@@ -203,11 +203,15 @@ end:
return
ret
;
}
extern
int
g_fps
;
int
CVideoDecoder
::
init_filters
(
void
)
{
const
char
*
filter_spec
;
unsigned
int
i
;
int
ret
;
char
fps_filter_spec
[
128
];
filter_ctx
=
(
FilteringContext
*
)
av_malloc_array
(
ifmt_ctx
->
nb_streams
,
sizeof
(
*
filter_ctx
));
if
(
!
filter_ctx
)
return
AVERROR
(
ENOMEM
);
...
...
@@ -222,9 +226,10 @@ int CVideoDecoder::init_filters(void)
if
(
ifmt_ctx
->
streams
[
i
]
->
codec
->
codec_type
==
AVMEDIA_TYPE_VIDEO
)
{
filter_spec
=
"fps=fps=20"
;
/* passthrough (dummy) filter for video */
sprintf
(
fps_filter_spec
,
"fps=fps=%d"
,
g_fps
);
filter_spec
=
fps_filter_spec
;
/* passthrough (dummy) filter for video */
_codec_timebase
.
num
=
1
;
_codec_timebase
.
den
=
20
;
_codec_timebase
.
den
=
g_fps
;
}
else
filter_spec
=
"anull"
;
/* passthrough (dummy) filter for audio */
...
...
pip/media_info.h
查看文件 @
0bc119d
...
...
@@ -83,7 +83,6 @@ typedef struct FilteringContext {
#define AFRAME_DURATION_MS 21.333333
#define VFRAME_DURATION_MS 50
#if LIBAVCODEC_VERSION_MAJOR < 57
#define PCM_USING_FLTP_FOR_AAC_ENCODE
...
...
pip/merge_pip.cpp
查看文件 @
0bc119d
...
...
@@ -1170,7 +1170,7 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size)
}
}
cur_time
=
videoTranscoder
.
transcode
();
cur_time
=
(
int64_t
)
videoTranscoder
.
transcode
();
encode_loop_count
++
;
if
(
encode_loop_count
==
1200
)
{
...
...
@@ -1202,7 +1202,7 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size)
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
printf
(
" merge_pip 2.0.
6
\n
"
);
printf
(
" merge_pip 2.0.
7
\n
"
);
printf
(
" merge video files to one pip video according to record info file,
\n
usage:"
);
printf
(
"
\n
%s record_info_filename [-t {0,1,2}] [-c codec.cfg] [-s {1,0}]"
,
argv
[
0
]);
printf
(
"
\n\n
"
);
...
...
请
注册
或
登录
后发表评论