优化bdnxml时间不准确

This commit is contained in:
猪小乐 2023-06-15 16:00:58 +00:00
parent c0ffea2773
commit 2ab8d6c2dc

View File

@ -148,6 +148,7 @@
*----------------------------------------------------------------------------*/
#include <stdint.h>
#include<math.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
@ -569,17 +570,18 @@ void swap_rb (stream_info_t *s_info, char *img, char *out)
}
/* SMPTE non-drop time code */
void mk_timecode (int frame, int fps, char *buf) /* buf must have length 12 (incl. trailing \0) */
void mk_timecode (int frame, int fpsNum, int fpsDen, char *buf) /* buf must have length 12 (incl. trailing \0) */
{
int frames, s, m, h;
double fps = (double)fpsNum / (double)fpsDen;
int tc = frame;
tc = frame;
frames = tc % fps;
frames = ceil(fmod(tc, fps));
tc /= fps;
s = tc % 60;
s = fmod(tc, 60);
tc /= 60;
m = tc % 60;
m = fmod(tc, 60);
tc /= 60;
h = tc;
@ -1322,8 +1324,8 @@ int main (int argc, char *argv[])
}
/* Write XML header */
mk_timecode(first_frame + to, fps, intc_buf);
mk_timecode(end_frame + to + auto_cut, fps, outtc_buf);
mk_timecode(first_frame + to, fps_num, fps_den, intc_buf);
mk_timecode(end_frame + to + auto_cut, fps_num, fps_den, outtc_buf);
fprintf(fh, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<BDN Version=\"0.93\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
"xsi:noNamespaceSchemaLocation=\"BD-03-006-0093b BDN File Format.xsd\">\n"
@ -1333,8 +1335,8 @@ int main (int argc, char *argv[])
"<Format VideoFormat=\"%s\" FrameRate=\"%s\" DropFrame=\"%s\"/>\n"
"<Events LastEventOutTC=\"%s\" FirstEventInTC=\"%s\"\n", track_name, language, video_format, frame_rate, drop_frame, outtc_buf, intc_buf);
mk_timecode(0, fps, intc_buf);
mk_timecode(frames + to, fps, outtc_buf);
mk_timecode(0, fps_num, fps_den, intc_buf);
mk_timecode(frames + to, fps_num, fps_den, outtc_buf);
fprintf(fh, "ContentInTC=\"%s\" ContentOutTC=\"%s\" NumberofEvents=\"%d\" Type=\"Graphic\"/>\n"
"</Description>\n"
"<Events>\n", intc_buf, outtc_buf, num_of_events);
@ -1345,12 +1347,12 @@ int main (int argc, char *argv[])
event = event_list_first(events);
do
{
mk_timecode(event->start_frame, fps, intc_buf);
mk_timecode(event->end_frame, fps, outtc_buf);
mk_timecode(event->start_frame, fps_num, fps_den, intc_buf);
mk_timecode(event->end_frame, fps_num, fps_den, outtc_buf);
if (auto_cut && event->end_frame == frames - 1)
{
mk_timecode(event->end_frame + 1, fps, outtc_buf);
mk_timecode(event->end_frame + 1, fps_num, fps_den, outtc_buf);
}
fprintf(fh, "<Event Forced=\"%s\" InTC=\"%s\" OutTC=\"%s\">\n", (event->forced ? "True" : "False"), intc_buf, outtc_buf);