A/V sync problem when muxing concatenated MP4 files

F8 1 Reputation point
2021-02-11T12:21:36.933+00:00

I'm testing live streaming using Azure Media Services. When the event is stopped, I'd like to get the recording as a single MP4 file, but Azure saves the video and audio tracks separately in a fragmented form. I figured out that I can concatenate these files (I used OSX cat command), so I do have perfectly working MP4 files for video and audio - both of them play without any interruptions and seem just fine.

I noticed the difference in duration of audio/video streams, but I thought that when I mux them, I would get a file in which the last few seconds would have just the audio track. I started with testing the most basic FFmpeg command ffmpeg -i video.mp4 -i audio.mp4 -c copy muxed.mp4, however the A/V turned out to be out of sync. What's even more strange, though, the audio delay is not constant or increasing, it's floating! Sometimes it's even 15 seconds behind, sometimes it's almost synched and that varies over the whole duration of the video.

Somebody suggested to me that Azure might not save timestamps in MP4 segments. Any ideas on that and how to properly concat and mux the live event output? BTW I am aware that I can get my requested output using Azure encoder, but for now I'm trying to test what's possible and how to achieve that.

Thanks a lot in advance!

Azure Media Services
Azure Media Services
A group of Azure services that includes encoding, format conversion, on-demand streaming, content protection, and live streaming services.
316 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Xavier Pouyat 591 Reputation points Microsoft Employee
    2021-02-11T12:56:56.677+00:00

    Hello,
    You can create a single MP4 file from a live archive with Azure Media Services. This process is called subclipping. A job will take the top video bitrate and audio from a live archive asset and will create a MP4 file in a new asset. Streams are copied and there is no loss of quality.

    Transform should be defined like this :

    {  
      "@odata.type": "#Microsoft.Media.StandardEncoderPreset",  
      "codecs": [  
        {  
          "@odata.type": "#Microsoft.Media.CopyAudio"  
        },  
        {  
          "@odata.type": "#Microsoft.Media.CopyVideo"  
        }  
      ],  
      "formats": [  
        {  
          "@odata.type": "#Microsoft.Media.Mp4Format",  
          "filenamePattern": "Archive-{Basename}{Extension}",  
          "outputFiles": []  
        }  
      ]  
    }  
    

    See https://video2.skills-academy.com/en-us/azure/media-services/latest/how-to-create-copy-video-audio-transform

    You can also specify the start timestamp and end timestamp when building the JobInputAsset object.
    See https://video2.skills-academy.com/en-us/azure/media-services/latest/subclip-video-dotnet-howto

    Note : the timestamp should be in absolute format. For live, this value can be very high as it contains often an offset. To calculate it, you can look to the first timestamp in the manifest.

    These values are calculated automatically when using AMSE (https://aka.ms/amse). Select a live archive asset, right click and choose "Subclip live/fragmented asset".


  2. Xavier Pouyat 591 Reputation points Microsoft Employee
    2021-02-11T13:42:45.687+00:00
    1. I don't know the pricing. I will do some research
    2. To my knowledge, you can only get the top video bitrate. Another option, is to re encode the live archive asset with a specific preset (but it's slower and probably more expensive).

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.