2011-10-04 64 views
5

我正在使用以下代码将.mov文件上传到youtube。它成功上传,但视频没有任何音频。请告诉我,如果我做错了什么....GData 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]; 
} 

请帮助我。提前致谢。

+0

还有其他问题上传AVAssetWriter的音频质量低,这就是为什么它无法上传... 。 – objectivecdeveloper

回答

0

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

1

我认为你需要改变MIME类型,如下

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

这件事工作正常,我也一件事我正在上传.mov文件不仅.MP4或.m4a的或者。FLV

1

以下应该可以帮助您:

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 Upload Quality

1

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

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];