concat a/v desync (only in MPC-HC)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

concat a/v desync (only in MPC-HC)

Basin Ilya
Hi List. I asked this on stackexchange, but never got an answer. ( https://video.stackexchange.com/q/33173/11453 )

I'm concatenating .ts chunks intended for an HLS player into a single .mp4 video. These chunks possess same stream properties, however, some chunks have audio stream shorter than video stream and in that case the resulting clip has audio artifacts when playing in Media Player Classic (MPC-HC).



Workaround: demux video and audio streams into separate .m4a and .m4v files, concatenate them and then mux again.

Goal: create single clips from .ts chunks *without intermediate files*

Please help me find proper ffmpeg flags.

I have created sample chunks (this repo) <https://github.com/basinilya/ffconcat-question> out of a freeware cartoon to demonstrate the problem. he chunk |516-x.ts| has audio stream 50ms shorter than video and in |517-x.ts| it's longer.

Download: https://github.com/basinilya/ffconcat-question/archive/master.zip <https://github.com/basinilya/ffconcat-question/archive/master.zip>

    ffmpeg -y -i playlist-x.ffconcat -c copy result.mp4

The created `result.mp4` is played fine in `ffplay` or Windows Media Player, but there's a short silence in MPC-HC in the second half of the clip.

Workaround script:

    ffmpeg -y -i 516-x.ts -an -c:v copy 516-x.m4v
    ffmpeg -y -i 516-x.ts -vn -c:a copy 516-x.m4a
   
    ffmpeg -y -i 517-x.ts -an -c:v copy 517-x.m4v
    ffmpeg -y -i 517-x.ts -vn -c:a copy 517-x.m4a
   
    ffmpeg -y -i playlist-x-a.ffconcat -c copy result.m4a
   
    ffmpeg -y -i playlist-x-v.ffconcat -c copy result.m4v
   
    ffmpeg -y -i result.m4v -i result.m4a -c copy result-good.mp4

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: concat a/v desync (only in MPC-HC)

Carl Eugen Hoyos-2


> Am 02.02.2021 um 20:09 schrieb [hidden email]:
>
> I'm concatenating .ts chunks intended for an HLS player into a single .mp4 video.

You should instead concatenate all ts chunks into a single transport stream:
$ cat 1.ts 2.ts 3.ts > out.ts

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: concat a/v desync (only in MPC-HC)

Carl Eugen Hoyos-2
Am Di., 2. Feb. 2021 um 22:18 Uhr schrieb Carl Eugen Hoyos <[hidden email]>:
>
> > Am 02.02.2021 um 20:09 schrieb [hidden email]:
> >
> > I'm concatenating .ts chunks intended for an HLS player into a single .mp4 video.
>
> You should instead concatenate all ts chunks into a single transport stream:
> $ cat 1.ts 2.ts 3.ts > out.ts

Or use the concat protocol instead of the concat demuxer.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: concat a/v desync (only in MPC-HC)

Basin Ilya
I tried both `cat` and `-i "concat..."`, but they produce the same artifact in MPC-HC.

I guess the audio PTS from the second chunk is adjusted relative to the video duration of the first chunk.

On 03.02.2021 1:05, Carl Eugen Hoyos wrote:

> Am Di., 2. Feb. 2021 um 22:18 Uhr schrieb Carl Eugen Hoyos <[hidden email]>:
>>> Am 02.02.2021 um 20:09 schrieb [hidden email]:
>>>
>>> I'm concatenating .ts chunks intended for an HLS player into a single .mp4 video.
>> You should instead concatenate all ts chunks into a single transport stream:
>> $ cat 1.ts 2.ts 3.ts > out.ts
> Or use the concat protocol instead of the concat demuxer.
>
> Carl Eugen
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: concat a/v desync (only in MPC-HC)

Basin Ilya
I was wrong. `cat` and "concat:" help to solve the problem with real world videos.

Looks like ffmpeg can detect sudden resets of the PTS. I mean, if we concatenate two .ts files and both have STARTPTS=0 then ffmpeg will begin adding a certain number to the PTS in the remaining frames. This number seems to be the same for both video and audio even though the stream durations differ.

However, if subsequent .ts files have STARTPTS where the previous .ts file ended then ffmpeg will not adjust PTS in them.

In my sample second chunk STARTPTS=0, but in real world videos they are continuous. Actually, I don't know how to split a video into .ts chunks with continuous PTS.

On 04.02.2021 10:26, [hidden email] wrote:

>
> I tried both `cat` and `-i "concat..."`, but they produce the same artifact in MPC-HC.
>
> I guess the audio PTS from the second chunk is adjusted relative to the video duration of the first chunk.
>
> On 03.02.2021 1:05, Carl Eugen Hoyos wrote:
>> Am Di., 2. Feb. 2021 um 22:18 Uhr schrieb Carl Eugen Hoyos <[hidden email]>:
>>>> Am 02.02.2021 um 20:09 schrieb [hidden email]:
>>>>
>>>> I'm concatenating .ts chunks intended for an HLS player into a single .mp4 video.
>>> You should instead concatenate all ts chunks into a single transport stream:
>>> $ cat 1.ts 2.ts 3.ts > out.ts
>> Or use the concat protocol instead of the concat demuxer.
>>
>> Carl Eugen
>> _______________________________________________
>> ffmpeg-user mailing list
>> [hidden email]
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>
>> To unsubscribe, visit link above, or email
>> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".