CameraX set Physical Id for Video Recorder

96 views
Skip to first unread message

Qasim Abdani

unread,
Nov 7, 2025, 1:17:18 AMNov 7
to Android CameraX Discussion Group
Hi i need helps to bind physical id of video recorder . It is binding for image capture but code is not working for video recorder. My task is to open wide angle camera . i have pixel 9 pro it gives me physical id which open wide angle camera for image capture but i dnt know what to do with video recorder i search in ai but the code it gives me iam getting error here it does not support  Extender method

val recorderBuilder = Recorder.Builder() .setQualitySelector(QualitySelector.from(Quality.HD))

Camera2Interop.Extender(recorderBuilder) .setPhysicalCameraId(PHYSICAL_CAMERA_ID


I need help to solve my issue here is code and help to set physical id for video recorder as well ..note when i use for physical id for capture it open wide angel but it does not preview same like wide angle but look like normal camera preview even wide angle lense open LaunchedEffect(Unit) {

    cameraProviderFuture.addListener({
        try {
            val cameraProvider = cameraProviderFuture.get()

            // Preview
            val preview = Preview.Builder()
                .setTargetAspectRatio(AspectRatio.RATIO_16_9)
                .build()
                .also { it.setSurfaceProvider(previewView.surfaceProvider) }

            // Image Capture
            val imageCapture = ImageCapture.Builder()
                .setTargetAspectRatio(AspectRatio.RATIO_16_9)
                .build()

            // Image Analysis
            val imageAnalyzer = ImageAnalysis.Builder()
                .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
                .build()
                .also {
                    it.setAnalyzer(Executors.newSingleThreadExecutor()) { imageProxy ->
                        val buffer = imageProxy.planes[0].buffer
                        val data = ByteArray(buffer.remaining())
                        buffer.get(data)
                        val exposure = data.map { it.toInt() and 0xFF }.average()
                        isLowLight = exposure < 60
                        imageProxy.close()
                    }
                }

            // === ULTRA-WIDE VIDEO با PHYSICAL ID ===
            val PHYSICAL_CAMERA_ID = "2"  // آپ کا log سے ملا ID

            val recorderBuilder = Recorder.Builder()
                .setQualitySelector(QualitySelector.from(Quality.HD))

            // اب یہ کام کرے گا! (CameraX 1.5.1)
            Camera2Interop.Extender(recorderBuilder)
                .setPhysicalCameraId(PHYSICAL_CAMERA_ID)

            val recorder = recorderBuilder.build()
            val videoCapture = VideoCapture.withOutput(recorder)

          

            // Bind
            cameraProvider.unbindAll()
            camera = cameraProvider.bindToLifecycle(
                lifecycleOwner,
                cameraSelector, // use back lense 
                preview,
                imageCapture,
                videoCapture,
                imageAnalyzer
            )

            // Log to confirm
            val activeId = Camera2CameraInfo.from(camera!!.cameraInfo).cameraId
            Log.d("VIDEO_CAM", "Ultra-Wide Active: $activeId")

            th...@LaunchedEffect.videoCapture = videoCapture

        } catch (e: Exception) {
            Log.e("CameraX", "Error: ${e.message}", e)
        }
    }, ContextCompat.getMainExecutor(context))
}





Leo Huang

unread,
Nov 7, 2025, 4:28:33 AMNov 7
to Android CameraX Discussion Group, qasimab...@gmail.com
You should call Camera2Interop with VideoCapture.Builder rather than Recorder.Builder

```
             val recorder = Recorder.Builder()
                .setQualitySelector(QualitySelector.from(Quality.HD))
                .build()
            val videoCaptureBuilder = VideoCapture.Builder(recorder)

            Camera2Interop.Extender(videoCaptureBuilder)
                .setPhysicalCameraId(PHYSICAL_CAMERA_ID)

            val videoCapture = videoCaptureBuilder.build()
```

qasimab...@gmail.com 在 2025年11月7日 星期五下午2:17:18 [UTC+8] 的信中寫道:

Qasim Abdani

unread,
Nov 7, 2025, 6:38:36 AMNov 7
to Android CameraX Discussion Group, leoh...@google.com, Qasim Abdani
Thank you for your code . Wide Angle video is opened but one issue still left that it is opening the lense but preview is not look wide angle or 0.5x zoom out ..it looks like same default camera preview .. iam sharing you my code again still looking help for preview like wide angle here is my updated code 
LaunchedEffect(Unit) {
cameraProviderFuture.addListener({
try {
val cameraProvider = cameraProviderFuture.get()

// 1. Preview (Main camera - default)
val preview = Preview.Builder()
.setTargetAspectRatio(AspectRatio.RATIO_16_9)
.build()
.also { it.setSurfaceProvider(previewView.surfaceProvider) }

val recorder = Recorder.Builder()
.setQualitySelector(QualitySelector.from(Quality.HD))
.build()
val videoCaptureBuilder = VideoCapture.Builder(recorder)

Camera2Interop.Extender(videoCaptureBuilder)
.setPhysicalCameraId("3")

val videoCapture = videoCaptureBuilder.build()

cameraProvider.unbindAll()

val backLensSelector = CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build()

// Bind Preview + Video → Main camera
cameraProvider.bindToLifecycle(
lifecycleOwner,
backLensSelector,
preview,
videoCapture
)


} catch (e: Exception) {

}
}, ContextCompat.getMainExecutor(context))
}

val previewView = remember {
PreviewView(context).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
clipToOutline = true // optional, helps clip overflowing preview
}
}

AndroidView(
factory = { previewView }, modifier = Modifier
.align(Alignment.Center)
.fillMaxWidth()
.fillMaxHeight())

Qasim Abdani

unread,
Nov 7, 2025, 9:36:22 AMNov 7
to Android CameraX Discussion Group, leoh...@google.com
Leo Huangcan you response of my code please Wide Angle video is opened but one issue still left that it is opening the lense but preview is not look wide angle or 0.5x zoom out ..it looks like same default camera preview .. iam sharing you my code again still looking help for preview like wide angle here is my updated code 



Leo Huang

unread,
Nov 7, 2025, 10:40:31 AMNov 7
to Android CameraX Discussion Group, qasimab...@gmail.com, Leo Huang

Hi,

Thanks for providing the code and detailed information.

When using Camera2Interop to set a physical camera ID for a UseCase, the same physical camera ID will be used for all UseCases that are bound together. The API documentation mentions that it "doesn't support binding use cases with different physical camera IDs."

I tested your code on a Pixel 9 with CameraX version 1.5.1, and I was able to see the wide-angle effect in both the preview and the video capture.

To help you debug, you can confirm that the physical camera ID is being applied to all camera streams by using the following adb command while the camera preview is running:

adb shell dumpsys media.camera | grep -A5 "Stream\["

The output should show the same physical camera ID for each stream, as in the example below:

``` Stream[0]: Output // Preview stream Consumer name: 1cfb912 SurfaceView[app.grapheneos.camera.dev/app.grapheneos.camera.ui.activities.MainActivity]#41(BLAST Consumer)41 State: 6 Dims: 1920 x 1080, format 0x23, dataspace 0x8810000 Max size: 0 Combined usage: 0x20900, max HAL buffers: 10 Physical camera id: 3 Dynamic Range Profile: 0x1 Color Space: -1 -- Stream[1]: Output // VideoCapture stream Consumer name: GraphicBufferSource State: 4 Dims: 1280 x 720, format 0x123, dataspace 0x8c10000 Max size: 0 Combined usage: 0x4000000030200, max HAL buffers: 10 Physical camera id: 3 Dynamic Range Profile: 0x1 Color Space: -1 ```
Here are a few suggestions that may help you resolve this issue:
  • Update CameraX version: Please update to the latest stable version of CameraX (1.5.1) to see if the issue persists.
  • Confirm physical camera ID: Use the adb command to verify that all streams are using the same physical camera ID.
  • Check your PreviewView layout: is it possible that the view is being cropped? You can try something like scaleType = PreviewView.ScaleType.FIT_CENTER to see if that resolves the issue.
qasimab...@gmail.com 在 2025年11月7日 星期五晚上10:36:22 [UTC+8] 的信中寫道:

Leo Huang

unread,
Nov 7, 2025, 10:43:38 AMNov 7
to Android CameraX Discussion Group, Leo Huang, qasimab...@gmail.com
Reformatting the sample log


    Stream[0]: Output    // Preview stream
      Consumer name: 1cfb912 SurfaceView[app.grapheneos.camera.dev/app.grapheneos.camera.ui.activities.MainActivity]#41(BLAST Consumer)41
      State: 6
      Dims: 1920 x 1080, format 0x23, dataspace 0x8810000
      Max size: 0
      Combined usage: 0x20900, max HAL buffers: 10
      Physical camera id: 3
      Dynamic Range Profile: 0x1
      Color Space: -1
--
    Stream[1]: Output     // VideoCapture stream
      Consumer name: GraphicBufferSource
      State: 4
      Dims: 1280 x 720, format 0x123, dataspace 0x8c10000
      Max size: 0
      Combined usage: 0x4000000030200, max HAL buffers: 10
      Physical camera id: 3
      Dynamic Range Profile: 0x1
      Color Space: -1

Leo Huang 在 2025年11月7日 星期五晚上11:40:31 [UTC+8] 的信中寫道:

Qasim Abdani

unread,
Nov 12, 2025, 5:42:52 AMNov 12
to Android CameraX Discussion Group, leoh...@google.com, Qasim Abdani

Hi Leo,

Actually, I don’t have the device right now — it will arrive on Monday. When I did have the device, I checked that the wide-angle lens opened successfully, but the preview looked like 1x zoom instead of 0.5x zoom.

I have one more question for you, since you’re the only person who can really help me with the wide-angle issue.

The problem is that on the Xiaomi Note 10, it doesn’t provide physical camera IDs, so how can I open the wide-angle camera in that case?

Also, what about Samsung devices that support wide-angle? What changes should I make in the code for Samsung? I need to handle Samsung devices as well.

Thanks!


Qasim Abdani

unread,
Nov 14, 2025, 4:43:55 AMNov 14
to Android CameraX Discussion Group, Qasim Abdani, leoh...@google.com
Hi am looking for answer please help me to resolve my issue:

I have one more question for you, since you’re the only person who can really help me with the wide-angle issue.

The problem is that on the Xiaomi Note 10, it doesn’t provide physical camera IDs, so how can I open the wide-angle camera in that case?

Also, what about Samsung devices that support wide-angle? What changes should I make in the code for Samsung? I need to handle Samsung devices as well.

Thanks!

Shinichi Kudo

unread,
Nov 14, 2025, 5:46:11 AMNov 14
to Qasim Abdani, Android CameraX Discussion Group, leoh...@google.com
🤎

Người gửi
Lương Quang Hùng 




Vào Th 6, 14 thg 11, 2025 lúc 16:44 Qasim Abdani <qasimab...@gmail.com> đã viết:
--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/9ba40eeb-ec80-4f73-8cbd-55f4af79a882n%40android.com.

Qasim Abdani

unread,
Nov 26, 2025, 2:36:13 AM (2 days ago) Nov 26
to Android CameraX Discussion Group, lhun...@gmail.com, Android CameraX Discussion Group, leoh...@google.com, Qasim Abdani
Hi please response

Leo Huang

unread,
Nov 26, 2025, 9:21:46 PM (2 days ago) Nov 26
to Qasim Abdani, TY Chang, Scott Nien, Android CameraX Discussion Group, lhun...@gmail.com

Qasim Abdani <qasimab...@gmail.com> 於 2025年11月26日 週三 下午3:36寫道:
Reply all
Reply to author
Forward
0 new messages