胡斌

read record files and make pip files

正在显示 1 个修改的文件 包含 88 行增加33 行删除
... ... @@ -52,6 +52,9 @@ public:
vector<fileinfo> media_files;
const char * MERGED_PREFIX = "";
const char * PIP_PREFIX = "pip_";
void run_shell_cmd(const char * cmd)
{
... ... @@ -113,6 +116,12 @@ char pip_param[1024];
bool first_time_set = false;
float start_time = 0.0f;
void init_read_file() {
first_time_set = false;
start_time = 0.0f;
}
void addinfo(string t, string name, bool bstart){
media_type mtype = name.substr(name.length() - 4, name.length()) == ".aac" ? mt_audio : mt_video;
if (bstart) {
... ... @@ -450,7 +459,6 @@ deque<media_info> sorted_infos;
vector<media_info> media_infos;
vector<string > merged_files;
vector<string> tmp_files;
int nv; // the index of processing video file
int nf;//the index of processing target merged ts
char destfile[1024], audio_file[1024], pic_file[1024];
char blank_pic_file[1024];
... ... @@ -474,6 +482,7 @@ void add_media_info(media_info m)
void add_media_infos()
{
sorted_media.clear();
for (int i = 0; i < media_files.size(); i++) {
fileinfo f = media_files[i];
media_info m;
... ... @@ -517,7 +526,6 @@ void unifiy_start_time()
void init_merge_av()
{
strcpy(blank_pic_file, cfg_path);
strcat(blank_pic_file, "blank.jpg");
... ... @@ -528,8 +536,8 @@ void init_merge_av()
get_duration_from_video_file();
add_media_infos();
nv = 0;
nf = 0;
merged_files.clear();
tmp_files.clear();
}
void init_merge_pip()
... ... @@ -538,8 +546,8 @@ void init_merge_pip()
add_media_infos();
nv = 0;
nf = 0;
merged_files.clear();
tmp_files.clear();
}
... ... @@ -1063,22 +1071,22 @@ int concate_files_and_adjust_timecode(const char * output_dest_file){
}
int get_output_file_name(int i, const char * file_prefix, char * outputfile){
char prefix[128];
const char * p = strstr(file_prefix, ".");
int get_output_file_name(int i, const char * filename, const char * prefix,char * outputfile){
char mainname[128];
const char * p = strstr(filename, ".");
if (p) {
strncpy(prefix, file_prefix, p - file_prefix);
prefix[p - file_prefix] = 0;
strncpy(mainname, filename, p - filename);
mainname[p - filename] = 0;
}
else {
strcpy(prefix, file_prefix);
strcpy(mainname, filename);
}
sprintf(outputfile, "pip_%s.ts", prefix, i);
sprintf(outputfile, "%s%s.ts",prefix, mainname, i);
return 0;
}
bool is_need_output(int nOutPutFile, vector<media_info> & cur_processing, const char * first_file, char * outputfile)
bool is_need_output(int nOutPutFile, vector<media_info> & cur_processing, const char * first_file, char * outputfile, const char * prefix="")
{
if (sorted_infos.size()) {
int lastEnd = cur_processing[cur_processing.size() - 1].type_time;
... ... @@ -1088,7 +1096,7 @@ bool is_need_output(int nOutPutFile, vector<media_info> & cur_processing, const
}
}
get_output_file_name(nOutPutFile, first_file, outputfile);
get_output_file_name(nOutPutFile, first_file, prefix, outputfile);
return true;
}
... ... @@ -1140,7 +1148,7 @@ int process_va_files()
start_file = cur_processing[0].name;
is_start = false;
}
if (is_need_output(nOutPutFile, cur_processing, start_file.c_str(), outputfile)){
if (is_need_output(nOutPutFile, cur_processing, start_file.c_str(), outputfile, MERGED_PREFIX)){
nOutPutFile++;
concate_files_and_adjust_timecode(outputfile);
save_out_info(start_time, outputfile);
... ... @@ -1182,7 +1190,7 @@ int process_merged_files()
start_file = cur_processing[0].name;
is_start = false;
}
if (is_need_output(nOutPutFile, cur_processing, start_file.c_str(), outputfile)){
if (is_need_output(nOutPutFile, cur_processing, start_file.c_str(), outputfile, PIP_PREFIX)){
nOutPutFile++;
concate_files_and_adjust_timecode(outputfile);
save_out_info(start_time, outputfile);
... ... @@ -1219,7 +1227,7 @@ int process_record_file_to_ts()
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);
get_output_file_name(i, audio.name.c_str(), MERGED_PREFIX, outputfile);
merge_audio_pic(audio.name.c_str(), blank_pic_file, outputfile);
save_out_info(audio.start_time, outputfile);
}
... ... @@ -1227,7 +1235,7 @@ int process_record_file_to_ts()
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);
get_output_file_name(i, video.name.c_str(), MERGED_PREFIX, outputfile);
merge_video_silence(video, silence_aac_file, destfile);
save_out_info(video.start_time, outputfile);
}
... ... @@ -1270,6 +1278,9 @@ int process_merged_files_to_pip_files()
int readfile(char * filename)
{
init_read_file();
media_files.clear();
ifstream fin(filename);
if (!fin) {
return -1;
... ... @@ -1329,8 +1340,12 @@ float get_start_time_from_filename(const char * filename)
return (float)(t) + minsec / 1000.0;
}
vector<string> all_input_files_for_pip;
int readfile(char * filename, int channel)
{
init_read_file();
ifstream fin(filename);
if (!fin) {
return -1;
... ... @@ -1346,10 +1361,11 @@ int readfile(char * filename, int channel)
split(str, " ", res);
if (res.size() == 3) {
if (bstart_time) {
start_time = get_start_time_from_filename(res[2].c_str());
start_time = get_start_time_from_filename(res[2].c_str() + strlen(MERGED_PREFIX));
bstart_time = false;
}
addinfo(atof(res[0].c_str()) + start_time ,atof(res[1].c_str()) , res[2], channel);
all_input_files_for_pip.push_back(res[2]);
}
}
return 0;
... ... @@ -1411,26 +1427,30 @@ void get_outinfo_file_name(char * input1 , char * input2)
strcat(out_info_file, input2);
}
void get_outinfo_file_name(char * input)
{
strcpy(out_info_file, input);
char * p = strstr(out_info_file, ".");
if (p) {
*p = 0;
}
strcat(out_info_file, "_out.txt");
}
int main(int argc, char * argv[])
{
if (argc < 3) {
printf(" pip 1.0.0\n");
printf(" run ffmpeg to merge video files to one pip video according to the processed record info file,\nusage:");
printf("\n %s record_info_out_filename1 record_info_out_filename2 [-p] [-k]", argv[0]);
printf(" run ffmpeg to merge video files to one pip video according to record info file,\nusage:");
printf("\n %s record_info_filename1 record_filename2 [-p] [-k]", argv[0]);
printf("\n -p :only print the command,don't run ffmpeg");
printf("\n -k :keep the temp files\n");
return -1;
}
if (readfile(argv[1], 0) < 0) {
printf("open file: %s error", argv[1]);
return -2;
}
get_config_path();
if (readfile(argv[2], 1) < 0) {
printf("open file: %s error", argv[1]);
return -2;
}
load_codec_param();
for (int i = 3; i < argc; i++){
if (!strcmp(argv[i], "-p")){
... ... @@ -1441,14 +1461,49 @@ int main(int argc, char * argv[])
}
}
get_outinfo_file_name(argv[1], argv[2]);
char merged_info1[1024];
if (readfile(argv[1]) < 0) {
printf("open file: %s error", argv[1]);
return -2;
}
get_config_path();
get_outinfo_file_name(argv[1]);
strcpy(merged_info1, out_info_file);
process_record_file_to_ts();
load_codec_param();
char merged_info2[1024];
if (readfile(argv[2]) < 0) {
printf("open file: %s error", argv[1]);
return -2;
}
get_outinfo_file_name(argv[2]);
strcpy(merged_info2, out_info_file);
process_record_file_to_ts();
media_files.clear();
if (readfile(merged_info1, 0) < 0) {
printf("open file: %s error", merged_info1);
return -2;
}
if (readfile(merged_info2, 1) < 0) {
printf("open file: %s error", merged_info2);
return -2;
}
get_outinfo_file_name(argv[1], argv[2]);
process_merged_files_to_pip_files();
if (!keep_tmp_files) {
removefiles(all_input_files_for_pip);
remove_file(merged_info1);
remove_file(merged_info2);
}
return 0;
}
... ...