diff --git a/src/lib_ccx/ccx_encoders_common.c b/src/lib_ccx/ccx_encoders_common.c index 9275c48ed..8288e42c8 100644 --- a/src/lib_ccx/ccx_encoders_common.c +++ b/src/lib_ccx/ccx_encoders_common.c @@ -709,9 +709,17 @@ void dinit_encoder(struct encoder_ctx **arg, LLONG current_fts) return; for (i = 0; i < ctx->nb_out; i++) { - if (ctx->end_credits_text != NULL) - try_to_add_end_credits(ctx, ctx->out + i, current_fts); - write_subtitle_file_footer(ctx, ctx->out + i); + struct ccx_s_write *out = ctx->out + i; + if (out->wrote_data) + { + if (ctx->end_credits_text != NULL) + try_to_add_end_credits(ctx, out, current_fts); + write_subtitle_file_footer(ctx, out); + } + else if (ctx->generates_file && out->filename != NULL && out->fh != STDOUT_FILENO) + { + remove(out->filename); + } } free_encoder_context(ctx->prev); @@ -940,6 +948,7 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) } freep(&data->xds_str); write_newline(context, 0); + out->wrote_data = 1; continue; } @@ -1015,7 +1024,10 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) break; } if (wrote_something) + { + out->wrote_data = 1; context->last_displayed_subs_ms = data->end_time; + } if (context->gui_mode_reports) write_cc_buffer_to_gui(sub->data, context); @@ -1093,6 +1105,9 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) default: break; } + + if (wrote_something && context->nb_out > 0) + context->out->wrote_data = 1; break; case CC_RAW: if (context->send_to_srv) @@ -1105,6 +1120,8 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) mprint("WARNING: Loss of data\n"); } } + context->out->wrote_data = 1; + wrote_something = 1; sub->nb_data = 0; break; case CC_TEXT: @@ -1147,6 +1164,8 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) default: break; } + if (wrote_something && context->nb_out > 0) + context->out->wrote_data = 1; sub->nb_data = 0; break; } diff --git a/src/lib_ccx/ccx_encoders_structs.h b/src/lib_ccx/ccx_encoders_structs.h index efecbb722..37a0c9ee3 100644 --- a/src/lib_ccx/ccx_encoders_structs.h +++ b/src/lib_ccx/ccx_encoders_structs.h @@ -25,6 +25,7 @@ struct ccx_s_write char *semaphore_filename; int with_playlist; // For m3u8 /webvtt: If 1, we'll generate a playlist and segments char *playlist_filename; + int wrote_data; // Tracks whether any payload was written so empty outputs can be skipped int renaming_extension; // Used for file rotations int append_mode; /* Append the file. Prevent overwriting of files */ };