Lip sync for BBC encodes from HD channels

Support forum for DGDecNV
Post Reply
DAE avatar
BarryW
Posts: 56
Joined: Fri Mar 18, 2011 7:50 pm

Lip sync for BBC encodes from HD channels

Post by BarryW »

The BBC changed their HD encoders again on 14th Nov 2013.
DGIndexNV 2046 now decodes the wrong audio offset.

Here's a sample:
38 second sample of Byzantium A Tale of Three Cities part 2 from BBC 4 HD (19MB)
https://db.tt/MXIzTTG7

To correct the lip sync you need to subtract about 360ms from the audio offset given by DGIndexNV.
When running the sample through DGIndexNV you'll get an offset of -1015ms.
This needs correcting to about -655ms.
I can supply more samples if you need any.

The BBC have also reduced the number of 'I' frames broadcast to reduce bitrate further.
It's not unusual to have a 60 second time gap between 'I' frames these days.
The sample above is edited between 2 'I' frames 38 seconds apart.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Lip sync for BBC encodes from HD channels

Post by admin »

I just made a slipstreamed fix to DGIndexNV that may affect this. Can you re-test it please?
DAE avatar
BarryW
Posts: 56
Joined: Fri Mar 18, 2011 7:50 pm

Re: Lip sync for BBC encodes from HD channels

Post by BarryW »

I'll check tonight.

For 6 channel audio (from HD channels of BBC channels) the correction seems to be about +60ms to +80ms compared to -360ms.
I suspect they're offseting the video w.r.t the PCR clock.

The biggest 'I' frame gap so far has been 17 minutes 43 seconds long in a news programme which contained scene changes.
It took TS Packet Editor a few minutes to find the 'I' frame.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Lip sync for BBC encodes from HD channels

Post by admin »

OK, thank you. If there is still an issue let me know and I'll look into it. Of course, a stream will be needed.
DAE avatar
BarryW
Posts: 56
Joined: Fri Mar 18, 2011 7:50 pm

Re: Lip sync for BBC encodes from HD channels

Post by BarryW »

Yes, that seems to have fixed it.

Here's a 40 second sample (25MB)
https://db.tt/nL0f1VVe

The old version of 2046 gives an audio offset of -1289ms which needed correcting by +360ms to give -929ms.
The new version of 2046 gives an audio offset of -1129ms (a difference of 160ms) but it appears to work ok.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Lip sync for BBC encodes from HD channels

Post by admin »

OK, thanks, good to hear. I'll have a look at your stream anyway to confirm it on my side.

EDIT: Yup, looks fine now. Thanks for the original report and update.
User avatar
clumpco
Posts: 17
Joined: Sat Sep 25, 2010 7:57 am

Re: [RESOLVED] Lip sync for BBC encodes from HD channels

Post by clumpco »

Just to chime in thatI have been suffering from this BBC HD lip sync problem too for quite some time now.
My workflow starts with an edit via Video-Redo so I don't seem to be getting the same delay. However if DGDecNV gives me a positive delay, I know that I have to add approx 148ms to it to get it reight, if the delay is negative (very often -192 ms) the I need to invert it, eg use +192 ms instead.

As I have on ly just found this thread I shall have to go and test the new version. Will keep you posted.

[UPDATE] Several encodes later I can confirm that the problem is nicely fixed. All HD soundtracks so far have come out with O delay and perfectly in sync.
DAE avatar
BarryW
Posts: 56
Joined: Fri Mar 18, 2011 7:50 pm

Re: [RESOLVED] Lip sync for BBC encodes from HD channels

Post by BarryW »

The only problem I've had is with 6 channel audio from HD channels from the BBC. Because the nearest 'I' frame is about 30 seconds before the start of the programme the audio is 2 channel upto where the programme starts and then switches to 6 channel. DGIndexNV decodes only 2 channel audio and mixes the 6 channel into 2 channel. The next 'I' could be 2 or 3 seconds after the start of the programme. So the only solution I've come up with is to edit as near to the start as possible (to allow DGIndexNV to decode the 6 channel) but the video frames are in random order between the 'I' frames. Then adjust the TRIM start value in the AVS script with the avsPmod utility to start at a stable position and adjust the audio with Audacity.

It's best to edit a short section of video from the start so that the audio can be viewed in Audacity to see the audio offset needed to correct tracks 3,4,5,6 - to bring them into sync with tracks 1 and 2. Then apply this correction to tracks 3,4,5,6 in the actual full audio file with Audacity.
DAE avatar
Nick007
Posts: 38
Joined: Wed Sep 29, 2010 12:20 pm

Re: [RESOLVED] Lip sync for BBC encodes from HD channels

Post by Nick007 »

Or you can demux with eac3to, run it through delaycut to find the place where it switches in miliseconds, then with eac3to apply that as negative delay and again as positive delay to strip the 2ch beginning.
DAE avatar
Ajidamal
Posts: 5
Joined: Wed Apr 27, 2011 6:48 pm

Re: [RESOLVED] Lip sync for BBC encodes from HD channels

Post by Ajidamal »

If I may stick my oar in as well, I've noticed some strange behaviour with the latest revision of v2046. To demonstrate, the following is a sample recording which contains a BBC ident leading into a few seconds of a weather forecast.

http://www.mediafire.com/download/6gal6 ... ample.m2ts

If I open the above TS in DGIndexNV, set the project range to start at the first I-frame of Weatherview, then index/demux, I get the following files:
  • sample PID 1519 2_0ch 48KHz 192Kbps DELAY 5314ms.ac3
  • sample PID 151a L2 2ch 48 256 DELAY 5382ms.mp2
where for both audio tracks, the calculated delay is completely wrong. However, if I set the project range as before, but instead of indexing, I save to a second TS, load that TS into DGIndexNV and index/demux from the start, I obtain:
  • sample PID 1519 2_0ch 48KHz 192Kbps DELAY -1125ms.ac3
  • sample PID 151a L2 2ch 48 256 DELAY -1057ms.mp2
with correct audio delays. This seems a bit odd... presume it's a bug?
DAE avatar
BarryW
Posts: 56
Joined: Fri Mar 18, 2011 7:50 pm

Re: [RESOLVED] Lip sync for BBC encodes from HD channels

Post by BarryW »

I get these numbers when decoding sample.m2ts from the start when using the latest v2046
sample PID 1519 2_0ch 48KHz 192Kbps DELAY -965ms.ac3
sample PID 151a L2 2ch 48 256 DELAY -897ms.mp2

I use TRIM(StartValue,EndValue) in the avs script along with avsPmod to find the start and end positions and then correct the audio in Audacity.
For 25fps the audio to remove at the start is StartValue*40-(AudioOffset)

The start position for sample.m2ts is frame 161 so the audio to remove from the AC3 file is:
161*40+965 = 7405 ms

I picked an artificial EndVaue frame position of 490
So the number of video frames = 490-161+1 = 330 frames which corresponds to 330/25 = 13.2 seconds.
Convert the run-time into AC3 audio packets 13.2*1000/32 = 412.5 and throw away the fraction giving 412 audio packets
Then convert the audio packets back into seconds 412*32/1000 = 13.184 seconds
Then remove audio from the end of the file starting at 13.183 (1ms below the calculated value).

The reason for the 1ms is because if you try to be too accurate you'll finish up with another 32ms AC3 packet. It's best to be slightly under. The Audacity Fade-In, Fade-Out, Normalise and Amplify functions come in useful.
Normalise is useful for reduce the audio level of the announcer at the end of a programme to match the same level as the programme.
Amplify is useful to bring the audio level up of the whole file - usually +6 to +7dB - and you can apply the same amplification to all episodes of a series.

When saving the audio file in Audacity make sure you change the audio delay in the filename to 0ms.
You could save as WAV or you can use the same codec as the source with the same bitrate.
DAE avatar
Ajidamal
Posts: 5
Joined: Wed Apr 27, 2011 6:48 pm

Re: [RESOLVED] Lip sync for BBC encodes from HD channels

Post by Ajidamal »

Very useful tips, thanks. As described in the process above, calculating the delay and cutting manually is what I've taken to doing in the last few weeks (only using delaycut rather than Audacity).

I forgot to mention in my previous post that v2046 seems to be calculating the delay incorrectly for all HD programmes I record, not just those from BBC channels - where the project range is set to start at a point after the beginning of the TS, that is. Trying it out on a programme from Channel 4 HD the other day, it reported the delay as ~15,000ms! Anyhow, as v2045 worked for non-BBC transport streams, I've downgraded for the time being.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: [RESOLVED] Lip sync for BBC encodes from HD channels

Post by admin »

I'll take a look at all this again after I finish a first release of DGMVCSource. There are some heuristics involved that can be better. Removing [RESOLVED] on this thread.
DAE avatar
BarryW
Posts: 56
Joined: Fri Mar 18, 2011 7:50 pm

Re: Lip sync for BBC encodes from HD channels

Post by BarryW »

Ajidamal

The problem might be caused by the video editor your using.
VideoReDo tries to correct the audio by bringing it into sync with the video - it tries to reduce the audio offset to 0ms.
TS Packet Editor has a similar feature called Timecode correction but you'll still finish up with a small audio offset of say -100ms.
I find it's best not to have any correction applied - I apply the correction in Audacity and bring the audio offset back to 0ms there.

The new BBC encoders on HD channels now only broadcast 'I' frames when they're needed.
This means the nearest 'I' frame is usually 20000ms to 30000ms before the start of a programme.
In Audacity you'll probably need to have 2 goes at removing the audio from the start - one large value and one small value.
If you need to remove say 20000ms and the nearest value you can get to is 19986ms then remove the 19986ms first and then remove another 14ms from the start to make 20000ms.
Then remove the spare audio from the end (-1ms) and export the file with "DELAY 0ms" in the filename using the AC3 codec and the same bitrate.
If the source audio is MP2 and the audio has been edited then still use AC3 as the output audio codec.
If the source audio is MP2 but not edited (only Normalise/Amplify/Fade-in/Fade-out was used) then you can save the output audio using the MP2 codec if you want to.

Then optionally convert the high bitrate AC3 or MP2 into a lower bitrate AAC-LC or HE-AAC.

Channel 4 HD is another exception - their audio has always been 100ms to 120ms out of sync in the past with previous versions of DGIndexNV requiring an extra correction in Audacity. I've read that Sky HD channels have had a similar error in the past. I'll do some tests with Channel 4 HD source and report back.
DAE avatar
Ajidamal
Posts: 5
Joined: Wed Apr 27, 2011 6:48 pm

Re: Lip sync for BBC encodes from HD channels

Post by Ajidamal »

Thanks for the tips once again, BarryW - the transport streams I've been running through DGIndexNV are straight from my PVR, however, and haven't been processed by any video editor.

The reason I avoid Audacity and use delaycut for the cutting/delay correction is that I record a fair number of music programmes, so I'm very keen to retain the original audio tracks where possible. Any residual delay of up to +/- 12/16 ms (half an MP2/AC3 frame resp.) is unnoticeable IMHO, but could be corrected completely by applying a small delay in the output container.

Regarding the distribution of I-frames within BBC HD streams, I haven't seen any difference of late; they still appear to be roughly 1-2 seconds apart (as in the posted sample). IDR-frames seem less frequent these days though.

It's also my understanding that DGIndexNV (as other video previewers/editors) can only seek to IDR-/I-frames, so if they were much further apart, surely this would make it practically impossible to navigate visually through a TS? Also, wouldn't you have to wait for minutes on end before you could start watching the TV? :D

@admin: Thanks for the reply - first I've heard of DGMVCSource, so good luck with the project. Also thanks for all your ongoing work on DGDecNV. :)
DAE avatar
BarryW
Posts: 56
Joined: Fri Mar 18, 2011 7:50 pm

Re: Lip sync for BBC encodes from HD channels

Post by BarryW »

All seems ok with the new v2046 with HD streams from BBC channels and Ch4. I've not seen any lip sync issues since the new version.
I used to apply an extra 100ms audio offset correction to Ch4 HD source but that doesn't seem to be needed any longer.
Post Reply