GData youtube视频上传缺少音频问题

发布于 2024-12-08 03:07:42 字数 2697 浏览 2 评论 0原文

我正在使用以下代码将 .mov 文件上传到 youtube。上传成功,但视频没有任何音频。如果我做错了什么,请告诉我......

- (void)uploadVideoFile {

  NSString *devKey = @"AI39si4w9QSgQj1JzNxzuiHhFbTm2iLt3mRerGh0UNvlryRPGgQhgIaJA8l95j4YwdC1jBIz6_JaX8eJm2GMgE06FtvIu7E9Sg";

  GDataServiceGoogleYouTube *service = [self youTubeService];
  [service setYouTubeDeveloperKey:devKey];

  NSString *username = txtYName.text;

  NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];

  // load the file data
  NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/movie.mov"]] retain];
  NSData *data = [NSData dataWithContentsOfFile:path];
  NSString *filename = [path lastPathComponent];

  // gather all the metadata needed for the mediaGroup
  NSString *titleStr = txtName.text;
  GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];

  NSString *categoryStr = @"Comedy";
  GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
  [category setScheme:kGDataSchemeYouTubeCategory];

  NSString *descStr = @"this is just test";
  GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];

  NSString *keywordsStr = @"SuperShredBros";
  GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];

  BOOL isPrivate = NO;

  GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
  [mediaGroup setMediaTitle:title];
  [mediaGroup setMediaDescription:desc];
  [mediaGroup addMediaCategory:category];
  [mediaGroup setMediaKeywords:keywords];
  [mediaGroup setIsPrivate:isPrivate];

  NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:path
                                             defaultMIMEType:@"video/quicktime"];

  // create the upload entry with the mediaGroup and the file data
  GDataEntryYouTubeUpload *entry;
  entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
                                                        data:data
                                                    MIMEType:mimeType
                                                        slug:filename];

  SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
  [service setServiceUploadProgressSelector:progressSel];

  GDataServiceTicket *ticket;
  ticket = [service fetchEntryByInsertingEntry:entry
                                           forFeedURL:url
                                             delegate:self
                             didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];

  [self setUploadTicket:ticket];
//  [self updateUI];
}

请帮助我。提前致谢。

I am using following code to upload .mov file to youtube. It upload successfully but the video don't have any audio. Please tell me if I am doing something wrong....

- (void)uploadVideoFile {

  NSString *devKey = @"AI39si4w9QSgQj1JzNxzuiHhFbTm2iLt3mRerGh0UNvlryRPGgQhgIaJA8l95j4YwdC1jBIz6_JaX8eJm2GMgE06FtvIu7E9Sg";

  GDataServiceGoogleYouTube *service = [self youTubeService];
  [service setYouTubeDeveloperKey:devKey];

  NSString *username = txtYName.text;

  NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];

  // load the file data
  NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/movie.mov"]] retain];
  NSData *data = [NSData dataWithContentsOfFile:path];
  NSString *filename = [path lastPathComponent];

  // gather all the metadata needed for the mediaGroup
  NSString *titleStr = txtName.text;
  GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];

  NSString *categoryStr = @"Comedy";
  GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
  [category setScheme:kGDataSchemeYouTubeCategory];

  NSString *descStr = @"this is just test";
  GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];

  NSString *keywordsStr = @"SuperShredBros";
  GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];

  BOOL isPrivate = NO;

  GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
  [mediaGroup setMediaTitle:title];
  [mediaGroup setMediaDescription:desc];
  [mediaGroup addMediaCategory:category];
  [mediaGroup setMediaKeywords:keywords];
  [mediaGroup setIsPrivate:isPrivate];

  NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:path
                                             defaultMIMEType:@"video/quicktime"];

  // create the upload entry with the mediaGroup and the file data
  GDataEntryYouTubeUpload *entry;
  entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
                                                        data:data
                                                    MIMEType:mimeType
                                                        slug:filename];

  SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
  [service setServiceUploadProgressSelector:progressSel];

  GDataServiceTicket *ticket;
  ticket = [service fetchEntryByInsertingEntry:entry
                                           forFeedURL:url
                                             delegate:self
                             didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];

  [self setUploadTicket:ticket];
//  [self updateUI];
}

please help me. Thanks in advance.

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

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

发布评论

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

评论(4

轻许诺言 2024-12-15 03:07:42

更改你的输出音频设置......它应该是这样的......

audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                              [ NSNumber numberWithInt: kAudioFormatMPEG4AAC ], AVFormatIDKey,
                              [ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey,
                              [ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
                              [ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
                              [ NSData dataWithBytes: &acl length: sizeof( acl ) ], AVChannelLayoutKey,
                              nil];

change your output audio setting.... it should be like this.....

audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                              [ NSNumber numberWithInt: kAudioFormatMPEG4AAC ], AVFormatIDKey,
                              [ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey,
                              [ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
                              [ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
                              [ NSData dataWithBytes: &acl length: sizeof( acl ) ], AVChannelLayoutKey,
                              nil];
演出会有结束 2024-12-15 03:07:42

我认为 Youtube 支持 flv 和 mp4 格式的视频文件。所以请更改 mimetype。
希望您能得到预期的结果。

i think Youtube supports flv and mp4 format video files. so please change mimetype.
Hope you get expected results.

万劫不复 2024-12-15 03:07:42

我认为你需要更改 mime 类型,如下所示,

NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:fetchPath
                                           defaultMIMEType:@"video/mp4"];

这对我来说效果很好,而且我还将 .Mov 文件上传到不仅是 .mp4 或 .m4a 或 .flv

I think you need to change mime type as below

NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:fetchPath
                                           defaultMIMEType:@"video/mp4"];

This thing works fine for me and also one more thing i am uploading .Mov file to not only .mp4 or .m4a or .flv

轮廓§ 2024-12-15 03:07:42

以下内容应该对您有帮助:

GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category]; 
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:NO];

NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:outputURL.relativePath defaultMIMEType:@"video/quicktime"];

GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup data:data MIMEType:mimeType slug:filename];

SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];

GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry forFeedURL:url delegate:self didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];

供参考:Youtube 上传质量

Following should help you:

GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category]; 
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:NO];

NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:outputURL.relativePath defaultMIMEType:@"video/quicktime"];

GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup data:data MIMEType:mimeType slug:filename];

SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];

GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry forFeedURL:url delegate:self didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];

for reference: Youtube Upload Quality

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