通过C#限制上传到YouTube的视频长度
我正在开发一个项目,该项目将使用 YouTube API 的 .NET 包装器。我们将向用户提供一个表格,他们可以在其中上传视频,视频将发布到 YouTube 上的特定页面。我们希望将上传的视频长度限制为 60 秒。是否可以在上传代码中在 C# 级别设置这样的长度限制?我在 API 文档 中找不到任何具体信息。
我怀疑这是无法完成的,因为您需要先上传实际视频才能确定其长度。
I'm working on a project that will use the .NET wrapper for the YouTube API. We will provide a form to users where they can upload a video and it will get posted to a specific page on YouTube. We'd like to limit the length of videos that are uploaded to 60 seconds. Is it possible to set such a length limit at the C#-level in the upload code? I was unable to find anything specific about this in the API docs.
I suspect that this cannot be done as you need to upload the actual video first to determine its length.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是对的。您必须上传然后检查文件属性以确定长度。理论上,您可以在流式传输时查询此内容,因为您可以查看标头中的元数据。我从来没有查询过视频,所以我不确定它是如何格式化的。如果您朝这个方向前进,并且标头的长度属性大于 60 秒,则可以中止流。
这里可能存在的问题是某些类型的媒体文件不包含长度属性。不过,我不确定可以上传到 YouTube 的类型。
You are correct. You would have to upload and then check the file attributes to determine length. Theoretically, you can query this while streaming, as you can look at the metadata in the header. I have never queried video, so I am not sure how this is formatted. If you head this direction, you can abort the stream if the header has a length attribute greater than 60 seconds.
A possible issue here is certain types of media files don't contain the length attribute. I am not sure about the types one can upload to YouTube, however.
在将文件传输到 YouTube 之前,您必须将文件本地保存在服务器上。然后,您必须使用媒体库加载视频并确认其长度,然后再进行任何进一步的处理。
请参阅 这是一个例子。
我没有使用 YouTube API,但另一种方法可能是上传视频,从 YouTube 检查其长度,如果违反了您的限制,则将其删除。
You will have to resort to saving the file locally on the server before transmitting it to YouTube. You would then have to use a Media Library to load the video and confirm its length before doing any further processing.
See this for an example.
I haven't used the YouTube API, but an alternative may be to upload the video, check its legnth from YouTube and remove it if it is in violation of your limits.