2

在 YouTube 直播的“直播控制室”中,我可以看到“流状态”视图,其中显示了正在发送到 YouTube 的 RTMP 端点的视频的详细信息。流状态

我点击liveStreams端点以获取流的“状态”,但这仅返回active,这意味着视频流已成功发送到 YouTube 的 RTMP 端点,但没有有关视频数据或质量的信息。

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

这是我在广播端检查直播状态的方法:

- (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 请求的通用方法:

- (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);
}

以下是我在消费者方面检查视频质量所做的工作:

我正在使用 Google 的YTPlayerView库。

- (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];
  }
  ...
}

但是质量“自动”似乎不是这个库中支持的质量常数:

// 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 页面上为此创建了一个问题。

4

2 回答 2

1

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

我们希望有更多关于该通话的信息​​,但基本上活动表示良好的流媒体,您的流媒体信息是https://developers.google.com/youtube/v3/live/docs/liveStreams#cdn.format您设置,并且可以看到格式。

所以暂时的答案是否定的,YouTube Livestreaming API 暂时无法提供此信息。如果/当更新 API 时,我会更新这个答案。

于 2014-12-11T21:02:55.170 回答
0

似乎 Youtube Live Streaming API 已更新以显示带有此属性的 Live Stream 健康状态:status.healthStatus.status

有关更多信息,请参阅他们最新的 API

于 2016-04-27T17:03:37.520 回答