首页 > 解决方案 > Agora: Why my m3u8 file does not contain timestamp?

问题描述

I'm using agora composition recording and want to retrieve the start timestamp to build Synchronous playback. The document says You can find the start timestamp at the start of each M3U8 file, however my M3U8 file does not contain any timestamp.

I can convert the output files (ts and m3u8) to mp4 by ffmpeg as expected.

The request body for start api is below;

const url = `${agoraApi}/v1/apps/${appId}/cloud_recording/resourceid/${resourceId}/mode/mix/start`

const body = {
  cname,
  uid,
  clientRequest: {
    token,
    storageConfig: {
      vendor: 1, // Amazon S3,
      region: 10, // AP_NORTHEAST_1
      accessKey: process.env.AWS_ACCESS_KEY_ID,
      secretKey: process.env.AWS_SECRET_ACCESS_KEY,
      bucket: process.env.AWS_S3_BUCKET,
      fileNamePrefix: ["records"],
    },
    recordingConfig: {
      channelType: 1, // default. 0: Communication profile, 1: Live broadcast profile
      // maxIdleTime: 30, // seconds (default)
      transcodingConfig: {
        width: 640, // default
        height: 360, // default
        fps: 15, // default
        bitrate: 600,
        mixedVideoLayout: 0, // default
      },
    },
  },
};

The output M3U8 file

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:18
#EXTINF:16.038000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064340040.ts
#EXTINF:15.972000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064357105.ts
#EXTINF:16.038000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064413077.ts
#EXTINF:15.971000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064429115.ts
#EXTINF:16.039000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064445086.ts
#EXTINF:15.972000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064501125.ts
#EXTINF:15.972000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064517097.ts
#EXTINF:16.038000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064533069.ts
#EXTINF:15.972000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064549107.ts
#EXTINF:16.038000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064605079.ts
#EXTINF:15.972000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064621117.ts
#EXTINF:16.038000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064637088.ts
#EXTINF:11.679000
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064653127.ts
#EXT-X-ENDLIST

Am i missing some configuration?

标签: agora.io

解决方案


While you are correct to point out that there is no Epoch/Unix timestamp, there is a "timestamp" included the name of each segment. If you notice at the end of the name of the segments, is a human readable date and time.

for example, the first .ts file is named:

8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064340040.ts

If you split the name using the _ as the delimiter, the last element of the array is your timestamp. using the above name for example, the time-stamp would be 20210603064340040.

Taking this further you can break this down as:

yyyy mm dd hh mm ss ms
------------------------
2021 06 03 06 43 40 040

Using the next three files in the list we can see

8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064357105.ts
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064413077.ts
8893be119d40bbc66f7ef9a26a676a12_live-aea67a87-f821-4234-894b-1512fcdae181_20210603064429115.ts
yyyy mm dd hh mm ss ms
------------------------
2021 06 03 06 43 57 105
2021 06 03 06 44 13 077
2021 06 03 06 44 29 115

推荐阅读