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
胡斌
2017-12-07 09:21:38 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3569f789a98304752e8696dabbf6fc21458edb4e
3569f789
1 parent
6a662776
for the record file only have audio,merge with blank.jpg
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
137 行增加
和
78 行删除
merge_av/ReadMe.txt
merge_av/merge_av.cpp
test/record_only_audio/61712260_20171122130331753.aac
test/record_only_audio/uid_61712260_20171122130331754.txt
merge_av/ReadMe.txt
查看文件 @
3569f78
...
...
@@ -50,7 +50,23 @@ ffmpeg -y -i m.ts -acodec copy -vcodec copy dest.ts
调用ffmpeg时,视频编码参数是: -vcodec libx264 -level 3.1 -preset veryfast -g 40 -r 20
音频编码参数是: -acodec copy
如果要修改,windows下在merge_av.exe同目录下新建merge_av.cfg文本文件,第一行保存视频编码,第二行保存音频编码;linux 下,merge_av.cfg保存在HOME目录。
如果要修改,windows下在merge_av.exe同目录下新建merge_av.cfg文本文件,第一行保存视频编码,第二行保存音频编码;linux 下,merge_av.cfg保存在HOME目录下的merge_av目录。
对于录像文件只有音频的情况,merge_av把音频与blank.jpg合并成视频文件。blank.jpg 在windows系统里,与merge_av.exe放在同一目录。在linux下,放在HOME目录下的merge_av目录。
例如:
uid_61712260_20171122130331754.txt内容如下:
0.000 61712260_20171122130331753.aac create
1366.801 61712260_20171122130331753.aac close
运行mergeav uid_61712260_20171122130331754.txt执行的命令是,linux下,HOME目录为/home/hubin
windows(假定merge_av.exe在d:\Merge_av目录):
ffmpeg -y -loop 1 -i D:\Merge_av\blank.jpg -i 61712260_20171122130331753.aac -loop 0 -shortest -acodec copy -vcodec libx264 -level 3.1 -preset veryfast -g 40 -r 20 dest.ts
linux(linux下,假定HOME目录为/home/hubin):
ffmpeg -y -loop 1 -i /home/hubin/merge_av/blank.jpg -i 61712260_20171122130331753.aac -loop 0 -shortest -acodec copy -vcodec libx264 -level 3.1 -preset veryfast -g 40 -r 20 dest.ts
...
...
merge_av/merge_av.cpp
查看文件 @
3569f78
...
...
@@ -36,14 +36,48 @@ void run_shell_cmd(const char * cmd)
}
}
#ifdef WIN32
#include <Windows.h>
char
exe_path
[
MAX_PATH
]
=
{
0
};
int
GetExePath
()
{
char
path_buffer
[
MAX_PATH
]
=
""
;
char
drive
[
32
]
=
""
;
char
dir
[
256
]
=
""
;
char
fname
[
64
]
=
""
;
char
ext
[
32
]
=
""
;
GetModuleFileNameA
(
NULL
,
path_buffer
,
256
);
_splitpath
(
path_buffer
,
drive
,
dir
,
fname
,
ext
);
strcpy
(
exe_path
,
drive
);
strcat
(
exe_path
,
dir
);
return
0
;
}
#endif
char
cfg_path
[
1024
];
void
get_config_path
(){
#ifdef WIN32
GetExePath
();
strcpy
(
cfg_path
,
exe_path
);
#else
strcpy
(
cfg_path
,
getenv
(
"HOME"
));
strcat
(
cfg_path
,
"/merge_av/"
);
#endif
}
const
char
*
default_vcodec_param
=
"-vcodec libx264 -level 3.1 -preset veryfast -g 40 -r 20"
;
const
char
*
default_acodec_param
=
"-acodec copy"
;
char
vcodec_param
[
1024
];
char
acodec_param
[
1024
];
void
addinfo
(
string
t
,
string
name
,
bool
bstart
){
media_type
mtype
=
name
.
substr
(
name
.
length
()
-
4
,
name
.
length
())
==
".aac"
?
type_audio
:
type_video
;
void
addinfo
(
string
t
,
string
name
,
bool
bstart
){
media_type
mtype
=
name
.
substr
(
name
.
length
()
-
4
,
name
.
length
())
==
".aac"
?
type_audio
:
type_video
;
if
(
bstart
)
{
fileinfo
f
;
f
.
start_time
=
atof
(
t
.
c_str
());
...
...
@@ -105,7 +139,14 @@ void get_video_first_frame_jpeg(fileinfo video, char * destfile)
void
merge_audio_pic
(
fileinfo
audio
,
int
nf
,
fileinfo
video
,
const
char
*
destfile
)
{
char
buf
[
2048
];
sprintf
(
buf
,
"ffmpeg -y -loop 1 -i %s.jpg -i %d_%s -loop 0 -shortest %s %s %s"
,
video
.
name
.
c_str
(),
nf
,
audio
.
name
.
c_str
(),
acodec_param
,
vcodec_param
,
destfile
);
sprintf
(
buf
,
"ffmpeg -y -loop 1 -i %s.jpg -i %d_%s -loop 0 -shortest %s %s %s"
,
video
.
name
.
c_str
(),
nf
,
audio
.
name
.
c_str
(),
acodec_param
,
vcodec_param
,
destfile
);
run_shell_cmd
(
buf
);
}
void
merge_audio_pic
(
fileinfo
audio
,
const
char
*
picfile
,
const
char
*
destfile
)
{
char
buf
[
2048
];
sprintf
(
buf
,
"ffmpeg -y -loop 1 -i %s -i %s -loop 0 -shortest %s %s %s"
,
picfile
,
audio
.
name
.
c_str
(),
acodec_param
,
vcodec_param
,
destfile
);
run_shell_cmd
(
buf
);
}
...
...
@@ -140,7 +181,7 @@ void concate_files(vector<string > merged_files, const char * destfile)
run_shell_cmd
(
buf
);
}
void
adjust_dest_timecode
(
const
char
*
src
,
const
char
*
dest
)
void
adjust_dest_timecode
(
const
char
*
src
,
const
char
*
dest
)
{
char
buf
[
2048
];
sprintf
(
buf
,
"ffmpeg -y -i %s -acodec copy -vcodec copy %s"
,
src
,
dest
);
...
...
@@ -172,61 +213,86 @@ int process_files(const char * output_dest_file)
int
nf
=
0
;
char
destfile
[
1024
];
for
(
int
i
=
0
;
i
<
filesaudio
.
size
();
i
++
){
//
fileinfo
audio
=
filesaudio
[
i
];
float
audio_start
=
0
;
for
(;
nv
<
filesvideo
.
size
();
nv
++
)
{
fileinfo
video
=
filesvideo
[
nv
];
if
(
video
.
start_time
-
audio_start
>
0.100
)
{
sprintf
(
destfile
,
"%d_%s"
,
nf
,
audio
.
name
.
c_str
()
);
split_audio
(
audio
,
audio_start
,
video
.
start_time
-
audio_start
,
destfile
);
tmp_files
.
push_back
(
destfile
);
audio_start
=
video
.
start_time
;
sprintf
(
destfile
,
"%s.jpg"
,
video
.
name
.
c_str
());
get_video_first_frame_jpeg
(
video
,
destfile
);
tmp_files
.
push_back
(
destfile
);
sprintf
(
destfile
,
"%d.ts"
,
nf
);
merge_audio_pic
(
audio
,
nf
,
video
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
get_config_path
();
if
(
filesvideo
.
size
())
{
//has video files
for
(
int
i
=
0
;
i
<
filesaudio
.
size
();
i
++
){
//
fileinfo
audio
=
filesaudio
[
i
];
float
audio_start
=
0
;
for
(;
nv
<
filesvideo
.
size
();
nv
++
)
{
fileinfo
video
=
filesvideo
[
nv
];
if
(
video
.
start_time
-
audio_start
>
0.100
)
{
sprintf
(
destfile
,
"%d_%s"
,
nf
,
audio
.
name
.
c_str
());
split_audio
(
audio
,
audio_start
,
video
.
start_time
-
audio_start
,
destfile
);
tmp_files
.
push_back
(
destfile
);
audio_start
=
video
.
start_time
;
sprintf
(
destfile
,
"%s.jpg"
,
video
.
name
.
c_str
());
get_video_first_frame_jpeg
(
video
,
destfile
);
tmp_files
.
push_back
(
destfile
);
sprintf
(
destfile
,
"%d.ts"
,
nf
);
merge_audio_pic
(
audio
,
nf
,
video
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
if
(
nv
!=
filesvideo
.
size
()
-
1
)
{
// not the last one
sprintf
(
destfile
,
"%d_%s"
,
nf
,
audio
.
name
.
c_str
());
split_audio
(
audio
,
video
.
start_time
,
video
.
end_time
-
video
.
start_time
,
destfile
);
tmp_files
.
push_back
(
destfile
);
audio_start
=
video
.
end_time
;
sprintf
(
destfile
,
"%d.ts"
,
nf
);
megre_audio_video
(
audio
,
nf
,
video
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
else
{
sprintf
(
destfile
,
"%d_%s"
,
nf
,
audio
.
name
.
c_str
());
split_audio
(
audio
,
video
.
start_time
,
audio
.
end_time
-
video
.
start_time
,
destfile
);
tmp_files
.
push_back
(
destfile
);
audio_start
=
video
.
end_time
;
sprintf
(
destfile
,
"%d.ts"
,
nf
);
megre_audio_video
(
audio
,
nf
,
video
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
}
if
(
nv
!=
filesvideo
.
size
()
-
1
)
{
// not the last one
sprintf
(
destfile
,
"%d_%s"
,
nf
,
audio
.
name
.
c_str
());
split_audio
(
audio
,
video
.
start_time
,
video
.
end_time
-
video
.
start_time
,
destfile
);
tmp_files
.
push_back
(
destfile
);
audio_start
=
video
.
end_time
;
sprintf
(
destfile
,
"%d.ts"
,
nf
);
megre_audio_video
(
audio
,
nf
,
video
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
else
{
sprintf
(
destfile
,
"%d_%s"
,
nf
,
audio
.
name
.
c_str
());
split_audio
(
audio
,
video
.
start_time
,
audio
.
end_time
-
video
.
start_time
,
destfile
);
tmp_files
.
push_back
(
destfile
);
}
}
else
{
//only audio
char
blank_pic_file
[
1024
];
audio_start
=
video
.
end_time
;
strcpy
(
blank_pic_file
,
cfg_path
);
strcat
(
blank_pic_file
,
"blank.jpg"
);
sprintf
(
destfile
,
"%d.ts"
,
nf
);
megre_audio_video
(
audio
,
nf
,
video
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
if
(
filesaudio
.
size
()
==
1
){
fileinfo
audio
=
filesaudio
[
0
];
merge_audio_pic
(
audio
,
blank_pic_file
,
"dest.ts"
);
return
0
;
}
for
(
int
i
=
0
;
i
<
filesaudio
.
size
();
i
++
){
fileinfo
audio
=
filesaudio
[
i
];
sprintf
(
destfile
,
"%d.ts"
,
nf
);
merge_audio_pic
(
audio
,
blank_pic_file
,
destfile
);
merged_files
.
push_back
(
destfile
);
nf
++
;
}
}
concate_files
(
merged_files
,
"m.ts"
);
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
);
...
...
@@ -260,27 +326,6 @@ int readfile(char * filename)
return
0
;
}
#ifdef WIN32
#include <Windows.h>
char
exe_path
[
MAX_PATH
]
=
{
0
};
int
GetExePath
()
{
char
path_buffer
[
MAX_PATH
]
=
""
;
char
drive
[
32
]
=
""
;
char
dir
[
256
]
=
""
;
char
fname
[
64
]
=
""
;
char
ext
[
32
]
=
""
;
GetModuleFileNameA
(
NULL
,
path_buffer
,
256
);
_splitpath
(
path_buffer
,
drive
,
dir
,
fname
,
ext
);
strcpy
(
exe_path
,
drive
);
strcat
(
exe_path
,
dir
);
return
0
;
}
#endif
void
load_codec_param
()
{
...
...
@@ -288,14 +333,10 @@ void load_codec_param()
strcpy
(
vcodec_param
,
default_vcodec_param
);
char
cfgfile
[
1024
];
#ifdef WIN32
GetExePath
();
strcpy
(
cfgfile
,
exe_path
);
#else
strcpy
(
cfgfile
,
getenv
(
"HOME"
));
strcat
(
cfgfile
,
"/"
);
#endif
strcpy
(
cfgfile
,
cfg_path
);
strcat
(
cfgfile
,
"merge_av.cfg"
);
ifstream
fin
(
cfgfile
);
if
(
!
fin
)
{
return
;
...
...
test/record_only_audio/61712260_20171122130331753.aac
0 → 100644
查看文件 @
3569f78
不能预览此文件类型
test/record_only_audio/uid_61712260_20171122130331754.txt
0 → 100644
查看文件 @
3569f78
0.000 61712260_20171122130331753.aac create
1366.801 61712260_20171122130331753.aac close
...
...
请
注册
或
登录
后发表评论