Topic: Solving Crunchyroll/HorribleSubs audio desync with mpv+SVP4
EDIT 22/02/2017: contrary to what I said before, this is still a problem. However, it actually depends of the type of video detected by SVPtube: M3U8 streams are parsed directly by mpv, works perfectly, and this seems the format used by more recently releases at Crunchyroll. RTMP streams needs to be muxed in a "video.mp4" file and brings the wrong FPS problem.
EDIT 19/02/2017: since latest SVPtube update, the procedure described in this topic does not seem to be necessary anymore. The problem seems to be fixed since SVPtube know uses a very long string as filename (with ".m3u"8 extension), instead if the old "video.mp4". They probably started to feed the HLS stream directly to mpv instead of trying to remux the video, solving the problem.
So I finally solved the problem of audio desync when using mpv+SVP4 and Crunchyroll (using SVPTube or directly by mpv+youtube-dl) or HorribleSubs. This seems to be a common problem:
https://www.svp-team.com/forum/viewtopic.php?id=3563
https://www.svp-team.com/forum/viewtopic.php?id=3584
https://www.svp-team.com/forum/viewtopic.php?id=3357
The problem is basically what is described in this post: Crunchyroll encoded videos reports a FPS of 23.810, instead of the more common 23.976. Actually, this seems to be a lie: the video is actually encoded with 23.976FPS, however the container reports a lower FPS for some reason. This doesn't cause any problem for normal playback, however when we use SVP this makes the video go faster than the audio, causing a desync.
The cause of the problem seems to be in the vapoursynth support in mpv: vapoursynth does not have any information about the video, so mpv fills some variables accesible to vapoursynth scripts with some information about the video. The variable that stores the video FPS is container_fps, however this variable reports the container FPS instead of the actual video FPS (I don't know if mpv actually has this information btw). So vapoursynth gets the wrong FPS, and SVP by instance gets the wrong FPS too, scalling the video to 59.6852 or 60.6073 instead of the correct 59.97FPS that we see in videos with proper FPS.
FYI, HorribleSubs basically dumps and mux Crunchyroll streams, so they get it wrong too.
So, how to fix it? We will create a special mpv.conf file that will force the correct FPS in the video, allowing us to watch anime from Crunchyroll without audio desync (however there are still some minor problems, I will describe it better later).
Press Win+R and type "%appdata%\mpv", this will open a new Windows Explorer window. Create a new .txt file there, name it "mpv.conf" and edit it as below:
[svp-crunchyroll]
profile-desc="Crunchyroll fix for SVPTube"
fps=23.976
no-correct-pts
sub-delay=0.166
#sub-speed=23.976/23.810
[extension.mp4]
profile=svp-crunchyroll
So basically what we're doing is create a new profile that makes mpv to assume the video is running at 23.976FPS, and now SVP correctly scales the video to 59.97FPS. no-correct-pts makes mpv to assume that the video metadata is broken so it should assume the FPS we set before. Since we are using [extension.mp4] it will only apply to .mp4 files, since SVPTube mux the output to a video.mp4 file. If you're watching from HorribleSubs, you probably should add a [extension.mkv] too.
Now for the problems: the subtitles still assume a video playing with 23.810, so they will be slightly behind and sometimes they will be too fast. I fixed the first problem with sub-delay, however the second problem I tried to fix with the sub-speed option without success. If someone can fix the second problem it would be interesting, so I leave it to someone to try. However even with this problem, the videos from Crunchyroll/HorribleSubs are watchable.
The other problem is, since we use this profile for every video file with mp4/mkv extension, this will break other videos you try to play with mpv. There isn't a simple way to fix this: you can comment those lines in mpv before playing other type of video, however this a pretty bad solution.
I hope the SVP team comes with a better workaround for this problem. If we could pass parameters for mpv from SVPTube, for example, we could simple pass mpv --profile=svp-crunchyroll when playing Crunchyroll videos, and mpv --profile=default when playing normal, non-broken content. For now at least this is a workaround.
Edit: MPC-HC does not seem to suffer from this problem at all. However mpv, at least in my experience, is much smoother than MPC-HC. And MPC-HC does not support RTMP streams like mpv, so your only option is to use HorribleSubs or download the video with SVPTube.