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
胡斌
2018-02-09 22:53:02 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
52e59565861c621c7c8fb8c7c46981562be9c70a
52e59565
1 parent
ff7eb97f
part of merge the code of merge_av and merge_pip,not finished
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
291 行增加
和
8 行删除
pip/pip.cpp
pip/pip.cpp
查看文件 @
52e5956
...
...
@@ -382,6 +382,25 @@ void get_duration_from_video_file()
}
void
check_audio_duration
()
{
bool
tmp
=
only_print
;
only_print
=
false
;
for
(
int
i
=
0
;
i
<
media_files
.
size
();
i
++
){
if
(
media_files
[
i
].
m_type
==
mt_audio
)
{
fileinfo
f
=
media_files
[
i
];
if
(
f
.
end_time
-
f
.
start_time
<
0.1
){
//avoid no close
float
duration
=
get_file_duration
(
f
.
name
.
c_str
(),
false
);
media_files
[
i
].
end_time
=
f
.
start_time
+
duration
;
printf
(
"file:%s , duration in recording file maybe is not set, duration parsed from file: %.3f
\n
"
,
f
.
name
.
c_str
(),
duration
);
}
}
}
only_print
=
tmp
;
}
int
merge_audio_file
(
vector
<
string
>
&
files
,
const
char
*
dest
)
{
char
buf
[
2048
],
tsfile
[
1024
];
...
...
@@ -474,7 +493,7 @@ void add_media_infos()
}
list
<
media_info
>::
iterator
it
=
sorted_media
.
begin
();
for
(
int
i
=
0
;
it
!=
sorted_media
.
end
();
it
++
,
i
++
){
for
(
;
it
!=
sorted_media
.
end
();
it
++
){
sorted_infos
.
push_back
(
*
it
);
}
}
...
...
@@ -496,14 +515,25 @@ void unifiy_start_time()
}
}
void
init
()
void
init
_merge_av
()
{
strcpy
(
blank_pic_file
,
cfg_path
);
strcat
(
blank_pic_file
,
"blank.jpg"
);
strcpy
(
silence_aac_file
,
cfg_path
);
strcat
(
silence_aac_file
,
"silence.aac"
);
check_audio_duration
();
get_duration_from_video_file
();
add_media_infos
();
nv
=
0
;
nf
=
0
;
}
void
init_merge_pip
()
{
unifiy_start_time
();
add_media_infos
();
...
...
@@ -567,6 +597,59 @@ int merge_audio_video(vector<media_info> & files)
return
0
;
}
int
merge_audio_pic
(
vector
<
media_info
>
&
files
)
{
media_info
audio
=
files
[
0
];
media_info
audio_end
=
files
[
1
];
if
(
audio
.
type_time
-
audio
.
start_time
>
0.10
||
audio_end
.
end_time
-
audio_end
.
type_time
>
0.10
)
{
sprintf
(
audio_file
,
"%d_%s"
,
nf
,
audio
.
name
.
c_str
());
split_audio
(
audio
.
name
.
c_str
(),
audio
.
type_time
-
audio
.
start_time
,
audio_end
.
type_time
-
audio
.
type_time
,
audio_file
);
tmp_files
.
push_back
(
audio_file
);
}
else
{
strcpy
(
audio_file
,
audio
.
name
.
c_str
());
}
sprintf
(
destfile
,
"%d.ts"
,
nf
);
int
i
=
0
;
for
(;
i
<
sorted_infos
.
size
();
i
++
){
if
(
sorted_infos
[
i
].
m_type
==
mt_video
){
string
name
=
sorted_infos
[
i
].
name
;
sprintf
(
pic_file
,
"%s.jpg"
,
name
.
c_str
());
get_video_first_frame_jpeg
(
name
.
c_str
(),
pic_file
);
tmp_files
.
push_back
(
pic_file
);
break
;
}
}
if
(
i
==
sorted_infos
.
size
()){
strcpy
(
pic_file
,
blank_pic_file
);
}
merge_audio_pic
(
audio_file
,
pic_file
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
return
0
;
}
int
find_video_between_the_audio
()
{
int
index
=
sorted_infos
[
0
].
index
;
int
video_index
=
0
;
for
(
int
i
=
1
;
i
<
sorted_infos
.
size
();
i
++
){
if
(
sorted_infos
[
i
].
index
==
index
)
break
;
if
(
sorted_infos
[
i
].
m_type
==
mt_video
)
{
video_index
=
i
;
break
;
}
}
return
video_index
;
}
int
merge_video_pip
(
vector
<
media_info
>
&
files
)
{
char
ch0_file
[
1024
],
ch1_file
[
1024
];
...
...
@@ -854,6 +937,105 @@ void get_front_info(int index_to, vector<media_info> &cur_processing)
}
}
int
process_va
()
{
vector
<
media_info
>
cur_processing
;
while
(
sorted_infos
.
size
())
{
media_type
mt
=
sorted_infos
[
0
].
m_type
;
if
(
mt
==
mt_audio
){
int
index
=
find_video_between_the_audio
();
if
(
index
>
0
)
//have_video
{
split_audio_for_pic
(
cur_processing
);
}
else
{
get_front_info
(
1
,
cur_processing
);
}
merge_audio_pic
(
cur_processing
);
}
else
{
int
index
=
find_video_end
();
if
(
is_audio_start
(
index
-
1
))
{
split_audio_for_video
(
index
-
1
,
cur_processing
);
}
else
{
get_front_info
(
index
,
cur_processing
);
}
merge_audio_video
(
cur_processing
);
}
}
return
0
;
}
int
process_files_to_1file
(
const
char
*
output_dest_file
)
{
//don't split video, for a video, using merged audios to mix with it
//for audio, mix with video or jpg
init_merge_av
();
if
(
!
media_files
.
size
()){
return
0
;
}
// judge if it is only one type
media_type
mt
=
media_files
[
0
].
m_type
;
bool
only_one_type
=
true
;
for
(
int
i
=
1
;
i
<
media_files
.
size
();
i
++
){
if
(
mt
!=
media_files
[
i
].
m_type
){
only_one_type
=
false
;
break
;
}
}
if
(
only_one_type
){
if
(
mt
==
mt_audio
)
{
if
(
media_files
.
size
()
==
1
){
fileinfo
audio
=
media_files
[
0
];
merge_audio_pic
(
audio
.
name
.
c_str
(),
blank_pic_file
,
"dest.ts"
);
return
0
;
}
for
(
int
i
=
0
;
i
<
media_files
.
size
();
i
++
){
fileinfo
audio
=
media_files
[
i
];
sprintf
(
destfile
,
"%d.ts"
,
nf
);
merge_audio_pic
(
audio
.
name
.
c_str
(),
blank_pic_file
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
}
else
{
if
(
media_files
.
size
()
==
1
){
fileinfo
video
=
media_files
[
0
];
merge_video_silence
(
video
,
silence_aac_file
,
"dest.ts"
);
return
0
;
}
for
(
int
i
=
0
;
i
<
media_files
.
size
();
i
++
){
fileinfo
video
=
media_files
[
i
];
sprintf
(
destfile
,
"%d.ts"
,
nf
);
merge_video_silence
(
video
,
silence_aac_file
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
}
}
else
{
process_va
();
}
concate_files
(
merged_files
,
"m.ts"
);
tmp_files
.
push_back
(
"m.ts"
);
adjust_dest_timecode
(
"m.ts"
,
output_dest_file
);
if
(
!
keep_tmp_files
)
{
removefiles
(
tmp_files
);
removefiles
(
merged_files
);
}
return
0
;
}
int
concate_files_and_adjust_timecode
(
const
char
*
output_dest_file
){
...
...
@@ -918,7 +1100,6 @@ void save_out_info(float start_time, char * outputfile)
}
}
int
process_va_files
()
{
char
outputfile
[
1024
];
...
...
@@ -931,6 +1112,56 @@ int process_va_files()
while
(
sorted_infos
.
size
())
{
media_type
mt
=
sorted_infos
[
0
].
m_type
;
if
(
mt
==
mt_audio
){
int
index
=
find_video_between_the_audio
();
if
(
index
>
0
)
//have_video
{
split_audio_for_pic
(
cur_processing
);
}
else
{
get_front_info
(
1
,
cur_processing
);
}
merge_audio_pic
(
cur_processing
);
}
else
{
int
index
=
find_video_end
();
if
(
is_audio_start
(
index
-
1
))
{
split_audio_for_video
(
index
-
1
,
cur_processing
);
}
else
{
get_front_info
(
index
,
cur_processing
);
}
merge_audio_video
(
cur_processing
);
}
//if the duration between the processed end and the start of not processed is large than 200 ms, reopen a new file
if
(
is_start
){
start_time
=
cur_processing
[
0
].
start_time
;
start_file
=
cur_processing
[
0
].
name
;
is_start
=
false
;
}
if
(
is_need_output
(
nOutPutFile
,
cur_processing
,
start_file
.
c_str
(),
outputfile
)){
nOutPutFile
++
;
concate_files_and_adjust_timecode
(
outputfile
);
save_out_info
(
start_time
,
outputfile
);
is_start
=
true
;
}
}
return
0
;
}
int
process_merged_files
()
{
char
outputfile
[
1024
];
vector
<
media_info
>
cur_processing
;
int
nOutPutFile
=
0
;
float
start_time
;
bool
is_start
=
true
;
string
start_file
;
while
(
sorted_infos
.
size
())
{
int
channel
=
sorted_infos
[
0
].
channel
;
if
(
sorted_infos
[
1
].
index
==
sorted_infos
[
0
].
index
)
{
...
...
@@ -961,8 +1192,59 @@ int process_va_files()
return
0
;
}
int
process_record_file_to_ts
()
{
//don't split video, for a video, using merged audios to mix with it
//for audio, mix with video or jpg
char
outputfile
[
1024
];
init_merge_av
();
int
process_files
()
if
(
!
media_files
.
size
()){
return
0
;
}
fp_out_info
=
fopen
(
out_info_file
,
"wt"
);
// judge if it is only one type
media_type
mt
=
media_files
[
0
].
m_type
;
bool
only_one_type
=
true
;
for
(
int
i
=
1
;
i
<
media_files
.
size
();
i
++
){
if
(
mt
!=
media_files
[
i
].
m_type
){
only_one_type
=
false
;
break
;
}
}
if
(
only_one_type
){
if
(
mt
==
mt_audio
)
{
for
(
int
i
=
0
;
i
<
media_files
.
size
();
i
++
){
fileinfo
audio
=
media_files
[
i
];
get_output_file_name
(
i
,
audio
.
name
.
c_str
(),
outputfile
);
merge_audio_pic
(
audio
.
name
.
c_str
(),
blank_pic_file
,
outputfile
);
save_out_info
(
audio
.
start_time
,
outputfile
);
}
}
else
{
for
(
int
i
=
0
;
i
<
media_files
.
size
();
i
++
){
fileinfo
video
=
media_files
[
i
];
get_output_file_name
(
i
,
video
.
name
.
c_str
(),
outputfile
);
merge_video_silence
(
video
,
silence_aac_file
,
destfile
);
save_out_info
(
video
.
start_time
,
outputfile
);
}
}
}
else
{
process_va_files
();
}
if
(
fp_out_info
)
{
fclose
(
fp_out_info
);
}
return
0
;
}
int
process_merged_files_to_pip_files
()
{
//don't split video, for a video, using merged audios to mix with it
//for audio, mix with video or jpg
...
...
@@ -973,11 +1255,11 @@ int process_files()
return
0
;
}
init
();
init
_merge_pip
();
fp_out_info
=
fopen
(
out_info_file
,
"wt"
);
process_
va
_files
();
process_
merged
_files
();
if
(
fp_out_info
)
{
fclose
(
fp_out_info
);
...
...
@@ -1010,6 +1292,7 @@ int readfile(char * filename)
}
return
0
;
}
// parse the filename like 4165000_20180203013327202.aac
#define get_sub_str_to_x(x , source, len, result) strncpy(x, source, len); x[len] = 0; source += len; result = atoi(x);
time_t
time_sec_1970_base
=
0
;
...
...
@@ -1083,7 +1366,7 @@ void load_codec_param()
char
cfgfile
[
1024
];
strcpy
(
cfgfile
,
cfg_path
);
strcat
(
cfgfile
,
"merge_
av
.cfg"
);
strcat
(
cfgfile
,
"merge_
pip
.cfg"
);
ifstream
fin
(
cfgfile
);
if
(
!
fin
)
{
...
...
@@ -1164,7 +1447,7 @@ int main(int argc, char * argv[])
load_codec_param
();
process_files
();
process_
merged_files_to_pip_
files
();
return
0
;
}
...
...
请
注册
或
登录
后发表评论