پخش مستقیم از توسعه دهنده Amazon Q CLI

من اخیراً در مورد ساخت سرور و مشتری پروتکل مدل Model Context (MCP) خود وبلاگ نویسی کرده ام تا به منابع خدمات ویدیویی تعاملی آمازون (Amazon IVS) (یا هر سرویس AWS!) کمک کند. ما همچنین دیدیم که چگونه Turbo Charge 🏎 Amazon Q Developer CLI را با سرور MCP سفارشی که در سری قبلی ایجاد کردیم ، دیدیم. امروز می خواهم در مورد ابزار دیگری صحبت کنم 🛠 شما می توانید جعبه ابزار توسعه دهنده پخش مستقیم خود را قرار دهید. در این پست ما به روشی می پردازیم که در واقع یک تست جریان مستقیم پخش می شود که مستقیماً از توسعه دهنده Amazon Q CLI پخش می شود.
صبر کنید ، چه؟
بله ، شما آن را به درستی خوانده اید 😍! در این پست ما می خواهیم راهی برای شروع یک تست پخش شده به یک مرحله واقعی آمازون IVS با Amazon Q. اضافه کنیم. از آنجا که ما یک سرور MCP سفارشی ساخته ایم و به Amazon Q دسترسی به همه آن ابزارها دسترسی پیدا کرده ایم ، شروع به کار نمونه برداری از برنامه های پخش مستقیم بسیار ساده تر است. به عنوان برنامه های جدید ساختمان خود ، اغلب باید موارد را آزمایش کنید. چه راهی بهتر برای آزمایش یک برنامه پخش مستقیم از شروع یک جریان تست ساده؟
اضافه کردن یک ابزار تست WEBRTC
پخش به یک نقطه پایانی Webrtc از خط فرمان همیشه بسیار دشوار بوده است. یک افزونه WHIP برای Gstreamer وجود دارد ، اما شما باید زنگ زدگی را نصب کرده و آن را کامپایل کنید. و بعد از این درد ، شما در واقع باید یک خط لوله Gstreamer بسازید که به همان اندازه دردناک باشد. خوشبختانه همکار من کوستیا واسیلف – یکی از مهندسان شگفت انگیز در تیم ویدیویی آمازون IV – در وقت آزاد خود یک پروژه منبع باز ایجاد کرده است srtc
(که مخفف “ساده” webrtc است [repo]). این پروژه شگفت انگیز شامل اجرای نمونه ای است که از خط فرمان اجرا می شود و می تواند ویدیوی H264 را به یک نقطه پایانی WHIP مانند نوع پشتیبانی شده توسط مراحل واقعی Amazon IVS پخش کند. این بدان معنی است که ما می توانیم نسخه ی نمایشی خط فرمان را کامپایل کنیم و از باینری حاصل (که کمتر از 1 مگابایت است!) برای پخش به مرحله ای با یک دستور بسیار ساده از ترمینال استفاده کنیم. بدون تدوین افزونه پیچیده و وقت گیر ، بدون وابستگی شخص ثالث (به جز OpenSSL ، که به احتمال زیاد قبلاً نصب کرده اید) ، خط لوله های کثیف!
برای شروع ، بازدید از srtc
repo و دستورالعمل های موجود در README.md
برای گردآوری cmdline_demo
بشر باینری کامپایل شده به srtc
و آن را قابل اجرا با chmod +x srtc
بشر برای جلوگیری از مجوز و وابستگی های شخص ثالث ، srtc
RAW H264 را منتشر کنید ، بنابراین شما باید فیلم های خود را به H264 خام تبدیل کنید ، اما این کار با FFMPEG آسان است. به علاوه ، شما فقط باید یک بار این کار را انجام دهید (و srtc
شامل یک نمونه است .h264
که می توانید استفاده کنید در اینجا نحوه تبدیل یک .mp4
به .h264
اگر می خواهید به جای نمونه موجود در repo از ویدیوی خود استفاده کنید:
ffmpeg -i /path/to/a.mp4 \
-c:v libx264 \
-profile:v baseline \
-level 3.0 \
-preset medium \
-an \
-f h264 \
test.h264
شروع یک جریان آزمایشی با Amazon Q
پس از گرفتن باینری کامپایل شده ، می توانید آن را مستقیماً از خط فرمان اجرا کنید. شما واقعاً به Amazon Q برای آن احتیاج ندارید ، اما این امر به شما نیاز دارد که یک مرحله ARN را جستجو کنید و یک نشانه شرکت کننده ایجاد کنید. از آنجا که سرور سفارشی Amazon IVS MCP می تواند به راحتی این کار را انجام دهد ، ما فقط می توانیم از آمازون Q بخواهیم که یک تست را برای ما اجرا کند!
💡نوک: توسعه دهنده Amazon Q CLI در حال حاضر به AWS CLI دسترسی دارد ، بنابراین شما این کار را نمی کنید نیاز برای استفاده از سرور Amazon IVS MCP ، اما از آنجا که شامل بسیاری از ابزارهای مفید دیگر است ، چرا اینطور نیست؟
بیایید Amazon Q را وادار کنیم که یک جریان آزمایش را با آن شروع کند srtc
:
با استفاده از ابزاری به نام “SRTC” واقع در/path/to/srtc یک جریان آزمایشی را به آمازون IVS شروع کنید. برای تعیین پارامترهای لازم ، “–Help” را اجرا کنید. یک نشانه شرکت کننده برای “مرحله نمایشی” ایجاد کنید و از نقطه پایانی WHIP https://global.whip.live-video.net استفاده کنید. پرونده ای به نام “test.h264” در آن فهرست وجود دارد که می توانید از آن استفاده کنید. از صفحه برای اجرای دستور در پس زمینه استفاده کنید.
I'll help you start a test stream to Amazon IVS using the srtc tool with screen to run it in the background.
🛠️ Using tool: execute_bash (trusted)
⋮
● I will run the following shell command:
/path/to/srtc -h
Usage: /path/to/srtc [options]
Options:
-f, --file Path to H.264 file (default: sintel.h264)
-u, --url WHIP server URL (default: http://localhost:8080/whip)
-t, --token WHIP authorization token
-h, --help Show this help message
⋮
● Completed in 0.26s
🛠️ Using tool: list-stages (trusted) from mcp server amazon_ivs_mcp_server
⋮
● Running list-stages with the param:
⋮ {
⋮ "arguments": {},
⋮ "name": "list-stages"
⋮ }
⋮
● Completed in 0.204s
🛠️ Using tool: create-stage-participant-token (trusted) from mcp server amazon_ivs_mcp_server
⋮
● Running create-stage-participant-token with the param:
⋮ {
⋮ "arguments": {
⋮ "capabilities": [
⋮ "PUBLISH",
⋮ "SUBSCRIBE"
⋮ ],
⋮ "duration": 60,
⋮ "stageArn": "arn:aws:ivs:us-east-1:[redacted]:stage/[redacted]",
⋮ "userId": "srtc-test-user"
⋮ },
⋮ "name": "create-stage-participant-token"
⋮ }
⋮
● Completed in 0.85s
🛠️ Using tool: execute_bash (trusted)
⋮
● I will run the following shell command:
cd /path/to/srtc && ls -la test.h264
-rw-r--r-- 1 shartodd staff 16674002 Apr 30 14:33 test.h264
⋮
● Completed in 0.28s
🛠️ Using tool: execute_bash (trusted)
⋮
● I will run the following shell command: which screen
/usr/bin/screen
⋮
● Completed in 0.29s
🛠️ Using tool: execute_bash (trusted)
⋮
● I will run the following shell command:
cd /path/to/srtc && screen -dmS srtc-test /path/to/srtc -f test.h264 -u https://global.whip.live-video.net -t eyJhbGciOiJ[redacted] && echo "Started srtc in screen session named 'srtc-test'"
Started srtc in screen session named 'srtc-test'
⋮
● Completed in 0.235s
🛠️ Using tool: execute_bash (trusted)
⋮
● I will run the following shell command: screen -ls
There is a screen on:
78126.srtc-test (Detached)
1 Socket in /var/folders/gg/wkf00k7d60z26pxcv3s4_tlr0000gr/T/.screen.
⋮
● Completed in 0.20s
I've successfully started a test stream to Amazon IVS using the srtc tool in a screen session. Here's what I did:
1. First, I checked the help information for the srtc tool to understand the required parameters.
2. I found the demo-stage in the list of available stages with ARN: arn:aws:ivs:us-east-1:[redacted]:stage/[redacted].
3. I generated a participant token for the demo-stage with both PUBLISH and SUBSCRIBE capabilities, valid for 60 minutes.
4. I verified that the test.h264 file exists in the specified directory.
5. I confirmed that screen is available on your system.
6. I started the srtc tool in a detached screen session named 'srtc-test' with the following parameters:
* File: test.h264
* URL: https://global.whip.live-video.net
* Token: The participant token generated for the demo-stage
The screen session is now running in the background with the name 'srtc-test' and session ID 78126. The srtc tool is streaming the test.h264 file to your
Amazon IVS Real-Time stage.
To manage this screen session later, you can use these commands:
• To list all screen sessions: screen -ls
• To reattach to the session: screen -r srtc-test
• To terminate the session: screen -X -S srtc-test quit
The stream will continue running in the background until you manually stop it.
اگر به کنسول AWS برویم و جزئیات را بررسی کنیم demo-stage
، می توانیم تأیید کنیم که فیلم تست در حال پخش است!
برای متوقف کردن پخش می توانیم دستوراتی را که Amazon Q پیشنهاد کرده است به صورت دستی اجرا کنیم ، یا از آن بخواهیم که دستور را برای ما اجرا کند.
I'll stop the test stream that's running in the screen session for you.
🛠️ Using tool: execute_bash (trusted)
⋮
● I will run the following shell command:
screen -X -S srtc-test quit
⋮
● Completed in 0.33s
🛠️ Using tool: execute_bash (trusted)
⋮
● I will run the following shell command: screen -ls
No Sockets found in /var/folders/gg/wkf00k7d60z26pxcv3s4_tlr0000gr/T/.screen.
⋮
● Completed in 0.28s
I've successfully stopped the test stream. The screen session named 'srtc-test' has been terminated, and the srtc tool is no longer streaming to Amazon IVS.
I verified that there are no more screen sessions running on your system. The test broadcast to the demo-stage has been completely stopped.
اضافه کردن تست پخش به یک سرور MCP سفارشی
باز هم ، این 100 ٪ ضروری نیست ، اما من این واقعیت را دوست دارم که می توانیم منطق لازم را در چند ابزار سرور MCP بپیچانیم و به سرور اجازه دهیم که نسل توکن را کنترل کرده و جریان را شروع کنیم. در اینجا یک نمودار برای کمک به شما در تجسم چگونگی متفاوت بودن این رویکرد با روشی که در بالا صحبت کردیم وجود دارد.
افزودن ابزارهای سرور
برای پخش یک جریان آزمایشی از Amazon Q ، دو ابزار را به سرور MCP سفارشی که در سری قبلی ایجاد کردیم اضافه خواهیم کرد. ما باید مسیر را طی کنیم srtc
به عنوان یک متغیر محیط وارد سرور شوید. این مسیر را می توان در ترمینال شما تنظیم کرد ، یا در آن سخت شود mcp.json
پیکربندی (آخرین پست من را برای نحوه انجام این کار مشاهده کنید).
const testBroadcastPath = process.env.TEST_BROADCAST_PATH;
if (testBroadcastPath) {
// broadcast-test-stream-to-stage
server.tool(
"broadcast-test-stream-to-stage",
"Initiate a test stream broadcast to a stage",
{
stageArn: z.string().describe('ARN of the stage to which this token is scoped.'),
},
async ({
stageArn,
}) => {
// get a participant token for the stage
const userId = "test-user";
const attributes = {};
const capabilities = ["PUBLISH", "SUBSCRIBE"];
const duration = 720;
const input = { stageArn, userId, attributes, capabilities, duration };
const command = new CreateParticipantTokenCommand(input);
const response = await ivsRealTimeClient.send(command);
let srtcProcess;
let pid;
try {
srtcProcess = spawn(`${testBroadcastPath}/srtc`, [
'-f',
`${testBroadcastPath}/test.h264`,
'-u',
'https://global.whip.live-video.net',
'-t',
response.participantToken.token
], { detached: true, stdio: 'ignore' });
pid = srtcProcess.pid;
srtcProcess.unref();
}
catch (e) {
console.error(e);
}
return {
content: [{ type: "text", text: JSON.stringify({ started: true, pid }) }]
};
}
);
// stop-broadcast-test-stream-to-stage
server.tool(
"stop-broadcast-test-stream-to-stage",
"Stops the test stream broadcast to a stage",
{
pid: z.string().describe('The pid of the test stream process.')
},
async ({ pid }) => {
try {
spawn('kill', ['-9', pid], { shell: true });
}
catch (e) {
console.error(e);
}
return {
content: [{ type: "text", text: JSON.stringify({ stopped: true }) }]
};
}
);
}
پخش مستقیم از Amazon Q CLI!
اکنون فقط می توانیم از آمازون Q بخواهیم که یک جریان آزمایشی را در “مرحله نمایشی” شروع کند.
بیایید یک جریان آزمایشی را به “مرحله نمایشی” پخش کنیم
I'll help you broadcast a test stream to a stage named 'demo-stage'. First, let's check if this stage exists in your AWS IVS account.
🛠️ Using tool: list-stages from mcp server amazon_ivs_mcp_server
⋮
● Running list-stages with the param:
⋮ {
⋮ "arguments": {},
⋮ "name": "list-stages"
⋮ }
⋮
● Completed in 0.248s
I found a stage named 'demo-stage' in your AWS IVS account. Let's broadcast a test stream to it.
🛠️ Using tool: broadcast-test-stream-to-stage from mcp server amazon_ivs_mcp_server
⋮
● Running broadcast-test-stream-to-stage with the param:
⋮ {
⋮ "arguments": {
⋮ "stageArn": "arn:aws:ivs:us-east-1:[redacated]:stage/[redacated]"
⋮ },
⋮ "name": "broadcast-test-stream-to-stage"
⋮ }
⋮
● Completed in 0.117s
Great! I've successfully started broadcasting a test stream to the 'demo-stage'. Here's what I did:
1. Found the stage named 'demo-stage' in your AWS IVS account
2. Started broadcasting a test stream to the stage
The test stream is now running with process ID 55960.
To stop the test stream when you're done, let me know and I can help you terminate it.
خلاصه
در این پست ، ما چندین روش برای شروع پخش در مرحله واقعی آمازون IVS را بررسی کردیم تا به شما در آزمایش برنامه های پخش مستقیم خود کمک کند.
آیا در گردش کار توسعه خود ابزارهای تولیدی را پذیرفته اید؟ در نظرات زیر به من اطلاع دهید!