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
38 changes: 25 additions & 13 deletions src/lib_ccx/ccx_encoders_webvtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,35 +245,47 @@ void write_webvtt_header(struct encoder_ctx *context)
if (ccx_options.webvtt_create_css)
{
char *basefilename = get_basename(context->first_input_file);
if (basefilename == NULL) // No input filename to derive from, or out of memory
basefilename = get_basename("untitled");
if (basefilename == NULL)
{
fatal(EXIT_NOT_ENOUGH_MEMORY, "In write_webvtt_header: Out of memory allocating basefilename.");
}
size_t css_file_name_size = strlen(basefilename) + 5; // strlen(".css") + 1 for null
char *css_file_name = (char *)malloc(css_file_name_size);
if (!css_file_name)
{
free(basefilename);
fatal(EXIT_NOT_ENOUGH_MEMORY, "In write_webvtt_header: Out of memory allocating css_file_name.");
}
snprintf(css_file_name, css_file_name_size, "%s.css", basefilename);
free(basefilename);

FILE *f = fopen(css_file_name, "wb");
if (f == NULL)
{
// Carry on without the stylesheet. Returning here would leave
// wrote_webvtt_header unset, so the header block would be written
// again before every later cue.
mprint("Warning: Error creating the file %s\n", css_file_name);
free(css_file_name);
return;
}
fprintf(f, "%s", webvtt_inline_css);
fclose(f);

size_t outline_css_file_size = strlen(css_file_name) + strlen(webvtt_outline_css) + 1;
char *outline_css_file = (char *)malloc(outline_css_file_size);
if (!outline_css_file)
else
{
free(css_file_name);
fatal(EXIT_NOT_ENOUGH_MEMORY, "In write_webvtt_header: Out of memory allocating outline_css_file.");
fprintf(f, "%s", webvtt_inline_css);
fclose(f);

size_t outline_css_file_size = strlen(css_file_name) + strlen(webvtt_outline_css) + 1;
char *outline_css_file = (char *)malloc(outline_css_file_size);
if (!outline_css_file)
{
free(css_file_name);
fatal(EXIT_NOT_ENOUGH_MEMORY, "In write_webvtt_header: Out of memory allocating outline_css_file.");
}
snprintf(outline_css_file, outline_css_file_size, webvtt_outline_css, css_file_name);
write_wrapped(context->out->fh, outline_css_file, strlen(outline_css_file));
free(outline_css_file);
}
snprintf(outline_css_file, outline_css_file_size, webvtt_outline_css, css_file_name);
write_wrapped(context->out->fh, outline_css_file, strlen(outline_css_file));
free(css_file_name);
free(outline_css_file);
}
else if (ccx_options.use_webvtt_styling)
{
Expand Down
Loading