@jimeex posted a new topic, subject "Resolution and Listing of Webcams". It read:

   Hello everyone,  
    We have an art project and we call someone to build a code that will allow us to switch between 3 webcams, with a duration and choice of the webcam, like a musical partition.  
    So he write this :
    
    > /******************/  
    >  // MultiCamSwitch //  
    >  /******************/  
    >  // Dependency: Capture library
    > 
    > import processing.video.*;
    > 
    > // Set the number of camera you need  
    >  Capture cam1, cam2, cam3;  
    >  Capture[] camList= {cam1, cam2, cam3};
    > 
    > int startTime; // Beginning of the loop  
    >  int time; // Elapsed time in seconds
    > 
    > int currentSeq; // Each sequence match a camera and a duration
    > 
    > // Setup the duration of each sequence and the respective camera  
    >  // (take care of having the same number of arguments on each array)  
    >  int[] camOrder = {0, 1, 2, 0, 2, 1}; // Camera sequencing (first camera is 0!!)  
    >  int[] camDuration = {10, 05, 05, 02, 05, 10}; // Duration sequencing (in seconds)  
    >  int[] camTime = new int[camDuration.length]; // Array of accumulated durations (used to compare with elapsed time)
    > 
    > void setup() {  
    >  // Choose to run fullscreen or in window mode:  
    >  //fullScreen(); // prod  
    >  size(1920, 1080); //dev
    > 
    > // Load camTime with accumulation of durations  
    >  camTime[0] = camDuration[0];  
    >  for (int i = 0; i < camDuration.length-1; i++)  
    >  {  
    >  camTime[i+1] = camTime[i] + camDuration[i+1];  
    >  }
    > 
    > // Check the name of your cameras the first time you setup the installation  
    >  // Skiping the camCheck, make the program load faster  
    >  // Uncomment to check if your cameras are ok  
    >  camCheck(); //dev
    > 
    > // Setup camera number with the camera name  
    >  // (cameras' names could be found runing camcheck() function  
    >  // Camera #0  
    >  camList[0] = new Capture(this, width, height, “AUKEY PC-LM1A Webcam”, 30);  
    >  camList[0].start();  
    >  // Camera #1  
    >  camList[1] = new Capture(this, width, height, “AUKEY PC-LM1A Webcam#2”, 30);  
    >  camList[1].start();  
    >  // Camera #2  
    >  camList[2] = new Capture(this, width, height, “AUKEY PC-LM1A Webcam#3”, 30);  
    >  camList[2].start();
    > 
    > startTime = millis();  
    >  currentSeq = 0;
    > 
    > logCam(currentSeq);  
    >  }
    > 
    > void draw() {
    > 
    > // Get elapsed time since the beginning of the draw()  
    >  time = (millis() - startTime)/1000;
    > 
    > // Check if the active camera have to change  
    >  if (time > camTime[currentSeq])  
    >  {  
    >  if (currentSeq == camOrder.length-1)  
    >  {  
    >  // End of the loop, restart from begining  
    >  startTime = millis();  
    >  currentSeq = 0;  
    >  }  
    >  else  
    >  {  
    >  currentSeq++;  
    >  }
    [code] 
    >     logCam(currentSeq);
    >     
    [/code]
    > 
    > }
    > 
    > readCam(camList[camOrder[currentSeq]]);
    > 
    > }
    > 
    > // Access the given camera and show the image  
    >  void readCam(Capture cam) {  
    >  if (cam.available()) {  
    >  cam.read();  
    >  set(0, 0, cam);  
    >  }  
    >  }
    > 
    > // Print the state of sequence in the console  
    >  void logCam(int seq) {  
    >  println(  
    >  (seq+1) + ": " +  
    >  “cam#” + camOrder[seq] + " is live " +  
    >  "for " + camDuration[seq]/60 + "m " + camDuration[seq] + “s…”  
    >  );  
    >  }
    > 
    > // Print into console the list of the cameras connected to the computer  
    >  // Use it to get the cameras' names  
    >  void camCheck () {  
    >  String[] cameras = Capture.list();
    > 
    > if (cameras.length == 0)  
    >  {  
    >  println(“There are no cameras available for capture.”);  
    >  exit();  
    >  }  
    >  else  
    >  {  
    >  String[] camName = new String[camList.length];  
    >  int j = 0;
    [code] 
    >     // Add the first camera name (necessarily the first cam)
    >     camName[j] = match(cameras[0], "name=(.*?),")[1];
    >     
    >     // Then run throught the list of all cameras variants to only get the different names
    >     println("---------------");
    >     println("Available cameras:");
    >     for (String i : cameras)
    >     {
    >       println(i);
    >       String currentName = match(i, "name=(.*?),")[1];
    >       
    >       // Check if it is a new camera name and add it to the camName list
    >       if (currentName.equals(camName[j]) == false)
    >       {
    >           j++;
    >           camName[j] = currentName;
    >       }
    >     }
    >     
    >     println("---------------");
    >     println("Cameras List:");
    >     printArray(camName);
    >     
    [/code]
    > 
    > }
    > 
    > }
    
    ## The problem is the listing of the webcams and the awful listing of all the resolutions available for each cameras. Mac osx is automatically put numbers on each cameras. I use windows, so il edit their names into the registry editor (and it seems to be not so stable, after restarting the computer, some of the webcams lost their custom names) to be recognized by processing or i was getting a null.
    
    **> Available cameras:**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x480,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x480,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=2048x1536,fps=20**  
    **> name=AUKEY PC-LM1A Webcam#2,size=1920x1080,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=1920x1080,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=1280x720,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=1280x720,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x360,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x360,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=352x288,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=352x288,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=320x240,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=320x240,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x480,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x480,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=1920x1080,fps=5**  
    **> name=AUKEY PC-LM1A Webcam#2,size=1280x720,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x360,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=640x360,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=352x288,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=352x288,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#2,size=320x240,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#2,size=320x240,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x480,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x480,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=2048x1536,fps=20**  
    **> name=AUKEY PC-LM1A Webcam#1,size=1920x1080,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=1920x1080,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=1280x720,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=1280x720,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x360,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x360,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=352x288,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=352x288,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=320x240,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=320x240,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x480,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x480,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=1920x1080,fps=5**  
    **> name=AUKEY PC-LM1A Webcam#1,size=1280x720,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x360,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=640x360,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=352x288,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=352x288,fps=30**  
    **> name=AUKEY PC-LM1A Webcam#1,size=320x240,fps=10**  
    **> name=AUKEY PC-LM1A Webcam#1,size=320x240,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=640x480,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=640x480,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=2048x1536,fps=20**  
    **> name=AUKEY PC-LM1A Webcam,size=1920x1080,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=1920x1080,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=1280x720,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=1280x720,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=640x360,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=640x360,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=352x288,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=352x288,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=320x240,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=320x240,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=640x480,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=640x480,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=1920x1080,fps=5**  
    **> name=AUKEY PC-LM1A Webcam,size=1280x720,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=640x360,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=640x360,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=352x288,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=352x288,fps=30**  
    **> name=AUKEY PC-LM1A Webcam,size=320x240,fps=10**  
    **> name=AUKEY PC-LM1A Webcam,size=320x240,fps=30**
    
    > * * *
    > 
    > Cameras List:  
    >  [0] “AUKEY PC-LM1A Webcam#2”  
    >  [1] “AUKEY PC-LM1A Webcam#1”  
    >  [2] “AUKEY PC-LM1A Webcam”  
    >  1: cam#0 is live for 0m 10s…  
    >  2: cam#1 is live for 0m 5s…  
    >  3: cam#2 is live for 0m 5s…
    
    Ok. There are like 4 resolutions that is working with different frames. One of them is 640x360,fps=30. So i put it on size at void setup. But one of the cameras is not working with this resolution. If i put for example 1920x1080, none of the cameras is working. If i put 640x480, only one camera is working… I think there is a problem with which of the camera is chosen to display, and the resolution chosen is not working. If i put like 1024 x 728, processing tells me that the device is not supporting this resolution.  
    So that's it. I can run this code with just only one resolution, and it's not the ideal for the installation. If you have any ideas where to start, or where the problem is, i will be so grateful.  
    Sorry for approximate english, and have a nice day.  
    Guilhem.

After which, @zenemig (Marcos Gimenez) added

    Hi @jimeex,
    
    I dont have much time right know to look in deep on your question, but I can tell you that I had problems using multiple webcams in processing in windows, mainly if the cameras are of the same model. I think maybe theres a thing with the drivers on windows. In the time I needed this, the solution was using two diferents cameras.

Then @jeremydouglass (Jeremy Douglass) said

    In the past I also found this to be the case – although this was a few years ago. Solutions at that time were:
    
      1. don't use Windows
      2. use two different model cameras (i.e. they must expose different names, and the same model exposes the same name)

@jimeex replied

    Thanks for your answers. I was thinking on going macOS but i put some AMD processors on these custom computers… Maybe i should try Linux, but i've seen some posts about the same problem. I will update if i find a solution.

Then @neilcsmith (Neil C Smith) said

    This should work fine, and potentially perform better, in PraxisLIVE if you'd be happy to use that instead? Sketch code would need a little adaptation.


{'source': 'discourse', 'url': 'https://discourse.processing.org/t/resolution-and-listing-of-webcams/10752', 'title': 'Resolution and Listing of Webcams', 'views': 573, 'has_accepted_answer': False, 'word_count': 1641, 'like_count': 3, 'reply_count': 1, 'participant_count': 4, 'posts': 5, 'tags': '', 'author': '@jimeex', 'participants': '@jimeex, @zenemig (Marcos Gimenez), @jeremydouglass (Jeremy Douglass), @neilcsmith (Neil C Smith)', 'image_url': [None], 'created_at': '2019-04-29T11:27:10.559Z', 'last_posted_at': '2019-05-11T12:29:58.705Z'}