AVMutableComposition - 视频资源之间的空白/黑框
我目前正在尝试使用 AVMutableComposition 将 5 个视频背靠背放置,如下所示:
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset1.duration) ofAsset:asset1 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration) ofAsset:asset2 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset3.duration) ofAsset:asset3 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset4.duration) ofAsset:asset4 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset5.duration) ofAsset:asset5 atTime:[mixComposition duration] error:nil];
然后我使用 AVAssetExportSession 导出视频,但它在每个视频之间工作,我得到一个需要删除的空白/黑色帧。以前有人遇到过这个问题吗?如果有的话,你解决了吗?
此外,空白帧不在源视频文件中。
提前致谢。
I'm currently trying to put 5 videos back to back using AVMutableComposition like so:
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset1.duration) ofAsset:asset1 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration) ofAsset:asset2 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset3.duration) ofAsset:asset3 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset4.duration) ofAsset:asset4 atTime:[mixComposition duration] error:nil];
[mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset5.duration) ofAsset:asset5 atTime:[mixComposition duration] error:nil];
I then use an AVAssetExportSession to export the video, which works however between each video I'm getting a blank/black frame which I need to remove. Has anyone had this problem before and if so did you manage to fix it?
Also, the blank frames aren't in the source video files.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
前几天我也遇到了同样的问题。
如果您通过从再次使用 insertTimeRange 创建的其他资产导出资产(资产 1、资产 2 等)来获取资产,则情况相同。
问题是,当您导出使用 insertTimeRange 创建的资源时,导出不会正确,当您附加此类视频时,它们之间会出现黑框。
尝试使用 AVAssetExportSession 的“timeRange”选项,并从主资源中剪切所需的范围。然后你的资产就会正确附加。
I had the same problem the other day.
If you got your assets(asset1, asset2, etc.) by exporting them from other asset which was created using again insertTimeRange, then it's the same case.
The problem is that when you export assets created using insertTimeRange, the export doesn't go correct, when you attach such videos black frames appear between them.
Try using "timeRange" option of the AVAssetExportSession, and cut the range you need from the main asset. Then your assets will attach correct.
我刚刚遇到了同样的问题。结果解决方案是使用 AVMutableCompositionTrack 并合成视频轨道,类似这样。
对于音频部分,我认为您必须添加一个具有 AVMediaTypeAudio 类型的单独轨道。
I just met the same problem. Turn out the solution is using AVMutableCompositionTrack and compositing the video tracks, something like this.
For the audio part I think you must add a separate track with AVMediaTypeAudio type.