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
胡斌
2020-07-24 06:21:01 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
94f685d537613ec310c96802d2a0958bf9742d05
94f685d5
1 parent
1b4fc690
new feature, if no video in all student and teacher,the output mp4 is also no video
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
83 行增加
和
23 行删除
pip/AVTranscoder.cpp
pip/AVTranscoder.h
pip/merge_pip.cpp
pip/AVTranscoder.cpp
查看文件 @
94f685d
...
...
@@ -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
;
}
...
...
pip/AVTranscoder.h
查看文件 @
94f685d
...
...
@@ -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
);
...
...
pip/merge_pip.cpp
查看文件 @
94f685d
...
...
@@ -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
(
"
\n
error 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
;
...
...
请
注册
或
登录
后发表评论