胡斌

ver 1.0.5,support recording file without aac or webm closed

... ... @@ -233,30 +233,11 @@ void removefiles(vector<string> files)
}
}
float get_video_duration(const char *videofile)
float parse_ffmpeg_duration(const char * file)
{
char buf[2048];
sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", videofile, videofile);
run_shell_cmd(buf);
#ifdef WIN32
sprintf(buf, "ffmpeg -i %s.mkv > %s.txt 2>&1", videofile, videofile);
#else
sprintf(buf, "ffmpeg -i %s.mkv &> %s.txt", videofile, videofile);
#endif
run_shell_cmd(buf);
if (!keep_tmp_files) {
char buf[2048];
sprintf(buf, "%s.mkv", videofile);
remove_file(buf);
}
sprintf(buf, "%s.txt", videofile);
FILE * fp = fopen(buf, "rb");
FILE * fp = fopen(file, "rb");
if (!fp) {
printf("\nOpen %s error\n", buf);
printf("\nOpen %s error\n", file);
return -1.0;
}
fseek(fp, 0l, SEEK_END);
... ... @@ -270,21 +251,19 @@ float get_video_duration(const char *videofile)
content[file_len] = 0;
if (!keep_tmp_files) {
char buf[2048];
sprintf(buf, "%s.txt", videofile);
remove_file(buf);
remove_file(file);
}
char * pDuration = strstr(content, "Duration:");
if (!pDuration){
printf("\ncan't find 'Duration:' in %s\n", buf);
printf("\ncan't find 'Duration:' in %s\n", file);
delete content;
return -1.0;
}
char * pComma = strstr(pDuration, ",");
if (!pDuration){
printf("\ncan't find ',' after 'Duration:' in %s\n", buf);
printf("\ncan't find ',' after 'Duration:' in %s\n", file);
delete content;
return -1.0;
}
... ... @@ -297,7 +276,7 @@ float get_video_duration(const char *videofile)
delete content;
if (hms.size() != 3) {
printf("\nerro parsing duration in %s, the duration string is:%s\n", buf, content);
printf("\nerro parsing duration in %s, the duration string is:%s\n", file, content);
delete content;
return -1.0;
}
... ... @@ -309,6 +288,35 @@ float get_video_duration(const char *videofile)
return hour * 3600 + minute * 60 + sec;
}
float get_file_duration(const char *mediafile, bool bVideo)
{
char buf[2048];
if (bVideo){
sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", mediafile, mediafile);
}
else {
sprintf(buf, "ffmpeg -y -i %s -acodec copy -vn %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);
return parse_ffmpeg_duration(buf);
}
void get_duration_from_video_file()
{
vector<fileinfo> & filesvideo = media_files[type_video];
... ... @@ -319,7 +327,7 @@ void get_duration_from_video_file()
for (int i = 0; i < filesvideo.size(); i++){
float duration = get_video_duration(filesvideo[i].name.c_str());
float duration = get_file_duration(filesvideo[i].name.c_str(), true);
if (duration >= 0.10) {
printf("file:%s , duration in recording file: %.3f, duration parsed from file: %.3f\n", filesvideo[i].name.c_str(), filesvideo[i].end_time - filesvideo[i].start_time, duration);
filesvideo[i].end_time = filesvideo[i].start_time + duration;
... ... @@ -329,6 +337,28 @@ void get_duration_from_video_file()
only_print = tmp;
}
void check_audio_duration()
{
vector<fileinfo> & filesaudio = media_files[type_audio];
vector<string> tmp_files;
bool tmp = only_print;
only_print = false;
for (int i = 0; i < filesaudio.size(); i++){
fileinfo f = filesaudio[i];
if (f.end_time - f.start_time < 0.1){
float duration = get_file_duration(f.name.c_str(), false);
filesaudio[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 process_files(const char * output_dest_file)
{
vector<fileinfo> & filesaudio = media_files[type_audio];
... ... @@ -347,6 +377,7 @@ int process_files(const char * output_dest_file)
strcpy(silence_aac_file, cfg_path);
strcat(silence_aac_file, "silence.aac");
check_audio_duration();
get_duration_from_video_file();
if (filesvideo.size()) {//has video files
... ... @@ -553,7 +584,7 @@ void load_codec_param()
int main(int argc, char * argv[])
{
if (argc < 2) {
printf(" merge_av 1.0.4\n");
printf(" merge_av 1.0.5\n");
printf(" run ffmpeg to merge audio and video files according to the record info file,\nusage:");
printf("\n %s record_info_filename [-p] [-k]", argv[0]);
printf("\n -p :only print the command,don't run ffmpeg");
... ...