菜鸟教程小白 发表于 2022-12-13 14:28:02

ios - AVFileCapture 输出 : Not recording at 240 fps


                                            <p><p>我似乎在将相机设置为以 240 FPS 录制时遇到了问题,但由于某种原因,输出文件只有 30 FPS。 </p>

<p>这是我设置相机的代码(这是首先实例化的):</p>

<pre><code>class HFRCamera {
public:
    HFRCamera();

    AVCaptureDeviceInput *camera;
    AVCaptureDeviceInput *microphone;
    AVCaptureDevice *videoCam;
    AVCaptureDevice *audioInput;
    AVCaptureSession *capSession;

    void start();
    void config();
    void stop();

};

HFRCamera::HFRCamera() {

   // Set up capture session and add video camera and microphone
    this-&gt;capSession = [ init];
    this-&gt;videoCam = ;
   this-&gt;config();


}

void HFRCamera::start() {
    ;
}

void HFRCamera::stop() {
    ;
}

void HFRCamera::config() {

const CGFloat desiredFPS = 240;
AVCaptureDeviceFormat *selectedFormat = nil;
AVFrameRateRange *frameRateRange = nil;
int32_t maxWidth = 0;

for (AVCaptureDeviceFormat *format in ) {

    for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {

      CMFormatDescriptionRef desc = format.formatDescription;
      CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(desc);
      int32_t width = dimensions.width;

      if (range.minFrameRate &lt;= desiredFPS &amp;&amp; desiredFPS &lt;= range.maxFrameRate &amp;&amp; width &gt;= maxWidth) {

            selectedFormat = format;
            frameRateRange = range;
            maxWidth = width;
      }
    }
}

if () {
    std::cout &lt;&lt; &#34;HERE\n&#34;;
    NSLog(@&#34;selected format:%@&#34;, selectedFormat);
    this-&gt;videoCam.activeFormat = selectedFormat;
    this-&gt;videoCam.activeVideoMinFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
    this-&gt;videoCam.activeVideoMaxFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
    ;

    NSLog(@&#34;%s AVCaptureDevice: %@&#34;, __PRETTY_FUNCTION__, selectedFormat);
}



if (this-&gt;videoCam) {
    NSError *err;
    this-&gt;camera = ;

    if (!err) {
      if ()
            ;
      else
            NSLog(@&#34;Could not add video input.&#34;);
    } else
      NSLog(@&#34;Could not create video input&#34;);
} else {
    NSLog(@&#34;Could not create video capture device.&#34;);
}

this-&gt;audioInput = ;
NSError *err = nil;
this-&gt;microphone = ;
if (this-&gt;microphone)
    ;

// Configure camera
;

}
</code></pre>

<p>最后,在 ViewController 中设置 AVCameraFileOutput:</p>

<pre><code>// Configure the movie file output
self.movieFile = [ init];
self.movieFile.minFreeDiskSpaceLimit = 1024 * 1024;

CMTime maxDuration = CMTimeMakeWithSeconds(60*60, 240); // 1 hour at 240 fps should be more than enough
self.movieFile.maxRecordedDuration = maxDuration;
if ()
    ;
</code></pre>

<p>我哪里错了?</p>

<p>编辑:这是 ffprobe 对结果文件的输出。</p>

<p><code>Stream #0:0(und):视频:h264(高)(avc1/0x31637661)、yuv420p(tv、bt709)、1920x1080、15166 kb/s、30 fps、30 tbr、600 tbn、 1200 tbc(默认)</code></p>

<p>但是,这应该是 activeFormat:</p>

<p><code>AVCaptureDevice: <AVCaptureDeviceFormat: 0x17401f780 'vide'/'420f' 1280x 720, { 6-240 fps}, fov:59.680, binned, support vis, max zoom:65.50 (upscales @1.45), AF System :1, ISO:22.0-704.0, SS:0.000002-0.166667, 支持广色></code></p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>有两种基本不兼容的方式来配置捕获 session : session 预设和设备格式。预设就是预设,格式就是格式,两者永远不会相遇。 </p>

<p>当您在捕获设备上 <code>setActiveFormat</code> 时,它(以及任何进一步的自定义,如最小/最大帧持续时间)会覆盖来自之前设置的任何 session 预设的任何设置。在这种情况下, session 预设更改为 <code>AVCaptureSessionPresetInputPriority</code> 以指示 session 的设置不再控制一切。</p>

<p>如果在设备上设置事件格式(并进一步自定义设备设置)后,您在捕获 session 上调用 <code>setSessionPreset</code>,则新预设会覆盖/撤消设备格式设置。这就是你似乎正在做的事情。由于您已经设置和配置了设备格式,因此您根本不需要使用 session 预设 - 只需在配置函数末尾省略 <code>setSessionPreset</code> 调用。</p>

<hr/>

<p>有关更多详细信息:关于 session 预设与设备格式的最佳概述是 <a href="https://developer.apple.com/videos/play/wwdc2013/610/" rel="noreferrer noopener nofollow">this video from WWDC13</a> , 当设备格式 API 被引入时。 (尽管该视频早于许多 <a href="https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html" rel="noreferrer noopener nofollow">features</a> ,例如高 FPS/慢动作录制,需要通过 <code>activeFormat</code> 而不是 <code>sessionPreset</code> 进行配置。)</p>

<p><sub>(哇,我可以在这么短的时间内用同一个链接回答两个问题,它还在我的剪贴板上。)</sub></p>

<hr/>

<p>另外,请注意,用于查找所需格式的循环可能并不总是得到您想要的格式,因为它选择 <code>AVCaptureDevice.formats</code> 数组中的 <em>first</em>匹配您想要的 fps 和宽度。例如,根据您是否/如何处理样本缓冲区,您可能会关心您获得的是 <code>420f</code> 还是 <code>420v</code> 格式,并且取决于您在做什么对于输出文件,您可能会关心支持广色域的设备(如 iPhone 7 和 iPad Pro 9.7 英寸)是在 sRGB 还是 P3 中捕获。查看 <a href="https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html" rel="noreferrer noopener nofollow">camera features</a> 的完整列表以确保您在多个设备上都能获得所需的内容。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - AVFileCapture 输出 : Not recording at 240 fps,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41108950/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41108950/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - AVFileCapture 输出 : Not recording at 240 fps