X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fmain.cpp;h=4c54d332d24951b9118798b86c90ef3ab10e464b;hb=a3b76e5ad9493b0af08fdcbe6d6b689d91496f85;hp=c13e19694783e3e2b178ce2f28ef5b6e8fcb3702;hpb=4a9e97065dade428e373a83618bc973cd93cbe52;p=nageru diff --git a/futatabi/main.cpp b/futatabi/main.cpp index c13e196..4c54d33 100644 --- a/futatabi/main.cpp +++ b/futatabi/main.cpp @@ -79,7 +79,7 @@ FrameOnDisk write_frame(int stream_idx, int64_t pts, const uint8_t *data, size_t { if (open_frame_files.count(stream_idx) == 0) { char filename[256]; - snprintf(filename, sizeof(filename), "%s/frames/cam%d-pts%09ld.frames", + snprintf(filename, sizeof(filename), "%s/frames/cam%d-pts%09" PRId64 ".frames", global_flags.working_directory.c_str(), stream_idx, pts); FILE *fp = fopen(filename, "wb"); if (fp == nullptr) { @@ -145,7 +145,7 @@ FrameOnDisk write_frame(int stream_idx, int64_t pts, const uint8_t *data, size_t frames[stream_idx].push_back(frame); } - if (++file.frames_written_so_far >= 1000) { + if (++file.frames_written_so_far >= FRAMES_PER_FILE) { size_t size = ftell(file.fp); // Start a new file next time. @@ -255,6 +255,12 @@ int main(int argc, char **argv) load_existing_frames(); + for (int stream_idx = 0; stream_idx < MAX_STREAMS; ++stream_idx) { + if (!frames[stream_idx].empty()) { + assert(start_pts > frames[stream_idx].back().pts); + } + } + MainWindow main_window; main_window.show(); @@ -269,7 +275,6 @@ int main(int argc, char **argv) should_quit = true; record_thread.join(); - JPEGFrameView::shutdown(); return ret; } @@ -497,7 +502,8 @@ void record_thread_func() if (av_read_frame(format_ctx.get(), &pkt) != 0) { break; } - if (pkt.stream_index >= MAX_STREAMS) { + if (pkt.stream_index >= MAX_STREAMS || + format_ctx->streams[pkt.stream_index]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) { continue; } @@ -529,8 +535,10 @@ void record_thread_func() current_pts = pts; } - fprintf(stderr, "%s: Hit EOF. Waiting one second and trying again...\n", global_flags.stream_source.c_str()); - sleep(1); + if (!should_quit.load()) { + fprintf(stderr, "%s: Hit EOF. Waiting one second and trying again...\n", global_flags.stream_source.c_str()); + sleep(1); + } start_pts = last_pts + TIMEBASE; }