tavenc: proper sync packet after i-frames

This commit is contained in:
minjaesong
2025-12-09 04:44:40 +09:00
parent 621c312922
commit 5d99191b5e
3 changed files with 22 additions and 9 deletions

View File

@@ -269,6 +269,7 @@ void tav_encoder_get_stats(tav_encoder_context_t *ctx, tav_encoder_stats_t *stat
#define TAV_PACKET_LOOP_START 0xF0 // Loop point start (no payload) #define TAV_PACKET_LOOP_START 0xF0 // Loop point start (no payload)
#define TAV_PACKET_GOP_SYNC 0xFC // GOP sync (frame count marker) #define TAV_PACKET_GOP_SYNC 0xFC // GOP sync (frame count marker)
#define TAV_PACKET_TIMECODE 0xFD // Timecode metadata #define TAV_PACKET_TIMECODE 0xFD // Timecode metadata
#define TAV_PACKET_SYNC 0xFF // Sync packet (no payload)
// ============================================================================= // =============================================================================
// Tile Settings (for multi-tile mode) // Tile Settings (for multi-tile mode)

View File

@@ -704,7 +704,7 @@ int tav_encoder_encode_frame(tav_encoder_context_t *ctx,
// Encode GOP // Encode GOP
int result; int result;
if (ctx->enable_temporal_dwt && ctx->gop_size > 1) { if (ctx->enable_temporal_dwt) {
result = encode_gop_unified(ctx, &slot); result = encode_gop_unified(ctx, &slot);
} else { } else {
result = encode_gop_intra_only(ctx, &slot); result = encode_gop_intra_only(ctx, &slot);

View File

@@ -686,6 +686,16 @@ static int write_gop_sync_packet(FILE *fp, int frame_count) {
return 0; return 0;
} }
/**
* Write sync packet (0xFF) for intra-only mode.
* Format: [type(1)] (no payload)
*/
static int write_sync_packet(FILE *fp) {
uint8_t packet = TAV_PACKET_SYNC;
fwrite(&packet, 1, 1, fp);
return 0;
}
// ============================================================================= // =============================================================================
// Audio Encoding Functions // Audio Encoding Functions
// ============================================================================= // =============================================================================
@@ -1517,12 +1527,14 @@ static int encode_video_mt(cli_context_t *cli) {
cli->total_bytes += job->packet->size; cli->total_bytes += job->packet->size;
cli->gop_count++; cli->gop_count++;
// Write GOP_SYNC // Write sync packet
if (job->packet->packet_type == TAV_PACKET_GOP_UNIFIED) { if (job->packet->packet_type == TAV_PACKET_GOP_UNIFIED) {
// For 3D-DWT mode, write GOP_SYNC (0xFC) with frame count
int frames_in_gop = job->packet->data[1]; int frames_in_gop = job->packet->data[1];
write_gop_sync_packet(cli->output_fp, frames_in_gop); write_gop_sync_packet(cli->output_fp, frames_in_gop);
} else if (job->packet->packet_type == TAV_PACKET_IFRAME) { } else if (job->packet->packet_type == TAV_PACKET_IFRAME) {
write_gop_sync_packet(cli->output_fp, 1); // For intra-only mode, write SYNC (0xFF) with no payload
write_sync_packet(cli->output_fp);
} }
tav_encoder_free_packet(job->packet); tav_encoder_free_packet(job->packet);
@@ -1583,7 +1595,7 @@ static int encode_video_mt(cli_context_t *cli) {
if (job->packet->packet_type == TAV_PACKET_GOP_UNIFIED) { if (job->packet->packet_type == TAV_PACKET_GOP_UNIFIED) {
write_gop_sync_packet(cli->output_fp, job->packet->data[1]); write_gop_sync_packet(cli->output_fp, job->packet->data[1]);
} else if (job->packet->packet_type == TAV_PACKET_IFRAME) { } else if (job->packet->packet_type == TAV_PACKET_IFRAME) {
write_gop_sync_packet(cli->output_fp, 1); write_sync_packet(cli->output_fp);
} }
tav_encoder_free_packet(job->packet); tav_encoder_free_packet(job->packet);
@@ -1718,7 +1730,7 @@ static int encode_video_mt(cli_context_t *cli) {
if (job->packet->packet_type == TAV_PACKET_GOP_UNIFIED) { if (job->packet->packet_type == TAV_PACKET_GOP_UNIFIED) {
write_gop_sync_packet(cli->output_fp, job->packet->data[1]); write_gop_sync_packet(cli->output_fp, job->packet->data[1]);
} else if (job->packet->packet_type == TAV_PACKET_IFRAME) { } else if (job->packet->packet_type == TAV_PACKET_IFRAME) {
write_gop_sync_packet(cli->output_fp, 1); write_sync_packet(cli->output_fp);
} }
tav_encoder_free_packet(job->packet); tav_encoder_free_packet(job->packet);
@@ -2002,12 +2014,12 @@ static int encode_video(cli_context_t *cli) {
cli->total_bytes += packet->size; cli->total_bytes += packet->size;
cli->gop_count++; cli->gop_count++;
// 4. Write GOP_SYNC after GOP packets // 4. Write sync packet after video packets
if (packet->packet_type == TAV_PACKET_GOP_UNIFIED) { if (packet->packet_type == TAV_PACKET_GOP_UNIFIED) {
int frames_in_gop = packet->data[1]; int frames_in_gop = packet->data[1];
write_gop_sync_packet(cli->output_fp, frames_in_gop); write_gop_sync_packet(cli->output_fp, frames_in_gop);
} else if (packet->packet_type == TAV_PACKET_IFRAME) { } else if (packet->packet_type == TAV_PACKET_IFRAME) {
write_gop_sync_packet(cli->output_fp, 1); write_sync_packet(cli->output_fp);
} }
tav_encoder_free_packet(packet); tav_encoder_free_packet(packet);
@@ -2066,12 +2078,12 @@ static int encode_video(cli_context_t *cli) {
cli->total_bytes += packet->size; cli->total_bytes += packet->size;
cli->gop_count++; cli->gop_count++;
// 4. Write GOP_SYNC after GOP packets // 4. Write sync packet after video packets
if (packet->packet_type == TAV_PACKET_GOP_UNIFIED) { if (packet->packet_type == TAV_PACKET_GOP_UNIFIED) {
int frames_in_gop = packet->data[1]; int frames_in_gop = packet->data[1];
write_gop_sync_packet(cli->output_fp, frames_in_gop); write_gop_sync_packet(cli->output_fp, frames_in_gop);
} else if (packet->packet_type == TAV_PACKET_IFRAME) { } else if (packet->packet_type == TAV_PACKET_IFRAME) {
write_gop_sync_packet(cli->output_fp, 1); write_sync_packet(cli->output_fp);
} }
tav_encoder_free_packet(packet); tav_encoder_free_packet(packet);