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-06-28 21:34:12 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
04e7b37e25293bed35580b11be0c6b5293129487
04e7b37e
1 parent
95cb7c20
for only convert mp4,only get the codec,don't get the true duration
显示空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
74 行增加
和
0 行删除
merge_av/merge_av.cpp
merge_av/merge_av.cpp
查看文件 @
04e7b37
...
...
@@ -337,6 +337,24 @@ float parse_ffmpeg_duration(const char * file, bool * beH264 = NULL)
return
hour
*
3600
+
minute
*
60
+
sec
;
}
float
get_mp4_duration_from_header
(
const
char
*
mediafile
,
bool
*
bH264
)
{
char
buf
[
2048
];
#ifdef WIN32
sprintf
(
buf
,
"ffmpeg -i %s > %s.txt 2>&1"
,
mediafile
,
mediafile
);
#else
sprintf
(
buf
,
"ffmpeg -i %s &> %s.txt"
,
mediafile
,
mediafile
);
#endif
run_shell_cmd
(
buf
);
sprintf
(
buf
,
"%s.txt"
,
mediafile
);
return
parse_ffmpeg_duration
(
buf
,
bH264
);
}
//because the duration in mp4 header is wrong in some file,so convert it to ts and to mkv to get the right duration
float
get_mp4_duration
(
const
char
*
mediafile
,
bool
bVideo
,
bool
*
bH264
)
{
char
buf
[
2048
];
...
...
@@ -382,6 +400,40 @@ float get_mp4_duration(const char *mediafile, bool bVideo, bool * bH264)
#define strcasecmp _stricmp
#endif
float
get_file_codec_h264
(
const
char
*
mediafile
,
bool
*
beH264
=
NULL
)
{
char
buf
[
2048
];
int
len
=
strlen
(
mediafile
);
if
(
len
>
3
)
{
if
(
!
strcasecmp
(
mediafile
+
len
-
4
,
".mp4"
))
{
return
get_mp4_duration_from_header
(
mediafile
,
beH264
);
}
}
sprintf
(
buf
,
"ffmpeg -y -i %s -acodec copy -vcodec copy %s.mkv"
,
mediafile
,
mediafile
);
run_shell_cmd
(
buf
);
#ifdef WIN32
sprintf
(
buf
,
"ffmpeg -i %s.mkv > %s.txt 2>&1"
,
mediafile
,
mediafile
);
#else
sprintf
(
buf
,
"ffmpeg -i %s.mkv &> %s.txt"
,
mediafile
,
mediafile
);
#endif
run_shell_cmd
(
buf
);
if
(
!
keep_tmp_files
)
{
char
buf
[
2048
];
sprintf
(
buf
,
"%s.mkv"
,
mediafile
);
remove_file
(
buf
);
}
sprintf
(
buf
,
"%s.txt"
,
mediafile
);
float
duration
=
parse_ffmpeg_duration
(
buf
,
beH264
);
return
duration
;
}
float
get_file_duration
(
const
char
*
mediafile
,
bool
bVideo
,
bool
*
beH264
=
NULL
)
{
char
buf
[
2048
];
...
...
@@ -438,6 +490,23 @@ void get_duration_from_video_file()
only_print
=
tmp
;
}
void
get_video_codec_h264
()
{
bool
tmp
=
only_print
;
only_print
=
false
;
for
(
int
i
=
0
;
i
<
media_files
.
size
();
i
++
){
if
(
media_files
[
i
].
m_type
==
mt_video
)
{
bool
bH264
=
false
;
get_file_codec_h264
(
media_files
[
i
].
name
.
c_str
(),
&
bH264
);
media_files
[
i
].
is_h264
=
bH264
;
}
}
only_print
=
tmp
;
}
void
check_audio_duration
()
{
...
...
@@ -546,8 +615,13 @@ void init()
strcpy
(
silence_aac_file
,
cfg_path
);
strcat
(
silence_aac_file
,
"silence.aac"
);
if
(
only_convert_mp4
)
{
get_video_codec_h264
();
}
else
{
check_audio_duration
();
get_duration_from_video_file
();
}
add_media_infos
();
...
...
请
注册
或
登录
后发表评论