From: John Stebbins Date: Fri, 2 Aug 2019 18:41:13 +0000 (-0700) Subject: add subtitle track name read/write X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d62dfce98fda79ef6cd10d4089141c81fe994223;p=handbrake add subtitle track name read/write Works similar to audio track names. If source has a subtitle track name, hb_subtitle_t.name is set. To set output subtitle track name, set hb_subtitle_config_t.name. Source track names are available in title returned by hb_title_to_dict and hb_title_to_json in SubtitleList[].Name In job dict it is also SubtitleList[].Name hb_preset_job_init and hb_preset_job_init_json initialize output tracks with the source track name. Also adds subtitle name support to LinGui --- diff --git a/gtk/src/ghb3.ui b/gtk/src/ghb3.ui index eccd56efc..1a7eea08a 100644 --- a/gtk/src/ghb3.ui +++ b/gtk/src/ghb3.ui @@ -8732,6 +8732,7 @@ Setting this to 0 means there is no maximum height. + vertical True False 6 @@ -8796,264 +8797,298 @@ Setting this to 0 means there is no maximum height. + + 0 + + + + + 2 + True + False + 5 + center + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Source Track + + + 0 + 0 + 1 + 1 + + + + + GTK_ALIGN_CENTER + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + List of subtitle tracks available from your source. + + + + 1 + 0 + 1 + 1 + + + + + True + False + Track Name: + True + center + + + 0 + 1 + 1 + 1 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Set the subtitle track name. + +Players may use this in the subtitle selection list. + 80 + 40 + True + True + + + + 1 + 1 + 1 + 1 + + + 1 - - horizontal + True + 2 False - 6 + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 4 - + True - 2 False GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 4 - - - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Language - - - 0 - 1 - 1 - 1 - - - - - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Character Code - - - 0 - 2 - 1 - 1 - - - - - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - File: - end - - - 2 - 0 - 1 - 1 - - - - - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Offset (ms) - - - 0 - 4 - 1 - 1 - - - - - GTK_ALIGN_CENTER - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Set the language of this subtitle. + Language + + + 0 + 1 + 1 + 1 + + + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Character Code + + + 0 + 2 + 1 + 1 + + + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + File: + end + + + 2 + 0 + 1 + 1 + + + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Offset (ms) + + + 0 + 4 + 1 + 1 + + + + + GTK_ALIGN_CENTER + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Set the language of this subtitle. This value will be used by players in subtitle menus. - - - - 1 - 1 - 1 - 1 - - - - - GTK_ALIGN_FILL - 150 - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Set the character code used by the SRT file you are importing. + + + + 1 + 1 + 1 + 1 + + + + + GTK_ALIGN_FILL + 150 + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Set the character code used by the SRT file you are importing. SRTs come in all flavours of character sets. We translate the character set to UTF-8. The source's character code is needed in order to perform this translation. - - True - - - True - - - - - 1 - 2 - 1 - 1 - - - - - True - True - Select the SRT file to import. - False - True - Import File - - - - 2 - 1 - 2 - 1 - - - - - GTK_ALIGN_FILL - False - 8 - True + + True + + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Adjust the offset in milliseconds between video and SRT timestamps - adjustment31 - - - 1 - 4 - 1 - 1 - - 0 + 1 + 2 + 1 + 1 - - vertical + True - False - - - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Track - - - 0 - - - - - GTK_ALIGN_CENTER - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - List of subtitle tracks available from your source. - - - - 1 - - + True + Select the SRT file to import. + False + True + Import File + - 1 + 2 + 1 + 2 + 1 - - vertical + + GTK_ALIGN_FILL + False + 8 True - False - - - Forced Subtitles Only - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Use only subtitles that have been flagged + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Adjust the offset in milliseconds between video and SRT timestamps + adjustment31 + + + + 1 + 4 + 1 + 1 + + + + + 2 + + + + + vertical + True + False + 12 + + + Forced Subtitles Only + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Use only subtitles that have been flagged as forced in the source subtitle track "Forced" subtitles are usually used to show subtitles during scenes where someone is speaking a foreign language. - start - True - - - - 0 - - - - - Burn into video - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Render the subtitle over the video. + start + True + + + + 0 + + + + + Burn into video + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Render the subtitle over the video. The subtitle will be part of the video and can not be disabled. - start - True - - - - 1 - - - - - Set Default Track - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Set the default output subtitle track. + start + True + + + + 1 + + + + + Set Default Track + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Set the default output subtitle track. Most players will automatically display this subtitle track whenever the video is played. This is useful for creating a "forced" track in your output. - start - True - - - - 2 - - + start + True + 2 @@ -9061,7 +9096,7 @@ in your output. - 2 + 3 @@ -9170,7 +9205,8 @@ in your output. Set the audio track name. Players may use this in the audio selection list. - 40 + 80 + 40 True True True diff --git a/gtk/src/ghb4.ui b/gtk/src/ghb4.ui index a43645944..ca4d3d36a 100644 --- a/gtk/src/ghb4.ui +++ b/gtk/src/ghb4.ui @@ -7335,210 +7335,244 @@ Setting this to 0 means there is no maximum height. - - horizontal + + 2 True False - 6 + 5 + center - + True - 2 False - 4 - - - True - False - Language - - 0 - 1 - - - - - - True - False - Character Code - - 0 - 2 - - - - - - True - False - File: - end - - 2 - 0 - - - - - - True - False - Offset (ms) - - 0 - 4 - - - - - - GTK_ALIGN_CENTER - True - False - Set the language of this subtitle. + Source Track + + 0 + 0 + + + + + + GTK_ALIGN_CENTER + True + False + List of subtitle tracks available from your source. + + + 1 + 0 + + + + + + True + False + Track Name: + True + center + + 0 + 1 + + + + + + True + True + Set the subtitle track name. + +Players may use this in the subtitle selection list. + 80 + 40 + True + True + + + 1 + 1 + + + + + + + + True + 2 + False + 4 + + + True + False + Language + + 0 + 1 + + + + + + True + False + Character Code + + 0 + 2 + + + + + + True + False + File: + end + + 2 + 0 + + + + + + True + False + Offset (ms) + + 0 + 4 + + + + + + GTK_ALIGN_CENTER + True + False + Set the language of this subtitle. This value will be used by players in subtitle menus. - - - 1 - 1 - - - - - - GTK_ALIGN_FILL - 150 - True - False - Set the character code used by the SRT file you are importing. + + + 1 + 1 + + + + + + GTK_ALIGN_FILL + 150 + True + False + Set the character code used by the SRT file you are importing. SRTs come in all flavours of character sets. We translate the character set to UTF-8. The source's character code is needed in order to perform this translation. - - True - - 1 - 2 - - - - True - - - - - - - True - True - Select the SRT file to import. - False - True - Import File - - - 2 - 1 - 2 - - - - - - GTK_ALIGN_FILL - False - 8 - True + + True + + 1 + 2 + + + True - Adjust the offset in milliseconds between video and SRT timestamps - adjustment31 - - - 1 - 4 - - - vertical + True - False - - - True - False - Track - - - - - GTK_ALIGN_CENTER - True - False - List of subtitle tracks available from your source. - - - + True + Select the SRT file to import. + False + True + Import File + + + 2 + 1 + 2 + - - vertical + + GTK_ALIGN_FILL + False + 8 True - False - - - Forced Subtitles Only - True - True - False - Use only subtitles that have been flagged + True + Adjust the offset in milliseconds between video and SRT timestamps + adjustment31 + + + 1 + 4 + + + + + + + + vertical + True + False + 12 + + + Forced Subtitles Only + True + True + False + Use only subtitles that have been flagged as forced in the source subtitle track "Forced" subtitles are usually used to show subtitles during scenes where someone is speaking a foreign language. - start - True - - - - - - Burn into video - True - True - False - Render the subtitle over the video. + start + True + + + + + + Burn into video + True + True + False + Render the subtitle over the video. The subtitle will be part of the video and can not be disabled. - start - True - - - - - - Set Default Track - True - True - False - Set the default output subtitle track. + start + True + + + + + + Set Default Track + True + True + False + Set the default output subtitle track. Most players will automatically display this subtitle track whenever the video is played. This is useful for creating a "forced" track in your output. - start - True - - - + start + True + diff --git a/gtk/src/subtitlehandler.c b/gtk/src/subtitlehandler.c index fcf530cc7..684603895 100644 --- a/gtk/src/subtitlehandler.c +++ b/gtk/src/subtitlehandler.c @@ -27,6 +27,7 @@ #include "hb.h" #include "settings.h" #include "jobdict.h" +#include "titledict.h" #include "hb-backend.h" #include "values.h" #include "callbacks.h" @@ -428,7 +429,6 @@ subtitle_get_track_description(GhbValue *settings, GhbValue *subsettings) static GhbValue* subtitle_add_track( signal_user_data_t *ud, GhbValue *settings, - const hb_title_t *title, int track, int mux, gboolean default_track, @@ -437,10 +437,14 @@ static GhbValue* subtitle_add_track( gboolean burn, gboolean *burned) { + const char * name = NULL; if (track >= 0 && !import) { - hb_subtitle_t *subtitle = hb_list_item(title->list_subtitle, track); - source = subtitle->source; + GhbValue * strack; + + strack = ghb_get_title_subtitle_track(settings, track); + source = ghb_dict_get_int(strack, "Source"); + name = ghb_dict_get_string(strack, "Name"); } burn |= !hb_subtitle_can_pass(source, mux); @@ -474,6 +478,10 @@ static GhbValue* subtitle_add_track( g_free(filename); } + if (name != NULL && name[0] != 0) + { + ghb_dict_set_string(subsettings, "Name", name); + } ghb_dict_set_int(subsettings, "Track", track); ghb_dict_set_int(subsettings, "Offset", 0); ghb_dict_set_bool(subsettings, "Forced", track == -1); @@ -640,14 +648,26 @@ subtitle_update_dialog_widgets(signal_user_data_t *ud, GhbValue *subsettings) import = ghb_dict_get(subsettings, "Import"); source = get_sub_source(ud->settings, subsettings); - val = ghb_dict_get(subsettings, "Track"); + val = ghb_dict_get_value(subsettings, "Name"); + if (val != NULL) + { + ghb_ui_update(ud, "SubtitleTrackName", val); + } + else + { + ghb_ui_update(ud, "SubtitleTrackName", ghb_string_value("")); + } + + val = ghb_dict_get(subsettings, "Track"); if (val != NULL) { ghb_ui_update(ud, "SubtitleTrack", val); // Hide regular subtitle widgets - widget = GHB_WIDGET(ud->builder, "subtitle_track_box"); + widget = GHB_WIDGET(ud->builder, "subtitle_track_label"); + gtk_widget_set_visible(widget, import == NULL); + widget = GHB_WIDGET(ud->builder, "SubtitleTrack"); gtk_widget_set_visible(widget, import == NULL); // Show import subitle widgets @@ -665,7 +685,9 @@ subtitle_update_dialog_widgets(signal_user_data_t *ud, GhbValue *subsettings) else { // Hide widgets not needed for "Foreign audio search" - widget = GHB_WIDGET(ud->builder, "subtitle_track_box"); + widget = GHB_WIDGET(ud->builder, "subtitle_track_label"); + gtk_widget_set_visible(widget, FALSE); + widget = GHB_WIDGET(ud->builder, "SubtitleTrack"); gtk_widget_set_visible(widget, FALSE); widget = GHB_WIDGET(ud->builder, "subtitle_import_grid"); @@ -742,7 +764,9 @@ subtitle_update_dialog_widgets(signal_user_data_t *ud, GhbValue *subsettings) gtk_widget_set_visible(widget, FALSE); // Show regular subtitle widgets - widget = GHB_WIDGET(ud->builder, "subtitle_track_box"); + widget = GHB_WIDGET(ud->builder, "subtitle_track_label"); + gtk_widget_set_visible(widget, TRUE); + widget = GHB_WIDGET(ud->builder, "SubtitleTrack"); gtk_widget_set_visible(widget, TRUE); } } @@ -783,6 +807,21 @@ subtitle_track_changed_cb(GtkWidget *widget, signal_user_data_t *ud) } } +G_MODULE_EXPORT void +subtitle_name_changed_cb(GtkWidget *widget, signal_user_data_t *ud) +{ + ghb_widget_to_setting(ud->settings, widget); + const char *s = ghb_dict_get_string(ud->settings, "SubtitleTrackName"); + if (s != NULL && s[0] != 0) + { + subtitle_update_setting(ghb_widget_value(widget), "Name", ud); + } + else + { + subtitle_update_setting(NULL, "Name", ud); + } +} + G_MODULE_EXPORT void subtitle_forced_toggled_cb(GtkWidget *widget, signal_user_data_t *ud) { @@ -1129,13 +1168,13 @@ subtitle_add_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) for (subsettings = NULL, track = 0; subsettings == NULL && track < count; track++) { - subsettings = subtitle_add_track(ud, ud->settings, title, track, + subsettings = subtitle_add_track(ud, ud->settings, track, mux->format, FALSE, FALSE, VOBSUB, FALSE, &one_burned); } if (subsettings == NULL) { - subsettings = subtitle_add_track(ud, ud->settings, title, 0, + subsettings = subtitle_add_track(ud, ud->settings, 0, mux->format, FALSE, TRUE, IMPORTSRT, FALSE, &one_burned); } @@ -1247,7 +1286,7 @@ subtitle_add_all_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) int count = hb_list_count(title->list_subtitle); for (track = 0; track < count; track++) { - subtitle_add_track(ud, ud->settings, title, track, mux->format, + subtitle_add_track(ud, ud->settings, track, mux->format, FALSE, FALSE, VOBSUB, FALSE, &one_burned); } subtitle_refresh_list_ui(ud); diff --git a/libhb/common.c b/libhb/common.c index e21590fa2..df5d60467 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -4809,6 +4809,14 @@ hb_subtitle_t *hb_subtitle_copy(const hb_subtitle_t *src) subtitle->extradata = malloc( src->extradata_size ); memcpy( subtitle->extradata, src->extradata, src->extradata_size ); } + if (src->name != NULL) + { + subtitle->name = strdup(src->name); + } + if (src->config.name != NULL) + { + subtitle->config.name = strdup(src->config.name); + } } return subtitle; } @@ -4846,6 +4854,8 @@ void hb_subtitle_close( hb_subtitle_t **sub ) { if ( sub && *sub ) { + free ((char*)(*sub)->name); + free ((char*)(*sub)->config.name); free ((*sub)->extradata); free(*sub); *sub = NULL; @@ -4905,6 +4915,10 @@ int hb_subtitle_add(const hb_job_t * job, const hb_subtitle_config_t * subtitlec // "track" in job->list_audio is an index into title->list_audio subtitle->track = track; subtitle->config = *subtitlecfg; + if (subtitlecfg->name != NULL && subtitlecfg->name[0] != 0) + { + subtitle->config.name = strdup(subtitlecfg->name); + } subtitle->out_track = hb_list_count(job->list_subtitle) + 1; hb_list_add(job->list_subtitle, subtitle); return 1; @@ -4944,6 +4958,10 @@ int hb_import_subtitle_add( const hb_job_t * job, strcpy(subtitle->iso639_2, lang->iso639_2); subtitle->config = *subtitlecfg; + if (subtitlecfg->name != NULL && subtitlecfg->name[0] != 0) + { + subtitle->config.name = strdup(subtitlecfg->name); + } hb_list_add(job->list_subtitle, subtitle); return 1; diff --git a/libhb/common.h b/libhb/common.h index e7c9b2b5f..6cf949881 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -297,13 +297,14 @@ void hb_image_close(hb_image_t **_image); struct hb_subtitle_config_s { enum subdest { RENDERSUB, PASSTHRUSUB } dest; - int force; - int default_track; - + int force; + int default_track; + const char * name; + /* SRT subtitle tracks only */ - char src_filename[256]; - char src_codeset[40]; - int64_t offset; + char src_filename[256]; + char src_codeset[40]; + int64_t offset; }; /******************************************************************************* @@ -966,9 +967,10 @@ struct hb_subtitle_s enum subsource { VOBSUB, CC608SUB, /*unused*/CC708SUB, UTF8SUB, TX3GSUB, SSASUB, PGSSUB, IMPORTSRT, IMPORTSSA, SRTSUB = IMPORTSRT } source; - char lang[1024]; - char iso639_2[4]; - uint32_t attributes; /* Closed Caption, Childrens, Directors etc */ + const char * name; + char lang[1024]; + char iso639_2[4]; + uint32_t attributes; /* Closed Caption, Childrens, Directors etc */ // Color lookup table for VOB subtitle tracks. Each entry is in YCbCr format. // Must be filled out by the demuxer for VOB subtitle tracks. diff --git a/libhb/hb_json.c b/libhb/hb_json.c index 08e9400a0..09ef619d7 100644 --- a/libhb/hb_json.c +++ b/libhb/hb_json.c @@ -441,6 +441,10 @@ static hb_dict_t* hb_title_to_dict_internal( hb_title_t *title ) hb_error("json pack failure: %s", error.text); return NULL; } + if (subtitle->name != NULL) + { + hb_dict_set_string(subtitle_dict, "Name", subtitle->name); + } hb_value_array_append(subtitle_list, subtitle_dict); } hb_dict_set(dict, "SubtitleList", subtitle_list); @@ -889,6 +893,10 @@ hb_dict_t* hb_job_to_dict( const hb_job_t * job ) "Burn", hb_value_bool(subtitle->config.dest == RENDERSUB), "Offset", hb_value_int(subtitle->config.offset)); } + if (subtitle->config.name != NULL) + { + hb_dict_set_string(subtitle_dict, "Name", subtitle->config.name); + } hb_value_array_append(subtitle_list, subtitle_dict); } @@ -1579,10 +1587,12 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict ) int burn = 0; const char *importfile = NULL; json_int_t offset = 0; + const char *name = NULL; result = json_unpack_ex(subtitle_dict, &error, 0, - "{s?i, s?{s:s}, s?{s:s}}", + "{s?i, s?s, s?{s:s}, s?{s:s}}", "Track", unpack_i(&track), + "Name", unpack_s(&name), // Support legacy "SRT" import "SRT", "Filename", unpack_s(&importfile), @@ -1594,6 +1604,7 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict ) hb_job_close(&job); return NULL; } + // Embedded subtitle track if (track >= 0 && importfile == NULL) { @@ -1602,6 +1613,7 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict ) if (subtitle != NULL) { sub_config = subtitle->config; + sub_config.name = name; result = json_unpack_ex(subtitle_dict, &error, 0, "{s?b, s?b, s?b, s?I}", "Default", unpack_b(&sub_config.default_track), @@ -1650,6 +1662,7 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict ) hb_job_close(&job); return NULL; } + sub_config.name = name; sub_config.offset = offset; sub_config.dest = burn ? RENDERSUB : PASSTHRUSUB; strncpy(sub_config.src_codeset, srtcodeset, 39); diff --git a/libhb/muxavformat.c b/libhb/muxavformat.c index e353b0e32..353e519fc 100644 --- a/libhb/muxavformat.c +++ b/libhb/muxavformat.c @@ -960,6 +960,12 @@ static int avformatInit( hb_mux_object_t * m ) { av_dict_set(&track->st->metadata, "language", lang, 0); } + if (subtitle->config.name != NULL && subtitle->config.name[0] != 0) + { + // Set subtitle track title + av_dict_set(&track->st->metadata, "title", + subtitle->config.name, 0); + } } if (need_fonts) diff --git a/libhb/preset.c b/libhb/preset.c index 949b5f4a7..5a7425a96 100644 --- a/libhb/preset.c +++ b/libhb/preset.c @@ -891,13 +891,15 @@ static int find_subtitle_track(const hb_title_t *title, } static void add_subtitle(hb_value_array_t *list, int track, - int make_default, int force, int burn) + int make_default, int force, int burn, + const char * name) { hb_dict_t *subtitle_dict = hb_dict_init(); - hb_dict_set(subtitle_dict, "Track", hb_value_int(track)); - hb_dict_set(subtitle_dict, "Default", hb_value_bool(make_default)); - hb_dict_set(subtitle_dict, "Forced", hb_value_bool(force)); - hb_dict_set(subtitle_dict, "Burn", hb_value_bool(burn)); + hb_dict_set_int(subtitle_dict, "Track", track); + hb_dict_set_bool(subtitle_dict, "Default", make_default); + hb_dict_set_bool(subtitle_dict, "Forced", force); + hb_dict_set_bool(subtitle_dict, "Burn", burn); + hb_dict_set_string(subtitle_dict, "Name", name); hb_value_array_append(list, subtitle_dict); } @@ -962,7 +964,7 @@ static void add_subtitle_for_lang(hb_value_array_t *list, hb_title_t *title, behavior->burn_first &= !burn; behavior->one_burned |= burn; behavior->used[t] = 1; - add_subtitle(list, t, make_default, 0 /*!force*/, burn); + add_subtitle(list, t, make_default, 0 /*!force*/, burn, subtitle->name); } } @@ -1180,7 +1182,8 @@ int hb_preset_job_add_subtitles(hb_handle_t *h, int title_index, behavior.burn_first); behavior.used[track] = 1; behavior.one_burned |= burn; - add_subtitle(list, track, 0 /*default*/, 0 /*!force*/, burn); + add_subtitle(list, track, 0 /*default*/, 0 /*!force*/, burn, + subtitle->name); break; } } diff --git a/libhb/stream.c b/libhb/stream.c index 1448ac4f0..8182cb35c 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -5414,6 +5414,8 @@ static void add_ffmpeg_subtitle( hb_title_t *title, hb_stream_t *stream, int id { AVStream * st = stream->ffmpeg_ic->streams[id]; AVCodecParameters * codecpar = st->codecpar; + AVDictionaryEntry * tag_lang = av_dict_get(st->metadata, "language", NULL, 0 ); + AVDictionaryEntry * tag_name = av_dict_get(st->metadata, "title", NULL, 0); hb_subtitle_t *subtitle = calloc( 1, sizeof(*subtitle) ); @@ -5474,16 +5476,18 @@ static void add_ffmpeg_subtitle( hb_title_t *title, hb_stream_t *stream, int id return; } - AVDictionaryEntry *tag; iso639_lang_t *lang; - tag = av_dict_get( st->metadata, "language", NULL, 0 ); - lang = lang_for_code2( tag ? tag->value : "und" ); + lang = lang_for_code2(tag_lang ? tag_lang->value : "und"); snprintf(subtitle->lang, sizeof( subtitle->lang ), "%s [%s]", strlen(lang->native_name) ? lang->native_name : lang->eng_name, hb_subsource_name(subtitle->source)); strncpy(subtitle->iso639_2, lang->iso639_2, 3); subtitle->iso639_2[3] = 0; + if (tag_name != NULL) + { + subtitle->name = strdup(tag_name->value); + } // Copy the extradata for the subtitle track if (codecpar->extradata != NULL) diff --git a/macosx/HBJob+HBJobConversion.m b/macosx/HBJob+HBJobConversion.m index 073612b26..aa01aa56c 100644 --- a/macosx/HBJob+HBJobConversion.m +++ b/macosx/HBJob+HBJobConversion.m @@ -260,6 +260,7 @@ hb_subtitle_config_t sub_config; int type = subTrack.type; + sub_config.name = NULL; sub_config.offset = subTrack.offset; // we need to strncpy file name and codeset