Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating .ts chunks from .mp4 file

I need to create a .ts chunks from a .mp4 file without using ffmpeg API. I have already implemented this task using ffmpeg API, and it works, but my team lead wants me to get rid of it, and it is impossible to convince him against that. The code is supposed to run under load.

I have already found out how to read mp4 format, where to find frames, their offsets and sizes in a file, their pts's, for audio and video. A huge achievement for me as I haven't been working in this area for long.

All I managed is to create playlist where each chunk starts with I-frame. I feed the start and stop pts's of playlist entry to the old code(slightly modified) using ffmpeg API, and it creates proper ts chunks.

But but to create ts chunks without ffmpeg API I still cannot.

At first I tried to read the code of nginx rtmp module, the hls part of it, but couldn't understand anything there. It's too complex and I lack specific knowledge. Now I'd like to read something on ts format. Can anyone advise where to look?

Thanks.

like image 282
kopalvich Avatar asked Jan 19 '26 09:01

kopalvich


1 Answers

It is unfortunate that you cannot use available, tested and efficient tools like ffmpeg. Why reinventing the wheel ?

Anyway, basically you want to:

  • Split, compress your stream and encapsulate it into Packetized Elementary Stream packets, then Transport Packets
  • Introduce SI/PSI tables

Have a look at the standards.The format of the TS objects are nicely summarized here. You need at least:

  • a PMT to reference your video stream
  • a PAT to reference your PMT

This website is good starting point to get familiar with MPEG2 Transport Stream.

like image 147
n0p Avatar answered Jan 20 '26 23:01

n0p