如何使用 AVAssetWriter 制作缩小尺寸的视频?
我会制作缩小尺寸的视频,宽度可能为 50 像素,长度可能为 75 像素。这些是物理维度。
你如何设置呢?在视频设置中?我认为 AVVideoWidthKey 和 AVVideoHeightKey 更多的是为了分辨率而不是我需要的物理尺寸。
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt: 320], AVVideoWidthKey,
[NSNumber numberWithInt:480], AVVideoHeightKey,
nil];
AVAssetWriterInput* writerInput = [[AVAssetWriterInput
assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videoSettings] retain
I would make reduced size video, maybe 50 pixel across and 75 pixels for length. Those are the physical dimension.
How do you set that? in the videosettings? I think AVVideoWidthKey and AVVideoHeightKey are more for resolution not for physically dimension which what I needed.
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt: 320], AVVideoWidthKey,
[NSNumber numberWithInt:480], AVVideoHeightKey,
nil];
AVAssetWriterInput* writerInput = [[AVAssetWriterInput
assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videoSettings] retain
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置视频编解码器参数:
You need to set video codec parameters:
您需要拥有博士学位才能使用 AVAssetWriter - 这并不简单:
https: //developer.apple.com/library/mac/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html#//apple_ref/doc/uid/TP40010188-CH9-SW1
有一个令人惊叹的库可以做到这一点您想要的只是 AVAssetExportSession 的替代品,具有更重要的功能,例如更改比特率: https://github.com/rs/ SDAVAssetExportSession
使用方法如下:
You need a PhD to work with AVAssetWriter - it's non-trivial:
https://developer.apple.com/library/mac/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html#//apple_ref/doc/uid/TP40010188-CH9-SW1
There's an amazing library for doing exactly what you want which is just an AVAssetExportSession drop-in replacement with more crucial features like changing the bit rate: https://github.com/rs/SDAVAssetExportSession
Here's how to use it: