Skip to content

Commit 7bf8778

Browse files
committed
obs-ffmpeg: Add end action UI property for local file source
For local file, replace UI properties : "Loop" and "Show nothing when playback ends" by a property list call End Action with three possible values : Hide, Freeze, Loop
1 parent ff916e5 commit 7bf8778

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

plugins/obs-ffmpeg/data/locale/en-US.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ NVENC.CQLevel="CQ Level"
3333
FFmpegSource="Media Source"
3434
LocalFile="Local File"
3535
Looping="Loop"
36+
EndAction="End Action"
37+
EndAction.Hide="Hide"
38+
EndAction.Freeze="Freeze"
39+
EndAction.Loop="Loop"
3640
Input="Input"
3741
InputFormat="Input Format"
3842
BufferingMB="Network Buffering"

plugins/obs-ffmpeg/obs-ffmpeg-source.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,31 @@ static bool is_local_file_modified(obs_properties_t *props,
8686
obs_property_t *input_format =
8787
obs_properties_get(props, "input_format");
8888
obs_property_t *local_file = obs_properties_get(props, "local_file");
89-
obs_property_t *looping = obs_properties_get(props, "looping");
89+
obs_property_t *end_action = obs_properties_get(props, "end_action");
9090
obs_property_t *buffering = obs_properties_get(props, "buffering_mb");
9191
obs_property_t *seekable = obs_properties_get(props, "seekable");
9292
obs_property_t *speed = obs_properties_get(props, "speed_percent");
9393
obs_property_t *reconnect_delay_sec =
9494
obs_properties_get(props, "reconnect_delay_sec");
95+
obs_property_t *clear_on_media_end =
96+
obs_properties_get(props, "clear_on_media_end");
9597
obs_property_set_visible(input, !enabled);
9698
obs_property_set_visible(input_format, !enabled);
9799
obs_property_set_visible(buffering, !enabled);
98100
obs_property_set_visible(local_file, enabled);
99-
obs_property_set_visible(looping, enabled);
101+
obs_property_set_visible(end_action, enabled);
100102
obs_property_set_visible(speed, enabled);
101103
obs_property_set_visible(seekable, !enabled);
102104
obs_property_set_visible(reconnect_delay_sec, !enabled);
105+
obs_property_set_visible(clear_on_media_end, !enabled);
103106

104107
return true;
105108
}
106109

107110
static void ffmpeg_source_defaults(obs_data_t *settings)
108111
{
109112
obs_data_set_default_bool(settings, "is_local_file", true);
110-
obs_data_set_default_bool(settings, "looping", false);
113+
obs_data_set_default_int(settings, "end_action", 0);
111114
obs_data_set_default_bool(settings, "clear_on_media_end", true);
112115
obs_data_set_default_bool(settings, "restart_on_activate", true);
113116
obs_data_set_default_bool(settings, "linear_alpha", false);
@@ -165,7 +168,13 @@ static obs_properties_t *ffmpeg_source_getproperties(void *data)
165168
dstr_free(&filter);
166169
dstr_free(&path);
167170

168-
obs_properties_add_bool(props, "looping", obs_module_text("Looping"));
171+
prop = obs_properties_add_list(props, "end_action",
172+
obs_module_text("EndAction"),
173+
OBS_COMBO_TYPE_LIST,
174+
OBS_COMBO_FORMAT_INT);
175+
obs_property_list_add_int(prop, obs_module_text("EndAction.Hide"), 0);
176+
obs_property_list_add_int(prop, obs_module_text("EndAction.Freeze"), 1);
177+
obs_property_list_add_int(prop, obs_module_text("EndAction.Loop"), 2);
169178

170179
obs_properties_add_bool(props, "restart_on_activate",
171180
obs_module_text("RestartWhenActivated"));
@@ -410,7 +419,16 @@ static void ffmpeg_source_update(void *data, obs_data_t *settings)
410419
if (is_local_file) {
411420
input = (char *)obs_data_get_string(settings, "local_file");
412421
input_format = NULL;
413-
s->is_looping = obs_data_get_bool(settings, "looping");
422+
s->is_looping = false;
423+
s->is_clear_on_media_end = true; // end action : hide
424+
425+
int end_action = obs_data_get_int(settings, "end_action");
426+
if (end_action == 1) { // End action : Freeze
427+
s->is_clear_on_media_end = false;
428+
} else if (end_action == 2) { // End action : Loop
429+
s->is_clear_on_media_end = false;
430+
s->is_looping = true;
431+
}
414432
} else {
415433
input = (char *)obs_data_get_string(settings, "input");
416434
input_format =
@@ -431,6 +449,8 @@ static void ffmpeg_source_update(void *data, obs_data_t *settings)
431449
pthread_join(s->reconnect_thread, NULL);
432450
s->stop_reconnect = false;
433451
}
452+
s->is_clear_on_media_end =
453+
obs_data_get_bool(settings, "clear_on_media_end");
434454
}
435455

436456
s->close_when_inactive =
@@ -439,8 +459,6 @@ static void ffmpeg_source_update(void *data, obs_data_t *settings)
439459
s->input = input ? bstrdup(input) : NULL;
440460
s->input_format = input_format ? bstrdup(input_format) : NULL;
441461
s->is_hw_decoding = obs_data_get_bool(settings, "hw_decode");
442-
s->is_clear_on_media_end =
443-
obs_data_get_bool(settings, "clear_on_media_end");
444462
s->restart_on_activate =
445463
!astrcmpi_n(input, RIST_PROTO, sizeof(RIST_PROTO) - 1)
446464
? false

0 commit comments

Comments
 (0)