summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libhb/preset.c13
-rw-r--r--test/test.c36
2 files changed, 48 insertions, 1 deletions
diff --git a/libhb/preset.c b/libhb/preset.c
index 3fef7c686..c49073cf4 100644
--- a/libhb/preset.c
+++ b/libhb/preset.c
@@ -620,6 +620,17 @@ int hb_preset_job_add_subtitles(hb_handle_t *h, int title_index,
// We do not want to add the same track with the same settings twice
behavior.used = calloc(source_subtitle_count, sizeof(*behavior.used));
+ // Since this function can be called multiple times, we need to
+ // initialize the "used" array from the existing subtitles in the list.
+ int count, ii;
+ count = hb_value_array_len(list);
+ for (ii = 0; ii < count; ii++)
+ {
+ hb_value_t *sub = hb_value_array_get(list, ii);
+ int track = hb_value_get_int(hb_dict_get(sub, "Track"));
+ behavior.used[track] = 1;
+ }
+
const char *s;
s = hb_value_get_string(hb_dict_get(preset,
"SubtitleTrackSelectionBehavior"));
@@ -659,7 +670,7 @@ int hb_preset_job_add_subtitles(hb_handle_t *h, int title_index,
// Add tracks for all languages in the language list
hb_value_array_t *lang_list = hb_dict_get(preset, "SubtitleLanguageList");
- int count = hb_value_array_len(lang_list);
+ count = hb_value_array_len(lang_list);
const char *pref_lang = "und";
if (count > 0)
{
diff --git a/test/test.c b/test/test.c
index a32970e23..33624dafb 100644
--- a/test/test.c
+++ b/test/test.c
@@ -4077,6 +4077,42 @@ PrepareJob(hb_handle_t *h, hb_title_t *title, hb_dict_t *preset_dict)
}
}
}
+ else
+ {
+ if (subdefault > 0)
+ {
+ // "Default" flag can not be applied till after subtitles have
+ // been selected. Apply it here if subtitle selection was
+ // made by the preset.
+ hb_value_t *sub_dict = hb_dict_get(job_dict, "Subtitle");
+ hb_value_t *sub_list = hb_dict_get(sub_dict, "SubtitleList");
+ if (hb_value_array_len(sub_list) >= subdefault)
+ {
+ hb_value_t *sub = hb_value_array_get(sub_list, subdefault - 1);
+ hb_dict_set(sub, "Default", hb_value_bool(1));
+ }
+ }
+
+ if (subforce != NULL)
+ {
+ // "Forced" flag is not set during preset initialization except
+ // for "foreign audio" subtitles. Set additional request forced
+ // subtitle tracks here.
+ hb_value_t *sub_dict = hb_dict_get(job_dict, "Subtitle");
+ hb_value_t *sub_list = hb_dict_get(sub_dict, "SubtitleList");
+
+ int ii;
+ for (ii = 0; subforce[ii] != NULL; ii++ )
+ {
+ int idx = strtol(subforce[ii], NULL, 0) - 1;
+ if (idx >= 0 && hb_value_array_len(sub_list) > idx)
+ {
+ hb_value_t *sub = hb_value_array_get(sub_list, idx);
+ hb_dict_set(sub, "Forced", hb_value_bool(1));
+ }
+ }
+ }
+ }
if (srtfile != NULL)
{