有人可以解释一下源时间、电影时间、演示时间等吗?

发布于 2024-12-04 02:13:44 字数 940 浏览 0 评论 0原文

在我的 iOS 应用程序中,我需要将图像保存为短视频片段。我使用 AVAssetWriter 和 AVAssetWriterPixelBufferAdaptor 来完成这项工作,这要归功于该网站上的一些精彩帖子,但我不得不捏造开始和结束会话时间以及演示时间,因为我不太理解它们。

下面的片段创建了一个 2 秒的视频,但我通过反复试验设置了不同的时间。老实说,我不知道为什么它不创建 3 秒的视频。

// start session
videoWriter.movieFragmentInterval = CMTimeMake(1,600);
[videoWriter startWriting];
CMTime startTime = CMTimeMake(0, 600);
[videoWriter startSessionAtSourceTime:startTime];

while (1) {
    if (![writerInput isReadyForMoreMediaData]) {
        NSLog(@"Not ready for data");
    } else {
        [avAdaptor appendPixelBuffer:pixelBuffer 
                withPresentationTime:CMTimeMake(1200,600)];
        break;
    }
}

//Finish the session:
[writerInput markAsFinished];
CMTime endTime = CMTimeMake(1800, 600);
[videoWriter endSessionAtSourceTime:endTime];
[videoWriter finishWriting];

谁能解释一下这个片段中的各种时间设置,或者给我指出一个有帮助的文档?我已经阅读了苹果文档,直到我斗鸡眼,但我猜他们假设的知识比我目前拥有的知识更多。

蒂亚:约翰

In my iOS app, I need to save an image as a short video segment. I have this working using AVAssetWriter and AVAssetWriterPixelBufferAdaptor, thanks to some of the great posts on this site, but I've had to fudge the start and end session times, and presentation times, because I don't really understand them.

The following fragment creates a 2 second video, but I've set the various times by trial and error. I'm not sure why it doesn't create a 3 second video, to be honest.

// start session
videoWriter.movieFragmentInterval = CMTimeMake(1,600);
[videoWriter startWriting];
CMTime startTime = CMTimeMake(0, 600);
[videoWriter startSessionAtSourceTime:startTime];

while (1) {
    if (![writerInput isReadyForMoreMediaData]) {
        NSLog(@"Not ready for data");
    } else {
        [avAdaptor appendPixelBuffer:pixelBuffer 
                withPresentationTime:CMTimeMake(1200,600)];
        break;
    }
}

//Finish the session:
[writerInput markAsFinished];
CMTime endTime = CMTimeMake(1800, 600);
[videoWriter endSessionAtSourceTime:endTime];
[videoWriter finishWriting];

Can anyone explain the various time settings in this fragment, or point me to a document that will help? I've read the apple docs until I'm cross-eyed, but they assume more knowledge than I currently have, I guess.

TIA: John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文