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-06-05 16:23:27 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
61edffa6b785998a26e22be4cf85a935bae11c22
61edffa6
1 parent
0bc119d1
V2.0.7
2.修改在一对一布局下,有一个视频是竖屏时,对竖屏的缩放处理不正常
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
110 行增加
和
100 行删除
pip/AVTranscoder.cpp
pip/AVTranscoder.h
pip/ReadMe.txt
pip/merge_pip.cpp
pip/AVTranscoder.cpp
查看文件 @
61edffa
...
...
@@ -84,26 +84,13 @@ _one2one_same_size(one2one_same_size)
if
(
_one2one_same_size
)
{
int
max_width
=
_nOutputWidth
;
int
max_height
=
max
(
_teacher_height
,
_student_height
);
int
min_width
=
min
(
_teacher_width
,
_student_width
);
int
min_height
=
min
(
_teacher_height
,
_student_height
);
if
(
_teacher_width
<
_student_width
)
{
_teacher_width
=
_student_width
;
}
else
if
(
_student_width
<
_teacher_width
)
{
_student_width
=
_teacher_width
;
}
if
(
_teacher_height
<
_student_height
)
{
_teacher_height
=
_student_height
;
}
else
if
(
_student_height
<
_teacher_height
)
{
_student_height
=
_teacher_height
;
}
double
wh_ratio_teacher
=
_teacher_width
/
(
double
)
_teacher_height
;
double
wh_ratio_student
=
_student_width
/
(
double
)
_student_height
;
init_scale_context
(
&
_sws_ctx_w_h
,
&
_scaled_frame_w_h
,
min_width
,
min_height
,
max_width
,
max_height
);
init_scale_context
(
&
_sws_ctx_h_w
,
&
_scaled_frame_h_w
,
min_height
,
min_width
,
max_height
,
max_width
);
init_scale_context
(
&
_sws_ctx_h_h
,
&
_scaled_frame_h_h
,
min_height
,
min_height
,
max_height
,
max_height
);
double
max_ratio
=
max
(
wh_ratio_teacher
,
wh_ratio_student
);
_teacher_width
=
_student_width
=
max_width
;
_teacher_height
=
_student_height
=
(
int
)(
max_width
/
max_ratio
+
0.5
);
}
_nOutputHeight
=
_teacher_height
+
_student_height
;
...
...
@@ -734,16 +721,21 @@ int CAVTranscoder::open_output_file(const char *filename)
return
0
;
}
int
CAVTranscoder
::
scale_fill_one2one_teacherframe
(
AVFrame
*
pDstFrame
)
{
if
(
_src_width_teacher
!=
_teacherFrame
->
width
||
_src_height_teacher
!=
_teacherFrame
->
height
)
{
//init scale context
free_scale_context
(
&
_sws_ctx_teacher
,
&
_scaled_frame_teacher
);
if
(
_teacherFrame
->
width
>=
_teacherFrame
->
height
)
{
init_scale_context
(
&
_sws_ctx_teacher
,
&
_scaled_frame_teacher
,
_teacherFrame
->
width
,
_teacherFrame
->
height
,
_teacher_width
,
_teacher_height
);
}
else
{
init_scale_context
(
&
_sws_ctx_teacher
,
&
_scaled_frame_teacher
,
_teacherFrame
->
height
,
_teacherFrame
->
width
,
_teacher_width
,
_teacher_height
);
}
int
scaled_width
,
scaled_height
;
get_scaled_dest_size
(
_teacherFrame
,
_teacher_width
,
_teacher_height
,
&
scaled_width
,
&
scaled_height
);
init_scale_context
(
&
_sws_ctx_teacher
,
&
_scaled_frame_teacher
,
_teacherFrame
->
width
,
_teacherFrame
->
height
,
scaled_width
,
scaled_height
);
_src_width_teacher
=
_teacherFrame
->
width
;
_src_height_teacher
=
_teacherFrame
->
height
;
}
int
h
=
0
;
...
...
@@ -754,43 +746,27 @@ int CAVTranscoder::open_output_file(const char *filename)
av_frame_free
(
&
_teacherFrame
);
_teacherFrame
=
_scaled_frame_teacher
;
if
(
_teacherFrame
->
width
==
_teacher_width
&&
_teacherFrame
->
height
==
_teacher_height
)
{
if
(
_teacherFrame
->
pkt_dts
!=
90
){
if
(
_teacher_width
<
_nOutputWidth
)
{
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_teacher_height
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_teacher_height
/
2
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_teacher_height
/
2
);
}
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
0
,
0
);
if
(
_teacherFrame
->
pkt_dts
==
0
||
_teacherFrame
->
pkt_dts
==
180
)
{
if
(
_teacher_width
!=
_teacherFrame
->
width
||
_teacher_height
!=
_teacherFrame
->
height
){
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_teacher_height
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_teacher_height
/
2
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_teacher_height
/
2
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_nOutputWidth
-
_teacherFrame
->
width
)
/
2
,
(
_teacher_height
-
_teacherFrame
->
height
)
/
2
);
}
else
{
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
_nOutputWidth
*
_teacher_height
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
_nOutputWidth
*
_teacher_height
/
2
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
_nOutputWidth
*
_teacher_height
/
2
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_nOutputWidth
-
_teacher_height
)
/
2
,
0
,
(
_teacher_width
-
_teacher_height
)
/
2
,
0
,
_teacher_height
,
_teacher_height
);
}
}
else
if
(
_teacherFrame
->
width
==
_teacher_height
&&
_teacherFrame
->
height
==
_teacher_width
)
{
if
(
_teacherFrame
->
pkt_dts
==
90
){
if
(
_teacher_width
<
_nOutputWidth
)
{
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_teacher_height
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_teacher_height
/
2
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_teacher_height
/
2
);
}
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
0
,
0
);
}
else
{
}
else
{
if
(
_teacher_width
!=
_teacherFrame
->
height
||
_teacher_height
!=
_teacherFrame
->
width
){
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_teacher_height
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_teacher_height
/
2
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_teacher_height
/
2
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_nOutputWidth
-
_teacher_height
)
/
2
,
0
,
0
,
(
_teacher_width
-
_teacher_height
)
/
2
,
_teacher_height
,
_teacher_height
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_nOutputWidth
-
_teacherFrame
->
height
)
/
2
,
(
_teacher_height
-
_teacherFrame
->
width
)
/
2
);
}
else
{
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
0
,
0
);
}
}
else
if
(
_teacherFrame
->
width
==
_teacher_height
&&
_teacherFrame
->
height
==
_teacher_height
)
{
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_teacher_height
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_teacher_height
/
2
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_teacher_height
/
2
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_nOutputWidth
-
_teacher_height
)
/
2
,
0
);
}
return
0
;
...
...
@@ -800,12 +776,14 @@ int CAVTranscoder::open_output_file(const char *filename)
{
if
(
_src_width_student
!=
_studentFrame
->
width
||
_src_height_student
!=
_studentFrame
->
height
)
{
//init scale context
free_scale_context
(
&
_sws_ctx_student
,
&
_scaled_frame_student
);
if
(
_studentFrame
->
width
>=
_studentFrame
->
height
)
{
init_scale_context
(
&
_sws_ctx_student
,
&
_scaled_frame_student
,
_studentFrame
->
width
,
_studentFrame
->
height
,
_student_width
,
_student_height
);
}
else
{
init_scale_context
(
&
_sws_ctx_student
,
&
_scaled_frame_student
,
_studentFrame
->
height
,
_studentFrame
->
width
,
_student_width
,
_student_height
);
}
int
scaled_width
,
scaled_height
;
get_scaled_dest_size
(
_studentFrame
,
_student_width
,
_student_height
,
&
scaled_width
,
&
scaled_height
);
init_scale_context
(
&
_sws_ctx_student
,
&
_scaled_frame_student
,
_studentFrame
->
width
,
_studentFrame
->
height
,
scaled_width
,
scaled_height
);
_src_width_student
=
_studentFrame
->
width
;
_src_height_student
=
_studentFrame
->
height
;
}
int
h
=
0
;
...
...
@@ -816,43 +794,27 @@ int CAVTranscoder::open_output_file(const char *filename)
av_frame_free
(
&
_studentFrame
);
_studentFrame
=
_scaled_frame_student
;
if
(
_studentFrame
->
width
==
_student_width
&&
_studentFrame
->
height
==
_student_height
)
{
if
(
_studentFrame
->
pkt_dts
!=
90
){
if
(
_student_width
<
_nOutputWidth
)
{
memset
(
pDstFrame
->
data
[
0
]
+
y
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_student_height
);
memset
(
pDstFrame
->
data
[
1
]
+
y
*
pDstFrame
->
linesize
[
1
]
/
2
,
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_student_height
/
2
);
memset
(
pDstFrame
->
data
[
2
]
+
y
*
pDstFrame
->
linesize
[
2
]
/
2
,
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_student_height
/
2
);
}
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
y
);
if
(
_studentFrame
->
pkt_dts
==
0
||
_studentFrame
->
pkt_dts
==
180
)
{
if
(
_teacher_width
!=
_studentFrame
->
width
||
_teacher_height
!=
_studentFrame
->
height
){
memset
(
pDstFrame
->
data
[
0
]
+
y
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_student_height
);
memset
(
pDstFrame
->
data
[
1
]
+
y
*
pDstFrame
->
linesize
[
1
]
/
2
,
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_student_height
/
2
);
memset
(
pDstFrame
->
data
[
2
]
+
y
*
pDstFrame
->
linesize
[
2
]
/
2
,
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_student_height
/
2
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_nOutputWidth
-
_studentFrame
->
width
)
/
2
,
(
_student_height
-
_studentFrame
->
height
)
/
2
+
y
);
}
else
{
memset
(
pDstFrame
->
data
[
0
]
+
y
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
_nOutputWidth
*
_student_height
);
memset
(
pDstFrame
->
data
[
1
]
+
y
*
pDstFrame
->
linesize
[
1
]
/
2
,
_blank_u
,
_nOutputWidth
*
_student_height
/
2
);
memset
(
pDstFrame
->
data
[
2
]
+
y
*
pDstFrame
->
linesize
[
2
]
/
2
,
_blank_v
,
_nOutputWidth
*
_student_height
/
2
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_nOutputWidth
-
_student_height
)
/
2
,
y
,
(
_student_width
-
_student_height
)
/
2
,
0
,
_student_height
,
_student_height
);
}
}
else
if
(
_studentFrame
->
width
==
_student_height
&&
_studentFrame
->
height
==
_student_width
)
{
if
(
_studentFrame
->
pkt_dts
==
90
){
if
(
_student_width
<
_nOutputWidth
)
{
memset
(
pDstFrame
->
data
[
0
]
+
y
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_student_height
);
memset
(
pDstFrame
->
data
[
1
]
+
y
*
pDstFrame
->
linesize
[
1
]
/
2
,
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_student_height
/
2
);
memset
(
pDstFrame
->
data
[
2
]
+
y
*
pDstFrame
->
linesize
[
2
]
/
2
,
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_student_height
/
2
);
}
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
y
);
}
else
{
}
else
{
if
(
_teacher_width
!=
_studentFrame
->
height
||
_teacher_height
!=
_studentFrame
->
width
){
memset
(
pDstFrame
->
data
[
0
]
+
y
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_student_height
);
memset
(
pDstFrame
->
data
[
1
]
+
y
*
pDstFrame
->
linesize
[
1
]
/
2
,
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_student_height
/
2
);
memset
(
pDstFrame
->
data
[
2
]
+
y
*
pDstFrame
->
linesize
[
2
]
/
2
,
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_student_height
/
2
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_nOutputWidth
-
_student_height
)
/
2
,
y
,
0
,
(
_student_width
-
_student_height
)
/
2
,
_student_height
,
_student_height
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_nOutputWidth
-
_studentFrame
->
height
)
/
2
,
(
_student_height
-
_studentFrame
->
width
)
/
2
+
y
);
}
else
{
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
y
);
}
}
else
if
(
_studentFrame
->
width
==
_student_height
&&
_studentFrame
->
height
==
_student_height
)
{
memset
(
pDstFrame
->
data
[
0
]
+
y
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
pDstFrame
->
linesize
[
0
]
*
_student_height
);
memset
(
pDstFrame
->
data
[
1
]
+
y
*
pDstFrame
->
linesize
[
1
]
/
2
,
_blank_u
,
pDstFrame
->
linesize
[
1
]
*
_student_height
/
2
);
memset
(
pDstFrame
->
data
[
2
]
+
y
*
pDstFrame
->
linesize
[
2
]
/
2
,
_blank_v
,
pDstFrame
->
linesize
[
2
]
*
_student_height
/
2
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_nOutputWidth
-
_student_height
)
/
2
,
y
);
}
return
0
;
...
...
@@ -896,6 +858,34 @@ int CAVTranscoder::open_output_file(const char *filename)
}
void
CAVTranscoder
::
get_scaled_dest_size
(
AVFrame
*
pFrame
,
int
dest_width
,
int
dest_height
,
int
*
scaled_width
,
int
*
scaled_height
)
{
if
(
pFrame
->
pkt_dts
==
0
||
pFrame
->
pkt_dts
==
180
)
{
double
src_wh_ratio
=
pFrame
->
width
/
(
double
)
pFrame
->
height
;
double
dest_wh_ratio
=
dest_width
/
(
double
)
dest_height
;
if
(
src_wh_ratio
>
dest_wh_ratio
)
{
*
scaled_width
=
dest_width
;
*
scaled_height
=
(
int
)(
dest_width
/
src_wh_ratio
+
0.5
);
}
else
{
*
scaled_height
=
dest_height
;
*
scaled_width
=
(
int
)(
dest_height
*
src_wh_ratio
);
}
}
else
{
double
src_wh_ratio
=
pFrame
->
height
/
(
double
)
pFrame
->
width
;
double
dest_wh_ratio
=
dest_width
/
(
double
)
dest_height
;
if
(
src_wh_ratio
>
dest_wh_ratio
)
{
*
scaled_height
=
dest_width
;
*
scaled_width
=
(
int
)(
dest_width
/
src_wh_ratio
+
0.5
);
}
else
{
*
scaled_width
=
dest_height
;
*
scaled_height
=
(
int
)(
dest_height
*
src_wh_ratio
);
}
}
}
int
CAVTranscoder
::
mix_and_output_one2one_vframe
(
vector
<
CAVDecoder
*>
&
decoders_got_frame
)
{
//prepare one2one base frame
...
...
pip/AVTranscoder.h
查看文件 @
61edffa
...
...
@@ -80,5 +80,6 @@ public:
private
:
int
scale_fill_one2one_studentframe
(
AVFrame
*
pDstFrame
,
int
y
);
int
fill_one2one_student_frame
(
AVFrame
*
pDstFrame
,
int
y
);
void
get_scaled_dest_size
(
AVFrame
*
pFrame
,
int
dest_width
,
int
dest_height
,
int
*
scaled_width
,
int
*
scaled_height
);
};
...
...
pip/ReadMe.txt
查看文件 @
61edffa
...
...
@@ -82,4 +82,5 @@ V2.0.6
0 保持原有视频大小
V2.0.7
1.修改bug: 在V2.0.4开放了设置视频编码参数,由于修改不完整,其中fps设置如果不是默认的参数20,会导致音视频不同步。
\ No newline at end of file
1.修改bug: 在V2.0.4开放了设置视频编码参数,由于修改不完整,其中fps设置如果不是默认的参数20,会导致音视频不同步。
2.修改在一对一布局下,有一个视频是竖屏时,对竖屏的缩放处理不正常
\ No newline at end of file
...
...
pip/merge_pip.cpp
查看文件 @
61edffa
...
...
@@ -716,7 +716,7 @@ void add_media_infos()
for
(;
it
!=
sorted_media_with_end
.
end
();
it
++
){
if
(
it
->
m_type
==
mt_video
)
{
printf
(
"
\n
%2d %8.3f %s %s %4d %4d %3d"
,
it
->
sorted_index
,
it
->
type_time
,
it
->
name
.
c_str
(),
it
->
t_type
==
tt_start
?
"start"
:
"end"
,
it
->
width
,
it
->
height
,
it
->
rotate
);
if
(
it
->
width
>
it
->
height
)
{
if
(
it
->
rotate
==
0
||
it
->
rotate
==
180
)
{
if
(
width
<
it
->
width
)
{
width
=
it
->
width
;
}
...
...
@@ -734,7 +734,7 @@ void add_media_infos()
}
if
(
it
->
m_role
==
mr_teacher
)
{
has_teacher
=
true
;
if
(
it
->
width
>
it
->
height
)
{
if
(
it
->
rotate
==
0
||
it
->
rotate
==
180
)
{
if
(
width_teacher
<
it
->
width
)
{
width_teacher
=
it
->
width
;
}
...
...
@@ -752,7 +752,7 @@ void add_media_infos()
}
}
else
{
if
(
it
->
width
>
it
->
height
)
{
if
(
it
->
rotate
==
0
||
it
->
rotate
==
180
)
{
if
(
width_student
<
it
->
width
)
{
width_student
=
it
->
width
;
}
...
...
@@ -1088,7 +1088,7 @@ int load_record_info(char * record_info)
#define MIN_TIME_INTERVAL 25
int
process_av_files
(
char
*
record_info
,
int
piptype
,
bool
one2one_same_size
)
int
process_av_files
(
char
*
record_info
,
int
piptype
,
bool
one2one_same_size
,
int64_t
max_duration
)
{
time_t
start
,
end
;
time
(
&
start
);
...
...
@@ -1172,6 +1172,12 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size)
cur_time
=
(
int64_t
)
videoTranscoder
.
transcode
();
if
(
cur_time
>=
max_duration
){
printf
(
"
\n
max duration reached, stop now"
);
break
;
}
encode_loop_count
++
;
if
(
encode_loop_count
==
1200
)
{
encode_loop_count
=
0
;
...
...
@@ -1180,12 +1186,15 @@ int process_av_files(char * record_info, int piptype, bool one2one_same_size)
}
while
(
!
videoTranscoder
.
all_processed
()){
cur_time
=
videoTranscoder
.
transcode
();
encode_loop_count
++
;
if
(
encode_loop_count
==
1200
)
{
encode_loop_count
=
0
;
printf
(
"
\n
encoded : %d s
\n
"
,
cur_time
/
1000
);
}
if
(
cur_time
>=
max_duration
){
break
;
}
cur_time
=
videoTranscoder
.
transcode
();
encode_loop_count
++
;
if
(
encode_loop_count
==
1200
)
{
encode_loop_count
=
0
;
printf
(
"
\n
encoded : %d s
\n
"
,
cur_time
/
1000
);
}
}
videoTranscoder
.
close
();
...
...
@@ -1211,6 +1220,7 @@ int main(int argc, char * argv[])
int
piptype
=
0
;
bool
one2one_same_size
=
true
;
int64_t
max_duration
=
INT64_MAX
;
for
(
int
i
=
2
;
i
<
argc
;
i
++
){
if
(
!
strcmp
(
argv
[
i
],
"-t"
)){
i
++
;
...
...
@@ -1236,6 +1246,14 @@ int main(int argc, char * argv[])
}
one2one_same_size
=
argv
[
i
][
0
]
==
'1'
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"-d"
)){
i
++
;
if
(
i
>
argc
)
{
printf
(
"error,should be 1 or 0 after -d"
);
return
-
2
;
}
max_duration
=
atoi
(
argv
[
i
]);
}
}
...
...
@@ -1243,5 +1261,5 @@ int main(int argc, char * argv[])
load_codec_param
();
return
process_av_files
(
argv
[
1
],
piptype
,
one2one_same_size
);
return
process_av_files
(
argv
[
1
],
piptype
,
one2one_same_size
,
max_duration
);
}
...
...
请
注册
或
登录
后发表评论