[vlc-devel] [PATCH] Subsync: added an easier way to sync subtitles

Pascal Thomet pthomet at gmail.com
Sun Apr 7 22:13:37 CEST 2013


>From f09dbbc4d8fb5c7f88e9526d043a85b0385632f8 Mon Sep 17 00:00:00 2001
From: Pascal Thomet <pthomet at gmail.com>
Date: Sun, 7 Apr 2013 17:57:45 +0200
Subject: [PATCH] Subsync: added an easier way to sync subtitles

Added the following shortcuts (and made them configurable):
- Ctrl-H: sets a timestamp bookmark on the audio
- Ctrl-J: sets a timestamp bookmark on the subtitle
- Ctrl-K: corrects the delay between both bookmarks

Notes:
- This patch changes adds hotkeys to the control GUI. I suspect this kind
of change may require a more
  thorough analysis before being accepted.
- See http://forum.videolan.org/viewtopic.php?f=7&t=109641 for an
illustration of a possible use
  (I changed the wordings a little bit in the source)
- This is the kind of feature I'd like to have when my subtitles are out of
sync,
  and I want a quick way of solving it (without having to download/install
a dedicated
  3rd party software)
- Current implementation uses a static variable at hotkeys.c:125 (room for
improvement, i guess)
---
 include/vlc_keys.h        |  3 +++
 modules/control/hotkeys.c | 58
+++++++++++++++++++++++++++++++++++++++++++++++
 src/config/keys.c         |  3 +++
 src/libvlc-module.c       | 15 ++++++++++++
 4 files changed, 79 insertions(+)

diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index 141e4b9..c6d5feb 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -161,6 +161,9 @@ typedef enum vlc_action {
     /* end of contiguous zone */
     ACTIONID_SUBDELAY_UP,
     ACTIONID_SUBDELAY_DOWN,
+    ACTIONID_SUBSYNC_MARKAUDIO,
+    ACTIONID_SUBSYNC_MARKSUB,
+    ACTIONID_SUBSYNC_APPLY,
     ACTIONID_SUBPOS_UP,
     ACTIONID_SUBPOS_DOWN,
     ACTIONID_AUDIO_TRACK,
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 95bc0d0..913e7e0 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -120,6 +120,15 @@ static void Close( vlc_object_t *p_this )
     free( p_sys );
 }

+
+/*g_subtitle_delaybookmarks : placeholder for storing subtitle sync
timestamps*/
+static struct
+{
+    int64_t i_time_subtitle;
+    int64_t i_time_audio;
+} subtitle_delaybookmarks = { 0, 0 };
+
+
 static int PutAction( intf_thread_t *p_intf, int i_action )
 {
     intf_sys_t *p_sys = p_intf->p_sys;
@@ -368,6 +377,55 @@ static int PutAction( intf_thread_t *p_intf, int
i_action )
             }
             break;

+        case ACTIONID_SUBSYNC_MARKAUDIO:
+        {
+            subtitle_delaybookmarks.i_time_audio = mdate();
+            DisplayMessage( p_vout, _("Sub sync: bookmarked audio
timestamp"));
+            break;
+        }
+        case ACTIONID_SUBSYNC_MARKSUB:
+        {
+            subtitle_delaybookmarks.i_time_subtitle = mdate();
+            DisplayMessage( p_vout, _("Sub sync: bookmarked subtitle
timestamp"));
+            break;
+        }
+        case ACTIONID_SUBSYNC_APPLY:
+        {
+            /* Warning! Can yield a pause in the playback.
+            *  For example, the following succession of actions will yield
a 5 second delay :
+            *  - Pressing Ctrl-H (ACTIONID_SUBSYNC_MARKAUDIO)
+            *  - wait 5 second
+            *  - Press Ctrl-J (ACTIONID_SUBSYNC_MARKSUB)
+            *  - Press Ctrl-K (ACTIONID_SUBSYNC_APPLY)
+            *  --> 5 seconds pause
+            *   This is due to var_SetTime() (and ultimately
UpdatePtsDelay())
+            *   which causes the video to pause for an equivalent duration
+            *   (This problem is also present in the "Track
synchronization" window)
+            */
+            if ( p_input )
+            {
+                if ( (subtitle_delaybookmarks.i_time_audio==0) ||
(subtitle_delaybookmarks.i_time_subtitle == 0) )
+                {
+                    int64_t i_current_subdelay = var_GetTime( p_input,
"spu-delay" );
+                    DisplayMessage( p_vout, _( "Sub sync: set bookmarks
first!" ),
+                                            (int)(i_current_subdelay /
1000));
+                }
+                else
+                {
+                    int64_t i_current_subdelay = var_GetTime( p_input,
"spu-delay" );
+                    int64_t i_additional_subdelay =
subtitle_delaybookmarks.i_time_audio -
subtitle_delaybookmarks.i_time_subtitle;
+                    int64_t i_total_subdelay = i_current_subdelay +
i_additional_subdelay;
+                    var_SetTime( p_input, "spu-delay", i_total_subdelay);
+                    ClearChannels( p_intf, p_vout );
+                    DisplayMessage( p_vout, _( "Sub sync: corrected %i ms
(total delay = %i ms)" ),
+                                            (int)(i_additional_subdelay /
1000),
+                                            (int)(i_total_subdelay / 1000)
);
+                    subtitle_delaybookmarks.i_time_audio =
subtitle_delaybookmarks.i_time_subtitle = 0;
+                }
+            }
+            break;
+        }
+
         case ACTIONID_SUBDELAY_DOWN:
         case ACTIONID_SUBDELAY_UP:
         {
diff --git a/src/config/keys.c b/src/config/keys.c
index ee3c382..73b70bf 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -346,6 +346,9 @@ static const struct action actions[] =
     { "subdelay-up", ACTIONID_SUBDELAY_UP, },
     { "subpos-down", ACTIONID_SUBPOS_DOWN, },
     { "subpos-up", ACTIONID_SUBPOS_UP, },
+    { "subsync-apply", ACTIONID_SUBSYNC_APPLY, },
+    { "subsync-markaudio", ACTIONID_SUBSYNC_MARKAUDIO, },
+    { "subsync-marksub", ACTIONID_SUBSYNC_MARKSUB, },
     { "subtitle-track", ACTIONID_SUBTITLE_TRACK, },
     { "title-next", ACTIONID_TITLE_NEXT, },
     { "title-prev", ACTIONID_TITLE_PREV, },
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 34a229e..e706ec5 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1310,6 +1310,12 @@ static const char *const mouse_wheel_texts[] =
 #define SUBDELAY_UP_KEY_LONGTEXT N_("Select the key to increase the
subtitle delay.")
 #define SUBDELAY_DOWN_KEY_TEXT N_("Subtitle delay down")
 #define SUBDELAY_DOWN_KEY_LONGTEXT N_("Select the key to decrease the
subtitle delay.")
+#define SUBSYNC_MARKAUDIO_KEY_TEXT N_("Subtitle sync / bookmark audio
timestamp")
+#define SUBSYNC_MARKAUDIO_KEY_LONGTEXT N_("Select the key to bookmark
audio timestamp when syncing subtitles.")
+#define SUBSYNC_MARKSUB_KEY_TEXT N_("Subtitle sync / bookmark subtitle
timestamp")
+#define SUBSYNC_MARKSUB_KEY_LONGTEXT N_("Select the key to bookmark
subtitle timestamp when syncing subtitles.")
+#define SUBSYNC_APPLY_KEY_TEXT N_("Subtitle sync / correct delay between
bookmarks")
+#define SUBSYNC_APPLY_KEY_LONGTEXT N_("Select the key to correct the delay
between audio & subtitle bookmarks.")
 #define SUBPOS_UP_KEY_TEXT N_("Subtitle position up")
 #define SUBPOS_UP_KEY_LONGTEXT N_("Select the key to move subtitles
higher.")
 #define SUBPOS_DOWN_KEY_TEXT N_("Subtitle position down")
@@ -2178,6 +2184,9 @@ vlc_module_begin ()
 #   define KEY_VOL_MUTE           "Command+Alt+Down"
 #   define KEY_SUBDELAY_UP        "j"
 #   define KEY_SUBDELAY_DOWN      "h"
+#   define KEY_SUBSYNC_MARKAUDIO  "Ctrl+h"
+#   define KEY_SUBSYNC_MARKSUB    "Ctrl+j"
+#   define KEY_SUBSYNC_APPLY      "Ctrl+k"
 #   define KEY_SUBPOS_DOWN        NULL
 #   define KEY_SUBPOS_UP          NULL
 #   define KEY_AUDIODELAY_UP      "g"
@@ -2442,6 +2451,12 @@ vlc_module_begin ()
              SUBDELAY_UP_KEY_TEXT, SUBDELAY_UP_KEY_LONGTEXT, true )
     add_key( "key-subdelay-down", KEY_SUBDELAY_DOWN,
              SUBDELAY_DOWN_KEY_TEXT, SUBDELAY_DOWN_KEY_LONGTEXT, true )
+    add_key( "key-subsync-markaudio", KEY_SUBSYNC_MARKAUDIO,
+             SUBSYNC_MARKAUDIO_KEY_TEXT, SUBSYNC_MARKAUDIO_KEY_LONGTEXT,
true )
+    add_key( "key-subsync-marksub", KEY_SUBSYNC_MARKSUB,
+             SUBSYNC_MARKSUB_KEY_TEXT, SUBSYNC_MARKSUB_KEY_LONGTEXT, true )
+    add_key( "key-subsync-apply", KEY_SUBSYNC_APPLY,
+             SUBSYNC_APPLY_KEY_TEXT, SUBSYNC_APPLY_KEY_LONGTEXT, true )
     add_key( "key-subpos-up", KEY_SUBPOS_UP,
              SUBPOS_UP_KEY_TEXT, SUBPOS_UP_KEY_LONGTEXT, true )
     add_key( "key-subpos-down", KEY_SUBPOS_DOWN,
-- 
1.7.12.4 (Apple Git-37)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20130407/628bf214/attachment.html>


More information about the vlc-devel mailing list