代码之家  ›  专栏  ›  技术社区  ›  Gareth Simpson

是否可以从两个帧编号创建QTTimeRange?

  •  2
  • Gareth Simpson  · 技术社区  · 15 年前

    所有QTKit示例都使用秒来生成范围。一、 不幸的是,它有帧编号,并且需要精确到帧。我想我可以乘以帧速率,如果我能弄清楚如何从我的电影中获得帧速率的话。

    2 回复  |  直到 15 年前
        1
  •  1
  •   Bjoern    15 年前

    您应该能够通过查询以下内容来计算给定视频媒体的帧速率 mediaAttributes 属于 QTMedia :

    • QTMediaDurationAttribute

    • QTMediaSampleCountAttribute

    (QTKit文档中对其进行了描述 here )

    并使用以下公式进行计算:

    QTTime    duration     = ... // value get from mediaAttribute 
    NSNumber  sample_count = ... // value get from mediaAttribute
    double    fps = (sample_count.longValue * duration.timeScale) / duration.timeValue;
    

    请注意,我还没有尝试过这样做,但根据我在QuickTime C API和QuickTime文件格式方面的经验,我希望它能够正常工作。

    祝你好运!

        2
  •  0
  •   Nick Haddad    15 年前

    variable frame rates 以获得更好的压缩效果。在任何类型的电影中,你都会注意到这一点,电影的画面会冻结任何时间。见麦克布鲁克 The Road to 1080p, part1

    您可以使用QTMovie方法执行帧精确范围 frameStartTime:atTime frameEndTime:atTime

    // Initialize QTMovie object called 'movie', disable looping, etc
    
    [movie gotoEnd];
    QTTime endTime = [movie currentTime];
    
    [movie gotoBeginning];
    QTTime curTime = [movie currentTime];
    
    unsigned long numFrames = 0;
    while (true)
    {
        % get the end time of the current frame  
        [movie frameEndTime:&curTime];
    
        numFrames++;
    
        % If we get to the last frame, stop counting
        if (QTTimeCompare(curTime, endTime) == NSOrderedSame)
        {
           break;
        }
    }