Sync problems with audio and subs when encoding mkv

Started by gino2812, October 08, 2016, 06:12:50 AM

Previous topic - Next topic

gino2812

I have anime mkv videos (x264+m4a) with ass floating subs, which I tried to make hardcoded to watch on tv, mostly because of the karaoke and other effects a tv can't recognize on floating subs.
So, after encoding, audio and sub aren't in sync. Very easy to noticed, because of the karaoke effects (letters 'jumping' late). Also, Characters lips and sound aren't in sync.
I use mediainfo on the last one, and found this: (image attached) ... original audio has no delay, and avidemux audio is 50ms delay.
----
As a test, I use virtualdub to encode the same file.
And... ass subs fits ok with audio in new file.

It seems, avidemux is adding (or extracting) some time while converting. I upload a sample of 1 minute to mega. Is almost the last part (ending karaoke) in which the asynchronism is much noticeable.
Can you please watch it?

https://mega.nz/#!6tQEAATK!hiWrEVLWSMQ62Y9LOdvr8FSB2op_plKvhTDB9V-jjGw -> 13mb



eumagga0x2a

#1
Quote from: gino2812 on October 08, 2016, 06:12:50 AM
I have anime mkv videos (x264+m4a) with ass floating subs, which I tried to make hardcoded to watch on tv [...]
So, after encoding, audio and sub aren't in sync. [...] Also, Characters lips and sound aren't in sync.

Were character lips and sound in sync while playing the source video in Avidemux? What does ffprobe report about the source video? (Thinking about variable frame rate videos.)

Quoteoriginal audio has no delay, and avidemux audio is 50ms delay.

A 50ms delay is mostly too small to notice with lips (it would be just barely perceptible when watching string instrument players in a fast piece).

I'm sorry, I didn't look at the encoded video, because only the source might be of interest.

gino2812

Quote from: eumagga0x2a on October 08, 2016, 05:46:29 PM
Quote from: gino2812 on October 08, 2016, 06:12:50 AM
I have anime mkv videos (x264+m4a) with ass floating subs, which I tried to make hardcoded to watch on tv [...]
So, after encoding, audio and sub aren't in sync. [...] Also, Characters lips and sound aren't in sync.

Were character lips and sound in sync while playing the source video in Avidemux? What does ffprobe report about the source video? (Thinking about variable frame rate videos.)

Quoteoriginal audio has no delay, and avidemux audio is 50ms delay.

A 50ms delay is mostly too small to notice with lips (it would be just barely perceptible when watching string instrument players in a fast piece).

I'm sorry, I didn't look at the encoded video, because only the source might be of interest.

1. Original video is completely in-sync (audio+subs) in every player.
Do you think I'll post here otherwise?  :o

2. ALL info about original AND avidemux encode files are shown on the mediainfo image attached.
You didn't watch it either?  :-\

3. I know 50ms is too small... BUT, the results are obvious big enough to noticed. there is a possibility the delay is bigger than shown, Mediainfo is just a reference SOMETHING is happening about time frame when encoding.

4. Please, watch the video before posting what you think without knowing what's the problem about.

eumagga0x2a

Quote from: gino2812 on October 08, 2016, 07:17:29 PM

1. Original video is completely in-sync (audio+subs) in every player.

Good.

QuoteDo you think I'll post here otherwise?  :o

Well, this may not apply to the Windows version, but e.g. the "GTK" Qt theme on Linux causes progressive desync during playback in Avidemux with high frame rates (at least at 50fps, maybe also lower). It is never wrong to cross-check.

Quote2. ALL info about original AND avidemux encode files are shown on the mediainfo image attached.
You didn't watch it either?  :-\

I've looked at the screenshots attached to your post and they don't provide full information ffprobe would have provided in a few lines of text (no screenshots needed). They do show that the original file (.mkv) exhibits an audio delay of 50ms while no audio delay is noted for the encoded video. Have you tried to specify a similar delay in Avidemux?

Quote3. I know 50ms is too small... BUT, the results are obvious big enough to noticed.

These results have nothing to do with 50ms shift in the source video then.

Do you observe the same desync when encoding without subtitles? Why do you re-encode audio instead of using the copy mode?

WRT to watching a video from mega.nz, maybe Jan could help.

gino2812

Quote from: eumagga0x2a on October 08, 2016, 09:13:45 PM
Quote from: gino2812 on October 08, 2016, 07:17:29 PM

Do you think I'll post here otherwise?  :o

Well, this may not apply to the Windows version, but e.g. the "GTK" Qt theme on Linux causes progressive desync during playback in Avidemux with high frame rates (at least at 50fps, maybe also lower). It is never wrong to cross-check.

Quote2. ALL info about original AND avidemux encode files are shown on the mediainfo image attached.
You didn't watch it either?  :-\

I've looked at the screenshots attached to your post and they don't provide full information ffprobe would have provided in a few lines of text (no screenshots needed). They do show that the original file (.mkv) exhibits an audio delay of 50ms while no audio delay is noted for the encoded video. Have you tried to specify a similar delay in Avidemux?

Quote3. I know 50ms is too small... BUT, the results are obvious big enough to noticed.

These results have nothing to do with 50ms shift in the source video then.

Do you observe the same desync when encoding without subtitles? Why do you re-encode audio instead of using the copy mode?

WRT to watching a video from mega.nz, maybe Jan could help.

1. I use windows   :-\
2. Never used/needed ffprobe.
3. Original video = NO DELAY ... Encoded video= 50ms delay.  ::)
4. I need video WITH subs... why do I encode without if its useless to me?  ::)
5. Original audio is 6 channel. I only have stereo, and there is the reason of encoding.  By the way... are you kidding?   :o
What I do with my encoding, is because of what I am going to use/need.

Jan Gruuthuse

We only try to establish what your goal is going from original video to re-encoded target video.
We all have a way of doing things.

The uploaded video is ... (sample).mp4 the encoded endresult  with your ass subtitles from source?

Original video says:
QuoteDelay relative to video                  : 50ms
Probably you need to apply in audio output that 50 ms:
[v] Shift: [  ] this could be -50ms (negative) or 50ms (positive)

One issue could be video =  23.976 fps, however you screen shot shows audio = 46.875 fps


I presume you did encoding simultaneous video subtitles + audio?
Try 2 step approach
1 - encode subtitles (video) and leave audio alone (copy). Check if encoded is OK
2 - now re-encode the audio in the video from step 1

I wonder why your mp4 reports
QuoteBit rate mode                            : Constant
Channel(s)                               : 2 channels
Channel(s)_Original                      : 6 channels

as your sample shows:
QuoteAudio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 1 min 7 s
Bit rate mode                            : Variable
Bit rate                                 : 196 kb/s
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 spf)
Compression mode                         : Lossy
Stream size                              : 1.57 MiB (12%)
Title                                    : Stereo
Language                                 : Japanese
Encoded date                             : UTC 2016-10-08 06:02:40
Tagged date                              : UTC 2016-10-08 06:02:40

eumagga0x2a

Quote from: gino2812 on October 09, 2016, 12:09:07 AM
1. I use windows   :-\

While regrettable, this is not an issue here, not to mention that FFmpeg binaries for Windows are freely available.

Quote2. Never used/needed ffprobe.

Even in MediaInfo you have an option to save to a text file. Please use it and post the complete info about the videos, no screenshots. Though I don't know if MediaInfo provides correct and sufficient information, it is worth a try.

Quote
3. Original video = NO DELAY ... Encoded video= 50ms delay.  ::)

You wrote:

Quote from: gino2812 on October 08, 2016, 06:12:50 AM
I have anime mkv videos (x264+m4a) with ass floating subs, which I tried to make hardcoded to watch on tv, mostly because of the karaoke and other effects a tv can't recognize on floating subs.

This meant that the source video is in a mkv container, thus making the video on the left in mp4 container the product of filtered re-encoding with Avidemux. Is it the other way round, source as mp4 and output as mkv?

Quote4. I need video WITH subs... why do I encode without if its useless to me?  ::)

This would allow to judge if the desync is related to the subtitles video filter or not.

gino2812

#7
Quote from: Jan Gruuthuse on October 09, 2016, 08:06:19 AM
We only try to establish what your goal is going from original video to re-encoded target video.
We all have a way of doing things.

The uploaded video is ... (sample).mp4 the encoded endresult  with your ass subtitles from source?

Original video says:
QuoteDelay relative to video                  : 50ms
Probably you need to apply in audio output that 50 ms:
[v] Shift: [  ] this could be -50ms (negative) or 50ms (positive)

One issue could be video =  23.976 fps, however you screen shot shows audio = 46.875 fps


I presume you did encoding simultaneous video subtitles + audio?
Try 2 step approach
1 - encode subtitles (video) and leave audio alone (copy). Check if encoded is OK
2 - now re-encode the audio in the video from step 1

I wonder why your mp4 reports
QuoteBit rate mode                            : Constant
Channel(s)                               : 2 channels
Channel(s)_Original                      : 6 channels

as your sample shows:
QuoteAudio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 1 min 7 s
Bit rate mode                            : Variable
Bit rate                                 : 196 kb/s
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 spf)
Compression mode                         : Lossy
Stream size                              : 1.57 MiB (12%)
Title                                    : Stereo
Language                                 : Japanese
Encoded date                             : UTC 2016-10-08 06:02:40
Tagged date                              : UTC 2016-10-08 06:02:40


I want  a mkv or mp4 video with harcoded subs and aac stereo to watch on tv. That's my goal.

So, I have an 'original' mkv video with ass floating subs and 6 channel aac.
I tried to encode everything.
video= 2pass x264
audio= aac fac (192, remix stereo)
filter ass subs

--------------

The result is a video with audio AND subs out of sync. NOT just the audio.
I uploaded a sample video with the karaoke out-of-sync ending, to give a clear idea of both problems.

I'll tried to encode WITHOUT the audio. Subs were out of sync.
Audio was encoded by audacity with no problem.

So, I tried to encode video+subs on virtualdub, and everything goes ok. Then, added the audacity audio and file was finally everything ok.

I donÃ,´t know why this out-of-sync problem happened.

-----

I just downloaded the new updated avidemux (2.6.14 161007). Mine was from September.
I'll try again and update here what happens.

PS: attaching original mkv video mediainfo text file.

gino2812

#8
Well I tried the lat avidemux and problems with audio sync are lower, but still exist. About ass subtitle, it still has the same problem.
Here I attached the new mediainfo file about this last encoding.

As suggested, I'm now proceeding to encode just the video + subtitles.
I'll return here with news about it.

---EDIT---

The new encoding video + subs (copy audio), shows something interesting: Video and subs are out-of sync from audio.
Seems like encoding 'accelerates' the video a little, so images appear faster than audio. I calculate about 500ms (maybe more).
So, since audio was untouched, somehow adding hardcoded ass subs is the reason of the problem.
Could it be because original is a: 10bit+ High 4:4:4 Predictive@L5 + 16 frames; and after encoding I get a: 8bit+High@L4 + 4 frames video?

Adding new mediainfo attached file. Also the original one.

eumagga0x2a

Thank you for the info. I have looked at the short sample you provided as well and you're right that there is a small but still perceptible A/V offset and adding -delay 0.05 to mplayer command line (delaying video for 50ms) restores perfect A/V sync. Unfortunately, mediainfo doesn't provide one crucial bit of information ffprobe would have delivered: the PTS of the first frame. The re-encoded sample has PTS of the first frame equal to zero, but it would be important to know this value for the source video. What time does Avidemux show upon loading the source video or upon pressing the Pos1 key? If the source video actually starts at an offset, but the re-encoded video has none, I could imagine that the video frames might end up displayed ahead of audio (I haven't studied the source code thorough enough to be sure now).

I can't judge based on a sample 00:01:07.11 in duration whether the A/V offset stays the same throughout the complete video or video and audio drift farther apart.

If encoding seems to "accelerate" video, it might indicate that now and then some video frames get dropped but no correction is taken to keep audio in sync.

WRT to subtitles, I must admit to be unable to judge based on the sample. The subtitles video filter in Avidemux doesn't offer any means to compensate a possible time offset.

Jan Gruuthuse

Any timing issues with ass subtitles (could/should be checked/edited with subtitle editor) probably like aegisub. http://www.aegisub.org/
Load the video into aegisub, you see audio wave representation and should/would be able to check if subtitle is in sync.
or edit the timings accordingly.

Possible issues with Japanese manga 30/60 frames versus EU 25/50 frames or using FILM fps and one of these is offsetting the video. Check carefully what is going in avidemux and what is going out.
Possible setting left from previously testing?
Look for config2, config3 and defaultSettings.py delete these and re-enter you preferred settings.

mean

You might want to disable b pyramid if it is used

gino2812

#12
1. If anyone wanna try it, I can give the link from where I download the video I'm encoding without success in avidemux. (Episode 12) : mega:#F!s5AmxC6L!Ly4BEXPPyaZveQ4D-4neJA
Or, I can use that ffprobe (which I never used so I need some instructions) to update here the information you require to help.

2. I can extract any part of the new encoded file and upload it to the internet. Just tell me which part you prefer or maybe all of it. I don't have any problem at all. I want to help fixing this issue.

3. I use VLC and aegisub to correct and watch every result of subtitles on each episode. I have the same problem on almost every episode, but stronger on 1, 5, 7 and 12.
Aegisub showed not problem at all. Subs, video and audio looked ok on every episode. VLC and MPC, too (original video+audio+floating subs).

4. I also encode some other videos. 'Boruto: naruto the movie.'
Is about 95 minutes, and has no karaoke (not certain if its the reason of problem, but I just mention it).
Encoding was fine. Maybe a very little async now that I'm too drastic on the issue, but it's perfectly fine to view without problem.

5. Where on earth is the 'B pyramid' in avidemux? I spent 10 minutes looking and nothing found.
In mediainfo it shows: 'b_pyramid=2'.
How can I change it?

mean

5- It's called B frame as reference
Set it to disable, it might help

gino2812

Quote from: mean on October 11, 2016, 09:09:48 AM
5- It's called B frame as reference
Set it to disable, it might help

I found on 3 different sections (Partition, frame, analysis) on the x264 configuration screen. none of them is with number 2.
Where exactly, please?