2012-01-16 11 views
5

Tôi là một người mới trong AVFoundation và giải mã process.I cần phải giải mã một tập tin video h264 và chơi nó trong iphone ... bất cứ ai có thể cho tôi hướng dẫn để làm điều đó.giải mã h264 trong ios

Tôi không muốn sử dụng ffmpeg hoặc bất kỳ thư viện của bên thứ ba nào để thực hiện điều đó. Theo như tôi biết sử dụng mã hóa AVFoundation có thể ... đây là đoạn code mà tôi nghĩ được sử dụng để mã hóa nhưng không chắc chắn ở tất cả ...

float bitsPerPixel; 
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(currentFormatDescription); 
int numPixels = dimensions.width * dimensions.height; 
int bitsPerSecond; 

// Assume that lower-than-SD resolutions are intended for streaming, and use a lower bitrate 
if (numPixels < (640 * 480)) 
    bitsPerPixel = 4.05; // This bitrate matches the quality produced by AVCaptureSessionPresetMedium or Low. 
else 
    bitsPerPixel = 11.4; // This bitrate matches the quality produced by AVCaptureSessionPresetHigh. 

bitsPerSecond = numPixels * bitsPerPixel; 

NSDictionary *videoCompressionSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
              AVVideoCodecH264, AVVideoCodecKey, 
              [NSNumber numberWithInteger:dimensions.width], AVVideoWidthKey, 
              [NSNumber numberWithInteger:dimensions.height], AVVideoHeightKey, 
              [NSDictionary dictionaryWithObjectsAndKeys: 
              [NSNumber numberWithInteger:bitsPerSecond], AVVideoAverageBitRateKey, 
              [NSNumber numberWithInteger:30], AVVideoMaxKeyFrameIntervalKey, 
              nil], AVVideoCompressionPropertiesKey, 
              nil]; 
if ([assetWriter canApplyOutputSettings:videoCompressionSettings forMediaType:AVMediaTypeVideo]) { 
    assetWriterVideoIn = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeVideo outputSettings:videoCompressionSettings]; 
    assetWriterVideoIn.expectsMediaDataInRealTime = YES; 
    assetWriterVideoIn.transform = [self transformFromCurrentVideoOrientationToOrientation:self.referenceOrientation]; 
    if ([assetWriter canAddInput:assetWriterVideoIn]) 
     [assetWriter addInput:assetWriterVideoIn]; 
    else { 
     NSLog(@"Couldn't add asset writer video input."); 
     return NO; 
    } 
} 
else { 
    NSLog(@"Couldn't apply video output settings."); 
    return NO; 
} 

return YES; 

Tôi hoàn toàn ngây thơ về vấn đề này, xin vui lòng giúp đỡ .. .từ nơi bắt đầu ///

cảm ơn

+0

Tôi đang cố gắng làm điều tương tự khi bạn tìm ra giải pháp? –

+0

dự án đã bị hủy ... chúng tôi không tìm thấy giải pháp ... –

Trả lời

0

Giải pháp đơn giản hơn là sử dụng MPMoviePlayerController. Nó lấy đầu vào một tệp mov hoặc mv4 (từ hệ thống tệp cục bộ hoặc thông qua một URL).

Tùy chọn khác là sử dụng lớp AVPlayer.

Hy vọng nó sẽ giúp,

David

0

Bạn có thể tham khảo và xây dựng mẫu mã chính thức: AVPlayerDemo để xem cách nó hoạt động. Nó sử dụng khuôn khổ AV Foundation, chủ yếu là các API AVPlayer để phát các tệp video và hiệu suất là tuyệt vời. Để phát tệp video bằng AVPlayerDemo, bạn nên sao chép các tệp video vào thiết bị iOS của mình theo itunes và chọn thư viện iPod trên ứng dụng AVPlayerDemo.