<div dir="ltr">From f09dbbc4d8fb5c7f88e9526d043a85b0385632f8 Mon Sep 17 00:00:00 2001<br>From: Pascal Thomet <<a href="mailto:pthomet@gmail.com">pthomet@gmail.com</a>><br>Date: Sun, 7 Apr 2013 17:57:45 +0200<br>Subject: [PATCH] Subsync: added an easier way to sync subtitles<br>
<br>Added the following shortcuts (and made them configurable):<br>- Ctrl-H: sets a timestamp bookmark on the audio<br>- Ctrl-J: sets a timestamp bookmark on the subtitle<br>- Ctrl-K: corrects the delay between both bookmarks<br>
<br>Notes:<br>- This patch changes adds hotkeys to the control GUI. I suspect this kind of change may require a more<br> thorough analysis before being accepted.<br>- See <a href="http://forum.videolan.org/viewtopic.php?f=7&t=109641">http://forum.videolan.org/viewtopic.php?f=7&t=109641</a> for an illustration of a possible use<br>
(I changed the wordings a little bit in the source)<br>- This is the kind of feature I'd like to have when my subtitles are out of sync,<br> and I want a quick way of solving it (without having to download/install a dedicated<br>
3rd party software)<br>- Current implementation uses a static variable at hotkeys.c:125 (room for improvement, i guess)<br>---<br> include/vlc_keys.h | 3 +++<br> modules/control/hotkeys.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++<br>
src/config/keys.c | 3 +++<br> src/libvlc-module.c | 15 ++++++++++++<br> 4 files changed, 79 insertions(+)<br><br>diff --git a/include/vlc_keys.h b/include/vlc_keys.h<br>index 141e4b9..c6d5feb 100644<br>--- a/include/vlc_keys.h<br>
+++ b/include/vlc_keys.h<br>@@ -161,6 +161,9 @@ typedef enum vlc_action {<br> /* end of contiguous zone */<br> ACTIONID_SUBDELAY_UP,<br> ACTIONID_SUBDELAY_DOWN,<br>+ ACTIONID_SUBSYNC_MARKAUDIO,<br>+ ACTIONID_SUBSYNC_MARKSUB,<br>
+ ACTIONID_SUBSYNC_APPLY,<br> ACTIONID_SUBPOS_UP,<br> ACTIONID_SUBPOS_DOWN,<br> ACTIONID_AUDIO_TRACK,<br>diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c<br>index 95bc0d0..913e7e0 100644<br>
--- a/modules/control/hotkeys.c<br>+++ b/modules/control/hotkeys.c<br>@@ -120,6 +120,15 @@ static void Close( vlc_object_t *p_this )<br> free( p_sys );<br> }<br> <br>+<br>+/*g_subtitle_delaybookmarks : placeholder for storing subtitle sync timestamps*/<br>
+static struct<br>+{<br>+ int64_t i_time_subtitle;<br>+ int64_t i_time_audio;<br>+} subtitle_delaybookmarks = { 0, 0 };<br>+<br>+<br> static int PutAction( intf_thread_t *p_intf, int i_action )<br> {<br> intf_sys_t *p_sys = p_intf->p_sys;<br>
@@ -368,6 +377,55 @@ static int PutAction( intf_thread_t *p_intf, int i_action )<br> }<br> break;<br> <br>+ case ACTIONID_SUBSYNC_MARKAUDIO:<br>+ {<br>+ subtitle_delaybookmarks.i_time_audio = mdate();<br>
+ DisplayMessage( p_vout, _("Sub sync: bookmarked audio timestamp"));<br>+ break;<br>+ }<br>+ case ACTIONID_SUBSYNC_MARKSUB:<br>+ {<br>+ subtitle_delaybookmarks.i_time_subtitle = mdate();<br>
+ DisplayMessage( p_vout, _("Sub sync: bookmarked subtitle timestamp"));<br>+ break;<br>+ }<br>+ case ACTIONID_SUBSYNC_APPLY:<br>+ {<br>+ /* Warning! Can yield a pause in the playback.<br>
+ * For example, the following succession of actions will yield a 5 second delay :<br>+ * - Pressing Ctrl-H (ACTIONID_SUBSYNC_MARKAUDIO)<br>+ * - wait 5 second<br>+ * - Press Ctrl-J (ACTIONID_SUBSYNC_MARKSUB)<br>
+ * - Press Ctrl-K (ACTIONID_SUBSYNC_APPLY)<br>+ * --> 5 seconds pause<br>+ * This is due to var_SetTime() (and ultimately UpdatePtsDelay())<br>+ * which causes the video to pause for an equivalent duration<br>
+ * (This problem is also present in the "Track synchronization" window)<br>+ */<br>+ if ( p_input )<br>+ {<br>+ if ( (subtitle_delaybookmarks.i_time_audio==0) || (subtitle_delaybookmarks.i_time_subtitle == 0) )<br>
+ {<br>+ int64_t i_current_subdelay = var_GetTime( p_input, "spu-delay" );<br>+ DisplayMessage( p_vout, _( "Sub sync: set bookmarks first!" ),<br>+ (int)(i_current_subdelay / 1000));<br>
+ }<br>+ else<br>+ {<br>+ int64_t i_current_subdelay = var_GetTime( p_input, "spu-delay" );<br>+ int64_t i_additional_subdelay = subtitle_delaybookmarks.i_time_audio - subtitle_delaybookmarks.i_time_subtitle;<br>
+ int64_t i_total_subdelay = i_current_subdelay + i_additional_subdelay;<br>+ var_SetTime( p_input, "spu-delay", i_total_subdelay);<br>+ ClearChannels( p_intf, p_vout );<br>
+ DisplayMessage( p_vout, _( "Sub sync: corrected %i ms (total delay = %i ms)" ),<br>+ (int)(i_additional_subdelay / 1000),<br>+ (int)(i_total_subdelay / 1000) );<br>
+ subtitle_delaybookmarks.i_time_audio = subtitle_delaybookmarks.i_time_subtitle = 0;<br>+ }<br>+ }<br>+ break;<br>+ }<br>+<br> case ACTIONID_SUBDELAY_DOWN:<br>
case ACTIONID_SUBDELAY_UP:<br> {<br>diff --git a/src/config/keys.c b/src/config/keys.c<br>index ee3c382..73b70bf 100644<br>--- a/src/config/keys.c<br>+++ b/src/config/keys.c<br>@@ -346,6 +346,9 @@ static const struct action actions[] =<br>
{ "subdelay-up", ACTIONID_SUBDELAY_UP, },<br> { "subpos-down", ACTIONID_SUBPOS_DOWN, },<br> { "subpos-up", ACTIONID_SUBPOS_UP, },<br>+ { "subsync-apply", ACTIONID_SUBSYNC_APPLY, },<br>
+ { "subsync-markaudio", ACTIONID_SUBSYNC_MARKAUDIO, },<br>+ { "subsync-marksub", ACTIONID_SUBSYNC_MARKSUB, },<br> { "subtitle-track", ACTIONID_SUBTITLE_TRACK, },<br> { "title-next", ACTIONID_TITLE_NEXT, },<br>
{ "title-prev", ACTIONID_TITLE_PREV, },<br>diff --git a/src/libvlc-module.c b/src/libvlc-module.c<br>index 34a229e..e706ec5 100644<br>--- a/src/libvlc-module.c<br>+++ b/src/libvlc-module.c<br>@@ -1310,6 +1310,12 @@ static const char *const mouse_wheel_texts[] =<br>
#define SUBDELAY_UP_KEY_LONGTEXT N_("Select the key to increase the subtitle delay.")<br> #define SUBDELAY_DOWN_KEY_TEXT N_("Subtitle delay down")<br> #define SUBDELAY_DOWN_KEY_LONGTEXT N_("Select the key to decrease the subtitle delay.")<br>
+#define SUBSYNC_MARKAUDIO_KEY_TEXT N_("Subtitle sync / bookmark audio timestamp")<br>+#define SUBSYNC_MARKAUDIO_KEY_LONGTEXT N_("Select the key to bookmark audio timestamp when syncing subtitles.")<br>
+#define SUBSYNC_MARKSUB_KEY_TEXT N_("Subtitle sync / bookmark subtitle timestamp")<br>+#define SUBSYNC_MARKSUB_KEY_LONGTEXT N_("Select the key to bookmark subtitle timestamp when syncing subtitles.")<br>
+#define SUBSYNC_APPLY_KEY_TEXT N_("Subtitle sync / correct delay between bookmarks")<br>+#define SUBSYNC_APPLY_KEY_LONGTEXT N_("Select the key to correct the delay between audio & subtitle bookmarks.")<br>
#define SUBPOS_UP_KEY_TEXT N_("Subtitle position up")<br> #define SUBPOS_UP_KEY_LONGTEXT N_("Select the key to move subtitles higher.")<br> #define SUBPOS_DOWN_KEY_TEXT N_("Subtitle position down")<br>
@@ -2178,6 +2184,9 @@ vlc_module_begin ()<br> # define KEY_VOL_MUTE "Command+Alt+Down"<br> # define KEY_SUBDELAY_UP "j"<br> # define KEY_SUBDELAY_DOWN "h"<br>+# define KEY_SUBSYNC_MARKAUDIO "Ctrl+h"<br>
+# define KEY_SUBSYNC_MARKSUB "Ctrl+j"<br>+# define KEY_SUBSYNC_APPLY "Ctrl+k"<br> # define KEY_SUBPOS_DOWN NULL<br> # define KEY_SUBPOS_UP NULL<br> # define KEY_AUDIODELAY_UP "g"<br>
@@ -2442,6 +2451,12 @@ vlc_module_begin ()<br> SUBDELAY_UP_KEY_TEXT, SUBDELAY_UP_KEY_LONGTEXT, true )<br> add_key( "key-subdelay-down", KEY_SUBDELAY_DOWN,<br> SUBDELAY_DOWN_KEY_TEXT, SUBDELAY_DOWN_KEY_LONGTEXT, true )<br>
+ add_key( "key-subsync-markaudio", KEY_SUBSYNC_MARKAUDIO,<br>+ SUBSYNC_MARKAUDIO_KEY_TEXT, SUBSYNC_MARKAUDIO_KEY_LONGTEXT, true )<br>+ add_key( "key-subsync-marksub", KEY_SUBSYNC_MARKSUB,<br>
+ SUBSYNC_MARKSUB_KEY_TEXT, SUBSYNC_MARKSUB_KEY_LONGTEXT, true )<br>+ add_key( "key-subsync-apply", KEY_SUBSYNC_APPLY,<br>+ SUBSYNC_APPLY_KEY_TEXT, SUBSYNC_APPLY_KEY_LONGTEXT, true )<br>
add_key( "key-subpos-up", KEY_SUBPOS_UP,<br> SUBPOS_UP_KEY_TEXT, SUBPOS_UP_KEY_LONGTEXT, true )<br> add_key( "key-subpos-down", KEY_SUBPOS_DOWN,<br>-- <br>1.7.12.4 (Apple Git-37)<br>
</div>