This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

[Not Hybrid related] MPEG-TS files with corrupt timestamps
#1
Hello!

I have many MPEG-TS files that might contain corrupt timestamps. Meaning while I play the MPEG-TS file using MPC-HC or the PVR, the file plays through fine, but with simple audio and video bugs. If I try to re-encode the file using FFmpeg, Hybrid or tsMuxeR, I don't get any of the previous audio and video bugs, but rather the audio slowly goes out of sync from the video.

Avidemux is the only tool that converts it correctly to mkv, but doesn't allow me to deinterlace the file.

Is there any solution or FFmpeg command I can try and apply to keep the audio and video in sync?

Here is a part of the TS file: https://drive.google.com/file/d/1hVzWIre...1B0ln/view
Reply
#2
Moved the thread to the 'A/V Talk' section since it's not Hybrid related.

In general:
a. you should try remuxing the file with mkvtoolnix (it has some workarounds for some transportstream glitches)
b. you could try Cypheros TS-Doctor or similar tools to fix the file
c. ffmpeg and VLC usually can only help if there are just some slight problems with the headers

Will look at the file today after work.

Cu Selur
Reply
#3
What I tried:
a. remux with timecodes using Hybrid
Hybrid:
  • Config->Automation->On Load->Always extract timecodes from input + 'only some' disabled.
  • Loading the source. -> "Time codes from input do not indicate 'vfr' and will therefore be ignored."
  • Audio&Video processing set to Passthrough, using mkv as output
ended up with a file that does not contain any video. :/
Using mp4 I got a not playing file with audio&video in it.

b. simple ffmpeg remux:
ffmpeg -y -threads 8 -analyzeduration 200M -probesize 200M -i "C:\Users\Selur\Desktop\syncproblems_sample.ts" -codec copy -map_metadata -1 "E:\Output\ffmpeg.mkv"
No errors, no a/v sync. (the "-map_metadata -1" might be unnecessary)
Remuxing the above file with Hybrid and the output is sync too.

-> a simple remux with ffmpeg already seems to fix the issues. Smile

Cu Selur

Ps.: btw. that video isn't really interlaced seems to be a mix of progressive and field shifted content. Loading the remuxed file and using 'Overwrite scan type to' 'progressive' and using 'Frame->Misc->TFM' seems to get rid of all the combing artifacts in the scenes that are not progressive. Smile
Reply
#4
(30.08.2021, 05:55)Selur Wrote: Moved the thread to the 'A/V Talk' section since it's not Hybrid related.

Understandable. Sorry for the wrong subforum.

(30.08.2021, 05:55)Selur Wrote: In general:
a. you should try remuxing the file with mkvtoolnix (it has some workarounds for some transportstream glitches)
b. you could try Cypheros TS-Doctor or similar tools to fix the file
c. ffmpeg and VLC usually can only help if there are just some slight problems with the headers

Will look at the file today after work.

a. Tried, same as normal Hybrid or FFmpeg. Forgot to mention in the original message.
b. Did not try. I know the program, I don't seem to be able to get around it very well.
c. Makes sense.

(30.08.2021, 15:20)Selur Wrote: What I tried:
a. remux with timecodes using Hybrid
Hybrid:
  • Config->Automation->On Load->Always extract timecodes from input + 'only some' disabled.
  • Loading the source. -> "Time codes from input do not indicate 'vfr' and will therefore be ignored."
  • Audio&Video processing set to Passthrough, using mkv as output
ended up with a file that does not contain any video. :/
Using mp4 I got a not playing file with audio&video in it.

Tried that too myself. Same results.

(30.08.2021, 15:20)Selur Wrote: b. simple ffmpeg remux:
ffmpeg -y -threads 8 -analyzeduration 200M -probesize 200M -i "C:\Users\Selur\Desktop\syncproblems_sample.ts" -codec copy -map_metadata -1 "E:\Output\ffmpeg.mkv"
No errors, no a/v sync. (the "-map_metadata -1" might be unnecessary)
Remuxing the above file with Hybrid and the output is sync too.

-> a simple remux with ffmpeg already seems to fix the issues. Smile

Then I really overcomplicated it.
How come Hybrid can't remux it this way?

I see one problem with this: it sets the overall framerate to 50 FPS, variable, which is incorrect. If I load the source in Hybrid and try and Bob it, it exports a 100 FPS file.
While remuxing, it seems like FFmpeg ignores the "-r" flag.

Commands I tried to use:
ffmpeg -i d:\sample.ts -c copy d:\thing.mp4
Exports variable 50 FPS file, but timestamps seem ok.

ffmpeg -r 25 -i d:\sample.ts -c copy d:\thing.mp4
Exports variable 50 FPS file again.

(30.08.2021, 15:20)Selur Wrote: Ps.: btw. that video isn't really interlaced seems to be a mix of progressive and field shifted content. Loading the remuxed file and using 'Overwrite scan type to' 'progressive' and using 'Frame->Misc->TFM' seems to get rid of all the combing artifacts in the scenes that are not progressive. Smile

Interesting, but Hybrid exports a 100 FPS file for me, in this case.

I guess I'll just export & deinterlace them using FFmpeg.

Update: thie file still doesn't have proper timestamps. I get this error in FFmpeg after trying to deinterlace the remuxed file.
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0]

Command used:
ffmpeg -c:v h264_cuvid -deint 2 -i "d:\sample.mp4" -c:v libx264 -profile:v high -preset veryfast -crf 18 -x264opts "keyint=500" -c:a copy "d:\sample.mkv"
Reply
#5
Quote:How come Hybrid can't remux it this way?
Hybrid does extract the audio and video separately and not in one good.
Which isn't a problem if the source hasn't any defects, but can cause problem on damaged content.
(No Hybrid can't simply add this dehaviour, since it would require to rewrite tons of code.)

Quote:While remuxing, it seems like FFmpeg ignores the "-r" flag.
Probably since you only used it as input option.
Instead of:
ffmpeg -r 25 -i d:\sample.ts -c copy d:\thing.mp4
try:
ffmpeg -i d:\sample.ts -c copy -r 25 d:\thing.mp4
(adding "-fflags +genpts -r 25" before the '-i ' might also help)

Quote:Interesting, but Hybrid exports a 100 FPS file for me, in this case.

I guess I'll just export & deinterlace them using FFmpeg.
you could also use "Filtering->SpeedChange->Change speed" to tell Hybrid to change the fps flag on the output.

Quote:Update: thie file still doesn't have proper timestamps. I get this error in FFmpeg after trying to deinterlace the remuxed file.
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0]

Command used:
ffmpeg -c:v h264_cuvid -deint 2 -i "d:\sample.mp4" -c:v libx264 -profile:v high -preset veryfast -crf 18 -x264opts "keyint=500" -c:a copy "d:\sample.mkv"

try with "-fflags +genpts -r 25" before the ' -i ':
ffmpeg -c:v h264_cuvid -deint 2 -fflags +genpts -r 25 -i "d:\sample.mp4" -c:v libx264 -profile:v high -preset veryfast -crf 18 -x264opts "keyint=500" -c:a copy "d:\sample.mkv"
this should tell ffmpeg to recalculate the input time stamps.

Cu Selur
Reply
#6
(30.08.2021, 17:35)Selur Wrote: Hybrid does extract the audio and video separately and not in one good.
Which isn't a problem if the source hasn't any defects, but can cause problem on damaged content.
(No Hybrid can't simply add this dehaviour, since it would require to rewrite tons of code.)

I understand.

(30.08.2021, 17:35)Selur Wrote: try with "-fflags +genpts -r 25" before the ' -i ':
ffmpeg -c:v h264_cuvid -deint 2 -fflags +genpts -r 25 -i "d:\sample.mp4" -c:v libx264 -profile:v high -preset veryfast -crf 18 -x264opts "keyint=500" -c:a copy "d:\sample.mkv"
this should tell ffmpeg to recalculate the input time stamps.

I think this works fine. I'll update once I have the full file, just to be sure no desync appears.

As for the "-r" option, that only seems to not be ignored if I'm outputting to an mkv file.

EDIT: Actually, the "-r 25" should not be applied to cuvid, since it will output a 25 FPS bobbed video, which is not ok. "-r 50" is the solution there, but I think it's better if I take it step by step: first remux with "-r 25", then deinterlace with "-r 50". I will try doing it from one go, only using "-r 50", as that will be quicker; and I'll let you know if that works as well.
Reply
#7
No, it doesn't work. Avidemux still reports the mkv file as having corrupt timestamps when trying to convert to mp4.
Also, the audio slowly goes out of sync if re-encoded with cuvid & libx264.
Reply
#8
Quote:No, it doesn't work. Avidemux still reports the mkv file as having corrupt timestamps when trying to convert to mp4.
Even if you tell ffmpeg to generate new time codes (-fflags +genpts)?
The fps isn't really an issue and can be changed during reencoding.
If generating new time codes still doesn't help then using som repair software like TS Doctor or similar software.

Cu Selur
Reply
#9
It actually seems to work, but only if the output container is mp4. With mkv, +genpts is ignored.

It also seems to work all in one go, with the resulting mp4 file being 50 FPS constant, deinterlaced, in sync and valid timestamps - Avidemux doesn't complain anymore. I'll reupdate once I have the full file deinterlaced, as the sync issues can still appear later in the video.

Command used:
ffmpeg -c:v h264_cuvid -deint 2 -fflags +genpts -r 50 -i "d:\original.ts" -c:v libx264 -profile:v high -preset veryfast -crf 18 -x264opts "keyint=500" -c:a copy "d:\original.mp4"
Reply
#10
It works, but only if done step by step: first - a simple remux; command I used:
ffmpeg -fflags +genpts -i "d:\original.ts" -c copy "d:\original.mp4"

This will create a 50 FPS file, with fixed timestamps.
Then, a re-encode:

ffmpeg -c:v h264_cuvid -deint 2 -i "d:\original.mp4" -c:v libx264 -profile:v high -preset veryfast -crf 18 -x264opts "keyint=500" -r 50 -c:a copy "d:\original1.mp4"

This will output a constant 50 FPS file, deinterlaced, with audio in sync with video.



I'm going to try and find a command that tells FFmpeg to do both of these things in one go.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)