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

Zoran Turalija zoran.turalija at gmail.com
Tue Apr 9 08:51:19 CEST 2013


On Mon, Apr 08, 2013 at 11:37:38PM +0200, Pascal Thomet wrote:
> Added the following shortcuts (and made them configurable):
> - Shift-H: sets a timestamp bookmark on the audio
> - Shift-J: sets a timestamp bookmark on the subtitle
> - Shift-K: corrects the delay between both bookmarks
> - Command-Shift-K: resets the delay
> 
> Notes:
> - As per the remark of Rémi Denis-Courmont, there is still a static variable, but it is composed
>   of vlc_atomics.
> 	Rémi, could you please check I did not abuse them? I'm not quite sure I used them the preferred way.
> - As per the remark of Zoran Turalija, I changed the shortcuts and added a "reset delay" shortcut
> - 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)
> ---
>  include/vlc_keys.h        |    4 +++
>  modules/control/hotkeys.c |   68 +++++++++++++++++++++++++++++++++++++++++++++
>  src/config/keys.c         |    4 +++
>  src/libvlc-module.c       |   20 +++++++++++++
>  4 files changed, 96 insertions(+)
> 
> diff --git a/include/vlc_keys.h b/include/vlc_keys.h
> index 141e4b9..942ea48 100644
> --- a/include/vlc_keys.h
> +++ b/include/vlc_keys.h
> @@ -161,6 +161,10 @@ typedef enum vlc_action {
>      /* end of contiguous zone */
>      ACTIONID_SUBDELAY_UP,
>      ACTIONID_SUBDELAY_DOWN,
> +    ACTIONID_SUBSYNC_MARKAUDIO,
> +    ACTIONID_SUBSYNC_MARKSUB,
> +    ACTIONID_SUBSYNC_APPLY,
> +    ACTIONID_SUBSYNC_RESET,
>      ACTIONID_SUBPOS_UP,
>      ACTIONID_SUBPOS_DOWN,
>      ACTIONID_AUDIO_TRACK,
> diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
> index 95bc0d0..2b6b3ab 100644
> --- a/modules/control/hotkeys.c
> +++ b/modules/control/hotkeys.c
> @@ -31,6 +31,7 @@
>  #endif
>  
>  #include <vlc_common.h>
> +#include <vlc_atomic.h>
>  #include <vlc_plugin.h>
>  #include <vlc_interface.h>
>  #include <vlc_input.h>
> @@ -122,6 +123,14 @@ static void Close( vlc_object_t *p_this )
>  
>  static int PutAction( intf_thread_t *p_intf, int i_action )
>  {
> +    /*subtitle_delaybookmarks: placeholder for storing subtitle sync timestamps
> +     * under the form of static atomic int64_t */
> +    static struct
> +    {
> +        vlc_atomic_t ai_time_subtitle;
> +        vlc_atomic_t ai_time_audio;
> +    } subtitle_delaybookmarks = { {0}, {0} };
> +
>      intf_sys_t *p_sys = p_intf->p_sys;
>      playlist_t *p_playlist = pl_Get( p_intf );
>  
> @@ -368,6 +377,65 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
>              }
>              break;
>  
> +        case ACTIONID_SUBSYNC_MARKAUDIO:
> +        {
> +            vlc_atomic_set(&subtitle_delaybookmarks.ai_time_audio, mdate());
> +            DisplayMessage( p_vout, _("Sub sync: bookmarked audio timestamp"));
> +            break;
> +        }
> +        case ACTIONID_SUBSYNC_MARKSUB:
> +        {
> +            vlc_atomic_set(&subtitle_delaybookmarks.ai_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)
> +            */

s/Ctrl/Shift/g

Also, comment indent (except first line) off by one position.

> diff --git a/src/libvlc-module.c b/src/libvlc-module.c
> index 34a229e..0b0d9a0 100644
> --- a/src/libvlc-module.c
> +++ b/src/libvlc-module.c
> @@ -1310,6 +1310,14 @@ 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.")

Subtitle sync / synchronize audio & subtitle timestamps
Select the key to synchronize bookmarked audio & subtitle timestamps.

> +#define SUBSYNC_RESET_KEY_TEXT N_("Subtitle sync / reset delay")
> +#define SUBSYNC_RESET_KEY_LONGTEXT N_("Select the key to reset the delay between audio & subtitle.")

Subtitle sync / reset audio & subtitle synchronization
Select the key to reset synchronization of audio & subtitle timestamps.

>  #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 +2186,10 @@ vlc_module_begin ()
>  #   define KEY_VOL_MUTE           "Command+Alt+Down"
>  #   define KEY_SUBDELAY_UP        "j"
>  #   define KEY_SUBDELAY_DOWN      "h"
> +#   define KEY_SUBSYNC_MARKAUDIO  "Shift+h"
> +#   define KEY_SUBSYNC_MARKSUB    "Shift+j"
> +#   define KEY_SUBSYNC_APPLY      "Shift+k"
> +#   define KEY_SUBSYNC_RESET      "Command+Shift+k"
>  #   define KEY_SUBPOS_DOWN        NULL
>  #   define KEY_SUBPOS_UP          NULL
>  #   define KEY_AUDIODELAY_UP      "g"

You need to add these definitions further down in src/libvlc-module.c, in
order to assign shortcuts for linux/windows users:

+#   define KEY_SUBSYNC_MARKAUDIO  "Shift+h"
+#   define KEY_SUBSYNC_MARKSUB    "Shift+j"
+#   define KEY_SUBSYNC_APPLY      "Shift+k"
+#   define KEY_SUBSYNC_RESET      "Ctrl+Shift+k"

Your patch does sync audio and subtitle, but at least on linux, after sync is
being made, audio is gone for good.

And I'm not sure, but maybe you should check if audio track and subtitle track
are present before you try to set audio/subtitle timestamp bookmarks.

-- 
Kind regards,
Zoran Turalija



More information about the vlc-devel mailing list