Forum Linux.debian/ubuntu API pour camera/webcam

Posté par  . Licence CC By‑SA.
Étiquettes : aucune
2
9
déc.
2019

Bonjour à tous,

Je viens de commencer un projet de traitement video.

Pour le moment je me sers d'une webcam usb classique.

J'ai regardé les quelques projets autours, que voici :
-libusb
-v4l2
-uvcvideo

J'ai regardé les sources du projet "guvcview". Ils utilisent v4l2 et uvcvideo.

Avez-vous déjà tenté de récupérer les flux video d'une camera ou webcam via usb ou ethernet ?

Je pense partir sur l'utilisation de la lib uvcvideo, et peut être de v4l2 si besoin.

Merci pour vos retour d'expérience.

  • # VLC/RTSP

    Posté par  (site Web personnel) . Évalué à 2.

    J'ai déjà utilisé VLC pour capturer un flux RTSP envoyé sur le réseau par une petite caméra. Pour capturer (presque) une heure de vidéo, mon entrée de crontab ressemblait à ceci :

    /usr/bin/vlc -vvv rtsp://spy.home:554/live/ch0 --sout=file/ts:/data/media/spy/record-$(/bin/date +"%Y-%m-%dT%H%M").ts -I dummy --stop-time=3590 vlc://quit
    

    Parfait pour garder un œil sur le chat.

    Debian Consultant @ DEBAMAX

    • [^] # Re: VLC/RTSP

      Posté par  . Évalué à 1.

      Bonjour,

      Merci pour votre réponse.

      Je suis partie sur l'utilisation du driver UVC, qui est commun à tous les appareils.

      Je me heurte à un problème, voici le code que j’éxecute pour obtenir 30fps, un exemple de la libuvc.

      Avez-vous déjà fait un essai sur cette lib ?

            /* Initialize a UVC service context. Libuvc will set up its own libusb
             * context. Replace NULL with a libusb_context pointer to run libuvc
             * from an existing libusb context. */
            res = uvc_init(&ctx, NULL);
            if (res < 0) {
              uvc_perror(res, "uvc_init");
              return res;
            }
            puts("UVC initialized");
            /* Locates the first attached UVC device, stores in dev */
            res = uvc_find_device(
                ctx, &dev,
                3141, 25409, NULL); /* filter devices: vendor_id, product_id, "serial_num" */
                //33006, 48, NULL);
                //3141, 25409, NULL); /* filter devices: vendor_id, product_id, "serial_num" */
                //3141, 25409, "da1b7b94a31315e0");
      
            if (res < 0) {
              uvc_perror(res, "uvc_find_device"); /* no devices found */
            } else {
              puts("Device found");
      
              /* Try to open the device: requires exclusive access */
              //Special access : sudo sh -c "echo 'SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"0c45\", ATTRS{idProduct}==\"6341\", SYMLINK+=\"pt1\", GROUP=\"usb\", MODE=\"666\"' > /etc/udev/rules.d/99-pt1.rules"
              res = uvc_open(dev, &devh);
      
              if (res < 0) {
                uvc_perror(res, "uvc_open"); /* unable to open device */
              } else {
                puts("Device opened");
                /* Print out a message containing all the information that libuvc
                 * knows about the device */
                uvc_print_diag(devh, stderr);
      
                /* Try to negotiate a 640x480 30 fps YUYV stream profile */
                res = uvc_get_stream_ctrl_format_size(
                    devh, &ctrl, /* result stored in ctrl */
                    UVC_FRAME_FORMAT_YUYV, /* YUV 422, aka YUV 4:2:2. try _COMPRESSED */
                    640, 480, 30 /* width, height, fps */
                );
      
                /* Print out the result */
                uvc_print_stream_ctrl(&ctrl, stderr);
                if (res < 0) {
                  uvc_perror(res, "get_mode"); /* device doesn't provide a matching stream */
                } else {
                  /* Start the video stream. The library will call user function cb:
                   *   cb(frame, (void*) 12345)
                   */
      
                  res = uvc_start_streaming(devh, &ctrl, cb, user_ptr, 0);
                  if (res < 0) {
                    uvc_perror(res, "start_streaming"); /* unable to start stream */
                  } else {
                    puts("Streaming...");
                    uvc_set_ae_mode(devh, 1); /* e.g., turn on auto exposure */
                    QThread::msleep(10000); /* stream for 10 seconds */
                    /* End the stream. Blocks until last callback is serviced */
                    uvc_stop_streaming(devh);
                    puts("Done streaming.");
                  }
                }
                /* Release our handle on the device */
                uvc_close(devh);
                puts("Device closed");
              }
              /* Release the device descriptor */
              uvc_unref_device(dev);
            }
            /* Close the UVC context. This closes and cleans up any existing device handles,
             * and it closes the libusb context if one was not provided. */
            uvc_exit(ctx);
            puts("UVC exited");
            return 0;
      

      Le résultat est le suivant,

      14:47:00: Starting /home/jo/Qt_project/serveur_surveillance/build-serveur_surveillance-Desktop-Debug/serveur_surveillance...
      TEST
      4 Devices in list.
      Number of possible configurations: 1  Device Class: 239  VendorID: 3141  ProductID: 25409
      Interfaces: 4 ||| Number of alternate settings: 1 | Interface Number: 0 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 131 | Number of alternate settings: 7 | Interface Number: 1 | Number of endpoints: 0 | Interface Number: 1 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | Interface Number: 1 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | Interface Number: 1 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | Interface Number: 1 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | Interface Number: 1 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | Interface Number: 1 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | Number of alternate settings: 1 | Interface Number: 2 | Number of endpoints: 0 | Number of alternate settings: 2 | Interface Number: 3 | Number of endpoints: 0 | Interface Number: 3 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 132 | 
      
      
      Number of possible configurations: 1  Device Class: 9  VendorID: 7531  ProductID: 2
      Interfaces: 1 ||| Number of alternate settings: 1 | Interface Number: 0 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | 
      
      
      Number of possible configurations: 1  Device Class: 0  VendorID: 33006  ProductID: 33
      Interfaces: 1 ||| Number of alternate settings: 1 | Interface Number: 0 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | 
      
      
      Number of possible configurations: 1  Device Class: 9  VendorID: 7531  ProductID: 1
      Interfaces: 1 ||| Number of alternate settings: 1 | Interface Number: 0 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 129 | 
      
      
      unsupported descriptor subtype VS_STILL_IMAGE_FRAME
      unsupported descriptor subtype VS_STILL_IMAGE_FRAME
      unsupported descriptor subtype VS_COLORFORMAT
      DEVICE CONFIGURATION (0c45:6341/[none]) ---
      Status: idle
      VideoControl:
          bcdUVC: 0x0100
      VideoStreaming(1):
          bEndpointAddress: 129
          Formats:
          UncompressedFormat(1)
                bits per pixel: 16
                GUID: 5955593200001000800000aa00389b71 (YUY2)
                default frame: 1
                aspect ratio: 0x0
                interlace flags: 00
                copy protect: 00
                  FrameDescriptor(1)
                    capabilities: 00
                    size: 640x480
                    bit rate: 24576000-147456000
                    max frame size: 614400
                    default interval: 1/30
                    interval[0]: 1/30
                    interval[1]: 1/25
                    interval[2]: 1/20
                    interval[3]: 1/15
                    interval[4]: 1/10
                    interval[5]: 1/5
                              ......................
                              ......................
                  FrameDescriptor(18)
                    capabilities: 00
                    size: 1280x720
                    bit rate: 73728000-147456000
                    max frame size: 1843200
                    default interval: 1/10
                    interval[0]: 1/10
                    interval[1]: 1/5
          MJPEGFormat(2)
                bits per pixel: 0
                GUID: 4d4a5047000000000000000000000000 (MJPG)
                default frame: 1
                aspect ratio: 0x0
                interlace flags: 00
                copy protect: 00
                  FrameDescriptor(1)
                    capabilities: 00
                    size: 640x480
                    bit rate: 24599560-147597360
                    max frame size: 614989
                    default interval: 1/30
                    interval[0]: 1/30
                    interval[1]: 1/25
                    interval[2]: 1/20
                    interval[3]: 1/15
                    interval[4]: 1/10
                    interval[5]: 1/5
                  .................................
                              .................................
                  FrameDescriptor(18)
                    capabilities: 00
                    size: 1280x720
                    bit rate: 73751560-442509360
                    max frame size: 1843789
                    default interval: 1/30
                    interval[0]: 1/30
                    interval[1]: 1/25
                    interval[2]: 1/20
                    interval[3]: 1/15
                    interval[4]: 1/10
                    interval[5]: 1/5
      END DEVICE CONFIGURATION
      bmHint: 0001
      bFormatIndex: 1
      bFrameIndex: 1
      dwFrameInterval: 333333
      wKeyFrameRate: 0
      wPFrameRate: 0
      wCompQuality: 0
      wCompWindowSize: 0
      wDelay: 13646
      dwMaxVideoFrameSize: 614400
      dwMaxPayloadTransferSize: 3072
      bInterfaceNumber: 1
      attempt to claim already-claimed interface 1
      14:47:01: Le programme s'est terminé subitement.
      14:47:01: The process was ended forcefully.
      14:47:01: /home/jo/Qt_project/serveur_surveillance/build-serveur_surveillance-Desktop-Debug/serveur_surveillance crashed.
      

      Je suis bloqué après cette ligne de code : attempt to claim already-claimed interface 1

Suivre le flux des commentaires

Note : les commentaires appartiennent à ceux qui les ont postés. Nous n’en sommes pas responsables.