胡斌

parsing rotation=180 in record file,rotate the video when merge audio video

... ... @@ -33,6 +33,7 @@ public:
int index;
media_type m_type;
int channel;
int rotate; //degree,0,90,180 ...
};
class media_info {
... ... @@ -41,6 +42,7 @@ public:
float start_time;
float end_time;
string name;
int rotate;
float duration;
int index;
... ... @@ -133,6 +135,7 @@ void addinfo(string t, string name, bool bstart){
f.end_time = f.start_time;
f.name = name;
f.m_type = mtype;
f.rotate = 0;
if (!first_time_set) {
first_time_set = true;
... ... @@ -160,6 +163,21 @@ void addinfo(string t, string name, bool bstart){
}
}
void addinfo(const char * t, const char * name, const char * rotation){
int i = 0;
for (; i < media_files.size(); i++) {
if (media_files[i].name == name) {
media_files[i].rotate = atoi(rotation);
break;
}
}
if (i == media_files.size())
{
printf("\nerror ,file : %s info but not found!", name);
}
}
void addinfo(float start, float duration, string name, int channel){
media_type mtype = mt_av;
fileinfo f;
... ... @@ -231,10 +249,25 @@ void merge_audio_pic(const char * audio, const char * picfile, const char * dest
}
void merge_audio_video(const char * audio, const char * video, const char * destfile)
void merge_audio_video(const char * audio, const char * video, int rotate, const char * destfile)
{
char buf[2048];
if (0 == rotate) {
sprintf(buf, "ffmpeg -y -i %s -i %s %s %s %s", audio, video, acodec_param, vcodec_param, destfile);
}
else {
const char * vf = "";
if (rotate == 180){
vf = "-vf rotate=PI";
}
else if (rotate == 90) {
vf = "-vf rotate=PI/2";
}
else if (rotate == 270) {
vf = "-vf rotate=PI*3/2";
}
sprintf(buf, "ffmpeg -y -i %s -i %s %s %s %s %s", audio, video, acodec_param, vf, vcodec_param, destfile);
}
run_shell_cmd(buf);
}
... ... @@ -563,6 +596,7 @@ void add_media_infos()
m.channel = f.channel;
m.duration = f.end_time - f.start_time;
m.type_time = m.start_time;
m.rotate = f.rotate;
add_media_info(m);
m.t_type = tt_end;
m.type_time = m.end_time;
... ... @@ -666,7 +700,7 @@ int merge_audio_video(vector<media_info> & files)
sprintf(destfile, "%d.ts", nf);
merge_audio_video(audio_file, video.name.c_str(), destfile);
merge_audio_video(audio_file, video.name.c_str(), video.rotate, destfile);
merged_files.push_back(destfile);
nf++;
... ... @@ -1369,6 +1403,14 @@ int readfile(char * filename)
else if (res[2] == "close") {
addinfo(res[0], res[1], false);
}
else if (res[2] == "info") {
if (res.size() > 5) {
const char * pInfo = res[5].c_str();
if (!strncmp(pInfo, "rotation=", 9)){
addinfo(res[0].c_str(), res[1].c_str(), pInfo + 9);
}
}
}
}
}
return 0;
... ...