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

63,463

Solution 1

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

Solution 2

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.

Share:
63,463
Aleksandr Suvorov
Author by

Aleksandr Suvorov

Updated on November 29, 2020

Comments

  • Aleksandr Suvorov
    Aleksandr Suvorov over 3 years

    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.

  • slhck
    slhck almost 11 years
    … as a CLI tool, or just static libraries to be used with the API? I don't know.
  • Aleksandr Suvorov
    Aleksandr Suvorov almost 11 years
    As I understand I built app with static libraries as said at movie player for iOS using ffmpeg Also I built FFmpeg as a CLI tool and I can convert video from CLI, but I want to play live stream in iOS app. How can I do this? Is the only one solution to convert live stream on server?
  • Nik
    Nik almost 7 years
    Is it same as -c copy?
  • Prabhakar Kasi
    Prabhakar Kasi over 5 years