使用 USB 网络摄像头流进行 Telegram 视频通话 (pytgcalls)

发布于 2025-01-12 19:11:58 字数 2125 浏览 6 评论 0原文

我正在尝试使用 Telegram 上的 pytgcalls 发送 USB 网络摄像头的流。在 文档 中没有任何内容,但有几个流式 YouTube 视频或本地 mp4 文件的示例。我发现了这个流式传输 YouTube 视频的示例,我认为流式传输 USB 网络摄像头非常相似。 首先,导入模块:

import asyncio
from pyrogram import Client

from pytgcalls import idle
from pytgcalls import PyTgCalls
from pytgcalls import StreamType
from pytgcalls.types.input_stream import AudioImagePiped, AudioVideoPiped
from pytgcalls.types.input_stream.quality import HighQualityVideo, HighQualityAudio, LowQualityAudio, LowQualityVideo

现在,启动 Pyrogram 和 pytgcalls 客户端:

app = Client('py-tgcalls', api_id=API_ID, api_hash=API_HASH)

call_py = PyTgCalls(app)
call_py.start()

声明将 youtube 链接转换为流的函数:

def get_youtube_stream():
    async def run_async():
        proc = await asyncio.create_subprocess_exec(
            'youtube-dl',
            '-g',
            '-f',
            'best[height<=?720][width<=?1280]',
            # Some random YT link
            'https://www.youtube.com/watch?v=AAAAAAA',
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE,
        )
        stdout, stderr = await proc.communicate()
        return stdout.decode().split('\n')[0]
    return asyncio.get_event_loop().run_until_complete(run_async())

声明通过电报在组中发送流的函数:

def youtube():
    remote = get_youtube_stream()
    call_py.join_group_call(
        # Group ID
        -10011111111,
        AudioVideoPiped(
            remote,
            HighQualityAudio(),
            HighQualityVideo(),
        ),
        stream_type=StreamType().pulse_stream,
    )

现在函数 youtube( ) 可以执行:

youtube()

使用 idle() 来阻止脚本:

idle()

这是脚本,有人可以帮助我直播 USB 网络摄像头吗?

I'm trying to send the stream of a usb webcam with pytgcalls on Telegram. In the documentation there is nothing about that, but there are several example of streaming youtube video or local mp4 files. I have found this example of streaming a youtube video and I think that streaming a usb webcam is quite similar.
First of all, importing modules:

import asyncio
from pyrogram import Client

from pytgcalls import idle
from pytgcalls import PyTgCalls
from pytgcalls import StreamType
from pytgcalls.types.input_stream import AudioImagePiped, AudioVideoPiped
from pytgcalls.types.input_stream.quality import HighQualityVideo, HighQualityAudio, LowQualityAudio, LowQualityVideo

Now, start pyrogram and pytgcalls clients:

app = Client('py-tgcalls', api_id=API_ID, api_hash=API_HASH)

call_py = PyTgCalls(app)
call_py.start()

Declare the function that will convert the youtube link to a stream:

def get_youtube_stream():
    async def run_async():
        proc = await asyncio.create_subprocess_exec(
            'youtube-dl',
            '-g',
            '-f',
            'best[height<=?720][width<=?1280]',
            # Some random YT link
            'https://www.youtube.com/watch?v=AAAAAAA',
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE,
        )
        stdout, stderr = await proc.communicate()
        return stdout.decode().split('\n')[0]
    return asyncio.get_event_loop().run_until_complete(run_async())

Declare the function for sending the stream via telegram, in a group:

def youtube():
    remote = get_youtube_stream()
    call_py.join_group_call(
        # Group ID
        -10011111111,
        AudioVideoPiped(
            remote,
            HighQualityAudio(),
            HighQualityVideo(),
        ),
        stream_type=StreamType().pulse_stream,
    )

Now the function youtube() can be executed:

youtube()

Using idle() for blocking the script:

idle()

This is the script, can somebody help me in streaming the live of a usb webcam?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最近 pytgcalls (0.9.0) 添加了从 upd 流进行流式传输的可能性,您可以直接使用 ffmpeg 捕获媒体设备并进行本地 UDP 流式传输

Recently by pytgcalls (0.9.0) was added the possibility to stream from an upd stream, you can use directly ffmpeg to capture the media device and make local UDP streaming

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文