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-01-05 15:27:07 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d117a17039a7838dd0eb517d1251c35662531806
d117a170
1 parent
f30ffbf0
refactored to use video width and height defined as variable
显示空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
67 行增加
和
62 行删除
pip/AVTranscoder.cpp
pip/AVTranscoder.h
pip/AVTranscoder.cpp
查看文件 @
d117a17
...
...
@@ -8,10 +8,7 @@ extern "C" {
#pragma comment(lib,"swscale.lib")
#endif
#define SCALED_W 100
#define SCALED_H 75
#define SRC_W 320
#define SRC_H 240
uint8_t
blank_r
=
0x16
;
uint8_t
blank_g
=
0x5a
;
uint8_t
blank_b
=
0x82
;
...
...
@@ -23,26 +20,30 @@ _nOutputWidth(320),
_cur_out_v_ts
(
0
),
_cur_out_a_ts
(
0
),
_max_audio
(
1
),
_swsCtx_320_240
(
NULL
),
_swsCtx_240_320
(
NULL
),
_swsCtx_240_240
(
NULL
),
_scaledFrame_320_240
(
NULL
),
_scaledFrame_240_320
(
NULL
),
_scaledFrame_240_240
(
NULL
),
_scaled_width
(
100
),
_scaled_height
(
75
),
_src_width
(
320
),
_src_height
(
240
),
_sws_ctx_w_h
(
NULL
),
_sws_ctx_h_w
(
NULL
),
_sws_ctx_h_h
(
NULL
),
_scaled_frame_w_h
(
NULL
),
_scaled_frame_h_w
(
NULL
),
_scaled_frame_h_h
(
NULL
),
_last_videos_got
(
-
1
),
_teacherFrame
(
NULL
),
_studentFrame
(
NULL
)
{
_one2one
=
bOne2One
;
if
(
_one2one
)
{
_nOutputHeight
=
480
;
_nOutputHeight
=
_src_height
*
2
;
}
else
{
_nOutputHeight
=
240
;
_nOutputHeight
=
_src_height
;
init_scale_context
(
&
_swsCtx_320_240
,
&
_scaledFrame_320_240
,
SRC_W
,
SRC_H
,
SCALED_W
,
SCALED_H
);
init_scale_context
(
&
_swsCtx_240_320
,
&
_scaledFrame_240_320
,
SRC_H
,
SRC_W
,
SCALED_H
,
SCALED_W
);
init_scale_context
(
&
_swsCtx_240_240
,
&
_scaledFrame_240_240
,
SRC_H
,
SRC_H
,
SCALED_H
,
SCALED_H
);
init_scale_context
(
&
_sws_ctx_w_h
,
&
_scaled_frame_w_h
,
_src_width
,
_src_height
,
_scaled_width
,
_scaled_height
);
init_scale_context
(
&
_sws_ctx_h_w
,
&
_scaled_frame_h_w
,
_src_height
,
_src_width
,
_scaled_height
,
_scaled_width
);
init_scale_context
(
&
_sws_ctx_h_h
,
&
_scaled_frame_h_h
,
_src_height
,
_src_height
,
_scaled_height
,
_scaled_height
);
}
RGB2YUV
(
blank_r
,
blank_g
,
blank_b
,
&
_blank_y
,
&
_blank_u
,
&
_blank_v
);
}
...
...
@@ -129,9 +130,9 @@ int CAVTranscoder::close()
flush_encoder
(
1
);
av_write_trailer
(
_ofmt_ctx
);
free_scale_context
(
&
_swsCtx_320_240
,
&
_scaledFrame_320_240
);
free_scale_context
(
&
_swsCtx_240_320
,
&
_scaledFrame_240_320
);
free_scale_context
(
&
_swsCtx_240_240
,
&
_scaledFrame_240_240
);
free_scale_context
(
&
_sws_ctx_w_h
,
&
_scaled_frame_w_h
);
free_scale_context
(
&
_sws_ctx_h_w
,
&
_scaled_frame_h_w
);
free_scale_context
(
&
_sws_ctx_h_h
,
&
_scaled_frame_h_h
);
#if USE_H264BSF
...
...
@@ -367,36 +368,36 @@ int CAVTranscoder::open_output_file(const char *filename)
continue
;
}
int
h
=
0
;
if
(
pFrame
->
width
==
SRC_W
&&
pFrame
->
height
==
SRC_H
)
{
h
=
sws_scale
(
_swsCtx_320_240
,
pFrame
->
data
,
pFrame
->
linesize
,
0
,
pFrame
->
height
,
_scaledFrame_320_240
->
data
,
_scaledFrame_320_240
->
linesize
);
if
(
pFrame
->
width
==
_src_width
&&
pFrame
->
height
==
_src_height
)
{
h
=
sws_scale
(
_sws_ctx_w_h
,
pFrame
->
data
,
pFrame
->
linesize
,
0
,
pFrame
->
height
,
_scaled_frame_w_h
->
data
,
_scaled_frame_w_h
->
linesize
);
if
(
h
<=
0
){
printf
(
"
\n
scale output result:%d?,ignored"
,
h
);
continue
;
}
_scaledFrame_320_240
->
pkt_dts
=
pFrame
->
pkt_dts
;
//pass rotation
fillDestFrame
(
pDstFrame
,
_scaledFrame_320_240
,
SRC_W
-
(
imageIdx
%
4
+
1
)
*
(
SCALED_H
+
5
)
+
4
,
SRC_H
-
SCALED_H
+
3
-
(
SCALED_H
+
1
)
*
(
imageIdx
/
4
),
(
SCALED_W
-
SCALED_H
)
/
2
,
0
,
SCALED_H
-
3
,
SCALED_H
-
3
);
_scaled_frame_w_h
->
pkt_dts
=
pFrame
->
pkt_dts
;
//pass rotation
fillDestFrame
(
pDstFrame
,
_scaled_frame_w_h
,
_src_width
-
(
imageIdx
%
4
+
1
)
*
(
_scaled_height
+
5
)
+
4
,
_src_height
-
_scaled_height
+
3
-
(
_scaled_height
+
1
)
*
(
imageIdx
/
4
),
(
_scaled_width
-
_scaled_height
)
/
2
,
0
,
_scaled_height
-
3
,
_scaled_height
-
3
);
}
else
if
(
pFrame
->
width
==
SRC_H
&&
pFrame
->
height
==
SRC_W
)
{
h
=
sws_scale
(
_swsCtx_240_320
,
pFrame
->
data
,
pFrame
->
linesize
,
0
,
pFrame
->
height
,
_scaledFrame_240_320
->
data
,
_scaledFrame_240_320
->
linesize
);
else
if
(
pFrame
->
width
==
_src_height
&&
pFrame
->
height
==
_src_width
)
{
h
=
sws_scale
(
_sws_ctx_h_w
,
pFrame
->
data
,
pFrame
->
linesize
,
0
,
pFrame
->
height
,
_scaled_frame_h_w
->
data
,
_scaled_frame_h_w
->
linesize
);
if
(
h
<=
0
){
printf
(
"
\n
scale output result:%d?,ignored"
,
h
);
continue
;
}
_scaledFrame_240_320
->
pkt_dts
=
pFrame
->
pkt_dts
;
//pass rotation
fillDestFrame
(
pDstFrame
,
_scaledFrame_240_320
,
SRC_W
-
(
imageIdx
%
4
+
1
)
*
(
SCALED_H
+
5
)
+
4
,
SRC_H
-
SCALED_H
+
3
-
(
SCALED_H
+
1
)
*
(
imageIdx
/
4
),
0
,
(
SCALED_W
-
SCALED_H
)
/
2
,
SCALED_H
-
3
,
SCALED_H
-
3
);
_scaled_frame_h_w
->
pkt_dts
=
pFrame
->
pkt_dts
;
//pass rotation
fillDestFrame
(
pDstFrame
,
_scaled_frame_h_w
,
_src_width
-
(
imageIdx
%
4
+
1
)
*
(
_scaled_height
+
5
)
+
4
,
_src_height
-
_scaled_height
+
3
-
(
_scaled_height
+
1
)
*
(
imageIdx
/
4
),
0
,
(
_scaled_width
-
_scaled_height
)
/
2
,
_scaled_height
-
3
,
_scaled_height
-
3
);
}
else
if
(
pFrame
->
width
==
SRC_H
&&
pFrame
->
height
==
SRC_H
)
{
h
=
sws_scale
(
_swsCtx_240_240
,
pFrame
->
data
,
pFrame
->
linesize
,
0
,
pFrame
->
height
,
_scaledFrame_240_240
->
data
,
_scaledFrame_240_240
->
linesize
);
else
if
(
pFrame
->
width
==
_src_height
&&
pFrame
->
height
==
_src_height
)
{
h
=
sws_scale
(
_sws_ctx_h_h
,
pFrame
->
data
,
pFrame
->
linesize
,
0
,
pFrame
->
height
,
_scaled_frame_h_h
->
data
,
_scaled_frame_h_h
->
linesize
);
if
(
h
<=
0
){
printf
(
"
\n
scale output result:%d?,ignored"
,
h
);
continue
;
}
_scaledFrame_240_240
->
pkt_dts
=
pFrame
->
pkt_dts
;
//pass rotation
fillDestFrame
(
pDstFrame
,
_scaledFrame_240_240
,
SRC_W
-
(
imageIdx
%
4
+
1
)
*
(
SCALED_H
+
5
)
+
4
,
SRC_H
-
SCALED_H
+
3
-
(
SCALED_H
+
1
)
*
(
imageIdx
/
4
),
0
,
0
,
SCALED_H
-
3
,
SCALED_H
-
3
);
_scaled_frame_h_h
->
pkt_dts
=
pFrame
->
pkt_dts
;
//pass rotation
fillDestFrame
(
pDstFrame
,
_scaled_frame_h_h
,
_src_width
-
(
imageIdx
%
4
+
1
)
*
(
_scaled_height
+
5
)
+
4
,
_src_height
-
_scaled_height
+
3
-
(
_scaled_height
+
1
)
*
(
imageIdx
/
4
),
0
,
0
,
_scaled_height
-
3
,
_scaled_height
-
3
);
}
else
{
printf
(
"
\n
the frame resolution %dx%d is unexpected! ignored!"
,
pFrame
->
width
,
pFrame
->
height
);
...
...
@@ -606,7 +607,7 @@ int CAVTranscoder::open_output_file(const char *filename)
}
if
(
_teacherFrame
)
{
if
(
_teacherFrame
->
width
==
SRC_W
&&
_teacherFrame
->
height
==
SRC_H
)
{
if
(
_teacherFrame
->
width
==
_src_width
&&
_teacherFrame
->
height
==
_src_height
)
{
if
(
_teacherFrame
->
pkt_dts
!=
90
){
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
0
,
0
);
}
...
...
@@ -614,10 +615,10 @@ int CAVTranscoder::open_output_file(const char *filename)
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
_nOutputWidth
*
_nOutputHeight
/
2
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
_nOutputWidth
*
_nOutputHeight
/
8
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
_nOutputWidth
*
_nOutputHeight
/
8
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
0
,
(
SRC_W
-
SRC_H
)
/
2
,
0
,
SRC_H
,
SRC_H
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_src_width
-
_src_height
)
/
2
,
0
,
(
_src_width
-
_src_height
)
/
2
,
0
,
_src_height
,
_src_height
);
}
}
else
if
(
_teacherFrame
->
width
==
SRC_H
&&
_teacherFrame
->
height
==
SRC_W
)
{
else
if
(
_teacherFrame
->
width
==
_src_height
&&
_teacherFrame
->
height
==
_src_width
)
{
if
(
_teacherFrame
->
pkt_dts
==
90
){
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
0
,
0
);
}
...
...
@@ -625,60 +626,60 @@ int CAVTranscoder::open_output_file(const char *filename)
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
_nOutputWidth
*
_nOutputHeight
/
2
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
_nOutputWidth
*
_nOutputHeight
/
8
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
_nOutputWidth
*
_nOutputHeight
/
8
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
0
,
0
,
(
SRC_W
-
SRC_H
)
/
2
,
SRC_H
,
SRC_H
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_src_width
-
_src_height
)
/
2
,
0
,
0
,
(
_src_width
-
_src_height
)
/
2
,
_src_height
,
_src_height
);
}
}
else
if
(
_teacherFrame
->
width
==
SRC_H
&&
_teacherFrame
->
height
==
SRC_H
)
{
else
if
(
_teacherFrame
->
width
==
_src_height
&&
_teacherFrame
->
height
==
_src_height
)
{
memset
(
pDstFrame
->
data
[
0
],
_blank_y
,
_nOutputWidth
*
_nOutputHeight
/
2
);
memset
(
pDstFrame
->
data
[
1
],
_blank_u
,
_nOutputWidth
*
_nOutputHeight
/
8
);
memset
(
pDstFrame
->
data
[
2
],
_blank_v
,
_nOutputWidth
*
_nOutputHeight
/
8
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
0
);
fillDestFrame
(
pDstFrame
,
_teacherFrame
,
(
_src_width
-
_src_height
)
/
2
,
0
);
}
else
{
printf
(
"
\n
resolution: %dx%d unexpected!"
,
_studentFrame
->
width
,
_studentFrame
->
height
);
}
if
(
_studentFrame
)
{
if
(
_studentFrame
->
width
==
SRC_W
)
{
if
(
_studentFrame
->
width
==
_src_width
)
{
if
(
_studentFrame
->
pkt_dts
!=
90
){
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
240
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
_src_height
);
}
else
{
memset
(
pDstFrame
->
data
[
0
]
+
240
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
_nOutputWidth
*
_nOutputHeight
/
2
);
memset
(
pDstFrame
->
data
[
1
]
+
120
*
pDstFrame
->
linesize
[
1
],
_blank_u
,
_nOutputWidth
*
_nOutputHeight
/
8
);
memset
(
pDstFrame
->
data
[
2
]
+
120
*
pDstFrame
->
linesize
[
2
],
_blank_v
,
_nOutputWidth
*
_nOutputHeight
/
8
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
240
,
(
SRC_W
-
SRC_H
)
/
2
,
0
,
SRC_H
,
SRC_H
);
memset
(
pDstFrame
->
data
[
0
]
+
_src_height
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
_nOutputWidth
*
_nOutputHeight
/
2
);
memset
(
pDstFrame
->
data
[
1
]
+
_src_height
/
2
*
pDstFrame
->
linesize
[
1
],
_blank_u
,
_nOutputWidth
*
_nOutputHeight
/
8
);
memset
(
pDstFrame
->
data
[
2
]
+
_src_height
/
2
*
pDstFrame
->
linesize
[
2
],
_blank_v
,
_nOutputWidth
*
_nOutputHeight
/
8
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_src_width
-
_src_height
)
/
2
,
_src_height
,
(
_src_width
-
_src_height
)
/
2
,
0
,
_src_height
,
_src_height
);
}
}
else
if
(
_studentFrame
->
pkt_dts
==
90
){
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
240
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
_src_height
);
}
else
{
memset
(
pDstFrame
->
data
[
0
]
+
240
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
_nOutputWidth
*
_nOutputHeight
/
2
);
memset
(
pDstFrame
->
data
[
1
]
+
120
*
pDstFrame
->
linesize
[
1
],
_blank_u
,
_nOutputWidth
*
_nOutputHeight
/
8
);
memset
(
pDstFrame
->
data
[
2
]
+
120
*
pDstFrame
->
linesize
[
2
],
_blank_v
,
_nOutputWidth
*
_nOutputHeight
/
8
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
240
,
0
,
(
SRC_W
-
SRC_H
)
/
2
,
SRC_H
,
SRC_H
);
memset
(
pDstFrame
->
data
[
0
]
+
_src_height
*
pDstFrame
->
linesize
[
0
],
_blank_y
,
_nOutputWidth
*
_nOutputHeight
/
2
);
memset
(
pDstFrame
->
data
[
1
]
+
_src_height
/
2
*
pDstFrame
->
linesize
[
1
],
_blank_u
,
_nOutputWidth
*
_nOutputHeight
/
8
);
memset
(
pDstFrame
->
data
[
2
]
+
_src_height
/
2
*
pDstFrame
->
linesize
[
2
],
_blank_v
,
_nOutputWidth
*
_nOutputHeight
/
8
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_src_width
-
_src_height
)
/
2
,
_src_height
,
0
,
(
_src_width
-
_src_height
)
/
2
,
_src_height
,
_src_height
);
}
}
}
else
if
(
_studentFrame
)
{
if
(
_studentFrame
->
width
==
SRC_W
&&
_studentFrame
->
height
==
SRC_H
)
{
if
(
_studentFrame
->
width
==
_src_width
&&
_studentFrame
->
height
==
_src_height
)
{
if
(
_studentFrame
->
pkt_dts
!=
90
){
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
0
);
}
else
{
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
0
,
(
SRC_W
-
SRC_H
)
/
2
,
0
,
SRC_H
,
SRC_H
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_src_width
-
_src_height
)
/
2
,
0
,
(
_src_width
-
_src_height
)
/
2
,
0
,
_src_height
,
_src_height
);
}
}
else
if
(
_studentFrame
->
width
==
SRC_H
&&
_studentFrame
->
height
==
SRC_W
)
{
else
if
(
_studentFrame
->
width
==
_src_height
&&
_studentFrame
->
height
==
_src_width
)
{
if
(
_studentFrame
->
pkt_dts
==
90
){
fillDestFrame
(
pDstFrame
,
_studentFrame
,
0
,
0
);
}
else
{
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
0
,
0
,
(
SRC_W
-
SRC_H
)
/
2
,
SRC_H
,
SRC_H
);
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_src_width
-
_src_height
)
/
2
,
0
,
0
,
(
_src_width
-
_src_height
)
/
2
,
_src_height
,
_src_height
);
}
}
else
if
(
_studentFrame
->
width
==
SRC_H
&&
_studentFrame
->
height
==
SRC_H
)
{
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
SRC_W
-
SRC_H
)
/
2
,
0
);
else
if
(
_studentFrame
->
width
==
_src_height
&&
_studentFrame
->
height
==
_src_height
)
{
fillDestFrame
(
pDstFrame
,
_studentFrame
,
(
_src_width
-
_src_height
)
/
2
,
0
);
}
else
{
printf
(
"
\n
resolution: %dx%d unexpected!"
,
_studentFrame
->
width
,
_studentFrame
->
height
);
...
...
pip/AVTranscoder.h
查看文件 @
d117a17
...
...
@@ -44,12 +44,16 @@ private:
void
*
_a_frame_pool
;
int
_max_audio
;
struct
SwsContext
*
_swsCtx_320_240
;
struct
SwsContext
*
_swsCtx_240_320
;
struct
SwsContext
*
_swsCtx_240_240
;
AVFrame
*
_scaledFrame_320_240
;
AVFrame
*
_scaledFrame_240_320
;
AVFrame
*
_scaledFrame_240_240
;
int
_scaled_width
;
int
_scaled_height
;
int
_src_width
;
int
_src_height
;
struct
SwsContext
*
_sws_ctx_w_h
;
struct
SwsContext
*
_sws_ctx_h_w
;
struct
SwsContext
*
_sws_ctx_h_h
;
AVFrame
*
_scaled_frame_w_h
;
AVFrame
*
_scaled_frame_h_w
;
AVFrame
*
_scaled_frame_h_h
;
int
_last_videos_got
;
AVFrame
*
_teacherFrame
;
AVFrame
*
_studentFrame
;
// for one2one,keep the last frame
...
...
请
注册
或
登录
后发表评论