#include <vector>
#include "clip_list.h"
+#include "timebase.h"
#include "ui_mainwindow.h"
using namespace std;
string pts_to_string(int64_t pts)
{
- // FIXME: This depends on a fixed timebase.
- int64_t t = lrint((pts / 12800.0) * 1e3); // In milliseconds.
+ int64_t t = lrint((pts / double(TIMEBASE)) * 1e3); // In milliseconds.
int ms = t % 1000;
t /= 1000;
int sec = t % 60;
string duration_to_string(int64_t pts_diff)
{
- // FIXME: This depends on a fixed timebase.
- int64_t t = lrint((pts_diff / 12800.0) * 1e3); // In milliseconds.
+ int64_t t = lrint((pts_diff / double(TIMEBASE)) * 1e3); // In milliseconds.
int ms = t % 1000;
t /= 1000;
int sec = t % 60;
#include "player.h"
#include "post_to_main_thread.h"
#include "ref_counted_gl_sync.h"
+#include "timebase.h"
#include "ui_mainwindow.h"
using namespace std;
if (av_read_frame(format_ctx.get(), &pkt) != 0) {
break;
}
+
+ // Convert pts to our own timebase.
+ // TODO: Figure out offsets, too.
+ AVRational stream_timebase = format_ctx->streams[pkt.stream_index]->time_base;
+ pkt.pts = av_rescale_q(pkt.pts, stream_timebase, AVRational{ 1, TIMEBASE });
+
//fprintf(stderr, "Got a frame from camera %d, pts = %ld, size = %d\n",
// pkt.stream_index, pkt.pts, pkt.size);
string filename = filename_for_frame(pkt.stream_index, pkt.pts);
assert(pkt.stream_index < MAX_STREAMS);
frames[pkt.stream_index].push_back(pkt.pts);
- // Hack. Assumes a given timebase.
+ // Hack. Remove when we're dealing with live streams.
if (last_pts != -1) {
- this_thread::sleep_for(microseconds((pkt.pts - last_pts) * 1000000 / 12800));
+ this_thread::sleep_for(microseconds((pkt.pts - last_pts) * 1000000 / TIMEBASE));
}
last_pts = pkt.pts;
current_pts = pkt.pts;
#include "jpeg_frame_view.h"
#include "mux.h"
#include "player.h"
+#include "timebase.h"
#include "video_stream.h"
using namespace std;
next_pts = *it;
}
- // FIXME: assumes a given timebase.
double speed = 0.5;
steady_clock::time_point next_frame_start =
- origin + microseconds((next_pts - pts_origin) * int(1000000 / speed) / 12800);
+ origin + microseconds((next_pts - pts_origin) * int(1000000 / speed) / TIMEBASE);
// Sleep until the next frame start, or until there's a new clip we're supposed to play.
{
next_next_pts = *it;
}
if (next_next_pts != -1) {
- auto frame_len = microseconds((next_next_pts - next_pts) * int(1000000 / speed) / 12800) / 2;
+ auto frame_len = microseconds((next_next_pts - next_pts) * int(1000000 / speed) / TIMEBASE) / 2;
int64_t interpolated_pts = pts + lrint(duration<double>(frame_len).count() * TIMEBASE);
video_stream->schedule_interpolated_frame(interpolated_pts, stream_idx, next_pts, next_next_pts, 0.5f);
}