Recherche avancée

Médias (0)

Mot : - Tags -/flash

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (28)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Mise à disposition des fichiers

    14 avril 2011, par

    Par défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
    Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
    Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

Sur d’autres sites (2150)

  • Using ffmpeg on Windows, what is the command to capture hardware encoded H264 stream from Logitech c930e

    2 mai 2015, par Jeff

    I am using ffmpeg on Windows 8 and I would like to capture the built-in H264 hardware encoded stream from the Logitech c930e camera. The H264 built-in encoded stream is part of the UVC 1.5 interface.

    Using this command I have noticed that the c930e exposes two video pins through DirectShow : 0 and 1.

    ffmpeg -report -list_options true -f dshow -i video="Logitech Webcam C930e"

    [dshow @ 0000000002d89360]  Pin "Capture" (alternative pin name "0")

    [dshow @ 0000000002d89360]  Pin "Capture" (alternative pin name "1")

    It doesn’t seem to matter if I choose Pin 0 or 1, I still get raw video from the Logitech c930e webcam. On Linux, the supposed command involves v4l2, but this does not appear to exist in the default Windows version of ffmpeg from http://ffmpeg.zeranoe.com/builds/

    Does the default Windows build of ffmpeg support the direct capture of the UVC interface ?

    This is the closest I have gotten on this journey, but still isn’t quite right :

    ffmpeg -report -f dshow -i video="Logitech Webcam C930e" -s 1920x1080 -r 30 -video_pin_name 1 -vcodec H264 -c copy -f mp4 Logitechc930eFeed.mp4

    As of April 17, 2015 I am still trying to figure this out and have two new pieces of info.

    I found this interesting article on Logitech’s website instructing the user to change the default Logitech driver to the generic USB Video Device driver :
    https://support.logitech.com/en_us/article/Install-native-UVC-drivers-for-your-Logitech-webcam?product=a0qi00000069v0MAAQ#

    I also found that my C930e had an older firmware (8.0.866), and Logitech recommends updating the firmware to 8.0.875 to fix an unspecified UVC H.264 issue.

    So now I have the latest firmware, and am using the generic "USB Video Device" on Windows 8.1.

    ffmpeg -list_devices true -f dshow -i

    which gives this output :

    ffmpeg version N-69608-g9dc45d1 Copyright (c) 2000-2015 the FFmpeg developers
     built with gcc 4.9.2 (GCC)
     configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
     libavutil      54. 18.100 / 54. 18.100
     libavcodec     56. 21.102 / 56. 21.102
     libavformat    56. 19.100 / 56. 19.100
     libavdevice    56.  4.100 / 56.  4.100
     libavfilter     5.  9.103 /  5.  9.103
     libswscale      3.  1.101 /  3.  1.101
     libswresample   1.  1.100 /  1.  1.100
     libpostproc    53.  3.100 / 53.  3.100
    [dshow @ 00000000045c9360] DirectShow video devices (some may be both video and audio devices)
    [dshow @ 00000000045c9360]  "Logitech Webcam C930e"
    [dshow @ 00000000045c9360]     Alternative name "@device_pnp_\\?\usb#vid_046d&pid_0843&mi_00#7&3693c0e6&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
    [dshow @ 00000000045c9360] DirectShow audio devices
    [dshow @ 00000000045c9360]  "Microphone (Logitech Webcam C930e)"
    [dshow @ 00000000045c9360]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{BB8BE70B-4DDC-465F-9247-86E6EC98D627}"
    dummy: Immediate exit requested

    And this command :
    ffmpeg -list_options true -f dshow -i video="Logitech Webcam C930e"

    still gives this output :

    ffmpeg version N-69608-g9dc45d1 Copyright (c) 2000-2015 the FFmpeg developers
     built with gcc 4.9.2 (GCC)
     configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
     libavutil      54. 18.100 / 54. 18.100
     libavcodec     56. 21.102 / 56. 21.102
     libavformat    56. 19.100 / 56. 19.100
     libavdevice    56.  4.100 / 56.  4.100
     libavfilter     5.  9.103 /  5.  9.103
     libswscale      3.  1.101 /  3.  1.101
     libswresample   1.  1.100 /  1.  1.100
     libpostproc    53.  3.100 / 53.  3.100
    [dshow @ 0000000004469360] DirectShow video device options (from video devices)
    [dshow @ 0000000004469360]  Pin "Capture" (alternative pin name "0")
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=640x480 fps=5 max s=640x480 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=640x480 fps=5 max s=640x480 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=160x120 fps=5 max s=160x120 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=160x120 fps=5 max s=160x120 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=176x144 fps=5 max s=176x144 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=176x144 fps=5 max s=176x144 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=320x180 fps=5 max s=320x180 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=320x180 fps=5 max s=320x180 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=320x240 fps=5 max s=320x240 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=320x240 fps=5 max s=320x240 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=352x288 fps=5 max s=352x288 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=352x288 fps=5 max s=352x288 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=424x240 fps=5 max s=424x240 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=424x240 fps=5 max s=424x240 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=480x270 fps=5 max s=480x270 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=480x270 fps=5 max s=480x270 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=640x360 fps=5 max s=640x360 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=640x360 fps=5 max s=640x360 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=800x448 fps=5 max s=800x448 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=800x448 fps=5 max s=800x448 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=800x600 fps=5 max s=800x600 fps=24
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=800x600 fps=5 max s=800x600 fps=24
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=848x480 fps=5 max s=848x480 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=848x480 fps=5 max s=848x480 fps=30
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=960x540 fps=5 max s=960x540 fps=15
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=960x540 fps=5 max s=960x540 fps=15
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1024x576 fps=5 max s=1024x576 fps=15
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1024x576 fps=5 max s=1024x576 fps=15
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1280x720 fps=5 max s=1280x720 fps=10
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1280x720 fps=5 max s=1280x720 fps=10
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1600x896 fps=5 max s=1600x896 fps=7.5
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1600x896 fps=5 max s=1600x896 fps=7.5
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5
    [dshow @ 0000000004469360]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=640x480 fps=5 max s=640x480 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=640x480 fps=5 max s=640x480 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=160x120 fps=5 max s=160x120 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=160x120 fps=5 max s=160x120 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=176x144 fps=5 max s=176x144 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=176x144 fps=5 max s=176x144 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=320x180 fps=5 max s=320x180 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=320x180 fps=5 max s=320x180 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=320x240 fps=5 max s=320x240 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=320x240 fps=5 max s=320x240 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=352x288 fps=5 max s=352x288 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=352x288 fps=5 max s=352x288 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=424x240 fps=5 max s=424x240 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=424x240 fps=5 max s=424x240 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=480x270 fps=5 max s=480x270 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=480x270 fps=5 max s=480x270 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=640x360 fps=5 max s=640x360 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=640x360 fps=5 max s=640x360 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=800x448 fps=5 max s=800x448 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=800x448 fps=5 max s=800x448 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=800x600 fps=5 max s=800x600 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=800x600 fps=5 max s=800x600 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=848x480 fps=5 max s=848x480 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=848x480 fps=5 max s=848x480 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=960x540 fps=5 max s=960x540 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=960x540 fps=5 max s=960x540 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1024x576 fps=5 max s=1024x576 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1024x576 fps=5 max s=1024x576 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1280x720 fps=5 max s=1280x720 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1280x720 fps=5 max s=1280x720 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1600x896 fps=5 max s=1600x896 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1600x896 fps=5 max s=1600x896 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1920x1080 fps=5 max s=1920x1080 fps=30
    [dshow @ 0000000004469360]   vcodec=mjpeg  min s=1920x1080 fps=5 max s=1920x1080 fps=30
    [dshow @ 0000000004469360]  Pin "Capture" (alternative pin name "1")
    video=Logitech Webcam C930e: Immediate exit requested
  • How to catch stdout stream in ffmpeg then pipe it to v4l2loopback

    29 août 2015, par Tveitan

    I’m trying to pipe my h264 stream to ffmpeg and then to my v4l2loopback device. Problem is that I’m fairly new to linux, so just can’t get it working.
    The stream can be outputted to stdout, but I do not know how to catch it again with ffmpeg and then again pipe it to my v4l2loopback device.

    Does anybody know how this could be done or maybe a pointer on how to solve it ?

    This is the capture program :

    PS ! You can find the options for the capture program almost in the bottom of the code.

    /*
    *  V4L2 video capture example, modified by Derek Molloy for the Logitech C920 camera
    *  Modifications, added the -F mode for H264 capture and associated help detail
    *  www.derekmolloy.ie
    *
    *  V4L2 video capture example
    *
    *  This program can be used and distributed without restrictions.
    *
    *      This program is provided with the V4L2 API
    * see http://linuxtv.org/docs.php for more information
    */

    #include
    #include
    #include
    #include

    #include              /* getopt_long() */

    #include               /* low-level i/o */
    #include
    #include
    #include <sys></sys>stat.h>
    #include <sys></sys>types.h>
    #include <sys></sys>time.h>
    #include <sys></sys>mman.h>
    #include <sys></sys>ioctl.h>

    #include <linux></linux>videodev2.h>

    #define CLEAR(x) memset(&amp;(x), 0, sizeof(x))

    enum io_method {
           IO_METHOD_READ,
           IO_METHOD_MMAP,
           IO_METHOD_USERPTR,
    };

    struct buffer {
           void   *start;
           size_t  length;
    };

    static char            *dev_name;
    static enum io_method   io = IO_METHOD_MMAP;
    static int              fd = -1;
    struct buffer          *buffers;
    static unsigned int     n_buffers;
    static int              out_buf;
    static int              force_format = 0;
    static int              frame_count = 100;

    static void errno_exit(const char *s)
    {
           fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno));
           exit(EXIT_FAILURE);
    }

    static int xioctl(int fh, int request, void *arg)
    {
           int r;

           do {
                   r = ioctl(fh, request, arg);
           } while (-1 == r &amp;&amp; EINTR == errno);

           return r;
    }

    static void process_image(const void *p, int size)
    {
           if (out_buf)
                   fwrite(p, size, 1, stdout);

           fflush(stderr);
           fprintf(stderr, ".");
           fflush(stdout);
    }

    static int read_frame(void)
    {
           struct v4l2_buffer buf;
           unsigned int i;

           switch (io) {
           case IO_METHOD_READ:
                   if (-1 == read(fd, buffers[0].start, buffers[0].length)) {
                           switch (errno) {
                           case EAGAIN:
                                   return 0;

                           case EIO:
                                   /* Could ignore EIO, see spec. */

                                   /* fall through */

                           default:
                                   errno_exit("read");
                           }
                   }

                   process_image(buffers[0].start, buffers[0].length);
                   break;

           case IO_METHOD_MMAP:
                   CLEAR(buf);

                   buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                   buf.memory = V4L2_MEMORY_MMAP;

                   if (-1 == xioctl(fd, VIDIOC_DQBUF, &amp;buf)) {
                           switch (errno) {
                           case EAGAIN:
                                   return 0;

                           case EIO:
                                   /* Could ignore EIO, see spec. */

                                   /* fall through */

                           default:
                                   errno_exit("VIDIOC_DQBUF");
                           }
                   }

                   assert(buf.index &lt; n_buffers);

                   process_image(buffers[buf.index].start, buf.bytesused);

                   if (-1 == xioctl(fd, VIDIOC_QBUF, &amp;buf))
                           errno_exit("VIDIOC_QBUF");
                   break;

           case IO_METHOD_USERPTR:
                   CLEAR(buf);

                   buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                   buf.memory = V4L2_MEMORY_USERPTR;

                   if (-1 == xioctl(fd, VIDIOC_DQBUF, &amp;buf)) {
                           switch (errno) {
                           case EAGAIN:
                                   return 0;

                           case EIO:
                                   /* Could ignore EIO, see spec. */

                                   /* fall through */

                           default:
                                   errno_exit("VIDIOC_DQBUF");
                           }
                   }

                   for (i = 0; i &lt; n_buffers; ++i)
                           if (buf.m.userptr == (unsigned long)buffers[i].start
                               &amp;&amp; buf.length == buffers[i].length)
                                   break;

                   assert(i &lt; n_buffers);

                   process_image((void *)buf.m.userptr, buf.bytesused);

                   if (-1 == xioctl(fd, VIDIOC_QBUF, &amp;buf))
                           errno_exit("VIDIOC_QBUF");
                   break;
           }

           return 1;
    }

    static void mainloop(void)
    {
           unsigned int count;
       unsigned int loopIsInfinite = 0;

           if (frame_count == 0) loopIsInfinite = 1; //infinite loop
       count = frame_count;

           while ((count-- > 0) || loopIsInfinite) {
                   for (;;) {
                           fd_set fds;
                           struct timeval tv;
                           int r;

                           FD_ZERO(&amp;fds);
                           FD_SET(fd, &amp;fds);

                           /* Timeout. */
                           tv.tv_sec = 2;
                           tv.tv_usec = 0;

                           r = select(fd + 1, &amp;fds, NULL, NULL, &amp;tv);

                           if (-1 == r) {
                                   if (EINTR == errno)
                                           continue;
                                   errno_exit("select");
                           }

                           if (0 == r) {
                                   fprintf(stderr, "select timeout\n");
                                   exit(EXIT_FAILURE);
                           }

                           if (read_frame())
                                   break;
                           /* EAGAIN - continue select loop. */
                   }
           }
    }

    static void stop_capturing(void)
    {
           enum v4l2_buf_type type;

           switch (io) {
           case IO_METHOD_READ:
                   /* Nothing to do. */
                   break;

           case IO_METHOD_MMAP:
           case IO_METHOD_USERPTR:
                   type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                   if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &amp;type))
                           errno_exit("VIDIOC_STREAMOFF");
                   break;
           }
    }

    static void start_capturing(void)
    {
           unsigned int i;
           enum v4l2_buf_type type;

           switch (io) {
           case IO_METHOD_READ:
                   /* Nothing to do. */
                   break;

           case IO_METHOD_MMAP:
                   for (i = 0; i &lt; n_buffers; ++i) {
                           struct v4l2_buffer buf;

                           CLEAR(buf);
                           buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                           buf.memory = V4L2_MEMORY_MMAP;
                           buf.index = i;

                           if (-1 == xioctl(fd, VIDIOC_QBUF, &amp;buf))
                                   errno_exit("VIDIOC_QBUF");
                   }
                   type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                   if (-1 == xioctl(fd, VIDIOC_STREAMON, &amp;type))
                           errno_exit("VIDIOC_STREAMON");
                   break;

           case IO_METHOD_USERPTR:
                   for (i = 0; i &lt; n_buffers; ++i) {
                           struct v4l2_buffer buf;

                           CLEAR(buf);
                           buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                           buf.memory = V4L2_MEMORY_USERPTR;
                           buf.index = i;
                           buf.m.userptr = (unsigned long)buffers[i].start;
                           buf.length = buffers[i].length;

                           if (-1 == xioctl(fd, VIDIOC_QBUF, &amp;buf))
                                   errno_exit("VIDIOC_QBUF");
                   }
                   type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                   if (-1 == xioctl(fd, VIDIOC_STREAMON, &amp;type))
                           errno_exit("VIDIOC_STREAMON");
                   break;
           }
    }

    static void uninit_device(void)
    {
           unsigned int i;

           switch (io) {
           case IO_METHOD_READ:
                   free(buffers[0].start);
                   break;

           case IO_METHOD_MMAP:
                   for (i = 0; i &lt; n_buffers; ++i)
                           if (-1 == munmap(buffers[i].start, buffers[i].length))
                                   errno_exit("munmap");
                   break;

           case IO_METHOD_USERPTR:
                   for (i = 0; i &lt; n_buffers; ++i)
                           free(buffers[i].start);
                   break;
           }

           free(buffers);
    }

    static void init_read(unsigned int buffer_size)
    {
           buffers = calloc(1, sizeof(*buffers));

           if (!buffers) {
                   fprintf(stderr, "Out of memory\n");
                   exit(EXIT_FAILURE);
           }

           buffers[0].length = buffer_size;
           buffers[0].start = malloc(buffer_size);

           if (!buffers[0].start) {
                   fprintf(stderr, "Out of memory\n");
                   exit(EXIT_FAILURE);
           }
    }

    static void init_mmap(void)
    {
           struct v4l2_requestbuffers req;

           CLEAR(req);

           req.count = 4;
           req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
           req.memory = V4L2_MEMORY_MMAP;

           if (-1 == xioctl(fd, VIDIOC_REQBUFS, &amp;req)) {
                   if (EINVAL == errno) {
                           fprintf(stderr, "%s does not support "
                                    "memory mapping\n", dev_name);
                           exit(EXIT_FAILURE);
                   } else {
                           errno_exit("VIDIOC_REQBUFS");
                   }
           }

           if (req.count &lt; 2) {
                   fprintf(stderr, "Insufficient buffer memory on %s\n",
                            dev_name);
                   exit(EXIT_FAILURE);
           }

           buffers = calloc(req.count, sizeof(*buffers));

           if (!buffers) {
                   fprintf(stderr, "Out of memory\n");
                   exit(EXIT_FAILURE);
           }

           for (n_buffers = 0; n_buffers &lt; req.count; ++n_buffers) {
                   struct v4l2_buffer buf;

                   CLEAR(buf);

                   buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                   buf.memory      = V4L2_MEMORY_MMAP;
                   buf.index       = n_buffers;

                   if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &amp;buf))
                           errno_exit("VIDIOC_QUERYBUF");

                   buffers[n_buffers].length = buf.length;
                   buffers[n_buffers].start =
                           mmap(NULL /* start anywhere */,
                                 buf.length,
                                 PROT_READ | PROT_WRITE /* required */,
                                 MAP_SHARED /* recommended */,
                                 fd, buf.m.offset);

                   if (MAP_FAILED == buffers[n_buffers].start)
                           errno_exit("mmap");
           }
    }

    static void init_userp(unsigned int buffer_size)
    {
           struct v4l2_requestbuffers req;

           CLEAR(req);

           req.count  = 4;
           req.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
           req.memory = V4L2_MEMORY_USERPTR;

           if (-1 == xioctl(fd, VIDIOC_REQBUFS, &amp;req)) {
                   if (EINVAL == errno) {
                           fprintf(stderr, "%s does not support "
                                    "user pointer i/o\n", dev_name);
                           exit(EXIT_FAILURE);
                   } else {
                           errno_exit("VIDIOC_REQBUFS");
                   }
           }

           buffers = calloc(4, sizeof(*buffers));

           if (!buffers) {
                   fprintf(stderr, "Out of memory\n");
                   exit(EXIT_FAILURE);
           }

           for (n_buffers = 0; n_buffers &lt; 4; ++n_buffers) {
                   buffers[n_buffers].length = buffer_size;
                   buffers[n_buffers].start = malloc(buffer_size);

                   if (!buffers[n_buffers].start) {
                           fprintf(stderr, "Out of memory\n");
                           exit(EXIT_FAILURE);
                   }
           }
    }

    static void init_device(void)
    {
           struct v4l2_capability cap;
           struct v4l2_cropcap cropcap;
           struct v4l2_crop crop;
           struct v4l2_format fmt;
           unsigned int min;

           if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &amp;cap)) {
                   if (EINVAL == errno) {
                           fprintf(stderr, "%s is no V4L2 device\n",
                                    dev_name);
                           exit(EXIT_FAILURE);
                   } else {
                           errno_exit("VIDIOC_QUERYCAP");
                   }
           }

           if (!(cap.capabilities &amp; V4L2_CAP_VIDEO_CAPTURE)) {
                   fprintf(stderr, "%s is no video capture device\n",
                            dev_name);
                   exit(EXIT_FAILURE);
           }

           switch (io) {
           case IO_METHOD_READ:
                   if (!(cap.capabilities &amp; V4L2_CAP_READWRITE)) {
                           fprintf(stderr, "%s does not support read i/o\n",
                                    dev_name);
                           exit(EXIT_FAILURE);
                   }
                   break;

           case IO_METHOD_MMAP:
           case IO_METHOD_USERPTR:
                   if (!(cap.capabilities &amp; V4L2_CAP_STREAMING)) {
                           fprintf(stderr, "%s does not support streaming i/o\n",
                                    dev_name);
                           exit(EXIT_FAILURE);
                   }
                   break;
           }


           /* Select video input, video standard and tune here. */


           CLEAR(cropcap);

           cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

           if (0 == xioctl(fd, VIDIOC_CROPCAP, &amp;cropcap)) {
                   crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                   crop.c = cropcap.defrect; /* reset to default */

                   if (-1 == xioctl(fd, VIDIOC_S_CROP, &amp;crop)) {
                           switch (errno) {
                           case EINVAL:
                                   /* Cropping not supported. */
                                   break;
                           default:
                                   /* Errors ignored. */
                                   break;
                           }
                   }
           } else {
                   /* Errors ignored. */
           }


           CLEAR(fmt);

           fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
       fprintf(stderr, "Force Format %d\n", force_format);
           if (force_format) {
           if (force_format==2){
                       fmt.fmt.pix.width       = 1920;    
                   fmt.fmt.pix.height      = 1080;  
               fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_H264;
                       fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
           }
           else if(force_format==1){
               fmt.fmt.pix.width   = 640;
               fmt.fmt.pix.height  = 480;
               fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
               fmt.fmt.pix.field   = V4L2_FIELD_INTERLACED;
           }

                   if (-1 == xioctl(fd, VIDIOC_S_FMT, &amp;fmt))
                           errno_exit("VIDIOC_S_FMT");

                   /* Note VIDIOC_S_FMT may change width and height. */
           } else {
                   /* Preserve original settings as set by v4l2-ctl for example */
                   if (-1 == xioctl(fd, VIDIOC_G_FMT, &amp;fmt))
                           errno_exit("VIDIOC_G_FMT");
           }

           /* Buggy driver paranoia. */
           min = fmt.fmt.pix.width * 2;
           if (fmt.fmt.pix.bytesperline &lt; min)
                   fmt.fmt.pix.bytesperline = min;
           min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
           if (fmt.fmt.pix.sizeimage &lt; min)
                   fmt.fmt.pix.sizeimage = min;

           switch (io) {
           case IO_METHOD_READ:
                   init_read(fmt.fmt.pix.sizeimage);
                   break;

           case IO_METHOD_MMAP:
                   init_mmap();
                   break;

           case IO_METHOD_USERPTR:
                   init_userp(fmt.fmt.pix.sizeimage);
                   break;
           }
    }

    static void close_device(void)
    {
           if (-1 == close(fd))
                   errno_exit("close");

           fd = -1;
    }

    static void open_device(void)
    {
           struct stat st;

           if (-1 == stat(dev_name, &amp;st)) {
                   fprintf(stderr, "Cannot identify '%s': %d, %s\n",
                            dev_name, errno, strerror(errno));
                   exit(EXIT_FAILURE);
           }

           if (!S_ISCHR(st.st_mode)) {
                   fprintf(stderr, "%s is no device\n", dev_name);
                   exit(EXIT_FAILURE);
           }

           fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);

           if (-1 == fd) {
                   fprintf(stderr, "Cannot open '%s': %d, %s\n",
                            dev_name, errno, strerror(errno));
                   exit(EXIT_FAILURE);
           }
    }

    static void usage(FILE *fp, int argc, char **argv)
    {
           fprintf(fp,
                    "Usage: %s [options]\n\n"
                    "Version 1.3\n"
                    "Options:\n"
                    "-d | --device name   Video device name [%s]\n"
                    "-h | --help          Print this message\n"
                    "-m | --mmap          Use memory mapped buffers [default]\n"
                    "-r | --read          Use read() calls\n"
                    "-u | --userp         Use application allocated buffers\n"
                    "-o | --output        Outputs stream to stdout\n"
                    "-f | --format        Force format to 640x480 YUYV\n"
            "-F | --formatH264    Force format to 1920x1080 H264\n"
                    "-c | --count         Number of frames to grab [%i] - use 0 for infinite\n"
                    "\n"
            "Example usage: capture -F -o -c 300 > output.raw\n"
            "Captures 300 frames of H264 at 1920x1080 - use raw2mpg4 script to convert to mpg4\n",
                    argv[0], dev_name, frame_count);
    }

    static const char short_options[] = "d:hmruofFc:";

    static const struct option
    long_options[] = {
           { "device", required_argument, NULL, 'd' },
           { "help",   no_argument,       NULL, 'h' },
           { "mmap",   no_argument,       NULL, 'm' },
           { "read",   no_argument,       NULL, 'r' },
           { "userp",  no_argument,       NULL, 'u' },
           { "output", no_argument,       NULL, 'o' },
           { "format", no_argument,       NULL, 'f' },
       { "formatH264", no_argument,   NULL, 'F' },
           { "count",  required_argument, NULL, 'c' },
           { 0, 0, 0, 0 }
    };

    int main(int argc, char **argv)
    {
           dev_name = "/dev/video0";

           for (;;) {
                   int idx;
                   int c;

                   c = getopt_long(argc, argv,
                                   short_options, long_options, &amp;idx);

                   if (-1 == c)
                           break;

                   switch (c) {
                   case 0: /* getopt_long() flag */
                           break;

                   case 'd':
                           dev_name = optarg;
                           break;

                   case 'h':
                           usage(stdout, argc, argv);
                           exit(EXIT_SUCCESS);

                   case 'm':
                           io = IO_METHOD_MMAP;
                           break;

                   case 'r':
                           io = IO_METHOD_READ;
                           break;

                   case 'u':
                           io = IO_METHOD_USERPTR;
                           break;

                   case 'o':
                           out_buf++;
                           break;

                   case 'f':
                           force_format=1;
                           break;

           case 'F':
               force_format=2;
               break;

                   case 'c':
                           errno = 0;
                           frame_count = strtol(optarg, NULL, 0);
                           if (errno)
                                   errno_exit(optarg);
                           break;

                   default:
                           usage(stderr, argc, argv);
                           exit(EXIT_FAILURE);
                   }
           }

           open_device();
           init_device();
           start_capturing();
           mainloop();
           stop_capturing();
           uninit_device();
           close_device();
           fprintf(stderr, "\n");
           return 0;
    }

    It’s a modified version of a V4L2 video capture example.
    Then I know that if I have outputed the streame to a file I would have to run this command to convert the raw format to mp4 format :

    ffmpeg -f h264 -i output.raw -vcodec copy output.mp4

    And the v4l2loopback program I’m using is foud here :
    https://github.com/umlaeute/v4l2loopback

    ------------------Update------------------

    Okay. So I got the pipe from the capture program to ffmpeg working. It captures, decodes the h264 and I can write it to a mp4 file with this command :

    ./capture -F -d /dev/video0 -o | ffmpeg -f h264 -i - -vcodec copy out.mp4

    Now I am trying to get the last pipe working with this command :

    ./capture -F -d /dev/video0 -o | ffmpeg -f h264 -i - -vcodec copy -f mp4 - | gst-launch-0.10 -v fdsrc ! v4l2sink device=/dev/video3

    I get these errors :

    • muxer does not support non seekable output
    • Could not write header for output file #0 (incorrect codec parameters ?) : Invalid argument

    Any ideas ?

  • EC2 for video-encoding

    24 septembre 2012, par TK Kocheran

    I have a potential job which will require me to do some video encoding with FFMPEG and x264. I'll have a series of files which I'll need to encode once, then I'll be able to bring down the instances. Since I'm not really sure of the resource utilization of x264 and FFMPEG, what kind of instances should I get ? I'm thinking either a

    High-CPU Extra Large Instance

    7 GB of memory
    20 EC2 Compute Units (8 virtual cores with 2.5 EC2 Compute Units each)
    1690 GB of instance storage
    64-bit platform
    I/O Performance : High
    API name : c1.xlarge

    or, alternatively a

    Cluster GPU Quadruple Extra Large Instance

    22 GB of memory
    33.5 EC2 Compute Units (2 x Intel Xeon X5570, quad-core “Nehalem” architecture)
    2 x NVIDIA Tesla “Fermi” M2050 GPUs
    1690 GB of instance storage
    64-bit platform
    I/O Performance : Very High (10 Gigabit Ethernet)
    API name : cg1.4xlarge

    What should I use ? Does x264/FFMPEG perform better with faster/more CPUs or does it really pound the GPU more ? In any case, it seems that the Cluster GPU seems to be the higher performance instance. What should I prefer ?