AVMutableComposition - 视频资源之间的空白/黑框

发布于 2024-12-14 08:33:51 字数 905 浏览 0 评论 0原文

我目前正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情出卖 2024-12-21 08:33:51

前几天我也遇到了同样的问题。

如果您通过从再次使用 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.

咿呀咿呀哟 2024-12-21 08:33:51

我刚刚遇到了同样的问题。结果解决方案是使用 AVMutableCompositionTrack 并合成视频轨道,类似这样。

AVMutableCompositionTrack * videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

[videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:composition.duration error:&error];

对于音频部分,我认为您必须添加一个具有 AVMediaTypeAudio 类型的单独轨道。

I just met the same problem. Turn out the solution is using AVMutableCompositionTrack and compositing the video tracks, something like this.

AVMutableCompositionTrack * videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

[videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:composition.duration error:&error];

For the audio part I think you must add a separate track with AVMediaTypeAudio type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文