Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How to switch frontface camera to backface camera via videojs-record for image capturing?

Ask Question

This works for video (With the code snippet camera changes to backface camera)

 videoPlayer.record().stopDevice();
 videoPlayer.record().setVideoInput('backface-camera-device-id');

But analogically for image doesn't change anything. Camera still the same (Only frontface camera)

 imagePlayer.record().stopDevice();
 imagePlayer.record().setVideoInput('backface-camera-device-id');

My options for imagePlayer is

const options = {
                controls: true,
                width: width,
                height: height,
                controlBar: {
                    volumePanel: true
                plugins: {
                    record: {
                        image: true,
                        imageOutputType: 'blob',
                        mandatory: {
                            minWidth: 1280,
                            minHeight: 720,
                        frameWidth: 1280,
                        frameHeight: 720,
const imagePlayer = videojs('image-frame', options);

Image frame is

<video id="image-frame"></video>

My video options (works only with video)

const options = {
                controls: true,
                width: width,
                height: height,
                fluid: false,
                controlBar: {
                    volumePanel: false,
                    cameraButton: true,
                plugins: {
                    record: {
                        audio: true,
                        video: true,
                        videoEngine: 'recordrtc',
                        maxLength: 120,
                        debug: true,
                        mandatory: {
                            minWidth: 1280,
                            minHeight: 720,
                        frameWidth: 1280,
                        frameHeight: 720,
                        timeSlice: 1000

Glad to any help or clue to solve the camera switching problem!

What approaches did you try so far? Have you tried passing video: { deviceId: {exact: deviceId} } to the initializer instead of setting it afterwards? – Marcus Ilgner Feb 1, 2020 at 18:48 @milgner, I have tried both, video: { deviceId: {exact: deviceId} } and image: { deviceId: {exact: deviceId} } - still working only for video, but with image - doesn't work. – Andrii Kovalenko Feb 1, 2020 at 18:49
imagePlayer.record().recordImage = {deviceId: {exact: 'backface-camera-device-id'}};
imagePlayer.record().stopDevice();
imagePlayer.record().getDevice();

worked for me.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.