录制一段持手机纵向拿着的1280×720像素视频。

huangapple go评论89阅读模式
英文:

Recording a 1280x720 video holding the phone in portrait orientation

问题

我在使用CameraX API录制视频时遇到了困难,想要在纵向方向持握手机(肖像模式),以横向分辨率(1280x720)录制视频。但无论是使用camera1还是camera2,我都无法实现此目标。我已成功让ImageCapture用例和预览工作正常。然而,录制的视频始终以最接近的肖像模式分辨率进行录制。希望能得到任何帮助!

CameraSelector cameraSelector = new CameraSelector.Builder()
   .requireLensFacing(CameraSelector.LENS_FACING_BACK)
   .build();

Preview preview = new Preview.Builder()
   .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation())
   .setTargetResolution(new Size(1280, 720))
   .build();
preview.setSurfaceProvider(mVideoView.createSurfaceProvider());

ImageCapture.Builder imageCaptureBuilder = new ImageCapture.Builder();
mImageCapture = imageCaptureBuilder
   .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation())
   .setTargetResolution(new Size(1280, 720))
   .build();

VideoCapture.Builder videoCaptureBuilder = new VideoCapture.Builder();
mVideoCapture = videoCaptureBuilder
   .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation())
   .setTargetResolution(new Size(1280, 720))
   .build();

ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
Camera camera = cameraProvider.bindToLifecycle(
   RecordMediaCameraXActivity.this,
   cameraSelector,
   preview,
   mImageCapture,
   mVideoCapture
 );
英文:

I am struggling to record a video in a landscape resolution (1280x720) holding my phone in portrait orientation using the cameraX API (I also wasn't able to do it with any of the APIs, neither camera1 nor camera2). I was able to make it work for the ImageCapture use case and the preview though. The video keeps getting recorded in the nearest possible portrait resolution. Any help is appreciated!

CameraSelector cameraSelector = new CameraSelector.Builder()
   .requireLensFacing(CameraSelector.LENS_FACING_BACK)
   .build();

Preview preview = new Preview.Builder()
   .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation())
   .setTargetResolution(new Size(1280, 720))
   .build();
preview.setSurfaceProvider(mVideoView.createSurfaceProvider());

ImageCapture.Builder imageCaptureBuilder = new ImageCapture.Builder();
mImageCapture = imageCaptureBuilder
   .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation())
   .setTargetResolution(new Size(1280, 720))
   .build();

VideoCapture.Builder videoCaptureBuilder = new VideoCapture.Builder();
mVideoCapture = videoCaptureBuilder
   .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation())
   .setTargetResolution(new Size(1280, 720))
   .build();

ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
Camera camera = cameraProvider.bindToLifecycle(
   RecordMediaCameraXActivity.this,
   cameraSelector,
   preview,
   mImageCapture,
   mVideoCapture
 );

答案1

得分: 1

这个设备不太可能支持你所寻找的分辨率。

基本上,你想要的分辨率看起来像这样:

4:3 全画幅传感器
   |---------+========+---------|
   |         : 9:16   :         |
   |         : 720p   :         |
   |         : 剪裁    :         |
   |         :        :         |
   |         :        :         |
   |         :        :         |
   |         :        :         |
   |         :        :         |
   |---------+========+---------|

但这不是大多数设备支持的内容。它们只支持与图像传感器相同对齐的剪裁:

4:3 全画幅传感器
   |----------------------------|
   |                            |
   +============================+
   : 16:9 720p 剪裁              :
   :                            :
   :                            :
   :                            :
   +============================+
   |                            |
   |----------------------------|

如果你想要这个,很可能需要自己从摄像头中剪裁帧。这需要使用类似 ImageAnalysis 或 Preview 的内容将结果直接传送到 GPU,并直接将结果提供给 MediaRecorder 或 MediaCodec/MediaMuxer。

另外,CameraX 目前还不正式支持视频录制,所以当它正式可用时可能会支持这种用例,但我不会对此抱太大期望。

英文:

It's unlikely that the device supports the resolution you're looking for.

Basically, you want a resolution that looks like this:

4:3 full sensor
   |---------+========+---------|
   |         : 9:16   :         |
   |         : 720p   :         |
   |         : crop   :         |
   |         :        :         |
   |         :        :         |
   |         :        :         |
   |         :        :         |
   |         :        :         |
   |---------+========+---------|

and that's just not something most devices support. They only support crops that are in the same alignment as the image sensor:

4:3 full sensor
   |----------------------------|
   |                            |
   +============================+
   : 16:9 720p crop             :
   :                            :
   :                            :
   :                            :
   +============================+
   |                            |
   |----------------------------|

If you want this, you'll likely need to crop the frames from the camera yourself.
That'd require using something like ImageAnalysis or Preview to the GPU, and directly feeding a MediaRecorder or MediaCodec/MediaMuxer with the results.

Also, CameraX doesn't yet officially support video recording, so it's possible that it'll support this kind of use case when it's officially available, but I wouldn't count on that.

huangapple
  • 本文由 发表于 2020年8月17日 21:14:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/63451604.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定