2011-09-29 189 views
1

我正在使用GData Api从ios应用程序上传YouTube上的视频。 它成功上传视频,但音频从中丢失。GData youtube视频上传缺少音频

我正在使用.mp4格式的视频。 任何人都有线索吗?

感谢

-(BOOL) setupWriter{ 
    NSError *error = nil; 
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
// NSString *documentsDirectory = [paths objectAtIndex:0]; 
// NSURL * url = [NSURL URLWithString:documentsDirectory]; 
// url = [url URLByAppendingPathComponent:@"om.mp4"]; 


    // NSString *path = [documentsDirectory stringByAppendingPathComponent:@"om.mp4"]; 
    // [data writeToFile:path atomically:YES]; 


NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/movie.mp4"]]; 
_videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:path] fileType:AVFileTypeQuickTimeMovie 
              error:&error]; 
NSParameterAssert(_videoWriter); 


    // Add video input 
NSDictionary *videoCompressionProps = [NSDictionary dictionaryWithObjectsAndKeys: 
             [NSNumber numberWithDouble:128.0*1024.0], AVVideoAverageBitRateKey, 
             nil ]; 

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
           AVVideoCodecH264, AVVideoCodecKey, 
           [NSNumber numberWithInt:192], AVVideoWidthKey, 
           [NSNumber numberWithInt:144], AVVideoHeightKey, 
           videoCompressionProps, AVVideoCompressionPropertiesKey, 
           nil]; 

_videoWriterInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo 
                 outputSettings:videoSettings] retain]; 


float angle = M_PI/2; //rotate 180°, or 1 π radians 
_videoWriterInput.transform = CGAffineTransformMakeRotation(angle); 


NSParameterAssert(_videoWriterInput); 
_videoWriterInput.expectsMediaDataInRealTime = YES; 


    // Add the audio input 
AudioChannelLayout acl; 
bzero(&acl, sizeof(acl)); 
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono; 


NSDictionary* audioOutputSettings = nil;   
    // Both type of audio inputs causes output video file to be corrupted. 
if(NO) { 
     // should work from iphone 3GS on and from ipod 3rd generation 
    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]; 
} else { 
     // should work on any device requires more space 
    audioOutputSettings = [ NSDictionary dictionaryWithObjectsAndKeys:      
          [ NSNumber numberWithInt: kAudioFormatAppleLossless ], AVFormatIDKey, 
          [ NSNumber numberWithInt: 16 ], AVEncoderBitDepthHintKey, 
          [ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey, 
          [ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey,          
          [ NSData dataWithBytes: &acl length: sizeof(acl) ], AVChannelLayoutKey, 
          nil ]; 
} 

_audioWriterInput = [[AVAssetWriterInput 
         assetWriterInputWithMediaType: AVMediaTypeAudio 
         outputSettings: audioOutputSettings ] retain]; 

_audioWriterInput.expectsMediaDataInRealTime = YES; 




    // add input 
[_videoWriter addInput:_videoWriterInput]; 
[_videoWriter addInput:_audioWriterInput]; 

return YES; 
} 

这是我使用捕捉音频设置的作家是拧的东西在这个????

回答

2

CamStudio Support Forum

.MOV/.MP4/.3GPP文件

MOV/MP4/3GPP文件是基于索引。简而言之,这意味着 文件中有一个索引,告诉我们在文件中存在视频和音频帧的位置 。没有 索引,几乎不可能知道特定的视频或音频帧的数据在哪里。该索引包含在文件中称为 'moov'原子的位置。

现在,如果索引位于文件的起始位置,它将启用 处理视频,并在文件的连续字节上传 时进行处理。另一方面,如果索引处于末尾,则处理 视频无法开始,直到整个上传完成 - 因为需要 索引来解释文件。

因此,对于MOV/MP4/3gpp文件,我们更喜欢 文件开头处的“moov”原子 - 也称为“快速启动”MP4/MOV文件。 网上有一些工具可以使你的MOV文件变平。通常 视频编辑/导出软件将有选项来创建您的 文件与moov原子在开始而不是您的 文件的末尾。如果您使用的是Apple编辑工具,然后看到 这篇文章怎样产生的“快速启动” MP4/MOV file./p>

下面是一些知名的格式列表YouTube支持:

WebM文件 - VP8视频编解码器和Vorbis音频编解码器

.MPEG4,3GPP和MOV文件 - 通常支持H264,MPEG4视频编解码器 ,以及AAC音频编解码器

.AVI - 许多相机都会输出这种格式 - 典型视频编解码器是 MJPEG和音频是PCM

.MPEGPS - 通常支持MPEG2视频编解码器和MP2音频

。WMV

的FLV - 的Adobe-FLV1视频编解码器,MP3音频

+1

感谢@ankit我使用相同的MP4格式,但它仅与....纽约线索它一​​起上传视频音频不? – objectivecdeveloper