Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/lib_ccx/ccx_encoders_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1361,17 +1361,36 @@ void switch_output_file(struct lib_ccx_ctx *ctx, struct encoder_ctx *enc_ctx, in
if (enc_ctx->out->filename != NULL)
{ // Close and release the previous handle
free(enc_ctx->out->filename);
enc_ctx->out->filename = NULL;
close(enc_ctx->out->fh);
enc_ctx->out->fh = -1;
}

const char *ext = get_file_extension(ctx->write_format);
char suffix[32];
snprintf(suffix, sizeof(suffix), "_%d", track_id);
char *basename = get_basename(enc_ctx->out->original_filename);
if (basename != NULL)
if (basename == NULL)
{
return;
}

enc_ctx->out->filename = create_outfilename(basename, suffix, ext);
if (enc_ctx->out->filename == NULL)
{
enc_ctx->out->filename = create_outfilename(basename, suffix, ext);
enc_ctx->out->fh = open(enc_ctx->out->filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE);
free(basename);
return;
}

enc_ctx->out->fh = open(enc_ctx->out->filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE);
free(basename);

if (enc_ctx->out->fh < 0)
{
// Clean up if the file descriptor failed to open
free(enc_ctx->out->filename);
enc_ctx->out->filename = NULL;
return;
}

write_subtitle_file_header(enc_ctx, enc_ctx->out);
Expand Down
Loading