视频编码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了视频编码相关的知识,希望对你有一定的参考价值。
将摄像头录制的视频转换为mp4格式的代码:
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path] options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
NSString *exportPath = [NSString stringWithFormat:@"%@/%@.mp4",
[NSHomeDirectory() stringByAppendingString:@"/tmp"],
@"1"];
exportSession.outputURL = [NSURL fileURLWithPath:exportPath];
NSLog(@"%@", exportPath);
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"转换成功");
break;
default:
break;
}
}];
}
使用H.264视频编码(压缩)
一般来说,如果动态图像数据未经压缩就使用的话,数据量非常大,容易造成通信线路故障及数据存储容量紧张。因此,在发送动态图像时、或者 把影像内容保存在DVD上时、以及使用存储介质容量较小的数码相机或相机手机拍摄映像时,就必须使用编解码器。虽然编解码器有许多种类, 但DVD-Video与微波数字电视等使用的主要是MPEG2,数码相机等摄像时主要使用MPEG4。
以上是关于视频编码的主要内容,如果未能解决你的问题,请参考以下文章