Opened 6 years ago

Closed 5 years ago

#12054 closed Bug Report - General (Fixed)

Local commercials confuse CEA-608 caption decoding

Reported by: faginbagin <mythtv@…> Owned by: Jim Stichnoth
Priority: minor Milestone: 0.27.5
Component: MythTV - Captions Version: 0.27-fixes
Severity: medium Keywords:
Cc: Ticket locked: no

Description

There's something about the way WOW inserts local commercials that effectively disables display of CEA-608 captions. When it happens, I can get the captions to display by stopping (with set bookmark on exit enabled) and resuming playback. I am attaching cc608-disappears.mpg, a one minute video clip that demonstrates the problem. To reproduce:

  • Put cc608-disappears.mpg in your video library.
  • Scan for changes
  • Generate filemarkup with: mythcommflag --video cc608-disappears.mpg
  • Play cc608-disappears.mpg.
  • Turn on closed captions. You can see the transition from end of the Gold Bond commercial is abrupt and goes to the last second of what I presume is a commercial provided by Comedy Central and replaced by WOW. This is followed by The Daily Show where you should see roll-up captions lagging a couple of seconds behind Jon Stewart introducing Jon Hamm, but none are displayed.
  • Back up to about the 17 second point, where The Daily Show resumes from the commercial break. Set a bookmark and exit.
  • Play the video from the bookmark.
  • Turn on closed captions. You should now see the roll-up captions.
  • Seek to the beginning of the video and resume playback. No captions are displayed.

Attachments (1)

scte.patch (2.5 KB) - added by Jim Stichnoth 5 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 5 years ago by Jim Stichnoth

Milestone: unknown0.27.4
Status: newinfoneeded_new

It doesn't look like the attachment made it. Can you try attaching again, or upload it somewhere else?

BTW, you can also attach the markup file after extracting it via "mythutil --getmarkup", though it probably doesn't matter for this case.

comment:2 Changed 5 years ago by faginbagin <mythtv@…>

Sorry about that. I had put it on my web server but failed to add a comment so you knew where to get it. Here it is: http://www.hbuus.com/~buus/cc608-disappears.mpg If you have trouble getting it from here, let me know where you'd like me to put it.

comment:3 Changed 5 years ago by Jim Stichnoth

Thanks, I downloaded the sample, but unfortunately MythTV master doesn't recognize any captions, though ccextractor finds them. I'll have to track down whether e.g. an ffmpeg sync caused a regression.

comment:4 Changed 5 years ago by Jim Stichnoth

So, I am having a hard time finding a recent version of MythTV that will display any captions at all from this sample. In particular, running the command:

mythccextractor -i cc608-disappears.mpg --nologserver -v vbi --loglevel debug

should produce a corresponding .srt file with captions, and/or print logs containing the expected caption characters.

Does mythccextractor do this correctly on your system, and if so, what version / git hash are you using? (Actually, regardless of mythccextractor, what git hash are you running? mythfrontend --version output)

For the record, this lack of captions seems to come from AVFD code that tries to decide whether to use ATSC or SCTE caption data, preferring ATSC if any is available, whereas in this sample, both are present but SCTE is the useful data. This hack manages to bring out the captions:

diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index 64325f8..853b306 100644
--- a/mythtv/libs/libmythtv/avformatdecoder.cpp
+++ b/mythtv/libs/libmythtv/avformatdecoder.cpp
@@ -3625,6 +3625,7 @@ bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic)
     uint8_t *cc_buf = mpa_pic->scte_cc_buf;
     bool scte = true;
 
+#if 0
     // If both ATSC and SCTE caption data are available, prefer ATSC
     if ((mpa_pic->atsc_cc_len > 0) || ignore_scte)
     {
@@ -3633,6 +3634,7 @@ bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic)
         cc_buf = mpa_pic->atsc_cc_buf;
         scte = false;
     }
+#endif
 
     // Decode CEA-608 and CEA-708 captions
     for (uint i = 0; i < cc_len; i += ((cc_buf[i] & 0x1f) * 3) + 2)

Going back to the original problem in the ticket description. This sounds reminiscent of #7861, where a broken caption timecode causes subsequent caption commands to be ignored, until a seek operation resets the caption state and captions start working again (at least until the next broken timecode).

After captions become disabled, if you seek forward or backward within the "good" caption region, do captions come back?

comment:5 Changed 5 years ago by faginbagin <mythtv@…>

I get the same result as you when I run mythccextractor. I am using mythtv packages from ubuntu. Here's the output from mythfrontend --version:

Please attach all output as a file in bug reports.
MythTV Version : v0.27.3-6-gfba8e80
MythTV Branch : fixes/0.27
Network Protocol : 77
Library API : 0.27.20140702-1
QT Version : 4.8.4
Options compiled in:
 linux profile use_hidesyms using_alsa using_oss using_pulse using_pulseoutput using_backend using_bindings_perl using_bindings_python using_bindings_php using_crystalhd using_dvb using_firewire using_frontend using_hdhomerun using_ceton using_hdpvr using_ivtv using_joystick_menu using_libcec using_libcrypto using_libdns_sd using_libfftw3 using_libxml2 using_lirc using_mheg using_opengl using_opengl_video using_qtwebkit using_qtscript using_qtdbus using_sdl using_taglib using_v4l2 using_x11 using_xrandr using_xv using_profiletype using_bindings_perl using_bindings_python using_bindings_php using_mythtranscode using_opengl using_vaapi using_vdpau using_ffmpeg_threads using_mheg using_libass using_libxml2

However, if I strip off the leading commercial from the clip using:

dd if=cc608-disappears.mpg of=temp.mpg bs=7828320 skip=1

Then, mythccextractor can extract the captions from temp.mpg. And the log output is roughly double what it was for the original cc608-disappears.mpg

Could it be that the commercial has ATSC caption data, but the actual program doesn't and that's what's confusing myth? Remember, I'm 99% sure the commercial was inserted by my local cable provider, WOW (aka Wide Open West), and was not part of the original stream provided by Comedy Central. Seeking doesn't fix things, only bookmarking, stopping and restarting playback from the bookmark gets the captions back. We have to do this with content recorded from other basic cable channels, too. And always after a commercial, but not after every commercial.

FWIW, we also see a possibly related problem on some PBSHD shows from the BBC where we turn on CCs and don't see any captions unless we use the menu to explicitly switch from ATSC to VBI. One in particular is "Death in Paradise" on Thursday nights at 9pm EDT. It's a crime drama with a sense of humor. If you're in the USA it would be interesting to know if your broadcast of this show has the same problem.

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

Replying to faginbagin <mythtv@…>:

FWIW, we also see a possibly related problem on some PBSHD shows from the BBC where we turn on CCs and don't see any captions unless we use the menu to explicitly switch from ATSC to VBI. One in particular is "Death in Paradise" on Thursday nights at 9pm EDT. It's a crime drama with a sense of humor. If you're in the USA it would be interesting to know if your broadcast of this show has the same problem.

Thanks for the tip. "Death in Paradise" recorded last night, and it has the problem where ccextractor produces good captions but MythTV fails to find any. I can start from there.

comment:7 Changed 5 years ago by paulh

Status: infoneeded_newnew

comment:8 Changed 5 years ago by Jim Stichnoth

OK, I think I got to the bottom of this. In #9829 and d526385aa4c1466b064e9544cdb663f357007e35, code was added such that the first time ATSC caption data is seen, any future SCTE caption data is explicitly ignored. (By the way, this was also thanks to WOW's encoding.) This is reasonable when the broadcaster duplicates caption data as both ATSC and SCTE, but not good when the broadcaster changes from one to the other every so often.

I attached a patch that lets the decoder go back to SCTE after it sees SCTE data 10 times in a row (approximately 10 frames, which I chose arbitrarily). It fixes the Jon Stewart sample.

Helen, could you try out the patch and check that (1) it works for these problematic recordings, and (2) it doesn't break anything else? It should apply to both master and fixes-0.27.

Changed 5 years ago by Jim Stichnoth

Attachment: scte.patch added

comment:9 Changed 5 years ago by faginbagin <mythtv@…>

Works for me. I've been playing content recorded from different channels and I'm seeing the problem is fixed by the patch and I'm not seeing any regressions.

comment:10 Changed 5 years ago by Jim Stichnoth <jstichnoth@…>

In 68bd03ffe5b7bb6456519639caac77486ea0941c/mythtv:

Subtitles: Allow transitions between ATSC and SCTE captions.

In changeset d526385aa4c1466b064e9544cdb663f357007e35 (refs #9829),
code was added such that the first time ATSC caption data is seen, any
future SCTE caption data is explicitly ignored. This was to deal with
broadcasts containing duplicate caption data.

This policy causes problems when the recording switches back and forth
between the two sources of caption data, such as when the broadcaster
splices in commercials.

The updated solution continues to favor ATSC data, but allows a switch
back to SCTE after SCTE data is seen 10 times in a row (a somewhat
arbitrarily chosen number) without intervening ATSC data.

Refs #12054.

comment:11 in reply to:  9 Changed 5 years ago by Jim Stichnoth

Milestone: 0.27.40.27.5
Status: newaccepted

Replying to faginbagin <mythtv@…>:

Works for me. I've been playing content recorded from different channels and I'm seeing the problem is fixed by the patch and I'm not seeing any regressions.

Thanks for testing. I'll backport to 0.27 after a few days assuming this doesn't cause unexpected problems.

comment:12 Changed 5 years ago by Jim Stichnoth <jstichnoth@…>

In bcdaa8865ef8700ccbb7214ec39dcbcd8392b2af/mythtv:

Subtitles: Allow transitions between ATSC and SCTE captions.

In changeset d526385aa4c1466b064e9544cdb663f357007e35 (refs #9829),
code was added such that the first time ATSC caption data is seen, any
future SCTE caption data is explicitly ignored. This was to deal with
broadcasts containing duplicate caption data.

This policy causes problems when the recording switches back and forth
between the two sources of caption data, such as when the broadcaster
splices in commercials.

The updated solution continues to favor ATSC data, but allows a switch
back to SCTE after SCTE data is seen 10 times in a row (a somewhat
arbitrarily chosen number) without intervening ATSC data.

Refs #12054.

(cherry picked from commit 68bd03ffe5b7bb6456519639caac77486ea0941c)

comment:13 Changed 5 years ago by Jim Stichnoth

Resolution: Fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.