sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.76k stars 566 forks source link

Merge .ts files #317

Open duncanokeyo opened 6 years ago

duncanokeyo commented 6 years ago

Its it possible to concat .ts files without converting to mp4

sannies commented 6 years ago

No, but you can typically just append them without any special tools. Just a binary append

duncanokeyo notifications@github.com schrieb am Sa., 14. Juli 2018, 5:12 vorm.:

Its it possible to concat .ts files without converting to mp4

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sannies/mp4parser/issues/317, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKUD097sZdhUvfm9Lo70p22YUhnfHZ0ks5uGWGzgaJpZM4VPtCC .

hampelratte commented 6 years ago

I'm trying to do something similar: Merging a recorded HLS stream (a bunch of .ts files) to one mp4. The transport stream contains h264 and aac, so it would be perfect for isoparser. The problem I'm facing is, that the recorded stream can contain corrupt segments or there can be segments missing. A binary append would lead to wrong timestamps/continuity counters and what not. I'll probably have to find a way to extract the raw streams from the transport stream and then feed that to isoparser. Is that right? (I'm totally new to video formats and don't have a clue ;) )

hampelratte commented 5 years ago

I think I'm quite close. I managed to extract the elementary streams and mux them into a mp4. It plays back in mpv (sound and video are fine), but audio and video are out of sync.

When I mux the streams with ffmpeg, I get the same problem and this output:

ffmpeg -i audio.aac -i video.h264 -c:v copy -c:a copy -f mp4 /tmp/test.mp4
[mp4 @ 0x55ff0b754140] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly

So I think, that something is wrong with the extracted elementary streams. Any ideas where to start to debug this?