aws / amazon-chime-sdk-js

A JavaScript client library for integrating multi-party communications powered by the Amazon Chime service.
Apache License 2.0
704 stars 475 forks source link

Cannot find concatenated result video from chimeSDKMediaPipelines.createMediaConcatenationPipeline #2531

Open jaeho0522 opened 1 year ago

jaeho0522 commented 1 year ago

I was able capture chime meeting screen using 1) 'chimeSDKMediaPipelines.createMediaCapturePipeline' to create pipeline and start recording 2) 'chimeSDKMediaPipelines.deleteMediaCapturePipeline' to stop recording 3) 'chimeSDKMediaPipelines.createMediaConcatenationPipeline' to concatenate captured junk files.

When I looked at S3 bucket, I can only find chunked files and not the concatenated file.

I read following references to implement concatenation. 1) https://docs.aws.amazon.com/chime-sdk/latest/dg/concat-architecture.html 2) https://docs.aws.amazon.com/chime-sdk/latest/dg/create-concat-pipe-steps.html

I double checked below information to make sure I did not make any mistakes 1) Capture bucket policy and Concatenation bucket policy 2) Concatenation bucket arn

And now I don't know what to look for.

I am currently using 'ap-southeast-1' region for the S3 buckets. And I am including source code and information that might help someone to help me solve this problem.

Thanks in advance

Jaeho Lee

  1. Bucket directories 1) Amazon S3 > Bucket > mk-recording-text (Capture bucket) 2) Amazon S3 > Bucket > mk-media-concatenation-bucket (Concatenation bucket)
  2. Bucket arn information 1) Capture bucket arn: arn:aws:s3:::mk-recording-test 2) Concatenation bucket arn: arn:aws:s3:::mk-media-concatenation-bucket
  3. Lambda handler code const AWS = require('aws-sdk'); const ddb = new AWS.DynamoDB(); const chimeSDKMediaPipelines = new AWS.ChimeSDKMediaPipelines({ region: 'us-east-1' }); const sts = new AWS.STS({ region: 'us-east-1' });

const meetingTable = {}; const { MEETINGS_TABLE_NAME, CAPTURE_S3_DESTINATION, CONCAT_BUCKET_ARN, } = process.env;

exports.handler = async(event) => { if (!CAPTURE_S3_DESTINATION) { console.warn("Cloud media capture not available"); return response(500, 'application/json', JSON.stringify({})); } const query = event.queryStringParameters; let action; if(query && query.action) { console.log("action: " + query.action); action = query.action; }

// 화상 녹화 시작 if (action == 'start'){ const pipelineInfo = await startCapture(query); return response(201, 'application/json', JSON.stringify(pipelineInfo)); } // 화상 녹화 끝내기 else if (action == 'end') { await endCapture(query); return response(200, 'application/json', JSON.stringify({}));
} // 화상 녹화 청크 연결하기 (온전한 영상파일로 변환) else if (action == 'concat') { const pipelineInfo = await concatCapture(query); return response(201, 'application/json', JSON.stringify(pipelineInfo)); } else { return response(404, 'text/html', '404 Not Found'); } };

async function endCapture(query) { const pipelineInfo = meetingTable[query.title]; console.log(JSON.stringify(pipelineInfo)); await chimeSDKMediaPipelines.deleteMediaCapturePipeline({ MediaPipelineId: pipelineInfo.MediaPipelineId }).promise(); // meetingTable[query.title] = undefined; return; }

async function startCapture(query) { let meeting = await getMeeting(query.title); if (!meeting) { return response(404, 'application/json', JSON.stringify({message: 'Meeting not found.'})); }

const callerInfo = await sts.getCallerIdentity().promise(); // @ts-ignore const pipelineInfo = await chimeSDKMediaPipelines.createMediaCapturePipeline({ SourceType: "ChimeSdkMeeting", SourceArn: arn:aws:chime::${callerInfo.Account}:meeting:${meeting.Meeting.MeetingId}, SinkType: "S3Bucket", SinkArn: CAPTURE_S3_DESTINATION, ChimeSdkMeetingConfiguration: { ArtifactsConfiguration: { Audio: { MuxType: "AudioWithCompositedVideo" //"AudioWithActiveSpeakerVideo" }, Video: { State: "Disabled", MuxType: "VideoOnly" }, Content: { State: "Disabled", MuxType: "ContentOnly" }, CompositedVideo: { Layout: "GridView", Resolution: "FHD", GridViewConfiguration: { ContentShareLayout: "PresenterOnly", PresenterOnlyConfiguration: { PresenterPosition: "BottomRight" } } } } } }).promise(); console.log(JSON.stringify(pipelineInfo)); meetingTable[query.title] = pipelineInfo.MediaCapturePipeline; return pipelineInfo; }

async function concatCapture(query) { let meeting = await getMeeting(query.title); if (!meeting) { return response(404, 'application/json', JSON.stringify({message: 'Meeting not found.'})); } // @ts-ignore const pipelineInfo = await chimeSDKMediaPipelines.createMediaConcatenationPipeline({ Sinks: [ { S3BucketSinkConfiguration: { Destination: CONCAT_BUCKET_ARN }, Type: 'S3Bucket', }, ], Sources: [ { MediaCapturePipelineSourceConfiguration: { ChimeSdkMeetingConfiguration: { ArtifactsConfiguration: { Audio: { State: 'Enabled' }, CompositedVideo: { State: 'Enabled' }, Content: { State: 'Disabled' }, DataChannel: { State: 'Enabled' }, MeetingEvents: { State: 'Enabled' }, TranscriptionMessages: { State: 'Enabled' }, Video: { State: 'Disabled' }, }, }, MediaPipelineArn: meetingTable[query.title].MediaPipelineArn, }, Type: 'MediaCapturePipeline', }, ], }).promise(); console.log(JSON.stringify(pipelineInfo)); return pipelineInfo; }

// Retrieves the meeting from the table by the meeting title async function getMeeting(title) { // @ts-ignore const result = await ddb.getItem({
TableName: MEETINGS_TABLE_NAME, Key: { 'Title': { S: title }, }, }).promise(); // @ts-ignore return result.Item ? JSON.parse(result.Item.Data.S) : null; }

function response(statusCode, contentType, body) { return { statusCode: statusCode, headers: { 'Content-Type': contentType, 'Access-Control-Allow-Origin': '*' }, body: body }; }


  1. Capture bucket policy { "Version": "2012-10-17", "Id": "AWSChimeMediaCaptureBucketPolicy", "Statement": [ { "Sid": "AWSChimeMediaCaptureBucketPolicy", "Effect": "Allow", "Principal": { "Service": "mediapipelines.chime.amazonaws.com" }, "Action": [ "s3:PutObject", "s3:PutObjectAcl", "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::mk-recording-test/*", "arn:aws:s3:::mk-recording-test" ] } ] }


  2. Concatenation bucket policy { "Version": "2012-10-17", "Id": "AWSChimeMediaConcatenationBucketPolicy", "Statement": [ { "Sid": " AWSChimeMediaConcatenationBucketPolicy ", "Effect": "Allow", "Principal": { "Service": "mediapipelines.chime.amazonaws.com" }, "Action": [ "s3:PutObject", "s3:PutObjectAcl" ], "Resource": "arn:aws:s3:::mk-media-concatenation-bucket/*" } ] }

MingcongQi commented 1 year ago

Could you help send the media pipeline id for capture and concatenation? so we could check backend logs. Thanks!

jaeho0522 commented 1 year ago

Hi,

I am including both media capture pipeline info and media concatenation pipeline info below.

Thanks for your help.

1) media capture pipeline info { "MediaCapturePipeline": { "MediaPipelineId": "1a0ce85f-5ea0-4fef-accd-77e6f9cd1b61", "MediaPipelineArn": "arn:aws:chime:us-east-1:****:media-pipeline/1a0ce85f-5ea0-4fef-accd-77e6f9cd1b61", "SourceType": "ChimeSdkMeeting", "SourceArn": "arn:aws:chime::****:meeting:f02a83d5-b6dc-4185-893b-7a91a1320706", "Status": "Initializing", "SinkType": "S3Bucket", "SinkArn": "arn:aws:s3:::mk-recording-test", "CreatedTimestamp": "2022-12-22T10:26:00.433Z", "UpdatedTimestamp": "2022-12-22T10:26:00.525Z", "ChimeSdkMeetingConfiguration": { "ArtifactsConfiguration": { "Audio": { "MuxType": "AudioWithCompositedVideo" }, "Video": { "State": "Disabled", "MuxType": "VideoOnly" }, "Content": { "State": "Disabled", "MuxType": "ContentOnly" }, "CompositedVideo": { "Layout": "GridView", "Resolution": "FHD", "GridViewConfiguration": { "ContentShareLayout": "PresenterOnly", "PresenterOnlyConfiguration": { "PresenterPosition": "BottomRight" } } } } } } }

2) media concatenation pipeline info { "MediaConcatenationPipeline": { "MediaPipelineId": "0779b2ec-211e-411a-82fc-77a49de8bcfe", "MediaPipelineArn": "arn:aws:chime:us-east-1:****:media-pipeline/0779b2ec-211e-411a-82fc-77a49de8bcfe", "Sources": [ { "Type": "MediaCapturePipeline", "MediaCapturePipelineSourceConfiguration": { "MediaPipelineArn": "arn:aws:chime:us-east-1:****:media-pipeline/1a0ce85f-5ea0-4fef-accd-77e6f9cd1b61", "ChimeSdkMeetingConfiguration": { "ArtifactsConfiguration": { "Audio": { "State": "Enabled" }, "Video": { "State": "Disabled" }, "Content": { "State": "Disabled" }, "DataChannel": { "State": "Enabled" }, "TranscriptionMessages": { "State": "Enabled" }, "MeetingEvents": { "State": "Enabled" }, "CompositedVideo": { "State": "Enabled" } } } } } ], "Sinks": [ { "Type": "S3Bucket", "S3BucketSinkConfiguration": { "Destination": "arn:aws:s3:::mk-media-concatenation-bucket" } } ], "Status": "Initializing", "CreatedTimestamp": "2022-12-22T10:26:14.420Z", "UpdatedTimestamp": "2022-12-22T10:26:15.310Z" } }

MingcongQi commented 1 year ago

Hi, the media concatenation pipeline failed because it couldn't download media chunks from the capture bucket. please follow https://docs.aws.amazon.com/chime-sdk/latest/dg/create-concat-pipe-steps.html to reconfigure your S3 bucket policy. Your meetings media region are hosted in ap-northeast-2, I would suggest you use ap-southeast-1 for media pipeline control region instead of us-east-1 and create s3 bucket in ap-northeast-2.

zhuang-chen0 commented 1 year ago

@MingcongQi I met the same problem as him. Please help me find out the reason. Here's what you get back after calling the method. create media pipeline:{ MediaCapturePipeline: { MediaPipelineId: '867af8e8-1b8e-4ab8-8f17-0a7300535a1c', MediaPipelineArn: 'arn:aws:chime:us-east-1::media-pipeline/867af8e8-1b8e-4ab8-8f17-0a7300535a1c', } create media concatenation pipeline: { MediaConcatenationPipeline: { MediaPipelineId: '18825763-d739-4c9a-9ef3-85104c198a07', MediaPipelineArn: 'arn:aws:chime:us-east-1::media-pipeline/18825763-d739-4c9a-9ef3-85104c198a07', Sources: [ [Object] ], Sinks: [ [Object] ], Status: 'Initializing', CreatedTimestamp: 2023-01-03T14:45:10.104Z, UpdatedTimestamp: 2023-01-03T14:45:10.272Z } }

MingcongQi commented 1 year ago

@chenzhuang0 Media pipeline failed to List Objects from your capture S3 bucket. Have you checked your S3 bucket policy following my previous comments?

jaeho0522 commented 1 year ago

@MingcongQi, I was able to solve this problem by creating s3 bucket in ap-northeast-2 region as you suggested. It seems s3 bucket and meeting must be on same region. If so, then do I need to always create s3 bucket according to meeting's region? Thanks for your help.

yuqil-amzn commented 1 year ago

Yes, you can create s3 bucket according to meeting's region.

paul365 commented 1 year ago

hi @yuqil-amzn, @MingcongQi Can you please help me determine why my mediaconcatenationpipeline failed MediaPipelineId: 54d8cc8a-7b98-4b1c-ae71-6be17c0f87cd I've had one concatenation pipeline that worked earlier, but now it always fails. The id here is one of those failed attempts.

also I am putting the mediacapture and mediaconcat results on the same s3 bucket and have this policy

{
            "Sid": "AWSChimeMediaCaptureBucketPolicy",
            "Effect": "Allow",
            "Principal": {
                "Service": "mediapipelines.chime.amazonaws.com"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::bucket/*",
                "arn:aws:s3:::bucket"
            ]
        },
        {
            "Sid": "AWSChimeMediaConcatenationBucketPolicy",
            "Effect": "Allow",
            "Principal": {
                "Service": "mediapipelines.chime.amazonaws.com"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::bucket/*",
                "arn:aws:s3:::bucket"
            ]
        }

following this guide. Not sure if this is the cause? thanks!

dmoughabghab commented 11 months ago

It seems that the media capture pipeline can only be used in certain regions, and needs to be in the same region as the bucket. I am trying to build an app and store the data in ap-southeast-2. Do you know when media capture pipelines will be able to be used in ap-southeast-2 and other regions?