Opened 5 years ago

Closed 2 years ago

Last modified 21 months ago

#12396 closed Bug Report - General (fixed)

external .srt subtitles go out of sync in some use cases since 59512d5e9d

Reported by: ismota@… Owned by: Peter Bennett
Priority: minor Milestone: 30.0
Component: MythTV - Video Playback Version: 0.27.4
Severity: medium Keywords: subtitle timing
Cc: Ticket locked: no

Description

After upgrading my 0.24 to 0.27 fixes I see subtitles timing problem. It manifests itself with .avi files and srt/sub subtitles. When you play avi file first time, subtitles are usually timed correctly (not allways). But when retrying watching from bookmark subtitles are allmost allways about 3sec late/early. This happens with various avi files. Also tested with different system running master, same problem.

Attachments (1)

0323-ticket12396-.srt-subs-go-out-of-sync.patch (970 bytes) - added by warpme@… 2 years ago.
workaround for .srt de-sync after seeks

Download all attachments as: .zip

Change History (23)

comment:1 Changed 5 years ago by ismota@…

I am little surprised that others does not notice this problem (I haven't seen any discussion about it in forums/mailing lists). Practically all my avi files have this problem. Subtitles are usually ok if video is started from beginning. But restarting it from bookmark and often also seeking/jumping in video sets subtitle timing wrong.

mkv files are allways ok. mp4 files suffers this problem.

comment:2 Changed 5 years ago by Jim Stichnoth

There's a good chance the timing issues will be solved by generating a seektable for the video using "mythcommflag --rebuild". Can you try that and report back?

Lack of complaints likely due to:

  1. MythTV doesn't record .avi files (i.e. you have to go to extra work to import them), so most people don't play them.
  2. Most people don't care about captions/subtitles.

IIRC, what's happening is that without a seektable, MythTV must ask the decoder (ffmpeg) to seek to the desired frame, but ffmpeg only seeks to the nearest keyframe, while MythTV believes it is at the exact frame. If keyframes in the .avi file are far apart, subtitles are likely to be out of sync. But if a seektable is present, MythTV seeks to a keyframe, then frame-by-frame advances to the desired frame.

comment:3 Changed 5 years ago by ismota@…

I generated seektables for few videos. Unfortunately, it did not fix the problem.

comment:4 in reply to:  2 ; Changed 5 years ago by JYA

Replying to stichnot:

Lack of complaints likely due to:

  1. MythTV doesn't record .avi files (i.e. you have to go to extra work to import them), so most people don't play them.
  2. Most people don't care about captions/subtitles.

this has happens to me many times... subtitles are good at first and then they start diverging to the point they are unusable. I've never managed to reproduce the problem correctly, and often I just blamed the subtitles and moved on.

IIRC, what's happening is that without a seektable, MythTV must ask the decoder (ffmpeg) to seek to the desired frame, but ffmpeg only seeks to the nearest keyframe, while MythTV believes it is at the exact frame. If keyframes in the .avi file are far apart, subtitles are likely to be out of sync. But if a seektable is present, MythTV seeks to a keyframe, then frame-by-frame advances to the desired frame.

That seems like a bug to me... Yes ffmpeg will seek to the next keyframe, but you still get the right time and adjust the subtitle for that time. Also, why not do like with the seek table present a move frame by frame then?

comment:5 Changed 5 years ago by ismota@…

One noticeable thing is, subtitles are always just 3sec behind or ahead. If this would be keyframe related problem, should timing offset vary?

comment:6 in reply to:  4 Changed 5 years ago by Jim Stichnoth

Replying to jyavenard:

Replying to stichnot:

Lack of complaints likely due to:

  1. MythTV doesn't record .avi files (i.e. you have to go to extra work to import them), so most people don't play them.
  2. Most people don't care about captions/subtitles.

this has happens to me many times... subtitles are good at first and then they start diverging to the point they are unusable. I've never managed to reproduce the problem correctly, and often I just blamed the subtitles and moved on.

That sounds like subtitle drift, which is separate from the OP's issue, I think. Drift can come from a mismatch between the video and the subtitle file, or even from inconsistency between the container's reported framerate and actual content (#11415 comes to mind).

IIRC, what's happening is that without a seektable, MythTV must ask the decoder (ffmpeg) to seek to the desired frame, but ffmpeg only seeks to the nearest keyframe, while MythTV believes it is at the exact frame. If keyframes in the .avi file are far apart, subtitles are likely to be out of sync. But if a seektable is present, MythTV seeks to a keyframe, then frame-by-frame advances to the desired frame.

That seems like a bug to me... Yes ffmpeg will seek to the next keyframe, but you still get the right time and adjust the subtitle for that time. Also, why not do like with the seek table present a move frame by frame then?

I thought I had debugged in the past the issue of seeking in a particular container type and seeing this kind of imprecision from ffmpeg, but I could be misremembering. In any case, the OP reporting that it snaps to +/-3sec off, plus no seektable difference, suggests that it's something else.

comment:7 Changed 5 years ago by ismota@…

Yes, this definitely is not subtitle drift problem. It happen to all avi and mp4 files, and I can play those files with mplayer/vlc with correct timing. Just skipping forward/backward, start watching from bookmark sets timing incorrect. Sometimes, if timing is incorrect when I continue watching from bookmark, I can skip few times backwards and then ahead, and get right timing again. But this is little painful. Usually I check that are subs ahead or behind and adjust subtitle delay +/- 3sec and get timing ok.

comment:8 Changed 5 years ago by Stuart Auchterlonie

Milestone: 0.27.50.27.6

comment:9 Changed 4 years ago by s2.akira@…

I have the same problem, and reported it on mythtv-users¹. Reverting commit 59512d5e9dad1ca fixes the issue, but I don't know what else broke that that commit fixed.

¹http://lists.mythtv.org/pipermail/mythtv-users/2015-October/382147.html

comment:10 Changed 4 years ago by wpcprez@…

I have the same problem. When I was on the old 26.x version I did not have the subtitle issue but now all of my downloaded mp4+srt files have drift issues. When playing the same videos on a windows machine on VLC or something similar the timing is fine.

comment:11 Changed 4 years ago by jklaas@…

I've also noticed this recently.

The srt subtitles go out of sync when skipping. I've noticed the problem is worse on a file that is variable frame rate and 1920x1080. There's also a problem on 1280x720, but it's less pronounced. It's nonexistant on other smaller files (848x480, constant frame rate).

I've played the files using VLC on the same machine and had no issues with synchronization.

comment:12 Changed 4 years ago by Karl Egly

Owner: changed from JYA to Jim Stichnoth
Status: newassigned
Summary: Mythvideo subtitle timing problemexternal .srt subtitles go out of sync in some use cases since 59512d5e9d

The mailing list discussion suggests to convert the .avi+.srt or .mp4+.srt into a Matroska file with a subtitle track as work around.

Jim, can you see how your commit causes such behavior?

comment:13 Changed 4 years ago by Karl Egly

Milestone: 0.27.60.27.7

Reschedule all tickets planned for, but not solved in time for, 0.27.6 to 0.27.7.

comment:14 Changed 4 years ago by wpcprez@…

Hello, I was wondering if this was fixed in 0.28? ismota or jklaas notice this? I haven't upgraded yet so I can't confirm either way.

comment:15 Changed 4 years ago by ismota@…

I can't tell as I am still on 0.27+fixes.

comment:16 in reply to:  14 Changed 4 years ago by s2.kira@…

Replying to wpcprez@…:

Hello, I was wondering if this was fixed in 0.28? ismota or jklaas notice this? I haven't upgraded yet so I can't confirm either way.

still broken on 0.28 fixes

comment:17 Changed 2 years ago by warpme@…

Well - it looks like GetSecondsPlayed?(false, 1); not delivers properly. Switch to GetDecoder?()->NormalizeVideoTimecode? solves problem albeit this is just workaround. patch attached...

Changed 2 years ago by warpme@…

workaround for .srt de-sync after seeks

comment:18 Changed 2 years ago by Peter Bennett

I tested this with an avi video with srt subtitles, skip 12 minutes in. Without the patch, the subtitles are way out of sync. With the patch they are in perfect sync.

comment:19 Changed 2 years ago by Peter Bennett

Owner: changed from Jim Stichnoth to Peter Bennett
Status: assignedaccepted

comment:20 Changed 2 years ago by Peter Bennett

Milestone: 0.27.730.0

comment:21 Changed 2 years ago by Peter Bennett <pbennett@…>

Resolution: fixed
Status: acceptedclosed

In 4465108861aa8bb8c93c42261ae591481516bcf1/mythtv:

Subtitles: Revert change that caused srt subtitles to be unsynchronized

Revert the part of commit 59512d5e9d that changes the way srt timings
are calculated. They work better using the original method.

Fixes #12396

comment:22 Changed 21 months ago by Peter Bennett

Owner: changed from Peter Bennett to Peter Bennett
Note: See TracTickets for help on using tickets.