问:
recording from webcam using ffmpeg at high framerate
I have a webcam (model Brio 4K stream edition from Logitech) that is able to record at resolution 1280x720 and 60 fps in guvcview on Ubuntu 16.04. I then use a video codec 'raw camera input'. This is working fine and as expected, and the result is well a 60 fps video at the desired resolution.

However, I need to record using command line and not GUI. The guvcview GUI crashes on my machine (segmentation fault, this has been reported by other users before), so I want to use ffmpeg instead.

Unfortunately, when I use the command (in terminal):

```<code>ffmpeg -i /dev/video1 -framerate 60 -video_size 1280x720 out.mkv
</code>```

I only get around 30 fps out. This is of course not due to the camera by itself (it works at 60 fps in guvcview), but I cannot understand why I get 30 fps when I ask for 60 fps explicitely. It also looks in the output of ffmpeg as it records at 30 fps:

```<code>Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv422p, 1280x720, q=-1--1, 30 fps, 1k tbn, 30 tbc
</code>```

Any suggestion how I can solve this and record at 60 fps using ffmpeg?

Note: I also tried something like this, with the same result (only 30 fps):

```<code>ffmpeg -f video4linux2 -i /dev/video1 -framerate 60.0 -video_size 1280x720 out.mkv
</code>```

Edit 1 thank you for the help in comment: order of arguments matters. Now using:

```<code>ffmpeg -framerate 60 -video_size 1280x720 -i /dev/video1 out.mkv
</code>```

I get still around 30 fps, and a new (probably more understandable) warning message:

```<code>[video4linux2,v4l2 @ 0x1ddc4e0] The driver changed the time per frame from 1/60 to 1/30
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 256338.694616, bitrate: 442368 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 442368 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
</code>```

I find several entries for this problem (video4linux2 + The driver changed the time per frame), but no clear solution.

Edit 2 + 3:

```<code>v4l2-ctl -d 1 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 160x120
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 176x144
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 352x288
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 340x340
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 440x440
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 480x270
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x448
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1024x576
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1600x896
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : Motion-JPEG
        Size: Discrete 640x480
            Interval: Discrete 0.008s (120.000 fps)
            Interval: Discrete 0.011s (90.000 fps)
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 160x120
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 176x144
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 352x288
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 480x270
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x448
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1024x576
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.011s (90.000 fps)
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1600x896
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 2560x1440
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 3840x2160
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 4096x2160
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)

    Index       : 2
    Type        : Video Capture
    Pixel Format: 'NV12'
    Name        : Y/CbCr 4:2:0
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
</code>```

Edit 4:

It looks like there may still be a problem using:

```<code>ffmpeg -f v4l2 -framerate 60 -video_size 1280x720 -input_format mjpeg -i /dev/video1 out.mkv
</code>```

As the output of ffmpeg looks like:

```<code>Output #0, matroska, to 'out.mkv':
  Metadata:
  encoder         : Lavf56.40.101
Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuvj422p(pc), 1280x720, q=-1--1, 60 fps, 1k tbn, 60 tbc
  Metadata:
  encoder         : Lavc56.60.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  198 fps= 37 q=-1.0 Lsize=    1043kB time=00:00:05.38 bitrate=1587.4kbits/s
</code>```

Is the fps indicated in the last line (37 instead of 60) reliable? It was working at 60 fps with guvcview, so I do not think the laptop write speeed or CPU is the problem.

Edit 5:

Thank you for the great help @LordNeckbeard , now it looks like everything works using your additional output argument command ffmpeg -f v4l2 -framerate 60 -video_size 1280x720 -input_format mjpeg -i /dev/video1 -preset faster -pix_fmt yuv420p out.mkv:

```<code>$ ffmpeg -f v4l2 -framerate 60 -video_size 1280x720 -input_format mjpeg -i /dev/video1 -preset faster -pix_fmt yuv420p out.mkv
ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[mjpeg @ 0x1d6f320] Changeing bps to 8
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 259410.922692, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, -10 kb/s, 60 fps, 60 tbr, 1000k tbn, 1000k tbc
[swscaler @ 0x1d7e480] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x1d72620] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x1d72620] profile High, level 3.2
[libx264 @ 0x1d72620] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=4 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=20 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'out.mkv':
  Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1280x720, q=-1--1, 60 fps, 1k tbn, 60 tbc
    Metadata:
      encoder         : Lavc56.60.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  467 fps= 59 q=-1.0 Lsize=     914kB time=00:00:07.83 bitrate= 955.8kbits/s
video:910kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.434447%
[libx264 @ 0x1d72620] frame I:2     Avg QP:21.96  size: 61186
[libx264 @ 0x1d72620] frame P:118   Avg QP:26.01  size:  4695
[libx264 @ 0x1d72620] frame B:347   Avg QP:27.54  size:   734
[libx264 @ 0x1d72620] consecutive B-frames:  0.4%  1.3%  0.6% 97.6%
[libx264 @ 0x1d72620] mb I  I16..4: 14.7% 45.2% 40.0%
[libx264 @ 0x1d72620] mb P  I16..4:  1.4%  3.7%  0.0%  P16..4: 29.9%  4.1%  0.5%  0.0%  0.0%    skip:60.4%
[libx264 @ 0x1d72620] mb B  I16..4:  0.2%  0.4%  0.0%  B16..8:  5.4%  0.2%  0.0%  direct: 4.3%  skip:89.6%  L0:53.4% L1:42.7% BI: 3.9%
[libx264 @ 0x1d72620] 8x8 transform intra:66.4% inter:71.8%
[libx264 @ 0x1d72620] coded y,uvDC,uvAC intra: 38.1% 50.7% 12.7% inter: 2.8% 7.6% 0.1%
[libx264 @ 0x1d72620] i16 v,h,dc,p: 36% 36% 16% 11%
[libx264 @ 0x1d72620] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 32% 37%  2%  2%  2%  4%  1%  5%
[libx264 @ 0x1d72620] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 46%  8%  2%  3%  3%  4%  3% 12%
[libx264 @ 0x1d72620] i8c dc,h,v,p: 56% 26% 16%  3%
[libx264 @ 0x1d72620] Weighted P-Frames: Y:9.3% UV:7.6%
[libx264 @ 0x1d72620] ref P L0: 58.6% 41.4%
[libx264 @ 0x1d72620] ref B L0: 56.9% 43.1%
[libx264 @ 0x1d72620] ref B L1: 85.5% 14.5%
[libx264 @ 0x1d72620] kb/s:946.85
</code>```

答:
Must choose proper format

This camera offers up to 90 fps using its MJPEG encoder, but only up to 30 using raw video, so you have to tell it which format you want with the -input_format input option:

```<code>ffmpeg -f v4l2 -framerate 90 -video_size 1280x720 -input_format mjpeg -i /dev/video1 out.mkv
</code>```

If your computer is too slow to encode at realtime

Stream copy it first then re-encode later at your leisure to your desired format:

```<code>ffmpeg -f v4l2 -framerate 90 -video_size 1280x720 -input_format mjpeg -i /dev/video1 -c copy mjpeg.mkv
</code>```

Then something like:

```<code>ffmpeg -i mjpeg.mkv -c:v libx264 -crf 23 -preset medium -pix_fmt yuv420p out.mkv
</code>```

Also see:

FFmpeg v4l2 docs and FFmpeg Wiki: Webcam

FFmpeg Wiki: H.264 Encoding

Body:
I have a webcam (model Brio 4K stream edition from Logitech) that is able to record at resolution 1280x720 and 60 fps in guvcview on Ubuntu 16.04. I then use a video codec 'raw camera input'. This is working fine and as expected, and the result is well a 60 fps video at the desired resolution.

However, I need to record using command line and not GUI. The guvcview GUI crashes on my machine (segmentation fault, this has been reported by other users before), so I want to use ffmpeg instead.

Unfortunately, when I use the command (in terminal):

ffmpeg -i /dev/video1 -framerate 60 -video_size 1280x720 out.mkv

I only get around 30 fps out. This is of course not due to the camera by itself (it works at 60 fps in guvcview), but I cannot understand why I get 30 fps when I ask for 60 fps explicitely. It also looks in the output of ffmpeg as it records at 30 fps:

Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv422p, 1280x720, q=-1--1, 30 fps, 1k tbn, 30 tbc

Any suggestion how I can solve this and record at 60 fps using ffmpeg?

Note: I also tried something like this, with the same result (only 30 fps):

ffmpeg -f video4linux2 -i /dev/video1 -framerate 60.0 -video_size 1280x720 out.mkv

Edit 1 thank you for the help in comment: order of arguments matters. Now using:

ffmpeg -framerate 60 -video_size 1280x720 -i /dev/video1 out.mkv

I get still around 30 fps, and a new (probably more understandable) warning message:

[video4linux2,v4l2 @ 0x1ddc4e0] The driver changed the time per frame from 1/60 to 1/30
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 256338.694616, bitrate: 442368 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 442368 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc

I find several entries for this problem (video4linux2 + The driver changed the time per frame), but no clear solution.

Edit 2 + 3:

v4l2-ctl -d 1 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 160x120
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 176x144
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 352x288
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 340x340
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 440x440
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 480x270
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x448
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1024x576
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1600x896
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : Motion-JPEG
        Size: Discrete 640x480
            Interval: Discrete 0.008s (120.000 fps)
            Interval: Discrete 0.011s (90.000 fps)
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 160x120
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 176x144
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 352x288
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 480x270
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x448
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1024x576
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.011s (90.000 fps)
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1600x896
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.017s (60.000 fps)
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 2560x1440
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 3840x2160
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 4096x2160
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)

    Index       : 2
    Type        : Video Capture
    Pixel Format: 'NV12'
    Name        : Y/CbCr 4:2:0
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)

Edit 4:

It looks like there may still be a problem using:

ffmpeg -f v4l2 -framerate 60 -video_size 1280x720 -input_format mjpeg -i /dev/video1 out.mkv

As the output of ffmpeg looks like:

Output #0, matroska, to 'out.mkv':
  Metadata:
  encoder         : Lavf56.40.101
Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuvj422p(pc), 1280x720, q=-1--1, 60 fps, 1k tbn, 60 tbc
  Metadata:
  encoder         : Lavc56.60.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  198 fps= 37 q=-1.0 Lsize=    1043kB time=00:00:05.38 bitrate=1587.4kbits/s

Is the fps indicated in the last line (37 instead of 60) reliable? It was working at 60 fps with guvcview, so I do not think the laptop write speeed or CPU is the problem.

Edit 5:

Thank you for the great help @LordNeckbeard , now it looks like everything works using your additional output argument command ffmpeg -f v4l2 -framerate 60 -video_size 1280x720 -input_format mjpeg -i /dev/video1 -preset faster -pix_fmt yuv420p out.mkv:

$ ffmpeg -f v4l2 -framerate 60 -video_size 1280x720 -input_format mjpeg -i /dev/video1 -preset faster -pix_fmt yuv420p out.mkv
ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[mjpeg @ 0x1d6f320] Changeing bps to 8
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 259410.922692, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, -10 kb/s, 60 fps, 60 tbr, 1000k tbn, 1000k tbc
[swscaler @ 0x1d7e480] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x1d72620] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x1d72620] profile High, level 3.2
[libx264 @ 0x1d72620] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=4 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=20 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'out.mkv':
  Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1280x720, q=-1--1, 60 fps, 1k tbn, 60 tbc
    Metadata:
      encoder         : Lavc56.60.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  467 fps= 59 q=-1.0 Lsize=     914kB time=00:00:07.83 bitrate= 955.8kbits/s
video:910kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.434447%
[libx264 @ 0x1d72620] frame I:2     Avg QP:21.96  size: 61186
[libx264 @ 0x1d72620] frame P:118   Avg QP:26.01  size:  4695
[libx264 @ 0x1d72620] frame B:347   Avg QP:27.54  size:   734
[libx264 @ 0x1d72620] consecutive B-frames:  0.4%  1.3%  0.6% 97.6%
[libx264 @ 0x1d72620] mb I  I16..4: 14.7% 45.2% 40.0%
[libx264 @ 0x1d72620] mb P  I16..4:  1.4%  3.7%  0.0%  P16..4: 29.9%  4.1%  0.5%  0.0%  0.0%    skip:60.4%
[libx264 @ 0x1d72620] mb B  I16..4:  0.2%  0.4%  0.0%  B16..8:  5.4%  0.2%  0.0%  direct: 4.3%  skip:89.6%  L0:53.4% L1:42.7% BI: 3.9%
[libx264 @ 0x1d72620] 8x8 transform intra:66.4% inter:71.8%
[libx264 @ 0x1d72620] coded y,uvDC,uvAC intra: 38.1% 50.7% 12.7% inter: 2.8% 7.6% 0.1%
[libx264 @ 0x1d72620] i16 v,h,dc,p: 36% 36% 16% 11%
[libx264 @ 0x1d72620] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 32% 37%  2%  2%  2%  4%  1%  5%
[libx264 @ 0x1d72620] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 46%  8%  2%  3%  3%  4%  3% 12%
[libx264 @ 0x1d72620] i8c dc,h,v,p: 56% 26% 16%  3%
[libx264 @ 0x1d72620] Weighted P-Frames: Y:9.3% UV:7.6%
[libx264 @ 0x1d72620] ref P L0: 58.6% 41.4%
[libx264 @ 0x1d72620] ref B L0: 56.9% 43.1%
[libx264 @ 0x1d72620] ref B L1: 85.5% 14.5%
[libx264 @ 0x1d72620] kb/s:946.85

Body:
Must choose proper format

This camera offers up to 90 fps using its MJPEG encoder, but only up to 30 using raw video, so you have to tell it which format you want with the -input_format input option:

ffmpeg -f v4l2 -framerate 90 -video_size 1280x720 -input_format mjpeg -i /dev/video1 out.mkv

If your computer is too slow to encode at realtime

Stream copy it first then re-encode later at your leisure to your desired format:

ffmpeg -f v4l2 -framerate 90 -video_size 1280x720 -input_format mjpeg -i /dev/video1 -c copy mjpeg.mkv

Then something like:

ffmpeg -i mjpeg.mkv -c:v libx264 -crf 23 -preset medium -pix_fmt yuv420p out.mkv

Also see:

FFmpeg v4l2 docs and FFmpeg Wiki: Webcam

FFmpeg Wiki: H.264 Encoding


来源: stackexchange

问:
Git - amending an historical commit
So you're working along like a good little developer: you commit one set of changes, let's call it foundation. Then you finish up the next segment and commit, lets call it framework. You're about to move onto the next step of cleanup when you realize: Oh No! I forgot to add an important change to my foundation commit! (let's call it patch)

But not to fear. Git allows us to edit history*. No one will ever see our mistakes...

to review this is what our commit history looks like

```<code>patch
|
framework
|
foundation
|
everything that came before
...
</code>```

As far as I know there are two basic ways we could go about this. First method, commit the changes of patch and then use git rebase -i to change the order of commits and squash/fixup patch into foundation. Second method, stash the changes in patch then using git rebase -i edit the foundation commit using git commit --amend. That is:

First method

git commit -am 'patch'

git rebase -i

```<code># Originally
# pick foundation
# pick framework
# pick patch

# Now
pick foundation
fixup patch
pick framework
</code>```

Second method

git stash

git rebase -i

```<code># Originally
# pick foundation
# pick framework

# Now
edit foundation
pick framework
</code>```

git stash apply

git commit --amend

git rebase --continue

At the end of both of these methods, we will have the commit history of

```<code>framework
|
foundation+patch
|
everything that came before
...
</code>```

So my question is

Should we prefer one process over another? And if so why? What benefits/risks are involved with one or the other?

*Disclaimer: Time travel is dangerous. Editing your history could destroy your repo, especially if it has been shared with multiple people. Use this power wisely...

答:
I have no reason to prefer either of those two methods.

Most commonly, especially for tricky cases, I use a third method! :-)

The key step is to rename the current experiment branch, and create a new experiment branch:

```<code>git branch -m experiment experiment.0  # increment number over time
git checkout -b experiment  # and add an upstream if desired
</code>```

Now you can commit the patch, including using git commit --fixup, and then run an interactive rebase (perhaps with --autosquash) and re-work the foundation and framework.

Each "abandoned" previous attempt thus remains as a visible, numbered previous attempt.  When all is good, I delete the old ones with git branch -D and they're now really-abandoned.

ContentLicense: CC BY-SA 3.0

Title: Git - amending an historical commit

Body:
So you're working along like a good little developer: you commit one set of changes, let's call it foundation. Then you finish up the next segment and commit, lets call it framework. You're about to move onto the next step of cleanup when you realize: Oh No! I forgot to add an important change to my foundation commit! (let's call it patch)

But not to fear. Git allows us to edit history*. No one will ever see our mistakes...

to review this is what our commit history looks like

patch
|
framework
|
foundation
|
everything that came before
...

As far as I know there are two basic ways we could go about this. First method, commit the changes of patch and then use git rebase -i to change the order of commits and squash/fixup patch into foundation. Second method, stash the changes in patch then using git rebase -i edit the foundation commit using git commit --amend. That is:

First method

git commit -am 'patch'

git rebase -i

# Originally
# pick foundation
# pick framework
# pick patch

# Now
pick foundation
fixup patch
pick framework

Second method

git stash

git rebase -i

# Originally
# pick foundation
# pick framework

# Now
edit foundation
pick framework

git stash apply

git commit --amend

git rebase --continue

At the end of both of these methods, we will have the commit history of

framework
|
foundation+patch
|
everything that came before
...

So my question is

Should we prefer one process over another? And if so why? What benefits/risks are involved with one or the other?

*Disclaimer: Time travel is dangerous. Editing your history could destroy your repo, especially if it has been shared with multiple people. Use this power wisely...

Body:
I have no reason to prefer either of those two methods.

Most commonly, especially for tricky cases, I use a third method! :-)

The key step is to rename the current experiment branch, and create a new experiment branch:

git branch -m experiment experiment.0  # increment number over time
git checkout -b experiment  # and add an upstream if desired

Now you can commit the patch, including using git commit --fixup, and then run an interactive rebase (perhaps with --autosquash) and re-work the foundation and framework.

Each "abandoned" previous attempt thus remains as a visible, numbered previous attempt.  When all is good, I delete the old ones with git branch -D and they're now really-abandoned.


问:
Return observable inside observable in canactivate guard of Angular 4
So I have to do two things in my canActivate guard of the router. First I have to check if the user is authorized, I do this by calling OpenIdcSecutiry service, and then if the user is authorized I must check the users roles by calling another service that returns UserProfile including its roles. I know I can return an Observable and in fact if I just do:

```<code>return this.oidcSecurityService.getIsAuthorized();
</code>```

It works, but obviously I does not check user roles. Right now I have this:

```<code>canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {

return this.oidcSecurityService.getIsAuthorized()
  .map(
    data => {
      if (data === false) {
        this.router.navigate(['/login']);
        return data;
      }
      if (data === true) {
        const roles = route.data['roles'] as Array<string>;
        if (roles) {
        this.profileService.getObservableUserProfileFromServer().map(userProfile => {
          const userRoles = userProfile.Roles;
          for (const role of roles) {
            if (userRoles.indexOf(role) > -1) {
              return true;
            }
          }
          return false;
        });
        }
        return data;
      }
    },
    error => {
      this.router.navigate(['/login']);
      return error;
    }
  );
</code>```

this.profileService.getObservableUserProfileFromServer() is never called and I dont know how to check the user roles after I know the user is Authorized. How can I do this? Can I return the observable inside my observable?

EDIT1: I changed the code to this:

```<code>canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {

return this.oidcSecurityService.getIsAuthorized()
  .map(
    data => {
      if (data === false) {
        this.router.navigate(['/login']);
        return data;
      }
      if (data === true) {
        const roles = route.data['roles'] as Array<string>;
        if (roles) {
          return this.profileService.getObservableUserProfileFromServer().toPromise().then(userProfile => {
              const userRoles = userProfile.Roles;
              for (const role of roles) {
                if (userRoles.indexOf(role) > -1) {
                  return true;
                }
              }
              return false;
          }
            );
        }
        return data;
      }
    },
    error => {
      this.router.navigate(['/login']);
      return error;
    }
  );
</code>```

// return this.oidcSecurityService.getIsAuthorized();

}

Now I can see how this.profileService.getObservableUserProfileFromServer is called and receive results from server, but the result is not evaluated in canActivate guard, it simply ignores the result and It says the Navigation was canceled.

EDIT FINAL:

@llai gave me the answer, two switchmaps must be used to chain several observables, final code here:

```<code>canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {

return this.oidcSecurityService.getIsAuthorized()
  .switchMap(
    data => {
      if (data === false) {
        this.router.navigate(['/login']);
        return Observable.of(false); // user not logged in, canActivate = false
      } else if (data === true) {
        const roles = route.data['roles'] as Array<string>;
        if (roles) {
          // return inner observable
          return this.profileService.getObservableUserProfileFromServer()
            .switchMap(userProfile => {
              const userRoles = userProfile.Roles;
              for (const role of roles) {
                if (userRoles.indexOf(role) > -1) {
                  // role found, canActivate = true
                  return Observable.of(true);
                }
              }
              // no matching role, canActivate = false
              return Observable.of(false);
            });
        } else {
          // no roles defined in route data, canActivate = false
          return Observable.of(true);
        }
      }
    });
</code>```

}

答:
As Christian mentioned in a comment, you should be using switchMap to chain your observables together.

In your first implementation you are not returning your inner observable therefore the router never subscribes to it, so it never gets called.

In your second implementation you are "subscribing" (convert to promise + then) to the observable within the map function, which makes the inner observable fire. However since the observable is not returned to the guard, the guard is not waiting for the inner observable to complete.

Instead you should chain the observables and return that chained sequence to the guard. This will allow the guard to subscribe to the sequence and wait for the proper response.

```<code>canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {

    return this.oidcSecurityService.getIsAuthorized()
      .switchMap(
        data => {
          if (data === false) {
            this.router.navigate(['/login']);
            return Observable.of(false); // user not logged in, canActivate = false
          }else if (data === true) {
            const roles = route.data['roles'] as Array<string>;
            if (roles) {
              // return inner observable
              return this.profileService.getObservableUserProfileFromServer()
                .map(userProfile => {
                  const userRoles = userProfile.Roles;
                  for (const role of roles) {
                    if (userRoles.indexOf(role) > -1) {
                      // role found, canActivate = true
                      return true;
                    }
                  }
                  // no matching role, canActivate = false
                  return false;
                });
            }else{
              // no roles defined in route data, canActivate = false
              return Observable.of(false)
            }
          }
        }
      }
    );

}
</code>```

Body:
So I have to do two things in my canActivate guard of the router. First I have to check if the user is authorized, I do this by calling OpenIdcSecutiry service, and then if the user is authorized I must check the users roles by calling another service that returns UserProfile including its roles. I know I can return an Observable and in fact if I just do:

return this.oidcSecurityService.getIsAuthorized();

It works, but obviously I does not check user roles. Right now I have this:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {

return this.oidcSecurityService.getIsAuthorized()
  .map(
    data => {
      if (data === false) {
        this.router.navigate(['/login']);
        return data;
      }
      if (data === true) {
        const roles = route.data['roles'] as Array<string>;
        if (roles) {
        this.profileService.getObservableUserProfileFromServer().map(userProfile => {
          const userRoles = userProfile.Roles;
          for (const role of roles) {
            if (userRoles.indexOf(role) > -1) {
              return true;
            }
          }
          return false;
        });
        }
        return data;
      }
    },
    error => {
      this.router.navigate(['/login']);
      return error;
    }
  );

this.profileService.getObservableUserProfileFromServer() is never called and I dont know how to check the user roles after I know the user is Authorized. How can I do this? Can I return the observable inside my observable?

EDIT1: I changed the code to this:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {

return this.oidcSecurityService.getIsAuthorized()
  .map(
    data => {
      if (data === false) {
        this.router.navigate(['/login']);
        return data;
      }
      if (data === true) {
        const roles = route.data['roles'] as Array<string>;
        if (roles) {
          return this.profileService.getObservableUserProfileFromServer().toPromise().then(userProfile => {
              const userRoles = userProfile.Roles;
              for (const role of roles) {
                if (userRoles.indexOf(role) > -1) {
                  return true;
                }
              }
              return false;
          }
            );
        }
        return data;
      }
    },
    error => {
      this.router.navigate(['/login']);
      return error;
    }
  );

// return this.oidcSecurityService.getIsAuthorized();

}

Now I can see how this.profileService.getObservableUserProfileFromServer is called and receive results from server, but the result is not evaluated in canActivate guard, it simply ignores the result and It says the Navigation was canceled.

EDIT FINAL:

@llai gave me the answer, two switchmaps must be used to chain several observables, final code here:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {

return this.oidcSecurityService.getIsAuthorized()
  .switchMap(
    data => {
      if (data === false) {
        this.router.navigate(['/login']);
        return Observable.of(false); // user not logged in, canActivate = false
      } else if (data === true) {
        const roles = route.data['roles'] as Array<string>;
        if (roles) {
          // return inner observable
          return this.profileService.getObservableUserProfileFromServer()
            .switchMap(userProfile => {
              const userRoles = userProfile.Roles;
              for (const role of roles) {
                if (userRoles.indexOf(role) > -1) {
                  // role found, canActivate = true
                  return Observable.of(true);
                }
              }
              // no matching role, canActivate = false
              return Observable.of(false);
            });
        } else {
          // no roles defined in route data, canActivate = false
          return Observable.of(true);
        }
      }
    });

}

Body:
As Christian mentioned in a comment, you should be using switchMap to chain your observables together.

In your first implementation you are not returning your inner observable therefore the router never subscribes to it, so it never gets called.

In your second implementation you are "subscribing" (convert to promise + then) to the observable within the map function, which makes the inner observable fire. However since the observable is not returned to the guard, the guard is not waiting for the inner observable to complete.

Instead you should chain the observables and return that chained sequence to the guard. This will allow the guard to subscribe to the sequence and wait for the proper response.

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {

    return this.oidcSecurityService.getIsAuthorized()
      .switchMap(
        data => {
          if (data === false) {
            this.router.navigate(['/login']);
            return Observable.of(false); // user not logged in, canActivate = false
          }else if (data === true) {
            const roles = route.data['roles'] as Array<string>;
            if (roles) {
              // return inner observable
              return this.profileService.getObservableUserProfileFromServer()
                .map(userProfile => {
                  const userRoles = userProfile.Roles;
                  for (const role of roles) {
                    if (userRoles.indexOf(role) > -1) {
                      // role found, canActivate = true
                      return true;
                    }
                  }
                  // no matching role, canActivate = false
                  return false;
                });
            }else{
              // no roles defined in route data, canActivate = false
              return Observable.of(false)
            }
          }
        }
      }
    );

}


问:
configuring dynamic url's in router
I'm using Codeigniter. Basically what I want is to remove the Controller name (Home) from the url.

Those urls look like:

```<code>http://localhost/mechanicly/Home
http://localhost/mechanicly/Home/about
http://localhost/mechanicly/Home/contactus
</code>```

now there are two ways I can remove the Home controller:

static definition of every url inside route:

```<code>$route['about'] = "Home/about";
$route['contactus'] = "Home/contactus";
</code>```

I can use call backs in routes in Codeigniter:

```<code>$route['(.+)'] = function ( $param ) {

  if( strpos( $param, "Admin" ) !== false ) {
    echo $param;
    return "Admin/".$param;
  }
  else{
    echo $param;
    return "Home/".$param;
  }
</code>```

};

this logic is much better as it is generic and I don't have to create new routes every time for new method inside the controller.

It is working fine for the client controller which is Home but I have another controller named as Admin and I want to redirect Admin requests to the Admin controller and Home request to the Home Controller.

Why does above code work fine for the Home controller but returns

not found

when I validate for the Admin controller?

I am using CI version 3.x

答:
If you really want to get crazy, you could parse the methods from the controller file and programatically create the "static" approach.

Pseudo code here

```<code>$controller_file_contents = file_get_contents('path/to/controller.php');
$controller_methods = function_that_parses_methods_from_file($controller_file_contents);
foreach ($controller_methods as $controller_method) {
    $route[$controller_method] = "Home/" . $controller_method;
}
</code>```

How function_that_parses_methods_from_file works is probably gonna involve a regex, something like function \w+. If you go with this approach, try to keep the controller as small as possible by offloading as much logic as possible into models, which is often a good idea anyways. That way the performance impact in the router is as small as possible.

Alternatively, you may be able to parse the controller using get_class_methods if you can figure out how to load the controller into memory inside the router without conflicting when you need to load the controller using the router or causing too much performance issues.

Pretty goofy, but every method you create in that controller will automatically create a route.

ContentLicense: CC BY-SA 4.0

Title: configuring dynamic url's in router

Body:
I'm using Codeigniter. Basically what I want is to remove the Controller name (Home) from the url.

Those urls look like:

http://localhost/mechanicly/Home
http://localhost/mechanicly/Home/about
http://localhost/mechanicly/Home/contactus

now there are two ways I can remove the Home controller:

static definition of every url inside route:

$route['about'] = "Home/about";
$route['contactus'] = "Home/contactus";

I can use call backs in routes in Codeigniter:

$route['(.+)'] = function ( $param ) {

  if( strpos( $param, "Admin" ) !== false ) {
    echo $param;
    return "Admin/".$param;
  }
  else{
    echo $param;
    return "Home/".$param;
  }

};

this logic is much better as it is generic and I don't have to create new routes every time for new method inside the controller.

It is working fine for the client controller which is Home but I have another controller named as Admin and I want to redirect Admin requests to the Admin controller and Home request to the Home Controller.

Why does above code work fine for the Home controller but returns

not found

when I validate for the Admin controller?

I am using CI version 3.x

Body:
If you really want to get crazy, you could parse the methods from the controller file and programatically create the "static" approach.

Pseudo code here

$controller_file_contents = file_get_contents('path/to/controller.php');
$controller_methods = function_that_parses_methods_from_file($controller_file_contents);
foreach ($controller_methods as $controller_method) {
    $route[$controller_method] = "Home/" . $controller_method;
}

How function_that_parses_methods_from_file works is probably gonna involve a regex, something like function \w+. If you go with this approach, try to keep the controller as small as possible by offloading as much logic as possible into models, which is often a good idea anyways. That way the performance impact in the router is as small as possible.

Alternatively, you may be able to parse the controller using get_class_methods if you can figure out how to load the controller into memory inside the router without conflicting when you need to load the controller using the router or causing too much performance issues.

Pretty goofy, but every method you create in that controller will automatically create a route.


问:
Coding Standard Wiki
At my place of work I've been put in charge of creating a coding standards document. Generally we follow what FxCop and StyleCop tools report to some degree but what we really require is document that will explain when to use a convention, why and maybe even a simple example.

This could be extended in the future for other purposes as well.

The first thing that came to my mind is to have an internal wiki site that we could build up and change easily over time but I've never used a wiki-based engine before and would like some recommendations.

If possible the engine should be in C# so we're able to tweak it to our needs if required.

If you think a wiki solution is the wrong way to go about this then please give an alternative :)

Update

I've just been informed, although we do have a php server it wont be staying, so I'm afraid php-based wiki ideas are off the table.

Update 2

Could you also (if possible) let me know if any of these solutions work with Active Directory?

Cheers
Tony

答:
In one project that I develop, I set up one MediaWiki wiki for development documentation, and one for online help.

I even generate part of the development documentation right from source code and database.

ContentLicense: CC BY-SA 2.5

Title: Coding Standard Wiki

OwnerDisplayName: devio


问:
Best way to handle dynamic css in a rails app
I'm researching a problem for handling dynamic css in a rails app.  Within the app, individual users and/or groups of users can have customized look and feel that is accomplished via CSS.  There will not be any fixed number of "look and feels" or css files, the number will grow as the number of users and groups grows and the look and feel is defined by the users via the  application's admin interface.  Throughout the course of a typical day thousands (it not tens of thousands) of different variations of the css will be served up.  The app will store the pre-built css in mongodb, so there it will not have to pay the price of constructing the css for every request, the question is more about how is the best way to serve up this dynamic css content.  I've seen other questions like [this one][1] that speak to using erb or sass, but some of these answers are dated by several years so I wanted to make sure there wasn't a better answer with Rails 3.</p>

答: This might give you a few ideas: Multiple robots.txt for subdomains in rails</p>


问:
Joining two tables where id does not equal
I'm struggling getting this query to produce the results I want.

I have:

table1, columns=empid, alt_id

table2, columns=empid, alt_id

I want to get the empid, and alt_id from table 1 where the alt_id does not match the alt_id in table2. They will both have alt_id numbers I just want to get the ones that do not match.

Any ideas?

答:
You seem to want not exists:

```<code>select t1.*
from table1 t1
where not exists (select 1 from table2 t2 where t2.alt_id = t1.alt_id);
</code>```

It is unclear whether or not you also want to join on empid, so you might really want:

```<code>select t1.*
from table1 t1
where not exists (select 1 from table2 t2 where t2.alt_id = t1.alt_id and t2.empid = t1.empid);
</code>```

Body:
You seem to want not exists:

select t1.*
from table1 t1
where not exists (select 1 from table2 t2 where t2.alt_id = t1.alt_id);

It is unclear whether or not you also want to join on empid, so you might really want:

select t1.*
from table1 t1
where not exists (select 1 from table2 t2 where t2.alt_id = t1.alt_id and t2.empid = t1.empid);


问:
How to represent empty char in Java Character class
I want to represent an empty character in Java as  "" in String...

Like that char ch = an empty character;

Actually I want to replace a character without leaving space.

I think it might be sufficient to understand what this means: no character not even space.

答:
As chars can be represented as Integers (ASCII-Codes), you can simply write:

```<code>char c = 0;
</code>```

The 0 in ASCII-Code is null.

Body:
As chars can be represented as Integers (ASCII-Codes), you can simply write:

char c = 0;

The 0 in ASCII-Code is null.


问:
Can't set title for terminal window when launched from Gnome menu launcher
I added a new Gnome menu option to launch a custom script application. I am using Redhat 6, Gnome 2. This is all working but when it launches in a new terminal window I cannot get the title to display anything other than the default 'Terminal'.

Here's how I have it configured; I have added the following files to get it working:

/usr/shared/applications/app.desktop ( configures launching of my application )

/usr/shared/desktop-directories/app.directory (specify a directory from menu for my app)

/etc/xdg/menu/application-merged/app.menu ( adds menu option to main Applications pull down menu)

The app.desktop file specifies the location of the script I want to run and I have set the 'Terminal' option to 'True' which launches it in a new terminal window. I have tried adding the following to during startup of the script but it doesn't change the title.

```<code>PROMPT_COMMAND='echo -ne "\033]0; APP TITLE\007"'
</code>```

Setting the 'PROMPT_COMMAND' from a separate, interactive terminal DOES work though. Not sure why it doesn't work when launching from the gnome application launcher.

答:
As far as I know, you can't really set the terminal window title I have tried everything even modifying files but to no avail. The method which your using is meant to be put in the .bashrc in the home folder but doesn't seem to work.

```<code>gnome-terminal --title="example"
</code>```

The command above which I have tried doesn't work either

Body:
I added a new Gnome menu option to launch a custom script application. I am using Redhat 6, Gnome 2. This is all working but when it launches in a new terminal window I cannot get the title to display anything other than the default 'Terminal'.

Here's how I have it configured; I have added the following files to get it working:

/usr/shared/applications/app.desktop ( configures launching of my application )

/usr/shared/desktop-directories/app.directory (specify a directory from menu for my app)

/etc/xdg/menu/application-merged/app.menu ( adds menu option to main Applications pull down menu)

The app.desktop file specifies the location of the script I want to run and I have set the 'Terminal' option to 'True' which launches it in a new terminal window. I have tried adding the following to during startup of the script but it doesn't change the title.

PROMPT_COMMAND='echo -ne "\033]0; APP TITLE\007"'

Setting the 'PROMPT_COMMAND' from a separate, interactive terminal DOES work though. Not sure why it doesn't work when launching from the gnome application launcher.

Body:
As far as I know, you can't really set the terminal window title I have tried everything even modifying files but to no avail. The method which your using is meant to be put in the .bashrc in the home folder but doesn't seem to work.

gnome-terminal --title="example"

The command above which I have tried doesn't work either


问:
Making a new list with tuples based on strings in the list
```<code>L = ["5", "0 1", "0 2", "1 3", "2 3", "2 4", "3 4"]
</code>```

Each number represents a person. So, there are five people from 0 to 4 in the list. L[0] always shows how many people are in the list.

```<code>L1 = [(0,[1,2]), (1, [3]), (2, [3,4]), (3, [4])]
</code>```

The person "0" is paired with 1 and 2. So, it has a list of 1, 2 in a tuple. My approach to get the result above is to compare the first character in L[1] to the end of the list. If the first letter in L[1] matches with the first letter in L[2], it bundles the second letter in L[2] with the second letter in L[1]. Finally, the new list is paired with 0 in a tuple. By the way, I cannot come up with such thing that can check the first letter in strings. I am not sure if this approach is right or not.

I am struggling to make such list L1 above. Could anyone let me know if my approach to this question is right? If it is wrong, please briefly give me a hint to solve this.

答:
Using list comprehension

Created a list in the required range, considering L[0]

Checks for matches between the element and the other items using startswith

```<code>L = ["5", "0 1", "0 2", "1 3", "2 3", "2 4", "3 4"]
L1 = [(0,[1,2]), (1, [3]), (2, [3,4]), (3, [4])]     # required list

L2 = [ (i, [ int(x[-1]) for x in L if str(x).startswith(str(i)) ]) for i in range(int(L[0])-1) ]
</code>```

Output

```<code>[(0, [1, 2]), (1, [3]), (2, [3, 4]), (3, [4])]
[(0, [1, 2]), (1, [3]), (2, [3, 4]), (3, [4])]
</code>```

Body:
L = ["5", "0 1", "0 2", "1 3", "2 3", "2 4", "3 4"]

Each number represents a person. So, there are five people from 0 to 4 in the list. L[0] always shows how many people are in the list.

L1 = [(0,[1,2]), (1, [3]), (2, [3,4]), (3, [4])]

The person "0" is paired with 1 and 2. So, it has a list of 1, 2 in a tuple. My approach to get the result above is to compare the first character in L[1] to the end of the list. If the first letter in L[1] matches with the first letter in L[2], it bundles the second letter in L[2] with the second letter in L[1]. Finally, the new list is paired with 0 in a tuple. By the way, I cannot come up with such thing that can check the first letter in strings. I am not sure if this approach is right or not.

I am struggling to make such list L1 above. Could anyone let me know if my approach to this question is right? If it is wrong, please briefly give me a hint to solve this.

Body:
Using list comprehension

Created a list in the required range, considering L[0]

Checks for matches between the element and the other items using startswith

L = ["5", "0 1", "0 2", "1 3", "2 3", "2 4", "3 4"]
L1 = [(0,[1,2]), (1, [3]), (2, [3,4]), (3, [4])]     # required list

L2 = [ (i, [ int(x[-1]) for x in L if str(x).startswith(str(i)) ]) for i in range(int(L[0])-1) ]

Output

[(0, [1, 2]), (1, [3]), (2, [3, 4]), (3, [4])]
[(0, [1, 2]), (1, [3]), (2, [3, 4]), (3, [4])]


问:
read and write files open() read()
i need  to make a program that read a file(arg[1]) and show it content but, with a specific number of bytes[arg2]. If no bytes are specified whole file will be printed.

```<code>void read(char *arg[]){
        int fh;
        char buffer[100];
        int rd;

        fh = open(arg[1],O_RDONLY);
        printf ("Printing %s\n",arg[1]);
        while (rd = read(fh,buffer,100)) {
                buffer[rd] = '\0';
                printf("%s",buffer);
                }
        }
</code>```

I need to use open(),read() at least.
Can someone help me?

答:
There are few observation about the program which you wrote,

void read(char *arg[])  here from main() function you are just passing the file name then whats the need of catching file name with array of char pointer, catching with single char pointer is sufficient. So modify it like void read(char *arg)

```<code>   `fh = open(arg[1],O_RDONLY);` open() is system call, whether its able to open the file or not,catch the return value & try to print error message using `perror().` So modify its like
</code>```

fh = open(arg[1],O_RDONLY);
if(fh == -1) // try to read man page first.
{
perror("open");
return ;
}

```<code>      `while (rd = read(fh,buffer,100)) { //some code }` why rotating loop ? you can read entire data of file at a time, for that use `stat()` system call and find the size of file and then create dynamic array equivalent to file size and then read whole/particular data using `read()` system call.
</code>```

So first go through man pages of open(), read(), stat() system calls.

Here is my solution for your requirements with explaination

```<code>#include <stdio.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

void my_read(char *arg1){
        int fh;
        //  char buffer[100];//don't use static array bcz we don't know how much data is there in file, create it dynamically
        int rd,n;

        fh = open(arg1,O_RDONLY);
        if(fh == -1)
        {
                perror("open");
                return;
        }
        else
        {
                //first find the size of file .. use stat() system call
                struct stat v;
                stat(arg1,&v);//storing all file related information into v
                int size = v.st_size;//st.szie is a member of stat structure and it holds size of file
                //create dynamic array equal to file size
                char *p = malloc(size * sizeof(char));

                printf("enter no of bytes you want to read :\n");
                scanf("%d",&n);

                if(n==0)
                {
                        //read data from file and copy into dynamic array and print
                        int ret = read(fh,p,size);
                        if(ret == -1)
                        {
                                perror("read");
                                return ;
                        }
                        else
                        {
                                printf("data readed from file is :\n");
                                printf("%s\n",p);
                        }

                }
                else
                {
                        //read data from file and copy into dynamic array and print
                        int ret = read(fh,p,n);
                        if(ret == -1)
                        {
                                perror("read");
                                return ;
                        }
                        else
                        {
                                printf("data readed from file is :\n");
                                printf("%s\n",p);
                        }
                }

         if (close(fh) < 0)
         {
             perror("c1");
             return;
         }
}
int main(int argc,char *argv[])
{
        char f_name[100];
        printf("enter the file name :\n");
        scanf("%s",f_name);
        my_read(f_name);
}

</code>```

Title: read and write files open() read()

Body:
i need  to make a program that read a file(arg[1]) and show it content but, with a specific number of bytes[arg2]. If no bytes are specified whole file will be printed.

void read(char *arg[]){
        int fh;
        char buffer[100];
        int rd;

        fh = open(arg[1],O_RDONLY);
        printf ("Printing %s\n",arg[1]);
        while (rd = read(fh,buffer,100)) {
                buffer[rd] = '\0';
                printf("%s",buffer);
                }
        }

I need to use open(),read() at least.
Can someone help me?

Body:
There are few observation about the program which you wrote,

void read(char *arg[])  here from main() function you are just passing the file name then whats the need of catching file name with array of char pointer, catching with single char pointer is sufficient. So modify it like void read(char *arg)

   `fh = open(arg[1],O_RDONLY);` open() is system call, whether its able to open the file or not,catch the return value & try to print error message using `perror().` So modify its like

fh = open(arg[1],O_RDONLY);
if(fh == -1) // try to read man page first.
{
perror("open");
return ;
}

      `while (rd = read(fh,buffer,100)) { //some code }` why rotating loop ? you can read entire data of file at a time, for that use `stat()` system call and find the size of file and then create dynamic array equivalent to file size and then read whole/particular data using `read()` system call.

So first go through man pages of open(), read(), stat() system calls.

Here is my solution for your requirements with explaination

#include <stdio.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

void my_read(char *arg1){
        int fh;
        //  char buffer[100];//don't use static array bcz we don't know how much data is there in file, create it dynamically
        int rd,n;

        fh = open(arg1,O_RDONLY);
        if(fh == -1)
        {
                perror("open");
                return;
        }
        else
        {
                //first find the size of file .. use stat() system call
                struct stat v;
                stat(arg1,&v);//storing all file related information into v
                int size = v.st_size;//st.szie is a member of stat structure and it holds size of file
                //create dynamic array equal to file size
                char *p = malloc(size * sizeof(char));

                printf("enter no of bytes you want to read :\n");
                scanf("%d",&n);

                if(n==0)
                {
                        //read data from file and copy into dynamic array and print
                        int ret = read(fh,p,size);
                        if(ret == -1)
                        {
                                perror("read");
                                return ;
                        }
                        else
                        {
                                printf("data readed from file is :\n");
                                printf("%s\n",p);
                        }

                }
                else
                {
                        //read data from file and copy into dynamic array and print
                        int ret = read(fh,p,n);
                        if(ret == -1)
                        {
                                perror("read");
                                return ;
                        }
                        else
                        {
                                printf("data readed from file is :\n");
                                printf("%s\n",p);
                        }
                }

         if (close(fh) < 0)
         {
             perror("c1");
             return;
         }
}
int main(int argc,char *argv[])
{
        char f_name[100];
        printf("enter the file name :\n");
        scanf("%s",f_name);
        my_read(f_name);
}


问:
How is P0522R0 breaking code?
Today I was reading the C++17 support page of clang. I've notice something odd. The feature Matching template template parameters to compatible arguments (P0522R0) is marked as partial, because it must be activate through a switch. Their note says:

Despite being the the resolution to a Defect Report, this feature is disabled by default in all language versions, and can be enabled explicitly with the flag -frelaxed-template-template-args in Clang 4. The change to the standard lacks a corresponding change for template partial ordering, resulting in ambiguity errors for reasonable and previously-valid code. This issue is expected to be rectified soon.

What kind of constructs breaks when this feature is activated? Why can it break code and how?

答:
You can have code like this:

```<code>template<template<typename> typename>
struct Foo {};

template<typename, typename = void>
struct Bar {};

Foo<Bar> unused;
</code>```

Without the defect resolution, unused would be ill-formed, because foo takes a template with only one template parameter, and not two. If you relied on this (maybe for SFINAE):

```<code>template<template<typename> typename>
void foo();

template<template<typename, typename> typename>
void foo();

template<typename, typename = void>
struct Bar {};

int main() {
    foo<Bar>(); // ambiguous after resolution!
}
</code>```

Then the call would fail! The problem is that there was no corresponding change to partial ordering, and so both candidate functions have the same viability, and the call is ambiguous.

Title: How is P0522R0 breaking code?

Body:
You can have code like this:

template<template<typename> typename>
struct Foo {};

template<typename, typename = void>
struct Bar {};

Foo<Bar> unused;

Without the defect resolution, unused would be ill-formed, because foo takes a template with only one template parameter, and not two. If you relied on this (maybe for SFINAE):

template<template<typename> typename>
void foo();

template<template<typename, typename> typename>
void foo();

template<typename, typename = void>
struct Bar {};

int main() {
    foo<Bar>(); // ambiguous after resolution!
}

Then the call would fail! The problem is that there was no corresponding change to partial ordering, and so both candidate functions have the same viability, and the call is ambiguous.


问:
how solve merge dex?
i have this error when i try to run my android app

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
  java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

i tried to clean project and rebuild project and tried to remove project but the same error don't solve
  gradle

```<code>apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.lef.planeeye"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.google.android.gms:play-services:11.6.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.android.gms:play-services-location:11.6.0'
    compile 'com.google.android.gms:play-services-maps:11.6.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.google.firebase:firebase-core:11.6.0'
    compile 'com.google.firebase:firebase-messaging:11.6.0'
    compile 'com.firebase:firebase-client-android:2.5.2'
    compile 'com.firebaseui:firebase-ui:0.2.0'
}
</code>```

答:
Before you start adding multi dex and changing your application to a multidexapplication. Consider minimizing your dependencies to the dependencies you need. You are importing the entire google play services.

Consider only including the ones you need or you will defintely exceed the 65,536 method limitation which will make you compile slower and have to adjust your gradle properties to speed things up with more memory.

If you must do multi-dex then update your application extends MultiDexApplication as well as your gradle properties to increase memory, but hopefully you don't have to do that.

Try to fix the problem properly before you patch it ;).

However, if it is not a multi-dex issue, it could be an issue dexing repeat dependencies of different versions. Possibly your google play service. I would run assembleRelease --info and get more info.

In the meantime, try forcing the play lib version all the way through in your manifest with this exact line

```<code> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"
        tools:replace="android:value" />
</code>```

inside the application tag

Title: how solve merge dex?

Body:
i have this error when i try to run my android app

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
  java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

i tried to clean project and rebuild project and tried to remove project but the same error don't solve
  gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.lef.planeeye"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.google.android.gms:play-services:11.6.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.android.gms:play-services-location:11.6.0'
    compile 'com.google.android.gms:play-services-maps:11.6.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.google.firebase:firebase-core:11.6.0'
    compile 'com.google.firebase:firebase-messaging:11.6.0'
    compile 'com.firebase:firebase-client-android:2.5.2'
    compile 'com.firebaseui:firebase-ui:0.2.0'
}

Body:
Before you start adding multi dex and changing your application to a multidexapplication. Consider minimizing your dependencies to the dependencies you need. You are importing the entire google play services.

Consider only including the ones you need or you will defintely exceed the 65,536 method limitation which will make you compile slower and have to adjust your gradle properties to speed things up with more memory.

If you must do multi-dex then update your application extends MultiDexApplication as well as your gradle properties to increase memory, but hopefully you don't have to do that.

Try to fix the problem properly before you patch it ;).

However, if it is not a multi-dex issue, it could be an issue dexing repeat dependencies of different versions. Possibly your google play service. I would run assembleRelease --info and get more info.

In the meantime, try forcing the play lib version all the way through in your manifest with this exact line

 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"
        tools:replace="android:value" />

inside the application tag