1diff --git a/.gitignore b/.gitignore
2index 0b0ee9c..fdaf05b 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -53,3 +53,5 @@ build*
6 contrib-*
7 install-*
8
9+# IDE
10+.idea
11diff --git a/include/vlc_actions.h b/include/vlc_actions.h
12index 404c166..bcc40ea 100644
13--- a/include/vlc_actions.h
14+++ b/include/vlc_actions.h
15@@ -182,6 +182,7 @@ typedef enum vlc_action_id {
16     ACTIONID_SUBTITLE_REVERSE_TRACK,
17     ACTIONID_SUBTITLE_TRACK,
18     ACTIONID_SUBTITLE_TOGGLE,
19+    ACTIONID_SUBTITLE_AUTOSYNC,
20     ACTIONID_SUBTITLE_TEXT_SCALE_NORMAL,
21     ACTIONID_SUBTITLE_TEXT_SCALE_UP,
22     ACTIONID_SUBTITLE_TEXT_SCALE_DOWN,
23diff --git a/modules/codec/avcodec/fourcc.c b/modules/codec/avcodec/fourcc.c
24index 40e98e0..ce8f810 100644
25--- a/modules/codec/avcodec/fourcc.c
26+++ b/modules/codec/avcodec/fourcc.c
27@@ -182,7 +182,7 @@ static const struct vlc_avcodec_fourcc video_codecs[] =
28     /* AV_CODEC_ID_V210X */
29     { VLC_CODEC_TMV, AV_CODEC_ID_TMV },
30     { VLC_CODEC_V210, AV_CODEC_ID_V210 },
31-    { VLC_CODEC_VUYA, AV_CODEC_ID_AYUV },
32+//    { VLC_CODEC_VUYA, AV_CODEC_ID_AYUV },
33     /* AV_CODEC_ID_DPX */
34     { VLC_CODEC_MAD, AV_CODEC_ID_MAD },
35     { VLC_CODEC_FRWU, AV_CODEC_ID_FRWU },
36diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
37index 91ebde8..ab93d9e 100644
38--- a/modules/control/hotkeys.c
39+++ b/modules/control/hotkeys.c
40@@ -701,6 +701,49 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
41             }
42             break;
43         }
44+        case ACTIONID_SUBTITLE_AUTOSYNC:
45+        {
46+            const char* home = getenv("HOME");
47+            char* strbuff[4906];
48+            snprintf(strbuff, 4096, "%s/.vlc/videoname.txt", home);
49+            FILE* vidname_fp = fopen(strbuff, "r");
50+            if (vidname_fp == NULL) {
51+                DisplayMessage(p_vout, "Error: could not determine video path.");
52+                break;
53+            }
54+            char vidname_buff[256];
55+            fgets(vidname_buff, 255, vidname_fp);
56+//            DisplayMessage(p_vout, "%s", vidname_buff);
57+            snprintf(strbuff, 4096, "%s/.vlc/subname.txt", home);
58+            FILE* subname_fp = fopen(strbuff, "r");
59+            if (subname_fp == NULL) {
60+                DisplayMessage(p_vout, "Error: could not determine subtitle path.");
61+                break;
62+            }
63+            char subname_buff[256];
64+            fgets(subname_buff, 255, subname_fp);
65+//            DisplayMessage(p_vout, "%s", subname_buff);
66+            fclose(vidname_fp);
67+            fclose(subname_fp);
68+            snprintf(strbuff, 4096, "subsync \"%s\" -i \"%s\" -o %s/.vlc/synchronized.srt --vlc-mode",
69+                    vidname_buff, subname_buff, home);
70+            FILE* output = popen(strbuff, "r");
71+            if (output == NULL) {
72+                DisplayMessage(p_vout, "Error: sync plugin not installed.");
73+                break;
74+            }
75+            int limit = 199;
76+            char *line = (char*) malloc(limit+1);
77+            while (getline(&line, &limit, output) != -1) {
78+                strtok(line, "\n");
79+                DisplayMessage(p_vout, _("Synchronizing subtitles... %s%%"), line);
80+            }
81+            free(line);
82+            pclose(output);
83+            snprintf(strbuff, 4096, "file://%s/.vlc/synchronized.srt", home);
84+            input_AddSlave(p_input, SLAVE_TYPE_SPU, strbuff, true, true, true);
85+            break;
86+        }
87         case ACTIONID_AUDIODELAY_DOWN:
88         case ACTIONID_AUDIODELAY_UP:
89         {
90diff --git a/src/input/input.c b/src/input/input.c
91index 0cb2729..be922e2 100644
92--- a/src/input/input.c
93+++ b/src/input/input.c
94@@ -1410,6 +1410,22 @@ static int Init( input_thread_t * p_input )
95     msg_Dbg( p_input, "`%s' successfully opened",
96              input_priv(p_input)->p_item->psz_uri );
97
98+    const char *psz_access, *psz_demux, *psz_path, *psz_anchor = NULL;
99+    /* Split uri */
100+    char *psz_dup = strdup( input_priv(p_input)->p_item->psz_uri );
101+    input_SplitMRL( &psz_access, &psz_demux, &psz_path, &psz_anchor, psz_dup );
102+//    const char* vidname_savepath = "/Users/me/.vlc/videoname.txt";
103+    const char* home = getenv("HOME");
104+    char vidname_savepath[256];
105+    snprintf(vidname_savepath, 256, "%s/.vlc", home);
106+    mkdir(vidname_savepath, 755);  // try to make sure the directory exists first
107+    snprintf(vidname_savepath, 256, "%s/.vlc/videoname.txt", home);
108+//    const char* vidname_savepath = sprintf("%s/.vlc/videoname.txt", home);
109+    msg_Dbg( p_input, "about to write path %s to file %s", get_path(psz_path), vidname_savepath);
110+    FILE* vidname_fp = fopen(vidname_savepath, "w");
111+    fputs(get_path(psz_path), vidname_fp);
112+    fclose(vidname_fp);
113+
114     /* initialization is complete */
115     input_ChangeState( p_input, PLAYING_S );
116
117@@ -3377,6 +3393,16 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
118     if( psz_forced_demux && p_source == NULL )
119         p_source = InputSourceNew( p_input, psz_uri, NULL, b_can_fail );
120
121+    if (i_type == SLAVE_TYPE_SPU) {
122+        const char* home = getenv("HOME");
123+        char subname_savepath[256];
124+        snprintf(subname_savepath, 256, "%s/.vlc/subname.txt", home);
125+        msg_Dbg( p_input, "about to write path %s to file %s", p_source->p_demux->psz_file, subname_savepath);
126+        FILE* subname_fp = fopen(subname_savepath, "w");
127+        fputs(p_source->p_demux->psz_file, subname_fp);
128+        fclose(subname_fp);
129+    }
130+
131     if( p_source == NULL )
132     {
133         msg_Warn( p_input, "failed to add %s as slave", psz_uri );
134diff --git a/src/libvlc-module.c b/src/libvlc-module.c
135index 0c06bc8..31a3603 100644
136--- a/src/libvlc-module.c
137+++ b/src/libvlc-module.c
138@@ -1394,6 +1394,8 @@ static const char *const mouse_wheel_texts[] = {
139 #define SUBTITLE_TRACK_KEY_LONGTEXT N_("Cycle through the available subtitle tracks.")
140 #define SUBTITLE_TOGGLE_KEY_TEXT N_("Toggle subtitles")
141 #define SUBTITLE_TOGGLE_KEY_LONGTEXT N_("Toggle subtitle track visibility.")
142+#define SUBTITLE_AUTOSYNC_KEY_TEXT N_("Autosync subtitles")
143+#define SUBTITLE_AUTOSYNC_KEY_LONGTEXT N_("Autosynchronize subtitles with video.")
144 #define PROGRAM_SID_NEXT_KEY_TEXT N_("Cycle next program Service ID")
145 #define PROGRAM_SID_NEXT_KEY_LONGTEXT N_("Cycle through the available next program Service IDs (SIDs).")
146 #define PROGRAM_SID_PREV_KEY_TEXT N_("Cycle previous program Service ID")
147@@ -2267,6 +2269,7 @@ vlc_module_begin ()
148 #   define KEY_AUDIO_TRACK        "l"
149 #   define KEY_SUBTITLE_TRACK     "s"
150 #   define KEY_SUBTITLE_TOGGLE    "Shift+s"
151+#   define KEY_SUBTITLE_AUTOSYNC  "Ctrl+Shift+s"
152 #   define KEY_SUBTITLE_REVTRACK  "Alt+s"
153 #   define KEY_PROGRAM_SID_NEXT   "x"
154 #   define KEY_PROGRAM_SID_PREV   "Shift+x"
155@@ -2589,6 +2592,8 @@ vlc_module_begin ()
156              SUBTITLE_TRACK_KEY_TEXT, SUBTITLE_TRACK_KEY_LONGTEXT, false )
157     add_key( "key-subtitle-toggle", KEY_SUBTITLE_TOGGLE,
158              SUBTITLE_TOGGLE_KEY_TEXT, SUBTITLE_TOGGLE_KEY_LONGTEXT, false )
159+    add_key( "key-subtitle-autosync", KEY_SUBTITLE_AUTOSYNC,
160+             SUBTITLE_AUTOSYNC_KEY_TEXT, SUBTITLE_AUTOSYNC_KEY_LONGTEXT, false )
161     add_key( "key-program-sid-next", KEY_PROGRAM_SID_NEXT,
162              PROGRAM_SID_NEXT_KEY_TEXT, PROGRAM_SID_NEXT_KEY_LONGTEXT, false )
163     add_key( "key-program-sid-prev", KEY_PROGRAM_SID_PREV,
164diff --git a/src/misc/actions.c b/src/misc/actions.c
165index 65178c1..4fc1a18 100644
166--- a/src/misc/actions.c
167+++ b/src/misc/actions.c
168@@ -347,6 +347,7 @@ static const struct name2action
169     { "subsync-markaudio", ACTIONID_SUBSYNC_MARKAUDIO, },
170     { "subsync-marksub", ACTIONID_SUBSYNC_MARKSUB, },
171     { "subsync-reset", ACTIONID_SUBSYNC_RESET, },
172+    { "subtitle-autosync", ACTIONID_SUBTITLE_AUTOSYNC, },
173     { "subtitle-revtrack", ACTIONID_SUBTITLE_REVERSE_TRACK, },
174     { "subtitle-text-scale-down", ACTIONID_SUBTITLE_TEXT_SCALE_DOWN, },
175     { "subtitle-text-scale-normal", ACTIONID_SUBTITLE_TEXT_SCALE_NORMAL, },
176