[vlc-commits] Subsync: added an easier way to sync subtitles
Pascal Thomet
git at videolan.org
Sat Apr 13 20:09:56 CEST 2013
vlc | branch: master | Pascal Thomet <pthomet at gmail.com> | Sat Apr 13 20:04:43 2013 +0200| [f7211d5efa4cd9ef392230d85fdf3470edefab39] | committer: Jean-Baptiste Kempf
Subsync: added an easier way to sync subtitles
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
See http://forum.videolan.org/viewtopic.php?f=7&t=109641 for an
illustration of a possible use
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f7211d5efa4cd9ef392230d85fdf3470edefab39
---
include/vlc_keys.h | 4 +++
modules/control/hotkeys.c | 65 +++++++++++++++++++++++++++++++++++++++++++++
src/config/keys.c | 4 +++
src/libvlc-module.c | 24 +++++++++++++++++
4 files changed, 97 insertions(+)
diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index 90d5d85..62a52fd 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -162,6 +162,10 @@ typedef enum vlc_action {
ACTIONID_PLAY_CLEAR,
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 4547316..7fcde53 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -48,6 +48,13 @@ struct intf_sys_t
{
vout_thread_t *p_last_vout;
int slider_chan;
+
+ /*subtitle_delaybookmarks: placeholder for storing subtitle sync timestamps*/
+ struct
+ {
+ int64_t i_time_subtitle;
+ int64_t i_time_audio;
+ } subtitle_delaybookmarks;
};
/*****************************************************************************
@@ -101,6 +108,8 @@ static int Open( vlc_object_t *p_this )
p_intf->p_sys = p_sys;
p_sys->p_last_vout = NULL;
+ p_sys->subtitle_delaybookmarks.i_time_audio = 0;
+ p_sys->subtitle_delaybookmarks.i_time_subtitle = 0;
var_AddCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf );
return VLC_SUCCESS;
@@ -373,6 +382,62 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
}
break;
+ case ACTIONID_SUBSYNC_MARKAUDIO:
+ {
+ p_sys->subtitle_delaybookmarks.i_time_audio = mdate();
+ DisplayMessage( p_vout, _("Sub sync: bookmarked audio timestamp"));
+ break;
+ }
+ case ACTIONID_SUBSYNC_MARKSUB:
+ {
+ p_sys->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 Shift-H (ACTIONID_SUBSYNC_MARKAUDIO)
+ * - wait 5 second
+ * - Press Shift-J (ACTIONID_SUBSYNC_MARKSUB)
+ * - Press Shift-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 ( (p_sys->subtitle_delaybookmarks.i_time_audio == 0) || (p_sys->subtitle_delaybookmarks.i_time_subtitle == 0) )
+ {
+ DisplayMessage( p_vout, _( "Sub sync: set bookmarks first!" ) );
+ }
+ else
+ {
+ int64_t i_current_subdelay = var_GetTime( p_input, "spu-delay" );
+ int64_t i_additional_subdelay = p_sys->subtitle_delaybookmarks.i_time_audio - p_sys->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) );
+ p_sys->subtitle_delaybookmarks.i_time_audio = 0;
+ p_sys->subtitle_delaybookmarks.i_time_subtitle = 0;
+ }
+ }
+ break;
+ }
+ case ACTIONID_SUBSYNC_RESET:
+ {
+ var_SetTime( p_input, "spu-delay", 0);
+ ClearChannels( p_intf, p_vout );
+ DisplayMessage( p_vout, _( "Sub sync: delay reset" ) );
+ p_sys->subtitle_delaybookmarks.i_time_audio = 0;
+ p_sys->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 07dd6ec..7fcbc37 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -347,6 +347,10 @@ 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, },
+ { "subsync-reset", ACTIONID_SUBSYNC_RESET, },
{ "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 fc791fd..4bd0227 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 / synchronize audio & subtitle timestamps")
+#define SUBSYNC_APPLY_KEY_LONGTEXT N_("Select the key to synchronize bookmarked audio & subtitle timestamps.")
+#define SUBSYNC_RESET_KEY_TEXT N_("Subtitle sync / reset audio & subtitle synchronization")
+#define SUBSYNC_RESET_KEY_LONGTEXT N_("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")
@@ -2182,6 +2190,10 @@ vlc_module_begin ()
# define KEY_SUBDELAY_DOWN "h"
# define KEY_SUBPOS_DOWN NULL
# define KEY_SUBPOS_UP NULL
+# 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_AUDIODELAY_UP "g"
# define KEY_AUDIODELAY_DOWN "f"
# define KEY_AUDIO_TRACK "l"
@@ -2293,6 +2305,10 @@ vlc_module_begin ()
# define KEY_SUBDELAY_DOWN "g"
# define KEY_SUBPOS_DOWN NULL
# define KEY_SUBPOS_UP NULL
+# 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"
# define KEY_AUDIODELAY_UP "k"
# define KEY_AUDIODELAY_DOWN "j"
# define KEY_RANDOM "r"
@@ -2448,6 +2464,14 @@ 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-subsync-reset", KEY_SUBSYNC_RESET,
+ SUBSYNC_RESET_KEY_TEXT, SUBSYNC_RESET_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,
More information about the vlc-commits
mailing list