Search code examples
iphonevideouploadyoutubegdata

GData youtube video upload missing audio


I am using GData Api to upload video on youtube from ios application. It successfully uploads the video but audio is missing from that.

I am using .mp4 format of video. Do any one has a clue?

Thanks

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

this is setup writer I am using to capture audio is something wring in this????


Solution

  • From the CamStudio Support Forum:

    .MOV / .MP4 / .3GPP files

    MOV /MP4 /3GPP files are index based. Simply put, this means that there is an index in the file that tells us the specific location of where in the file the video and audio frames are present. Without the index, it is almost impossible to know where the data for a specific video or audio frame is. This index is contained in what is called a 'moov' atom in the file.

    Now, if the index is at the beginning of the file, it will enable processing of the video as and when successive bytes of the file are uploaded. On the other hand, if the index is at the end, processing the video cannot begin until the entire upload is complete - since the index is needed to interpret the file.

    Hence, for MOV / MP4 / 3gpp files, we prefer the "moov" atom in the beginning of the file - also known as a "fast start"MP4 / MOV file. There are tools available on the web to flatten your MOV file. Usually the video editing/export software will have options to create your files with the moov atom in the beginning rather than the end of your file. If you are using Apple editing tools, then see this article on how to produce a "fast start" MP4/MOV file./p>

    Here's a list of some well-known formats that YouTube supports:

    WebM files - Vp8 video codec and Vorbis Audio codecs

    .MPEG4, 3GPP and MOV files - Typically supporting h264, mpeg4 video codecs, and AAC audio codec

    .AVI - Many cameras output this format - typically the video codec is MJPEG and audio is PCM

    .MPEGPS - Typically supporting MPEG2 video codec and MP2 audio

    .WMV

    .FLV - Adobe-FLV1 video codec, MP3 audio