YouTube Live API流状态和质量回调 [英] YouTube Live API Stream Status and Quality Callback

查看:112
本文介绍了YouTube Live API流状态和质量回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在YouTube直播的实时控制室"中,我可以看到流状态"视图,该视图向我显示了发送到YouTube RTMP端点的视频的详细信息.

In the "Live Control Room" of a YouTube Live broadcast, I can see a "Stream Status" view which shows me details of the video being sent to YouTube's RTMP endpoint.

我点击了 liveStreams 端点以获取状态",但仅返回active,表示视频流已成功发送到YouTube的RTMP端点,但没有有关视频数据或质量的信息.

I hit the liveStreams endpoint to get the "status" of the stream, but that only returns active, meaning that the video stream is being successfully sent to YouTube's RTMP endpoint, but no information about video data or quality.

此信息是否在API中公开?我还能看到有关视频的其他详细信息,例如发送到YouTube的比特率,fps等吗,以便我可以验证编码器是否正常工作?还是需要在客户端进行检查,并在离开编码器后立即检查视频,然后再到达RTMP端点.我正在编写iOS应用程序,因此对我来说,在网络上使用实时控制室"不是可行的解决方案.

Is this information exposed somewhere in the API? Can I also see additional details about the video, such as the bitrate, fps, etc. being sent to YouTube so I can verify my encoder is working correctly? Or does that check need to be done on the client-side and check the video right after it leaves the encoder before hitting the RTMP endpoint. I'm writing an iOS application, so using the "Live Control Room" on the web isn't a viable solution for me.

这是我在广播方面正在检查liveStream状态的内容:

Here's what I'm doing on the broadcasting side to check the liveStream status:

- (void)checkStreamStatus {
    [self getRequestWithURL:[NSString stringWithFormat:@"https://www.googleapis.com/youtube/v3/liveStreams?part=id,snippet,cdn,status&id=%@", self.liveStreamId] andBlock:^(NSDictionary *responseDict) {
        NSLog(@"response: %@", responseDict);

        // if stream is active, youtube is receiving data from our encoder
        // ready to transition to live
        NSArray *items = [responseDict objectForKey:@"items"];
        NSDictionary *itemsDict = [items firstObject];
        NSDictionary *statusDict = [itemsDict objectForKey:@"status"];
        if ([[statusDict objectForKey:@"streamStatus"] isEqualToString:@"active"]) {
            NSLog(@"stream ready to go live!");
            if (!userIsLive) {
                [self goLive]; // transition the broadcastStatus from "testing" to "live"
            }
        } else {
            NSLog(@"keep refreshing, broadcast object not ready on youtube's end");
        }
    }];
}

getRequestWithURL只是我创建的用于执行GET请求的通用方法:

getRequestWithURL is just a generic method I created to do GET requests:

- (void)getRequestWithURL:(NSString *)urlStr andBlock:(void (^)(NSDictionary *responseDict))completion {

    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];

    [request addValue:[NSString stringWithFormat:@"Bearer %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"]] forHTTPHeaderField:@"Authorization"];

    [request setHTTPMethod:@"GET"];

    // Set the content type
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        [self parseJSONwithData:data andBlock:completion];

    }];
}

- (void)parseJSONwithData:(NSData *)data andBlock:(void (^)(NSDictionary * responseDict))completion {
    NSError *error = nil;
    NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data
                                                                 options:kNilOptions
                                                                   error:&error];
    if (error) {
        NSLog(@"error: %@", [error localizedDescription]);
    }
    completion(responseDict);
}

这是我在消费者方面正在检查的视频质量:

Here's what I'm doing on the consumer side to check the video quality:

我正在使用Google的 YTPlayerView 库.

I am using the YTPlayerView library from Google.

- (void)notifyDelegateOfYouTubeCallbackUrl: (NSURL *) url {
  NSString *action = url.host;

  // We know the query can only be of the format http://ytplayer?data=SOMEVALUE,
  // so we parse out the value.
  NSString *query = url.query;
  NSString *data;
  if (query) {
    data = [query componentsSeparatedByString:@"="][4]; // data here is auto, meaning auto quality
  }
  ...
  if ([action isEqual:kYTPlayerCallbackOnPlaybackQualityChange]) {
    if ([self.delegate respondsToSelector:@selector(playerView:didChangeToQuality:)]) {
    YTPlaybackQuality quality = [YTPlayerView playbackQualityForString:data];
    [self.delegate playerView:self didChangeToQuality:quality];
  }
  ...
}

但是质量自动"似乎不是该库中受支持的质量常数:

But the quality "auto" doesn't seem to be a supported quality constant in this library:

// Constants representing playback quality.
NSString static *const kYTPlaybackQualitySmallQuality = @"small";
NSString static *const kYTPlaybackQualityMediumQuality = @"medium";
NSString static *const kYTPlaybackQualityLargeQuality = @"large";
NSString static *const kYTPlaybackQualityHD720Quality = @"hd720";
NSString static *const kYTPlaybackQualityHD1080Quality = @"hd1080";
NSString static *const kYTPlaybackQualityHighResQuality = @"highres";
NSString static *const kYTPlaybackQualityUnknownQuality = @"unknown";

...
@implementation YTPlayerView
...

/**
 * Convert a quality value from NSString to the typed enum value.
 *
 * @param qualityString A string representing playback quality. Ex: "small", "medium", "hd1080".
 * @return An enum value representing the playback quality.
 */
+ (YTPlaybackQuality)playbackQualityForString:(NSString *)qualityString {
  YTPlaybackQuality quality = kYTPlaybackQualityUnknown;

  if ([qualityString isEqualToString:kYTPlaybackQualitySmallQuality]) {
    quality = kYTPlaybackQualitySmall;
  } else if ([qualityString isEqualToString:kYTPlaybackQualityMediumQuality]) {
    quality = kYTPlaybackQualityMedium;
  } else if ([qualityString isEqualToString:kYTPlaybackQualityLargeQuality]) {
    quality = kYTPlaybackQualityLarge;
  } else if ([qualityString isEqualToString:kYTPlaybackQualityHD720Quality]) {
    quality = kYTPlaybackQualityHD720;
  } else if ([qualityString isEqualToString:kYTPlaybackQualityHD1080Quality]) {
    quality = kYTPlaybackQualityHD1080;
  } else if ([qualityString isEqualToString:kYTPlaybackQualityHighResQuality]) {
    quality = kYTPlaybackQualityHighRes;
  }

  return quality;
}

我为此在项目的上为此创建了一个问题. GitHub页面.

I created a issue for this on the project's GitHub page.

推荐答案

我收到了 Ibrahim Ulukaya 的回复.关于这个问题:

I received a reply from Ibrahim Ulukaya about this issue:

我们希望对该电话有更多信息,但基本上处于活动状态表示流媒体质量很好,而您的流媒体信息为 https://developers.google.com/youtube/v3/live/docs/liveStreams#cdn.format 在此处设置,并可以查看格式.

We are hoping to have more information to that call, but basically active indicates the good streaming, and your streaming info is https://developers.google.com/youtube/v3/live/docs/liveStreams#cdn.format where you set, and can see the format.

因此,暂时的答案是否",暂时无法从YouTube Livestreaming API获得此信息.如果/在更新API时,我将更新此答案.

So the answer for the time being is no, this information is not available from the YouTube Livestreaming API for the time being. I will updated this answer if/when the API is updated.

这篇关于YouTube Live API流状态和质量回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆