From d117b15e0f275105a7776447ed5bb56ce54f7120 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 24 Sep 2025 21:53:01 +0900 Subject: [PATCH] better NTSC framerate handling --- video_encoder/encoder_tav.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/video_encoder/encoder_tav.c b/video_encoder/encoder_tav.c index 173cbb7..04a17a2 100644 --- a/video_encoder/encoder_tav.c +++ b/video_encoder/encoder_tav.c @@ -3045,6 +3045,7 @@ int main(int argc, char *argv[]) { // Main encoding loop - process frames until EOF or frame limit int frame_count = 0; + int true_frame_count = 0; int continue_encoding = 1; int count_iframe = 0; @@ -3172,10 +3173,10 @@ int main(int argc, char *argv[]) { } else { // Process audio for this frame - process_audio(enc, frame_count, enc->output_fp); + process_audio(enc, true_frame_count, enc->output_fp); // Process subtitles for this frame - process_subtitles(enc, frame_count, enc->output_fp); + process_subtitles(enc, true_frame_count, enc->output_fp); // Write a sync packet only after a video is been coded uint8_t sync_packet = TAV_PACKET_SYNC; @@ -3183,8 +3184,13 @@ int main(int argc, char *argv[]) { // NTSC frame duplication: emit extra sync packet for every 1000n+500 frames if (enc->is_ntsc_framerate && (frame_count % 1000 == 500)) { + true_frame_count++; + // Process audio and subtitles for the duplicated frame to maintain sync + process_audio(enc, true_frame_count, enc->output_fp); + process_subtitles(enc, true_frame_count, enc->output_fp); + fwrite(&sync_packet, 1, 1, enc->output_fp); - printf("Frame %d: NTSC duplication - extra sync packet emitted\n", frame_count); + printf("Frame %d: NTSC duplication - extra sync packet emitted with audio/subtitle sync\n", frame_count); } if (is_keyframe) @@ -3197,6 +3203,7 @@ int main(int argc, char *argv[]) { swap_frame_buffers(enc); frame_count++; + true_frame_count++; enc->frame_count = frame_count; if (enc->verbose || frame_count % 30 == 0) {