[mythtv-users] FFMPeg Commercial cutting puts audio out of sync

John Finlay finlay at moeraki.com
Sat Sep 13 19:05:31 UTC 2014


On 9/13/2014 11:06 AM, Justin Alcorn wrote:
> On Sat, Sep 13, 2014 at 1:27 PM, Mike Perkins
> <mikep at randomtraveller.org.uk> wrote:
>> On 13/09/14 17:55, Justin Alcorn wrote:
>>> On Sat, Sep 13, 2014 at 5:21 AM, Mike Perkins
>>> <mikep at randomtraveller.org.uk> wrote:
>>>>> After hours of reading posts and playing with settings, I've cot a
>>>>> couple of theories.
>>>>>
>>>>> A) the video is cutting on 'key frames', not at exactly the time I say
>>>>> to cut, but the audio cuts at the exact mark
>>>>> B) The video being in variable bitrate throws off the cutting
>>>>>
>>>>> But I'm not sure how to solve either of these problems.
>>>>>
>>>> [snip]
>>>>>
>>>>>
>>>> The most obvious thing to say is that you should make sure your cuts are
>>>> all
>>>> on keyframes. This should reduce any difference between audio and video
>>>> to
>>>> the minimum.
>>>>
>>>> If you don't make cuts on keyframes then the video processor has to try
>>>> and
>>>> bridge data that really belongs to two different scenes and adjust
>>>> dynamically, which can look terrible on-screen. Keyframes is the way to
>>>> go.
>>>
>>>
>>> That fits with one of my theories so the question is - how do I get
>>> ffmpeg to cut at the keyframe closest to the time I specify?
>>>
>> I think that's more to do with how you specify the cuts.
>>
>> If you are just allowing the commercial-detecion program to do its thing
>> then you really ought to check it afterwards and make sure the edits fall at
>> keyframes.
>>
>> Otherwise, if you do it manually, then again, make sure you select keyframes
>> as cut points.
>>
>> To clarify, cutting at the end of a program segment you want to keep, you
>> can run /up to/ but not including the next keyframe (if suitable). That's
>> the natural way that the frames will arrive in any event. For the start of
>> any wanted segment, you really should begin it on a fresh keyframe to avoid
>> flicker and sound discrepancies.
>>
>>
>> --
>>
>> Mike Perkins
>>
<Fixed quoting>

> Sorry, but I'm going to need more basic help.
>
> I'm using the built-in commercial detection, so when my user job runs
> there's a cutlist.  I then edit in the mythtv frontend and fix the
> commercial detection, to get it right on the commercials.
>
> Does the original cutlist pay attention to key frames?  Are you saying
> I shouldn't change the cutlist?
>
> If I do need to change it, how to I tell ffmpeg to only cut at key frames?
>
> I'm missing something here.
> --
> Justin B. Alcorn
> PGP Fingerprint A36D D691 C5B0 BE15 5A2A AF49 AA1C 372C
>
>
ffmpeg will only cut at a keyframe (AFAIK) and will skip to the closest 
keyframe following the position you specify. Therefore to use the 
mythfronteend editor to specify cutpoints you'll have to specify 
keyframes as the cutpoints around commercials. Unfortunately, the 
keyframes may not line up with the start and end of commercials - this 
is what I experience with ATSC MPEG2 streams.

An additional problem with the mythfrontend editor is that it uses 
1-based counting of frames and ffmpeg uses 0-based so if you take the 
mythfrontend cutlist of keyframes and use it in ffmpeg you will find 
that ffmpeg will cut at the following keyframe the one specified. The 
workaround is to subtract 1 from every cutlist frame number.

I hacked together a python script as a lossless transcoding Job to use 
ffmpeg (mythffmpeg) to cut out commercials using the mythfrontend 
cutlist. It works for MPEG2 but I don't know about H264 but in theory it 
should work. Look at the ffmpeg segment muxer 
(https://www.ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment) 
for documentation.

John


More information about the mythtv-users mailing list