Skip to content

Commit

Permalink
Add basename and filename keywords to dynamic text
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Aug 9, 2023
1 parent 5ab1bde commit 5f9200e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/modules/plus/filter_dynamictext.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

#include <framework/mlt.h>

#include <libgen.h> // for basename()
#include <math.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -160,6 +162,32 @@ static void get_resource_str(mlt_filter filter, mlt_frame frame, char *text)
MAX_TEXT_LEN - strlen(text) - 1);
}

static void get_filename_str(mlt_filter filter, mlt_frame frame, char *text)
{
mlt_producer producer = mlt_producer_cut_parent(mlt_frame_get_original_producer(frame));
mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES(producer);
char *filename = mlt_properties_get(producer_properties, "resource");
if (access(filename, F_OK) == 0) {
strncat(text, basename(filename), MAX_TEXT_LEN - strlen(text) - 1);
}
}

static void get_basename_str(mlt_filter filter, mlt_frame frame, char *text)
{
mlt_producer producer = mlt_producer_cut_parent(mlt_frame_get_original_producer(frame));
mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES(producer);
char *filename = strdup(mlt_properties_get(producer_properties, "resource"));
if (access(filename, F_OK) == 0) {
char *bname = basename(filename);
char *ext = strrchr(bname, '.');
if (ext) {
*ext = '\0';
}
strncat(text, bname, MAX_TEXT_LEN - strlen(text) - 1);
}
free(filename);
}

static void get_createdate_str(const char *keyword, mlt_filter filter, mlt_frame frame, char *text)
{
time_t creation_date
Expand Down Expand Up @@ -196,6 +224,10 @@ static void substitute_keywords(mlt_filter filter, char *result, char *value, ml
get_localtime_str(keyword, result);
} else if (!strcmp(keyword, "resource")) {
get_resource_str(filter, frame, result);
} else if (!strcmp(keyword, "filename")) {
get_filename_str(filter, frame, result);
} else if (!strcmp(keyword, "basename")) {
get_basename_str(filter, frame, result);
} else if (!strncmp(keyword, "createdate", 10)) {
get_createdate_str(keyword, filter, frame, result);
} else {
Expand Down

0 comments on commit 5f9200e

Please sign in to comment.