D
D
DWZ2019-10-21 10:54:00
Video
DWZ, 2019-10-21 10:54:00

How to remux TS -> MP4 ignoring timings by hard-coded framerate?

Required under Windows to repack without losing the quality of video and sound from TS to MP4.
The task, at first glance, is trivial. But there is one big BUT .
For some reason beyond my control, the correct delta of the PCR / PTS / DTS increment between frames is violated in the input TS file, the remixers react to this mess and as a result, instead of this, it
5dad5c1b69b5d822823322.png
turns out something like this game, the
5dad5c43d0655524309369.png
players react to it
5dad5c63861ea772806346.png
and play accordingly. Frame-by-frame positioning is also broken. The TS-file itself plays normally, even if you grab the video from the player window :((((.
Is there such a magical remixer under Windows that would simply stupidly go through frames from the input TS and dump them frame by frame into the output MP4, putting values ​​in stts and ctts based on the delta that I hard-coded (40 milliseconds for 25 fps and 20 milliseconds for 50 fps interlaced.If mdhd has the standard TimeScale=90000, then these will be 3600 and 1800 respectively). Naturally, the correct order of B-frames must be maintained.
Well, or some magic keys for the standard ones? I tried ffmpeg, VLC PLayer, mp4box, Virtual Dub ;). The -fps switch for ffmpeg and mp4box does not help. Mp4box coped well, but it glitches in case of a PTS or PCR transition through 0. I tried to remove the transition through 0 using TS_Doctor, but instead of some glitches, others appear. The file corrected by TS_Doctor also plays normally.
You can, of course, "brush" the input TS before or the output MP4 after the remix, but I would like to get everything in one pass. In my opinion, the operation is not difficult for someone who works deeply with such files.
For clarity, I will repeat once again. I do NOT need to change the frame rate, I do NOT need to change the constant fps to a variable, I do NOT need to make the variable fps constant.
I just want the remixer to be smart and have the same frame rate in the output MP4 that was originally meant in the input TS.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DWZ, 2019-10-24
@DWZ

In short, split it into streams and remux it back.

ffmpeg -i source.mp4 -map 0:v -vcodec copy -bsf:v h264_mp4toannexb source-video.h264 -acodec copy -bsf:a aac_adtstoasc output.aac

ffmpeg -fflags +genpts -r 25 -i source-video.h264 -i output.aac -с copy output.mp4

After "-r" substitute your frame rate. See How to recover RAW h.264 and AAC timecodes without transcoding for details?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question