我正在尝试使用cURL编写一个从远程位置(在本例中为twitch.tv)获取JSON文件的脚本(不要认为该部分太相关,不过我最好还是提一下).例如,假设它返回的JSON对象在存储在变量中之后看起来像这样:
$json_object = {"_links":{"self":"https://api.twitch.tv/kraken/streams/gmansoliver","channel":"https://api.twitch.tv/kraken/channels/gmansoliver"},"stream":null}
Run Code Online (Sandbox Code Playgroud)
我访问"stream"属性,我试过以下代码:
<?php
$json_object = {"_links":{"self":"https://api.twitch.tv/kraken/streams/gmansoliver","channel":"https://api.twitch.tv/kraken/channels/gmansoliver"},"stream":null}
$json_decoded = json_decode($json_object, true);
echo $json_decoded->stream;
?>
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我收到错误"注意:尝试在第48行的D:\ Servers\IIS\Sites\mysite\getstream.php中获取非对象的属性".
我是否使用json_decode()错误,或者我是从抽搐发送的JSON对象有什么问题?
编辑:
我现在有了JSON对象:
{"access_token": "qwerty1235","refresh_token": "asdfghjkl=","scope": ["user_read"]}
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用它解码它json_decode()我得到以下错误:Object of class stdClass could not be converted to string.有什么建议?
在此先感谢您的帮助
我试图使用FFMPEG将已经录制的视频文件流式传输到抽搐服务器,但到目前为止我只获得音频,而没有视频。我尝试了几种设置,以及不同的文件(avi等),但是我仍然只获得音频。这是我的FFMPEG设置:
ffmpeg -re -i test.mp4 -vcodec libx264 -preset fast -crf 30 -acodec aac -ab 128k -ar 44100 -strict experimental -f flv rtmp://live-dfw.twitch.tv/app/"TWITCHKEY"
Run Code Online (Sandbox Code Playgroud)
有人钉过这个吗?我在Ubuntu下使用ffmpeg 0.8.17-6:0.8.17-1。
所以我正在制作一个 Discord Bot,当一个人在 Twitch.tv 上直播时会发帖。目前,我有一个运行机器人的 Python 程序和一个运行微型服务器以从 Twitch 服务器(webhook)接收数据的程序。我不确定如何将从我的服务器收到的数据传递给不和谐机器人。两个程序必须同时运行。
不和谐机器人
import discord
client = discord.Client()
async def goes_live(data):
print(data)
print('Going Live')
msg = '--- has gone live'
await client.send_message(discord.Object(id='---'), msg)
@client.event
async def on_message(message):
if message.author == client.user:
return
message.content = message.content.casefold()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run('---')
Run Code Online (Sandbox Code Playgroud)
网络服务器
import web
urls = ('/.*', 'hooks')
app = web.application(urls, globals())
class hooks:
def POST(self):
data = web.data()
print("")
print('DATA RECEIVED:')
print(data)
print("")
return 'OK'
def GET(self): …Run Code Online (Sandbox Code Playgroud) Twitch 有新的 API 和 V5 API,我想完全使用 V5 API,因为那个 API 提供了更多关于频道的信息。当我使用浏览器开发工具中的评估令牌时,API 正在工作。
但是当我使用通过 Omniauth 授权获得的asset_token 时,API 无法正常工作,并且{"error":"Gone","status":410,"message":"It's time to kick ass and serve v3... and I'm all outta v3. See https://dev.twitch.tv/docs"}经常出现类似错误。文档说 V5 API 仍在工作(尽管已弃用)。
Helix 和 Kraken API 具有不同类型的令牌(Bearer和OAuth)
如何OAuth在用户身份验证后准确获取access_token 以便能够使用 V5 API?来自浏览器开发工具的令牌与新 API 和 V5 API 一样工作,但从 Omniauth 获得的令牌仅适用于新 API。
解决了
访问令牌可用于新 API 和 V5 API。使用 V5 API 只需要在请求中添加Accept标头application/vnd.twitchtv.v5+json。
我想让我的软件定期(每 5 分钟左右)截取当前正在发生的直播的屏幕截图。我在 Youtube 和 Twitch 上都标记了这个问题,因为这两个网站都在直播,所以适用于其中任何一个的答案都是完美的。
我研究了一些较旧的库,例如 youtube-dl 和 livestreamer,但它们是 CLI,下载文件然后需要使用视频播放器读取。
设置是 Linux,ffmpeg 使用 kabylake iGPU。
我正在使用kmsgrab设备捕获正在运行的摇摆实例,这需要使用硬件后端在我的硬件上连贯地处理图像。只有 VA API 符合此要求。我想在编码过程中在右下角覆盖网络摄像头。然而,试图操纵过滤器图来实现这一点的尝试没有成功。这最终适用于 Twitch/Tube 流。
现在,我实际上是将网络摄像头捕获到 sdl 窗口,并使用单独的ffmpeg. 这实际上并没有解决我的问题,因为窗口很容易被工作区切换或其他窗口伪装。
这是解决方法:
#!/usr/bin/env zsh
# record webcam and open it in sdl window
ffmpeg -v quiet -hide_banner \
-re -video_size 640X480 -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i /dev/video0 \
-vf 'format=nv12,hwupload' -c:v hevc_vaapi -f hevc - \
| ffmpeg -v quiet -i - -f sdl2 - &
# wait for webcam window to open
until swaymsg -t get_tree | grep 'pipe:' …Run Code Online (Sandbox Code Playgroud) 我正在使用 nextJS,但很难从重定向中获取完整的 URL。
我正在从 Twitch 执行 oauth 流程,经过身份验证后,Twitch 会在 URL 上重定向回我的下一个应用程序,例如http://localhost:3000/auth/twitch/- 它们在该重定向 URL 上包含一堆额外数据,例如
http://localhost:3000/auth/twitch/callback#access_token=4kfdiopdsjendc539c9234&scope=user_read&token_type=bearer
/pages/auth/callback.js
export async function getServerSideProps(context) {
console.log(context);
return {
props: {},
};
}
Run Code Online (Sandbox Code Playgroud)
我试图从重定向中获取查询参数(例如 access_token),但由于 Twitch 使用 # 将其附加到我的重定向网址上,因此内部context似乎没有检测到它。
我知道如果我手动将#浏览器中的 更改为?thencontext.query就可以了。问题是,我无法决定 Twitch 如何攻击他们的 URL 数据。
如何访问查询参数?
我正在尝试制作我自己的小不和谐机器人,它可以从 Twitch 获取信息,但我对如何使机器人循环并检查条件感到困惑。
我希望机器人每隔几秒钟循环一段代码,以检查指定的 twitch 频道是否处于活动状态。
代码
import discord
from discord.ext import commands, tasks
from twitch import TwitchClient
from pprint import pformat
client = TwitchClient(client_id='<twitch token>')
bot = commands.Bot(command_prefix='$')
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.command()
async def info(ctx, username):
response = await ctx.send("Querying twitch database...")
try:
users = client.users.translate_usernames_to_ids(username)
for user in users:
print(user.id)
userid = user.id
twitchinfo = client.users.get_by_id(userid)
status = client.streams.get_stream_by_user(userid)
if status == None:
print("Not live")
livestat = twitchinfo.display_name + "is not …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用这个 twitch npm 包 ( https://www.npmjs.com/package/twitch ),并且在通过 creat-react-app / react-scripts 部署时遇到了一些问题。
根据我的理解,与 create-react-app 捆绑的 webpack 配置不喜欢这个 npm 包正在使用的 .mjs 文件。因此,当我尝试构建应用程序时,出现以下错误。
./node_modules/twitch/es/API/Kraken/Channel/ChannelApi.mjs
app_1 | Can't import the named export 'Cacheable' from non EcmaScript module (only default export is available)
Run Code Online (Sandbox Code Playgroud)
如果我手动删除了“es”文件夹,那么构建工作并且一切都按预期运行。但是,这不是真正的解决方案,因为当我推送到生产并在那里部署时,会重新安装节点模块并且构建再次失败。
构建过程并不是我的强项,在谷歌搜索一段时间后我无法找到解决方案。如果有人可以提供帮助或可以指出我正确的方向,那将不胜感激!
如果有帮助,这是我的 package.json
{
"name": "ui",
"version": "1.0.0",
"license": "UNLICENCED",
"private": true,
"dependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/register": "^7.0.0",
"axios": "^0.19.2",
"babel-plugin-dynamic-import-node": "^2.2.0",
"btoa": "^1.2.1",
"clipboard-copy": "^3.0.0",
"connected-react-router": "^6.8.0",
"dateformat": "^3.0.3",
"dotenv": "^8.0.0",
"draft-js": "^0.11.0",
"draft-js-export-html": "^1.4.1",
"express": "^4.16.4",
"file-loader": …Run Code Online (Sandbox Code Playgroud) 今天,我尝试使用Arch 解决方案通过 FFMPEG 进行流式传输,但由于 FFMPEG 上的一件简单的事情,我所有的尝试都徒劳无功。它说探针大小不够大,所以我本能地越来越大地增加探针大小......现在它-probesize "500M"仍然说它不够大。这是代码片段
[x11grab @ 0x5631f846cd00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0':
Duration: N/A, start: 1603397505.341400, bitrate: 1007124 kb/s
Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1366x768, 1007124 kb/s, 30 fps, 1000k tbr, 1000k tbn, 1000k tbc
0: Input/output error
Run Code Online (Sandbox Code Playgroud)
和代码
#!/bin/bash
INRES="1366x768" # input resolution
OUTRES="1366x768" # output resolution
FPS="30" # target FPS
GOP="60" # i-frame interval, should be double …Run Code Online (Sandbox Code Playgroud) twitch ×10
ffmpeg ×3
discord ×2
twitch-api ×2
youtube ×2
api ×1
discord.py ×1
javascript ×1
json ×1
next.js ×1
php ×1
python ×1
python-3.x ×1
reactjs ×1
rtmp ×1
screenshot ×1
streaming ×1
vaapi ×1
video ×1
webpack ×1