Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert (re-wrap) Transport Stream to MPEG-4 container in iOS app?

I have a live stream in .ts format, containing AAC audio and H.264 video. I want to play it on iOS devices. I tried to use a movie player based on FFmpeg to decode and play video, but the audio was lagging.

Can I rewrap this Transport Stream to an MPEG-4 container to play on iOS devices – without converting it server-side?

The server returns me a URL of the .ts live stream and my goal is to play this stream on iOS devices without an .m3u8 playlist because I can't get it from the server.

like image 916
Aleksandr Suvorov Avatar asked Jul 28 '13 11:07

Aleksandr Suvorov


People also ask

How to convert TS to MP4 using FFmpeg?

On the Command Prompt window, enter "cd bin" and then "exe" Finally, enter the following command to use FFmpeg to convert TS to MP4: ffmpeg -i yourvideoname. ts -c:v libx264 outputfilename. mp4.

What is Ffmpeg video format?

FFMPEG stands for Fast Forward Moving Picture Experts Group. It is a free and open source software project that offers many tools for video and audio processing. It's designed to run on a command line interface, and has many different libraries and programs to manipulate and handle video files.


2 Answers

To just re-mux without transcoding you can use: ffmpeg -i input.ts -acodec copy -vcodec copy out.mp4

like image 111
d33pika Avatar answered Oct 12 '22 06:10

d33pika


I used ffmpeg -i input.ts -acodec copy -vcodec copy out.mp4 and conversion failed.

I then used -bsf:a aac_adtstoasc flag & conversion passed, with 'Non-monotonous DTS' errors, resulting in incorrect timestamps in output file.
The out.mp4 file plays well, but when I extract audio from it, the length of audio is different to that of the video.

If I use the extracted audio to replace that one in original file, the audio in resulting video file is out of sync (audio lagging).

I then imported the out.mp4 clip into DaVinci Resolve video editor. The length of both the audio & video files showed the same, so I exported the audio only and got file size same as original video.

However, when I played the file & viewed audio graph in Audacity, I noticed many blanked out areas (no sound). Audio files created with Audacity, ffmpeg, VLC, VSDC Video Editor all gave audio files of different size than the original video file, although they all had sound.

I've heard of projectX to demux a/v, as a possible solution. Demux completed successfully, but created a 1KB mp1 file, with lots of errors: "PTS without a frame".

eac3to was successful in extracting AAC audio from TS video file. Both files were same size. Using ffmpeg to replace audio in video file results in perfect syn, no lagging or blank sounds.
No errors about 'Non-monotonous DTS' or incorrect timestamps.

Done.

like image 39
Zimba Avatar answered Oct 12 '22 06:10

Zimba