问:
FFMPEG failed to transcode mp4 Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Hi I tried using ffmpeg to convert a video with Drupal, however it fails on second pass. I get the following error: Any ideas?
I installed the default ffmppeg and libavcodec-extra-53 packages on Ubuntu.</p>

```<code> FFmpeg failed to transcode video.mp4.
    Reported errors

    PHPVideoToolkit error: Execute error. It was not possible to encode "/var/www/html/lms2/sites/default/files/videos/original/video.mp4"
as FFmpeg returned an error. Note, however the error was encountered
on the second pass of the encoding process and the first pass appear to
go fine. The error is with the video codec of the input file. FFmpeg
reports the error to be "Error while opening encoder for output
stream #0:0 - maybe incorrect parameters such as bit_rate, rate,
width or height".
    Executed commands and output

    /usr/bin/ffmpeg -i '/var/www/html/lms2/sites/default/files/videos/original/video.mp4' -vf 'scale=640:360' -strict experimental -vcodec 'h264' -qscale '12' -acodec 'aac' -ac '2' -pass '1' -passlogfile '/tmp/1499411044-595f326449e44-multipass'  -y /tmp/1499411044-595f326449d86.mp4
    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
      WARNING: library configuration mismatch
      avcodec     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 --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc --enable-libvo_amrwbenc
      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
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/lms2/sites/default/files/videos/original/video.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        creation_time   : 2017-04-28 15:24:27
      Duration: 00:08:21.18, start: 0.000000, bitrate: 443 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 314 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
    Please use -q:a or -q:v, -qscale is ambiguous
    [libx264 @ 0x1c89940] -qscale is ignored, -crf is recommended.
    [libx264 @ 0x1c89940] using SAR=1/1
    [libx264 @ 0x1c89940] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
    [libx264 @ 0x1c89940] profile Main, level 3.0
    [libx264 @ 0x1c89940] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0 me=dia subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=1 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=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 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, mp4, to '/tmp/1499411044-595f326449d86.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        encoder         : Lavf56.40.101
        Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, pass 1, 25 fps, 12800 tbn, 25 tbc (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 libx264
        Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 aac
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
      Stream #0:1 -> #0:1 (aac (native) -> aac (native))
    Press [q] to stop, [?] for help
    frame=   79 fps=0.0 q=28.0 size=      64kB time=00:00:02.87 bitrate= 181.6kbits/s
    frame=  155 fps=154 q=28.0 size=     156kB time=00:00:05.75 bitrate= 222.2kbits/s
    frame=  237 fps=158 q=28.0 size=     239kB time=00:00:09.00 bitrate= 217.6kbits/s
    frame=  315 fps=157 q=28.0 size=     339kB time=00:00:12.23 bitrate= 226.9kbits/s
    frame=  399 fps=159 q=28.0 size=     409kB time=00:00:15.48 bitrate= 216.4kbits/s
    frame=  467 fps=155 q=28.0 size=     516kB time=00:00:18.27 bitrate= 231.2kbits/s
    frame=  530 fps=151 q=28.0 size=     689kB time=00:00:21.06 bitrate= 268.1kbits/s
    frame=  606 fps=151 q=28.0 size=     786kB time=00:00:23.84 bitrate= 270.2kbits/s
    frame=  686 fps=152 q=28.0 size=     853kB time=00:00:27.09 bitrate= 257.8kbits/s
    frame=  765 fps=152 q=28.0 size=     942kB time=00:00:30.34 bitrate= 254.4kbits/s
    frame=  847 fps=153 q=28.0 size=    1041kB time=00:00:33.59 bitrate= 253.8kbits/s
    frame=  925 fps=153 q=28.0 size=    1103kB time=00:00:36.85 bitrate= 245.2kbits/s
    frame= 1003 fps=153 q=28.0 size=    1202kB time=00:00:39.63 bitrate= 248.3kbits/s
    frame= 1076 fps=153 q=28.0 size=    1267kB time=00:00:42.88 bitrate= 242.0kbits/s
    frame= 1153 fps=153 q=28.0 size=    1334kB time=00:00:45.67 bitrate=
    frame= 6790 fps=155 q=28.0 size=    6278kB time=00:04:31.37 bitrate= 189.5kbits/s
    frame= 6850 fps=155 q=28.0 size=    6284kB time=00:04:33.69 bitrate= 188.1kbits/s
    frame= 6909 fps=154 q=28.0 size=    6299kB time=00:04:36.01 bitrate= 186.9kbits/s
    frame= 6964 fps=154 q=28.0 size=    6324kB time=00:04:38.33 bitrate= 186.1kbits/s
    frame= 7023 fps=154 q=28.0 size=    6340kB time=00:04:40.65 bitrate= 185.1kbits/s
    frame= 7078 fps=153 q=28.0 size=    6345kB time=00:04:42.98 bitrate= 183.7kbits/s
    frame= 7132 fps=153 q=28.0 size=    6350kB time=00:04:44.83 bitrate= 182.6kbits/s
    frame= 7182 fps=152 q=28.0 size=    6383kB time=00:04:47.16 bitrate= 182.1kbits/s
    frame= 7239 fps=152 q=28.0 size=    6444kB time=00:04:49.15 bitrate= 182.6kbits/s
    frame= 7295 fps=151 q=28.0 size=    6469kB time=00:04:51.52 bitrate= 181.8kbits/s
    frame= 7355 fps=151 q=28.0 size=    6481kB time=00:04:53.66 bitrate= 180.8kbits/s
    frame= 7408 fps=150 q=28.0 size=    6489kB time=00:04:55.98 bitrate= 179.6kbits/s
    frame= 7459 fps=150 q=28.0 size=    6526kB time=00:04:58.21 bitrate= 179.3kbits/s
    frame= 7517 fps=150 q=28.0 size=    6533kB time=00:05:00.51 bitrate= 178.1kbits/s
    frame= 7574 fps=149 q=28.0 size=    6540kB time=00:05:02.88 bitrate= 176.9kbits/s
    frame= 7634 fps=149 q=28.0 size=    6546kB time=00:05:05.06 bitrate= 175.8kbits/s
    frame= 7679 fps=148 q=28.0 size=    6550kB time=00:05:06.92 bitrate= 174.8kbits/s
    frame= 8364 fps=145 q=28.0 size=    6754kB time=00:05:34.43 bitrate= 165.4kbits/s
    frame= 8425 fps=145 q=28.0 size=    6757kB time=00:05:36.85 bitrate= 164.3kbits/s
    frame= 9020 fps=142 q=28.0 size=    6856kB time=00:06:00.53 bitrate= 155.8kbits/s
    frame= 9085 fps=142 q=28.0 size=    6858kB time=00:06:02.85 bitrate= 154.8kbits/s
    frame= 9142 fps=142 q=28.0 size=    6860kB time=00:06:05.38 bitrate= 153.8kbits/s
    frame= 9200 fps=142 q=28.0 size=    6886kB time=00:06:07.80 bitrate= 153.4kbits/s
    frame= 9259 fps=142 q=28.0 size=    6888kB time=00:06:10.24 bitrate= 152.4kbits/s
    frame= 9318 fps=142 q=28.0 size=    6894kB time=00:06:12.61 bitrate= 151.6kbits/s
    frame= 9375 fps=141 q=28.0 size=    6916kB time=00:06:14.93 bitrate= 151.1kbits/s
    frame= 9438 fps=141 q=25.0 size=    6944kB time=00:06:17.25 bitrate= 150.8kbits/s
    frame= 9499 fps=141 q=28.0 size=    6947kB time=00:06:19.57 bitrate= 149.9kbits/s
    frame= 9561 fps=141 q=28.0 size=    6950kB time=00:06:22.01 bitrate= 149.0kbits/s
    frame= 9618 fps=141 q=28.0 size=    6955kB time=00:06:24.63 bitrate= 143.6kbits/s
    frame=10145 fps=139 q=28.0 size=    7080kB time=00:06:45.58 bitrate= 143.0kbits/s
    frame=10202 fps=139 q=28.0 size=    7105kB time=00:06:47.90 bitrate= 142.7kbits/s
    frame=10257 fps=139 q=28.0 size=    7124kB time=00:06:50.20 bitrate= 142.3kbits/s
    frame=10315 fps=139 q=28.0 size=    7143kB time=00:06:52.52 bitrate= 141.8kbits/s
    frame=10373 fps=139 q=28.0 size=    7145kB time=00:06:54.87 bitrate= 141.1kbits/s
    frame=10432 fps=138 q=28.0 size=    7174kB time=00:06:57.03 bitrate= 140.9kbits/s
    frame=10489 fps=138 q=28.0 size=    7180kB time=00:06:59.35 bitrate= 140.3kbits/s
    frame=10547 fps=138 q=28.0 size=    7199kB time=00:07:01.55 bitrate= 139.9kbits/s
    frame=10605 fps=138 q=28.0 size=    7215kB time=00:07:03.85 bitrate= 139.5kbits/s
    frame=10661 fps=138 q=28.0 size=    7223kB time=00:07:06.01 bitrate= 138.9kbits/s
    frame=10713 fps=138 q=28.0 size=    7277kB time=00:07:08.33 bitrate= 139.2kbits/s
    frame=10769 fps=137 q=28.0 size=    7303kB time=00:07:10.66 bitrate= 138.9kbits/s
    frame=10829 fps=137 q=28.0 size=    7309kB time=00:07:12.98 bitrate= 138.3kbits/s
    frame=10884 fps=137 q=28.0 size=    7329kB time=00:07:15.14 bitrate= 138.0kbits/s
    frame=10941 fps=137 q=28.0 size=    7355kB time=00:07:17.39 bitrate= 137.7kbits/s
    frame=11000 fps=137 q=28.0 size=    7360kB time=00:07:19.48 bitrate= 137.2kbits/s
    frame=11047 fps=137 q=28.0 size=    7407kB time=00:07:21.80 bitrate= 137.3kbits/s
    frame=11105 fps=136 q=28.0 size=    7423kB time=00:07:23.66 bitrate= 137.1kbits/s
    frame=11150 fps=136 q=28.0 size=    7472kB time=00:07:25.91 bitrate= 137.3kbits/s
    frame=11208 fps=136 q=28.0 size=    7541kB time=00:07:27.84 bitrate= 137.9kbits/s
    frame=11264 fps=136 q=28.0 size=    7553kB time=00:07:30.16 bitrate= 137.4kbits/s
    frame=11314 fps=136 q=28.0 size=    7589kB time=00:07:32.02 bitrate= 137.5kbits/s
    frame=11359 fps=135 q=28.0 size=    7635kB time=00:07:34.34 bitrate= 137.7kbits/s
    frame=11415 fps=135 q=28.0 size=    7698kB time=00:07:36.20 bitrate= 138.2kbits/s
    frame=11469 fps=135 q=28.0 size=    7740kB time=00:07:38.52 bitrate= 138.3kbits/s
    frame=11526 fps=135 q=28.0 size=    7752kB time=00:07:40.84 bitrate= 137.8kbits/s
    frame=11585 fps=135 q=28.0 size=    7755kB time=00:07:43.16 bitrate= 137.2kbits/s
    frame=11638 fps=135 q=28.0 size=    7791kB time=00:07:45.28 bitrate= 137.2kbits/s
    frame=12371 fps=133 q=28.0 size=    8045kB time=00:08:14.60 bitrate= 133.2kbits/s
    frame=12426 fps=133 q=28.0 size=    8068kB time=00:08:16.60 bitrate= 133.1kbits/s
    frame=12475 fps=133 q=25.0 size=    8113kB time=00:08:18.88 bitrate= 133.2kbits/s
    frame=12528 fps=133 q=28.0 size=    8135kB time=00:08:21.01 bitrate= 133.0kbits/s
    frame=12529 fps=133 q=28.0 Lsize=    8549kB time=00:08:21.17 bitrate= 139.7kbits/s
    video:3859kB audio:4279kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.047608%
    [libx264 @ 0x1c89940] frame I:52    Avg QP:14.60  size: 25036
    [libx264 @ 0x1c89940] frame P:3390  Avg QP:16.73  size:   657
    [libx264 @ 0x1c89940] frame B:9087  Avg QP:16.09  size:    47
    [libx264 @ 0x1c89940] consecutive B-frames:  3.0%  0.7%  0.8% 95.5%
    [libx264 @ 0x1c89940] mb I  I16..4: 53.8%  0.0% 46.2%
    [libx264 @ 0x1c89940] mb P  I16..4:  2.6%  0.0%  0.0%  P16..4:  2.9%  0.0%  0.0%  0.0%  0.0%    skip:94.5%
    [libx264 @ 0x1c89940] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.5%  0.0%  0.0%  direct: 0.1%  skip:99.3%  L0:44.8% L1:51.9% BI: 3.3%
    [libx264 @ 0x1c89940] coded y,uvDC,uvAC intra: 40.1% 21.9% 16.0% inter: 0.4% 0.4% 0.1%
    [libx264 @ 0x1c89940] i16 v,h,dc,p: 42% 53%  3%  1%
    [libx264 @ 0x1c89940] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 45% 11%  5%  3%  2%  4%  2%  5%
    [libx264 @ 0x1c89940] i8c dc,h,v,p: 68% 25%  6%  1%
    [libx264 @ 0x1c89940] Weighted P-Frames: Y:0.4% UV:0.3%
    [libx264 @ 0x1c89940] kb/s:63.07
    /usr/bin/ffmpeg -i '/var/www/html/lms2/sites/default/files/videos/original/video.mp4' -vf 'scale=640:360' -strict experimental -vcodec 'h264' -qscale '12' -acodec 'aac' -ac '2' -pass '2' -passlogfile '/tmp/1499411044-595f326449e44-multipass'  -y /tmp/1499411044-595f326449d86.mp4
    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
      WARNING: library configuration mismatch
      avcodec     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 --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc --enable-libvo_amrwbenc
      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
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/lms2/sites/default/files/videos/original/video.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        creation_time   : 2017-04-28 15:24:27
      Duration: 00:08:21.18, start: 0.000000, bitrate: 443 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 314 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
    Please use -q:a or -q:v, -qscale is ambiguous
    [libx264 @ 0x1c2b940] -qscale is ignored, -crf is recommended.
    [libx264 @ 0x1c2b940] using SAR=1/1
    [libx264 @ 0x1c2b940] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
    [libx264 @ 0x1c2b940] constant rate-factor is incompatible with 2pass.
    Output #0, mp4, to '/tmp/1499411044-595f326449d86.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        Stream #0:0(und): Video: h264, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 25 fps (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 libx264
        Stream #0:1(und): Audio: aac, 0 channels, 128 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 aac
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
      Stream #0:1 -> #0:1 (aac (native) -> aac (native))
    Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
</code>```

答:
qscale is ignored by libx264, so it defaults to CRF mode, except as the message in the log says, constant rate-factor is incompatible with 2pass.

Remove -qscale 12 and add -b:v 1000k or whatever your required bitrate is.

If you don't have a number in mind, remove -qscale 12, add -crf 25 and skip the second pass. Experiment with the CRF value for better quality or smaller files.

Body:
Hi I tried using ffmpeg to convert a video with Drupal, however it fails on second pass. I get the following error: Any ideas?
I installed the default ffmppeg and libavcodec-extra-53 packages on Ubuntu.

 FFmpeg failed to transcode video.mp4.
    Reported errors

    PHPVideoToolkit error: Execute error. It was not possible to encode "/var/www/html/lms2/sites/default/files/videos/original/video.mp4"
as FFmpeg returned an error. Note, however the error was encountered
on the second pass of the encoding process and the first pass appear to
go fine. The error is with the video codec of the input file. FFmpeg
reports the error to be "Error while opening encoder for output
stream #0:0 - maybe incorrect parameters such as bit_rate, rate,
width or height".
    Executed commands and output

    /usr/bin/ffmpeg -i '/var/www/html/lms2/sites/default/files/videos/original/video.mp4' -vf 'scale=640:360' -strict experimental -vcodec 'h264' -qscale '12' -acodec 'aac' -ac '2' -pass '1' -passlogfile '/tmp/1499411044-595f326449e44-multipass'  -y /tmp/1499411044-595f326449d86.mp4
    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
      WARNING: library configuration mismatch
      avcodec     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 --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc --enable-libvo_amrwbenc
      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
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/lms2/sites/default/files/videos/original/video.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        creation_time   : 2017-04-28 15:24:27
      Duration: 00:08:21.18, start: 0.000000, bitrate: 443 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 314 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
    Please use -q:a or -q:v, -qscale is ambiguous
    [libx264 @ 0x1c89940] -qscale is ignored, -crf is recommended.
    [libx264 @ 0x1c89940] using SAR=1/1
    [libx264 @ 0x1c89940] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
    [libx264 @ 0x1c89940] profile Main, level 3.0
    [libx264 @ 0x1c89940] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0 me=dia subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=1 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=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 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, mp4, to '/tmp/1499411044-595f326449d86.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        encoder         : Lavf56.40.101
        Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, pass 1, 25 fps, 12800 tbn, 25 tbc (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 libx264
        Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 aac
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
      Stream #0:1 -> #0:1 (aac (native) -> aac (native))
    Press [q] to stop, [?] for help
    frame=   79 fps=0.0 q=28.0 size=      64kB time=00:00:02.87 bitrate= 181.6kbits/s
    frame=  155 fps=154 q=28.0 size=     156kB time=00:00:05.75 bitrate= 222.2kbits/s
    frame=  237 fps=158 q=28.0 size=     239kB time=00:00:09.00 bitrate= 217.6kbits/s
    frame=  315 fps=157 q=28.0 size=     339kB time=00:00:12.23 bitrate= 226.9kbits/s
    frame=  399 fps=159 q=28.0 size=     409kB time=00:00:15.48 bitrate= 216.4kbits/s
    frame=  467 fps=155 q=28.0 size=     516kB time=00:00:18.27 bitrate= 231.2kbits/s
    frame=  530 fps=151 q=28.0 size=     689kB time=00:00:21.06 bitrate= 268.1kbits/s
    frame=  606 fps=151 q=28.0 size=     786kB time=00:00:23.84 bitrate= 270.2kbits/s
    frame=  686 fps=152 q=28.0 size=     853kB time=00:00:27.09 bitrate= 257.8kbits/s
    frame=  765 fps=152 q=28.0 size=     942kB time=00:00:30.34 bitrate= 254.4kbits/s
    frame=  847 fps=153 q=28.0 size=    1041kB time=00:00:33.59 bitrate= 253.8kbits/s
    frame=  925 fps=153 q=28.0 size=    1103kB time=00:00:36.85 bitrate= 245.2kbits/s
    frame= 1003 fps=153 q=28.0 size=    1202kB time=00:00:39.63 bitrate= 248.3kbits/s
    frame= 1076 fps=153 q=28.0 size=    1267kB time=00:00:42.88 bitrate= 242.0kbits/s
    frame= 1153 fps=153 q=28.0 size=    1334kB time=00:00:45.67 bitrate=
    frame= 6790 fps=155 q=28.0 size=    6278kB time=00:04:31.37 bitrate= 189.5kbits/s
    frame= 6850 fps=155 q=28.0 size=    6284kB time=00:04:33.69 bitrate= 188.1kbits/s
    frame= 6909 fps=154 q=28.0 size=    6299kB time=00:04:36.01 bitrate= 186.9kbits/s
    frame= 6964 fps=154 q=28.0 size=    6324kB time=00:04:38.33 bitrate= 186.1kbits/s
    frame= 7023 fps=154 q=28.0 size=    6340kB time=00:04:40.65 bitrate= 185.1kbits/s
    frame= 7078 fps=153 q=28.0 size=    6345kB time=00:04:42.98 bitrate= 183.7kbits/s
    frame= 7132 fps=153 q=28.0 size=    6350kB time=00:04:44.83 bitrate= 182.6kbits/s
    frame= 7182 fps=152 q=28.0 size=    6383kB time=00:04:47.16 bitrate= 182.1kbits/s
    frame= 7239 fps=152 q=28.0 size=    6444kB time=00:04:49.15 bitrate= 182.6kbits/s
    frame= 7295 fps=151 q=28.0 size=    6469kB time=00:04:51.52 bitrate= 181.8kbits/s
    frame= 7355 fps=151 q=28.0 size=    6481kB time=00:04:53.66 bitrate= 180.8kbits/s
    frame= 7408 fps=150 q=28.0 size=    6489kB time=00:04:55.98 bitrate= 179.6kbits/s
    frame= 7459 fps=150 q=28.0 size=    6526kB time=00:04:58.21 bitrate= 179.3kbits/s
    frame= 7517 fps=150 q=28.0 size=    6533kB time=00:05:00.51 bitrate= 178.1kbits/s
    frame= 7574 fps=149 q=28.0 size=    6540kB time=00:05:02.88 bitrate= 176.9kbits/s
    frame= 7634 fps=149 q=28.0 size=    6546kB time=00:05:05.06 bitrate= 175.8kbits/s
    frame= 7679 fps=148 q=28.0 size=    6550kB time=00:05:06.92 bitrate= 174.8kbits/s
    frame= 8364 fps=145 q=28.0 size=    6754kB time=00:05:34.43 bitrate= 165.4kbits/s
    frame= 8425 fps=145 q=28.0 size=    6757kB time=00:05:36.85 bitrate= 164.3kbits/s
    frame= 9020 fps=142 q=28.0 size=    6856kB time=00:06:00.53 bitrate= 155.8kbits/s
    frame= 9085 fps=142 q=28.0 size=    6858kB time=00:06:02.85 bitrate= 154.8kbits/s
    frame= 9142 fps=142 q=28.0 size=    6860kB time=00:06:05.38 bitrate= 153.8kbits/s
    frame= 9200 fps=142 q=28.0 size=    6886kB time=00:06:07.80 bitrate= 153.4kbits/s
    frame= 9259 fps=142 q=28.0 size=    6888kB time=00:06:10.24 bitrate= 152.4kbits/s
    frame= 9318 fps=142 q=28.0 size=    6894kB time=00:06:12.61 bitrate= 151.6kbits/s
    frame= 9375 fps=141 q=28.0 size=    6916kB time=00:06:14.93 bitrate= 151.1kbits/s
    frame= 9438 fps=141 q=25.0 size=    6944kB time=00:06:17.25 bitrate= 150.8kbits/s
    frame= 9499 fps=141 q=28.0 size=    6947kB time=00:06:19.57 bitrate= 149.9kbits/s
    frame= 9561 fps=141 q=28.0 size=    6950kB time=00:06:22.01 bitrate= 149.0kbits/s
    frame= 9618 fps=141 q=28.0 size=    6955kB time=00:06:24.63 bitrate= 143.6kbits/s
    frame=10145 fps=139 q=28.0 size=    7080kB time=00:06:45.58 bitrate= 143.0kbits/s
    frame=10202 fps=139 q=28.0 size=    7105kB time=00:06:47.90 bitrate= 142.7kbits/s
    frame=10257 fps=139 q=28.0 size=    7124kB time=00:06:50.20 bitrate= 142.3kbits/s
    frame=10315 fps=139 q=28.0 size=    7143kB time=00:06:52.52 bitrate= 141.8kbits/s
    frame=10373 fps=139 q=28.0 size=    7145kB time=00:06:54.87 bitrate= 141.1kbits/s
    frame=10432 fps=138 q=28.0 size=    7174kB time=00:06:57.03 bitrate= 140.9kbits/s
    frame=10489 fps=138 q=28.0 size=    7180kB time=00:06:59.35 bitrate= 140.3kbits/s
    frame=10547 fps=138 q=28.0 size=    7199kB time=00:07:01.55 bitrate= 139.9kbits/s
    frame=10605 fps=138 q=28.0 size=    7215kB time=00:07:03.85 bitrate= 139.5kbits/s
    frame=10661 fps=138 q=28.0 size=    7223kB time=00:07:06.01 bitrate= 138.9kbits/s
    frame=10713 fps=138 q=28.0 size=    7277kB time=00:07:08.33 bitrate= 139.2kbits/s
    frame=10769 fps=137 q=28.0 size=    7303kB time=00:07:10.66 bitrate= 138.9kbits/s
    frame=10829 fps=137 q=28.0 size=    7309kB time=00:07:12.98 bitrate= 138.3kbits/s
    frame=10884 fps=137 q=28.0 size=    7329kB time=00:07:15.14 bitrate= 138.0kbits/s
    frame=10941 fps=137 q=28.0 size=    7355kB time=00:07:17.39 bitrate= 137.7kbits/s
    frame=11000 fps=137 q=28.0 size=    7360kB time=00:07:19.48 bitrate= 137.2kbits/s
    frame=11047 fps=137 q=28.0 size=    7407kB time=00:07:21.80 bitrate= 137.3kbits/s
    frame=11105 fps=136 q=28.0 size=    7423kB time=00:07:23.66 bitrate= 137.1kbits/s
    frame=11150 fps=136 q=28.0 size=    7472kB time=00:07:25.91 bitrate= 137.3kbits/s
    frame=11208 fps=136 q=28.0 size=    7541kB time=00:07:27.84 bitrate= 137.9kbits/s
    frame=11264 fps=136 q=28.0 size=    7553kB time=00:07:30.16 bitrate= 137.4kbits/s
    frame=11314 fps=136 q=28.0 size=    7589kB time=00:07:32.02 bitrate= 137.5kbits/s
    frame=11359 fps=135 q=28.0 size=    7635kB time=00:07:34.34 bitrate= 137.7kbits/s
    frame=11415 fps=135 q=28.0 size=    7698kB time=00:07:36.20 bitrate= 138.2kbits/s
    frame=11469 fps=135 q=28.0 size=    7740kB time=00:07:38.52 bitrate= 138.3kbits/s
    frame=11526 fps=135 q=28.0 size=    7752kB time=00:07:40.84 bitrate= 137.8kbits/s
    frame=11585 fps=135 q=28.0 size=    7755kB time=00:07:43.16 bitrate= 137.2kbits/s
    frame=11638 fps=135 q=28.0 size=    7791kB time=00:07:45.28 bitrate= 137.2kbits/s
    frame=12371 fps=133 q=28.0 size=    8045kB time=00:08:14.60 bitrate= 133.2kbits/s
    frame=12426 fps=133 q=28.0 size=    8068kB time=00:08:16.60 bitrate= 133.1kbits/s
    frame=12475 fps=133 q=25.0 size=    8113kB time=00:08:18.88 bitrate= 133.2kbits/s
    frame=12528 fps=133 q=28.0 size=    8135kB time=00:08:21.01 bitrate= 133.0kbits/s
    frame=12529 fps=133 q=28.0 Lsize=    8549kB time=00:08:21.17 bitrate= 139.7kbits/s
    video:3859kB audio:4279kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.047608%
    [libx264 @ 0x1c89940] frame I:52    Avg QP:14.60  size: 25036
    [libx264 @ 0x1c89940] frame P:3390  Avg QP:16.73  size:   657
    [libx264 @ 0x1c89940] frame B:9087  Avg QP:16.09  size:    47
    [libx264 @ 0x1c89940] consecutive B-frames:  3.0%  0.7%  0.8% 95.5%
    [libx264 @ 0x1c89940] mb I  I16..4: 53.8%  0.0% 46.2%
    [libx264 @ 0x1c89940] mb P  I16..4:  2.6%  0.0%  0.0%  P16..4:  2.9%  0.0%  0.0%  0.0%  0.0%    skip:94.5%
    [libx264 @ 0x1c89940] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.5%  0.0%  0.0%  direct: 0.1%  skip:99.3%  L0:44.8% L1:51.9% BI: 3.3%
    [libx264 @ 0x1c89940] coded y,uvDC,uvAC intra: 40.1% 21.9% 16.0% inter: 0.4% 0.4% 0.1%
    [libx264 @ 0x1c89940] i16 v,h,dc,p: 42% 53%  3%  1%
    [libx264 @ 0x1c89940] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 45% 11%  5%  3%  2%  4%  2%  5%
    [libx264 @ 0x1c89940] i8c dc,h,v,p: 68% 25%  6%  1%
    [libx264 @ 0x1c89940] Weighted P-Frames: Y:0.4% UV:0.3%
    [libx264 @ 0x1c89940] kb/s:63.07
    /usr/bin/ffmpeg -i '/var/www/html/lms2/sites/default/files/videos/original/video.mp4' -vf 'scale=640:360' -strict experimental -vcodec 'h264' -qscale '12' -acodec 'aac' -ac '2' -pass '2' -passlogfile '/tmp/1499411044-595f326449e44-multipass'  -y /tmp/1499411044-595f326449d86.mp4
    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
      WARNING: library configuration mismatch
      avcodec     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 --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc --enable-libvo_amrwbenc
      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
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/lms2/sites/default/files/videos/original/video.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        creation_time   : 2017-04-28 15:24:27
      Duration: 00:08:21.18, start: 0.000000, bitrate: 443 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 314 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
    Please use -q:a or -q:v, -qscale is ambiguous
    [libx264 @ 0x1c2b940] -qscale is ignored, -crf is recommended.
    [libx264 @ 0x1c2b940] using SAR=1/1
    [libx264 @ 0x1c2b940] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
    [libx264 @ 0x1c2b940] constant rate-factor is incompatible with 2pass.
    Output #0, mp4, to '/tmp/1499411044-595f326449d86.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        Stream #0:0(und): Video: h264, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 25 fps (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 libx264
        Stream #0:1(und): Audio: aac, 0 channels, 128 kb/s (default)
        Metadata:
          creation_time   : 2017-04-28 15:24:27
          handler_name    : ISO Media file produced by Google Inc.
          encoder         : Lavc56.60.100 aac
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
      Stream #0:1 -> #0:1 (aac (native) -> aac (native))
    Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height


来源: stackexchange

问:
how to filter an object and get the desired output in javascript array?
I have an array of object like this,

```<code>[
  {imgUrl: "A"},
  {imgUrl: "B"},
  {imgUrl: "C", file: {fileName: "D"} }
]
</code>```

Desired output = ["A", "B", "D"];

答:
```<code>let yourResult = [
  {imgUrl: "A"},
  {imgUrl: "B"},
  {imgUrl: "C", fileName: "D"}
].reduce((result, item) => {
    result.push(item.fileName ? item.fileName : item.imgUrl);
    return result;
}, []);
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have an array of object like this,

[
  {imgUrl: "A"},
  {imgUrl: "B"},
  {imgUrl: "C", file: {fileName: "D"} }
]

Desired output = ["A", "B", "D"];


问:
Safari browser not invoking with protractor framework
I am trying to run test on Safari browser, it is working when run selenium server with selenium "selenium-server-standalone-2.47.1.jar" it working fine.

I have downloaded and installed safari webdriver driver extension.
Using Safari browser: 5.1.7 on window machine.
I added browser configuration in conf file:
     'browserName': 'safari'"

When I am running server with

webdriver-manager start

Getting below exception and safari browser not launched.

```<code>:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-
webdriver\error.js:27
super(opt_error);
     ^
WebDriverError: The best matching driver provider org.openqa.selenium.ie.InternetExplorerDriver can't create a new driver instance for Capabilities [{count=1, browserName=safari}]
 Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
 System info: host: 'Admin-PC', ip: '10.253.10.4', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_65'
 Driver info: driver.version: unknown at WebDriverError C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\error.js:27:10)
 at Object.checkLegacyResponse (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\error.js:580:13)
   at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:64:13
  at Promise.invokeCallback_ (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1329:14)
  at TaskQueue.execute_ (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2790:14)
at TaskQueue.executeNext_ (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2773:21)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2652:27
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7 at process._tickCallback (node.js:369:9)From: Task: WebDriver.createSession()
at acquireSession (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:62:22)
at Function.createSession (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\seleniu-webdriver\lib\webdriver.js:295:12) at Builder.build (C:\Users\Admin\AppData\R                           oaming\npm\node_modules\protractor\node_modules\selenium-webdriver\builder.js:458:24)
at [object Object].DriverProvider.getNewDriver (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\built\driverProviders\driverProvider.js:42:27)
at [object Object].Runner.createBrowser (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\built\runner.js:203:37)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\built\runner.js:293:21
at _fulfilled (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
</code>```

Let me know what I am missing.

答:
I belive you should use like this

```<code>multiCapabilities: [{
        name: 'ChromeIphone',
        logName: 'Chrome Iphone',
        browserName: 'chrome',
        chromeOptions: {
            'args': ['user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A405 Safari/600.1.4']
        },
        mobileEmulationEnabled: true
    }]
</code>```

in your conf.js file cause protractor works on windows machine with chromium and you have to set user-agent parameter to show that your go to your page through safari browser. So you are not able to run Safari browser directly on windows machine only through chrome driver.

Body:
I am trying to run test on Safari browser, it is working when run selenium server with selenium "selenium-server-standalone-2.47.1.jar" it working fine.

I have downloaded and installed safari webdriver driver extension.
Using Safari browser: 5.1.7 on window machine.
I added browser configuration in conf file:
     'browserName': 'safari'"

When I am running server with

webdriver-manager start

Getting below exception and safari browser not launched.

:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-
webdriver\error.js:27
super(opt_error);
     ^
WebDriverError: The best matching driver provider org.openqa.selenium.ie.InternetExplorerDriver can't create a new driver instance for Capabilities [{count=1, browserName=safari}]
 Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
 System info: host: 'Admin-PC', ip: '10.253.10.4', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_65'
 Driver info: driver.version: unknown at WebDriverError C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\error.js:27:10)
 at Object.checkLegacyResponse (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\error.js:580:13)
   at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:64:13
  at Promise.invokeCallback_ (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1329:14)
  at TaskQueue.execute_ (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2790:14)
at TaskQueue.executeNext_ (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2773:21)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2652:27
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7 at process._tickCallback (node.js:369:9)From: Task: WebDriver.createSession()
at acquireSession (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:62:22)
at Function.createSession (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\seleniu-webdriver\lib\webdriver.js:295:12) at Builder.build (C:\Users\Admin\AppData\R                           oaming\npm\node_modules\protractor\node_modules\selenium-webdriver\builder.js:458:24)
at [object Object].DriverProvider.getNewDriver (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\built\driverProviders\driverProvider.js:42:27)
at [object Object].Runner.createBrowser (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\built\runner.js:203:37)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\built\runner.js:293:21
at _fulfilled (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49

Let me know what I am missing.

Body:
I belive you should use like this

multiCapabilities: [{
        name: 'ChromeIphone',
        logName: 'Chrome Iphone',
        browserName: 'chrome',
        chromeOptions: {
            'args': ['user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A405 Safari/600.1.4']
        },
        mobileEmulationEnabled: true
    }]

in your conf.js file cause protractor works on windows machine with chromium and you have to set user-agent parameter to show that your go to your page through safari browser. So you are not able to run Safari browser directly on windows machine only through chrome driver.


问:
Random filter in jinja2 reuse the same value everytime
I'm trying to pick up a value from a list randomly in jinja2, this way:

```<code>{{ ['#EDD7C9', '#EDD7C9', '#EEE'] | random }}
</code>```

It selects an element randomly, but it reuses it every next time. If I change something in my template, then it picks up a different number again.

But weirdly, if I use range, it works just fine:

```<code>{{ range(1,100) |random }}
</code>```

Any ideas of how I can pick a random item from a fixed list without having to create my own filters?

Just to add a more complete example:

```<code>{% for i in range(5) %}
    {{ ['#EDD7C9', '#EDD7C9', '#EEE'] | random }}
    {{ range(1,100) | random }} <br/>
{% endfor %}
</code>```

outputs:

#EEE 8

#EEE 61

#EEE 58

#EEE 64

#EEE 76

Any help is appreciated!
thanks :)

答:
This appears to be a bug introduced in Jinja 2.9. I can reproduce it with any of the 2.9 releases (2.9 - 2.9.6). Jinja 2.8 and Jinja 2.8.1 work fine, and random values are mixed in the rendering:

```<code>$ cat test.py
from jinja2 import Template
template = Template('''
{%- for i in range(10) -%}
{{ ['foo', 'bar', 'baz', 'eggs', 'ham', 'spam'] | random }}{{ ' ' }}
{%- endfor %}
''')
print(template.render())
$ bin/python test.py
eggs eggs eggs eggs eggs eggs eggs eggs eggs eggs
$ bin/pip -U Jinja2==2.8.1
Collecting jinja2==2.8.1
  Using cached Jinja2-2.8.1-py2.py3-none-any.whl
Requirement already up-to-date: MarkupSafe in ./lib/python3.6/site-packages (from jinja2==2.8.1)
Installing collected packages: jinja2
  Found existing installation: Jinja2 2.9
    Uninstalling Jinja2-2.9:
      Successfully uninstalled Jinja2-2.9
Successfully installed jinja2-2.8.1
$ bin/python test.py
spam ham eggs spam spam eggs eggs baz bar foo
</code>```

Note that this only applies to a list literal embedded in the template with random directly after. If you pass in the list as a variable, then you do get a random() result each time; that variable can also be set in the template with {% set ... %}. It appears the template compiler is optimising one step too far somewhere.

So for now the work-arounds are:

Use {% set seq = ['#EDD7C9', '#EDD7C9', '#EEE'] %} and {{ seq | random }}

Pass in a list as a variable into the template and apply random to that

or to downgrade to 2.8.1.

<s>I've filed issue #739 with the project to track this.</s> The maintainers have excellent temporal skills and have fixed this a day ahead of time. A future version will include this fix (be it 2.9.7 or 2.10).

Body:
I'm trying to pick up a value from a list randomly in jinja2, this way:

{{ ['#EDD7C9', '#EDD7C9', '#EEE'] | random }}

It selects an element randomly, but it reuses it every next time. If I change something in my template, then it picks up a different number again.

But weirdly, if I use range, it works just fine:

{{ range(1,100) |random }}

Any ideas of how I can pick a random item from a fixed list without having to create my own filters?

Just to add a more complete example:

{% for i in range(5) %}
    {{ ['#EDD7C9', '#EDD7C9', '#EEE'] | random }}
    {{ range(1,100) | random }}

{% endfor %}

outputs:

#EEE 8

#EEE 61

#EEE 58

#EEE 64

#EEE 76

Any help is appreciated!
thanks :)

Body:
This appears to be a bug introduced in Jinja 2.9. I can reproduce it with any of the 2.9 releases (2.9 - 2.9.6). Jinja 2.8 and Jinja 2.8.1 work fine, and random values are mixed in the rendering:

$ cat test.py
from jinja2 import Template
template = Template('''
{%- for i in range(10) -%}
{{ ['foo', 'bar', 'baz', 'eggs', 'ham', 'spam'] | random }}{{ ' ' }}
{%- endfor %}
''')
print(template.render())
$ bin/python test.py
eggs eggs eggs eggs eggs eggs eggs eggs eggs eggs
$ bin/pip -U Jinja2==2.8.1
Collecting jinja2==2.8.1
  Using cached Jinja2-2.8.1-py2.py3-none-any.whl
Requirement already up-to-date: MarkupSafe in ./lib/python3.6/site-packages (from jinja2==2.8.1)
Installing collected packages: jinja2
  Found existing installation: Jinja2 2.9
    Uninstalling Jinja2-2.9:
      Successfully uninstalled Jinja2-2.9
Successfully installed jinja2-2.8.1
$ bin/python test.py
spam ham eggs spam spam eggs eggs baz bar foo

Note that this only applies to a list literal embedded in the template with random directly after. If you pass in the list as a variable, then you do get a random() result each time; that variable can also be set in the template with {% set ... %}. It appears the template compiler is optimising one step too far somewhere.

So for now the work-arounds are:

Use {% set seq = ['#EDD7C9', '#EDD7C9', '#EEE'] %} and {{ seq | random }}

Pass in a list as a variable into the template and apply random to that

or to downgrade to 2.8.1.

<s>I've filed issue #739 with the project to track this.</s> The maintainers have excellent temporal skills and have fixed this a day ahead of time. A future version will include this fix (be it 2.9.7 or 2.10).


问:
How should I write a regex to remove a specific word from a string?
I have been trying to come up with a suitable regrex to remove the word 'fries' from strings. However, it hasn't been very successful.

Ideally, the regrex expression should be able to remove the word 'fries' regardless of whether is it in upper case and/ or lower case and the word 'fries' shouldn't be removed under the following cases.

```<code>frenchfries
friesislove
ilovefriesverymuch
</code>```

This is what I have came up with so far

```<code>gsub('(?i)\\Wfries\\W','',string)
</code>```

One major flaw with the above is that regex expression isn't able to detect the word 'fries' if it's at either the start or the end of the string.

eg. 'I love fries', 'Fries is love'

答:
TRE regex engine does not support inline modifiers and to match a whole word you need to use word boundaries \b.

You may use a PCRE regex if you want to use an inline case insensitive modifier (?i):

```<code>gsub('(?i)\\bfries\\b','',string, perl = TRUE)
</code>```

or a TRE regex with ignore.case =TRUE argument:

```<code>gsub('\\bfries\\b','',string, ignore.case =TRUE)
</code>```

Body:
I have been trying to come up with a suitable regrex to remove the word 'fries' from strings. However, it hasn't been very successful.

Ideally, the regrex expression should be able to remove the word 'fries' regardless of whether is it in upper case and/ or lower case and the word 'fries' shouldn't be removed under the following cases.

frenchfries
friesislove
ilovefriesverymuch

This is what I have came up with so far

gsub('(?i)\\Wfries\\W','',string)

One major flaw with the above is that regex expression isn't able to detect the word 'fries' if it's at either the start or the end of the string.

eg. 'I love fries', 'Fries is love'

Body:
TRE regex engine does not support inline modifiers and to match a whole word you need to use word boundaries \b.

You may use a PCRE regex if you want to use an inline case insensitive modifier (?i):

gsub('(?i)\\bfries\\b','',string, perl = TRUE)

or a TRE regex with ignore.case =TRUE argument:

gsub('\\bfries\\b','',string, ignore.case =TRUE)


问:
How to rollback unit test while service layer is @Transactional
I am using Spring Boot 1.5.2.RELEASE and my service classes is annotated with

```<code>@Service
@Transactional(rollbackFor = Exception.class)
</code>```

My unit test class is annotated with:

```<code>@RunWith(SpringRunner.class)
@SpringBootTest
</code>```

I wish to roll back changes made in the database by unit test methods after test is finished.

One of the proposed solutions is to add @Transactional annotation over the test class, I tried it but this solution produces some issues, is that sometimes the test transaction is rolled back (even without no exceptions thrown!) before the service transaction is completed.

Is there another good solution to rollback test?

答: The solution with the @Transactional on the test class is the standard way of doing this. There is no way Spring Tx would roll back a transaction out of the blue, so I'd recommend looking closer into the issues that you encountered instead of inventing other solutions.

ContentLicense: CC BY-SA 4.0

Body:
I am using Spring Boot 1.5.2.RELEASE and my service classes is annotated with

@Service
@Transactional(rollbackFor = Exception.class)

My unit test class is annotated with:

@RunWith(SpringRunner.class)
@SpringBootTest

I wish to roll back changes made in the database by unit test methods after test is finished.

One of the proposed solutions is to add @Transactional annotation over the test class, I tried it but this solution produces some issues, is that sometimes the test transaction is rolled back (even without no exceptions thrown!) before the service transaction is completed.

Is there another good solution to rollback test?


问:
Register service as protected service
We are working on a Security Suite for Windows. We want our process to be unkillable like that of Kaspersky's or Avast's. While looking around the web I came across Windows Protected Services.

https://msdn.microsoft.com/en-us/library/windows/desktop/dn313124%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

How to register my product as a windows protected service?

Or is this service only available for Anti - Malware products alone? How about its availability for a Security Suite, which does stuff like USB device management, data protection and similar stuff?

答:
You need to write a ELAM (Early Launch Anti-Malware) driver to be able to create a protected service.

Each driver .sys file must be code signed by Microsoft, using a special certificate indicating that it is an Early Launch AM Driver.

Antimalware Vendor Participation Requirements:

Microsoft requires that Early Launch Antimalware vendors either be members of the Microsoft Virus Initiative (MVI) or pre-approved members of the Virus Information Alliance (VIA). This membership ensures that the vendors are active antimalware community participants with a positive industry reputation. Please reach out to mvi@microsoft.com if you have questions about ELAM driver signing or becoming a pre-approved VIA member.

Title: Register service as protected service


问:
Using css in converted svg to img
I am trying to convert an svg to an image format. Actually a lot works very fine and I know how to convert from SVG to canvas and from canvas to img. My problem is that the svg uses css that has been included as css file and by converting to canvas, the styles will be lost.

Does anyone has an idea how to copy the styles into my svg or canvas?

Here is my code: https://jsfiddle.net/DaWa/70w9db1d/

```<code><!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>SVG2IMG</title>
    <link rel="stylesheet" href="./circle.css">
</head>
<body>
<svg width="100" height="100">
    <circle cx="50" cy="50" r="40"/>
</svg>

<script>
  var svg = document.querySelector('svg');

  let xml  = new XMLSerializer().serializeToString(svg);
  let data = "data:image/svg+xml;base64," + btoa(xml);
  let img  = new Image();
  img.src  = data;
  document.body.appendChild(img)

</script>

</body>
</html>
</code>```

And my css:

```<code>circle {
    fill:red
}
</code>```

答:
I used this trick to add computed style of each node to its style attribute, and it works. may be it can help you.

Update 1: some browsers do not support the cssText property so you can use the code below which is a bit more cross browser.

Update 2: Firefox computes css quotes property which include some invalid string chars that btoa can not encode properly.

let addStyle = function(children) {
   for (let i = 0; i < children.length; i++) {
     let child = children[i];
     if (child instanceof Element) {
       let cssText = '';
       let computedStyle = window.getComputedStyle(child, null);
       for (let i = 0; i < computedStyle.length; i++) {
         let prop = computedStyle[i];
         cssText += prop + ':' + computedStyle.getPropertyValue(prop) + ';';
       }
       child.setAttribute('style', cssText);
       addStyle(child.childNodes);
     }
   }
 }

 let svg = document.querySelector('svg');
 addStyle(svg.childNodes);
 let xml = new XMLSerializer().serializeToString(svg);
 let data = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(xml)));
 let img = new Image();
 img.src = data;
 document.body.appendChild(img);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>circle {
  fill: red
}</code>```

<svg width="100" height="100">
  <circle cx="50" cy="50" r="40" />
</svg>```

Title: Using css in converted svg to img

Body:
I am trying to convert an svg to an image format. Actually a lot works very fine and I know how to convert from SVG to canvas and from canvas to img. My problem is that the svg uses css that has been included as css file and by converting to canvas, the styles will be lost.

Does anyone has an idea how to copy the styles into my svg or canvas?

Here is my code: https://jsfiddle.net/DaWa/70w9db1d/

<!DOCTYPE html>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>SVG2IMG</title>
    <link rel="stylesheet" href="./circle.css">

<svg width="100" height="100">
    <circle cx="50" cy="50" r="40"/>
</svg>

And my css:

circle {
    fill:red
}

Body:
I used this trick to add computed style of each node to its style attribute, and it works. may be it can help you.

Update 1: some browsers do not support the cssText property so you can use the code below which is a bit more cross browser.

Update 2: Firefox computes css quotes property which include some invalid string chars that btoa can not encode properly.

let addStyle = function(children) {
   for (let i = 0; i < children.length; i++) {
     let child = children[i];
     if (child instanceof Element) {
       let cssText = '';
       let computedStyle = window.getComputedStyle(child, null);
       for (let i = 0; i < computedStyle.length; i++) {
         let prop = computedStyle[i];
         cssText += prop + ':' + computedStyle.getPropertyValue(prop) + ';';
       }
       child.setAttribute('style', cssText);
       addStyle(child.childNodes);
     }
   }
 }

 let svg = document.querySelector('svg');
 addStyle(svg.childNodes);
 let xml = new XMLSerializer().serializeToString(svg);
 let data = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(xml)));
 let img = new Image();
 img.src = data;
 document.body.appendChild(img);

circle {
  fill: red
}

<svg width="100" height="100">
  <circle cx="50" cy="50" r="40" />
</svg>


问:
Is there a way to see the value of a variable as the program is running?
I'd like to see what value a variable is holding AS the program is running.

I remember Scott Hanselman blogging about something like a Variable Viewbox, but I can't seem to find the post.

I'd like to view the variable AS the program is running it's loop. Inside of Visual Studio.

答:
You can use DebugView from here : http://technet.microsoft.com/en-us/sysinternals/bb896647

just add to your code

System.Diagnostic.Trace.Write(myVar) ;

and see its value in debugView window in real time .

OwnerDisplayName: delete

LastEditorDisplayName: delete

ContentLicense: CC BY-SA 2.5


问:
Inline juqery syntax error
Inside a .php page i have a function.Inside that function, some of my code looks like the following:-

```<code>$html='';
$html.='<div id="imgContainer"></div>';
$html.='<img  src="elements/18_lr.jpg"  data-highres="elements/18_hr.jpg" onclick="$(this).mbZoomify({screen:'#imgContainer'});">';//<<----shows error near #imgContainer
</code>```

At the above indicated line, it shows incorrect HTML error.Please advise how to get rid of the error.

答:
Use backword slash "\"</p>

```<code>$html='';
$html.='<div id="imgContainer"></div>';
$html.='<img  src="elements/18_lr.jpg"  data-highres="elements/18_hr.jpg" onclick="$(this).mbZoomify({screen:\'#imgContainer\'});">';//<<----shows error near #imgContainer
</code>```

Title: Inline juqery syntax error

Body:
Inside a .php page i have a function.Inside that function, some of my code looks like the following:-

$html='';
$html.='

';
$html.='';//<<----shows error near #imgContainer

At the above indicated line, it shows incorrect HTML error.Please advise how to get rid of the error.

Body:
Use backword slash "\"

$html='';
$html.='<div id="imgContainer"></div>';
$html.='<img  src="elements/18_lr.jpg"  data-highres="elements/18_hr.jpg" onclick="$(this).mbZoomify({screen:\'#imgContainer\'});">';//<<----shows error near #imgContainer


问:
The animation scroll to top button does not work
a couple of days ago i started working with my companies website. I saw it was missing something so I decided to make a scroll to top button with animation. I am a noob in programming so i decided to look on the Internet. There I found this example. I literally copied the whole code but it does not work.

the button in the html:

```<code><a href="javascript:" id="return-to-top"><i class="icon-chevron-up"></i></a>
</code>```

and this is the jQuery:

```<code>$(window).scroll(function() {
    if ($(this).scrollTop() >= 50) {
        $('#return-to-top').fadeIn(200);
    } else {
        $('#return-to-top').fadeOut(200);
    }
});
$('#return-to-top').click(function() {
    $('body, html').animate({
        scrollTop : 0
    }, 500);
});
</code>```

I dont know what the problem is because it works on the codepen. Does anyone know how to fix this?

Thanks in advance

答: I noticed a lot of people were telling me to include the jquery library. I did add the library before but after I checked the answers I noticed that I added the wrong library. So now its fixed thanks a lot guys.</p>

Body:
a couple of days ago i started working with my companies website. I saw it was missing something so I decided to make a scroll to top button with animation. I am a noob in programming so i decided to look on the Internet. There I found this example. I literally copied the whole code but it does not work.

the button in the html:

and this is the jQuery:

$(window).scroll(function() {
    if ($(this).scrollTop() >= 50) {
        $('#return-to-top').fadeIn(200);
    } else {
        $('#return-to-top').fadeOut(200);
    }
});
$('#return-to-top').click(function() {
    $('body, html').animate({
        scrollTop : 0
    }, 500);
});

I dont know what the problem is because it works on the codepen. Does anyone know how to fix this?

Thanks in advance


问:
Sprites not displaying how I want them to display
I was making an SFML game, and I wanted to limit the number of bullets that can exist on the screen at the same time to 5 for now.

This is the minimal code needed:

```<code>#define max_bullets_displayed 5

//...

Bullet* pociski[max_bullets_displayed];

//...

for (int i = 0; i < 5; i++)
{
    pociski[i] = 0;
}

//...

//creating bullets when needed
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
    for (int i = 0; i < 5; i++)
    {
        if (pociski[i] == 0)
        {
            pociski[i] = new Bullet("pocisk.png", sf::Mouse::getPosition().x, sf::Mouse::getPosition().y, 23, 20);
        }
    }
}

//...

//displaying
for (int i = 0; i < 5; i++)
{
    if (pociski[i] != 0) window.draw(pociski[i]->sprite);
}
</code>```

I think there is something wrong with the pointers. Only one of the bullets can be displayed, the rest doesn't display even after clicking. No exceptions are thrown, and the memory is fine.

答:
All the bullets are spawned in the same position, so they are drawn on top of each other.</p>

```<code>pociski[i] = new Bullet("pocisk.png", sf::Mouse::getPosition().x, sf::Mouse::getPosition().y, 23, 20);
</code>```

Body:
I was making an SFML game, and I wanted to limit the number of bullets that can exist on the screen at the same time to 5 for now.

This is the minimal code needed:

#define max_bullets_displayed 5

//...

Bullet* pociski[max_bullets_displayed];

//...

for (int i = 0; i < 5; i++)
{
    pociski[i] = 0;
}

//...

//creating bullets when needed
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
    for (int i = 0; i < 5; i++)
    {
        if (pociski[i] == 0)
        {
            pociski[i] = new Bullet("pocisk.png", sf::Mouse::getPosition().x, sf::Mouse::getPosition().y, 23, 20);
        }
    }
}

//...

//displaying
for (int i = 0; i < 5; i++)
{
    if (pociski[i] != 0) window.draw(pociski[i]->sprite);
}

I think there is something wrong with the pointers. Only one of the bullets can be displayed, the rest doesn't display even after clicking. No exceptions are thrown, and the memory is fine.

Body:
All the bullets are spawned in the same position, so they are drawn on top of each other.

pociski[i] = new Bullet("pocisk.png", sf::Mouse::getPosition().x, sf::Mouse::getPosition().y, 23, 20);


问:
mysql persistent connection
How to close a mysql  persistent connection?</p>

答:
What language are you using?  Php?  Persistent connects will timeout if on an non-interactive session based on the wait_timeout variable in my.cnf.  See http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_wait_timeout

If you are using PHP (just guessing here) take a look at http://php.net/manual/en/function.mysql-pconnect.php and http://www.php.net/manual/en/features.persistent-connections.php

There are some interesting discussions on the use of persistent connections - http://www.mysqlperformanceblog.com/2006/11/12/are-php-persistent-connections-evil/

Title: mysql persistent connection


问:
Extract REGEXP Substring SQL Server
I want to extract a specific number value from this query...

Column: name
Four rows for this example:

1/2 Product1 some_description 1200 GR more data... (UND)

1/4 Product2 some_description 2400G more data (KG more data)

Product3 some_description 2200 GRS more data...

1/4 Product4 some_description 1800GR more data UND...

I want the integer value only. I want with the query:

1200

2400

2200

1800

The patterns are:

[0-9]{4} G

[0-9]{4}GR

[0-9]{4} GRS

How can i use this regexp on a SQL Query to parse an attribute value?

SELECT FROM myTable
SUBSTRING(name, (PATINDEX('%[0-9]%', [name])),4) as peso

This extract some values, but not in correct order... I think that i can apply LEFT with length until integer value, but i don't know how resolve it.

答:
```<code>CONVERT(
INT,
(REPLACE(
    SUBSTRING(
        nome,
        (
            PATINDEX(
                '%[0-9]%',
                REPLACE(
                    REPLACE(
                        nome,
                        '1/2',
                        ''
                    ),
                    '1/4',
                    ''
                )
            )
        ),
        4
    ),
    'G',
    ''
))) as pesoTotal
</code>```

This resolve the question, thanks.

Title: Extract REGEXP Substring SQL Server

Body:
CONVERT(
INT,
(REPLACE(
    SUBSTRING(
        nome,
        (
            PATINDEX(
                '%[0-9]%',
                REPLACE(
                    REPLACE(
                        nome,
                        '1/2',
                        ''
                    ),
                    '1/4',
                    ''
                )
            )
        ),
        4
    ),
    'G',
    ''
))) as pesoTotal

This resolve the question, thanks.


问:
JavaScript - Chart.js tooltip shows wrong x-axis value
I have a chart with two different datasets, but sometimes they have the same x, y coordinates. But when I hover a shared point, it sometimes shows the wrong date. The y value is correct, but it's the x value that is not showing correctly.

Try hovering a shared point here on codepen.

In the image below you can see I'm hovering { y: 56.04, x: April 05, 2014 }, but is shows the xLabel value of 58.28, which is April 15, 2012. Also, you can see in the chart that both 57.05 and 58.28 have April 15, 2012 as x-value, but they are not on the same y position!

The code is too long to share on stackoverflow, but I made this codepen so you can view, fork and edit it there.

Update

I updated the pen and fixed points that have the same date. I also added type: 'time' thanks to @Oluwafemi Sule.

Here my edited pen.

But now, the dates on the x-axis are weird. They don't say March 06, 2011 anymore, but they say Q1 2011. And the tooltips still bug.

答:
You defined a custom scale for a category cartesian axis in your chart configuration. Set the type for your xAxes to 'category'. This may not be neccessary as ChartJS picks this up by default.

```<code>options: {
    scales: {
        xAxes: [{
            type: 'category',
            ....
</code>```

Also, the second data set isn't formatted properly. You should supply the data points in {x: xval, y: yval} format.

References:

http://www.chartjs.org/docs/latest/axes/cartesian/time.html#time-cartesian-axis

Body:
You defined a custom scale for a category cartesian axis in your chart configuration. Set the type for your xAxes to 'category'. This may not be neccessary as ChartJS picks this up by default.

options: {
    scales: {
        xAxes: [{
            type: 'category',
            ....

Also, the second data set isn't formatted properly. You should supply the data points in {x: xval, y: yval} format.

References:

http://www.chartjs.org/docs/latest/axes/cartesian/time.html#time-cartesian-axis


问:
Using inheritence to simulate roles in C++ for DCI
I have been trying to learn about DCI (Data Context Interaction) (http://tidyjava.com/dci-architecture-visionary/)

It seems to me that 'roles' can be simulated by creating derived classes which inherit from a base class and have access to all the private members. Is that a reasonable statement?

Alternatively, could this be regarded as too much infrastructure? I mean, DCI seems to be about separating actions from classes. Isn't that just good ol' C, where you have functions that operate on structures?

答:
The difference between DCI objects and structs is explained early in the page you link:

The major difference between DCI‘s data object and a typical entity is
  that the data object is relatively stupid. It’s not anemic. It can
  still contain important domain methods that would preserve it’s
  invariants etc.

What that means is that classes still may contain the necessary boilerplate (getters, setters, constructors, destructor and more complex stuff), that maintain its consistency (i.e. make sure it is used correctly). So implementing your use cases is not burdened with these concerns.


问:
escape special character json angular
Is there a built in way to escape json characters in angular (4)

here's my returned json -  I want to remove the   return symbols etc. A regex feels a bit hacky, prefer to use native / built in function.

EDIT: The {{ val }} expression are deliberate and I want to keep these.

```<code>"values": [
    "<p>value {{ val }} </p>\n\n<p><strong>value2 {{ val2 }}</strong></p>\n"
]
</code>```

答:
I don't think there is any inbuilt method which will resolve your problem. but as of now, you can stringify it and then just use replace,
example : </p>

```<code>let jsonData  = {"values" : [    "<p>value {{ val }} </p>\n\n<p>
<strong>value2 {{ val2 }}</strong></p>\n"]}
 console.log(JSON.stringify(jsonData).replace(" ",''));
</code>```

Title: escape special character json angular

Body:
Is there a built in way to escape json characters in angular (4)

here's my returned json -  I want to remove the   return symbols etc. A regex feels a bit hacky, prefer to use native / built in function.

EDIT: The {{ val }} expression are deliberate and I want to keep these.

"values": [
    "
value {{ val }}
\n\n
value2 {{ val2 }}
\n"
]

Body:
I don't think there is any inbuilt method which will resolve your problem. but as of now, you can stringify it and then just use replace,
example :

let jsonData  = {"values" : [    "<p>value&nbsp;{{ val }}&nbsp;</p>\n\n<p>
<strong>value2 {{ val2 }}</strong></p>\n"]}
 console.log(JSON.stringify(jsonData).replace("&nbsp;",''));


问:
 larger break than usual?
This hasn't been a problem in the past, I don't know what has happened, but the
 element in my footer separates the text by like, 10px's. Wondering if I have some CSS or a tag I'm not aware of?

Here is my code:

.contentFake {
  background-color: #333;
  height: 200px;
}

.footer {
  width: 100%;
  position: fixed;
  margin-bottom: 0px;
  height: 80px;
  background-color: #1A1A1A;
  display: block;
}

.footerContent {
  width: 80%;
  margin: auto;
  padding: 20px;
  text-align: center;
  border-left: 1px solid #fff;
  border-right: 1px solid #fff;
  border: none;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class='contentFake'>
  <div class='footerContent'>
    <p>
      <font face="Helvetica" size="2" color="white">
        <font size="5" face="Indie Flower"><strong>THIS IS FOOTER</strong></font> <br />
        Home<br />
        Blog <br />
        Photo Feed <br />
        Vlogs <br />
        Farewell <br />
        BACK TO TOP <br /> © Jack Champions FOOTER All Rights Reserved 2017</font>
    </p>
  </div>
</div></code>```

jsfiddle: https://jsfiddle.net/gu1pdh5a/

The code  you run direct here, is the code I wish to see, yet on mine it turns up like this?

答:
From your image i see that there is a lot of space. I will give you some fixes for that and then you can try which is the right one for you.

Firstly that space is caused by
 or by  so lets remove padding and margin for each one

```<code>.footerContent br{
    margin:0px;
    padding:0px;
    font-size:16px;
}
</code>```

This one does the same for the  element

```<code>.footerContent a{
    margin:0px;
    padding:0px;
}
</code>```

Here you have a jsfiddle where i removed
 tags and just showing  as block one in each line and using margin.

And here is another jsfiddle using
 (This is better and easier to manage) .

Title: <br> larger break than usual?

Body:
This hasn't been a problem in the past, I don't know what has happened, but the
 element in my footer separates the text by like, 10px's. Wondering if I have some CSS or a tag I'm not aware of?

Here is my code:

.contentFake {
  background-color: #333;
  height: 200px;
}

.footer {
  width: 100%;
  position: fixed;
  margin-bottom: 0px;
  height: 80px;
  background-color: #1A1A1A;
  display: block;
}

.footerContent {
  width: 80%;
  margin: auto;
  padding: 20px;
  text-align: center;
  border-left: 1px solid #fff;
  border-right: 1px solid #fff;
  border: none;
}

        THIS IS FOOTER

        Home

        Blog

        Photo Feed

        Vlogs

        Farewell

        BACK TO TOP
 © Jack Champions FOOTER All Rights Reserved 2017

jsfiddle: https://jsfiddle.net/gu1pdh5a/

The code  you run direct here, is the code I wish to see, yet on mine it turns up like this?

Body:
From your image i see that there is a lot of space. I will give you some fixes for that and then you can try which is the right one for you.

Firstly that space is caused by <br> or by <a> so lets remove padding and margin for each one

.footerContent br{
    margin:0px;
    padding:0px;
    font-size:16px;
}

This one does the same for the <a> element

.footerContent a{
    margin:0px;
    padding:0px;
}

Here you have a jsfiddle where i removed <br> tags and just showing <a> as block one in each line and using margin.

And here is another jsfiddle using <ul> (This is better and easier to manage) .


问:
AAD: Not receiving password expiration notification
I've set up the notification in AAD cmdlet and also the office portal, referencing here, for my AAD tenant, but no email notification was sent when account password is about to expire. I tried setting a valid email address for both "Email" and "Alternate Email" properties in account profile on AAD.</p>

答:
but no email notification was sent when account password is about to
  expire.

For now, we will not receive any notification emails, because the only notification that O365 provides is a pop-up in the Windows Notification area of the Taskbar. Furthermore, mobile users(i.e. i.e. smartphones and tablets) will not receive any notification.

If you want to sent email when O365 account is about to expire, we can use powershell script to send emails to users. To send emails, we should have a email server, collect the information about smtpServer and emailaddress.

More information about how to notify office 365 users that passwords will expire, please refer to this link.


问:
Pick list items in VSTS gets auto sorted
I'm trying to add some items (strings) to a pick list in VSTS. The items get auto sorted alphabetically (ascending order).

Below is the scenario:

I entered 'test' then 'abc' and then 'xyz', but it auto sorts and displays 'abc' then 'test' and then 'xyz'.

Is there any way to avoid this sorting and the items should be inserted in the order they were entered?

And I want to achieve this without writing an extension.

答:
Yes, the values for the picklist (string) Type field can only ordered by alphabet so far.

But there has an user voice Custom Sort Order for TFS Fields (for VSTS, added in comment) about customzing sort order for fields, and you can vote and follow up.


问:
how to filter an object and get the desired output in javascript array?
I have an array of object like this,

```<code>[
  {imgUrl: "A"},
  {imgUrl: "B"},
  {imgUrl: "C", file: {fileName: "D"} }
]
</code>```

Desired output = ["A", "B", "D"];

答:
You could try to make use of the map Array's method.

var input = [
  {imgUrl: "A"},
  {imgUrl: "B"},
  {imgUrl: "C", file: {fileName: "D"} }
];

var output = input.map(function(item){
    return item.file
         ? item.file.fileName
         : item.imgUrl;
});

console.log(output)```

Body:
I have an array of object like this,

[
  {imgUrl: "A"},
  {imgUrl: "B"},
  {imgUrl: "C", file: {fileName: "D"} }
]

Desired output = ["A", "B", "D"];


问:
Python test script works when using -munittest, but fails due to ModuleNotFoundError when ran directly
I've got a test script which imports modules from my application. This works when run with python -munittest, but it fails with ModuleNotFoundError if I simply use python tests/test_app.py.

This also happens with other scripts in this project which aren't unit tests.

```<code>$ python tests/test_app.py
Traceback (most recent call last):
  File "tests/test_app.py", line 2, in <module>
    import myapp
ModuleNotFoundError: No module named 'myapp'

$ python -munittest tests.test_app
....
----------------------------------------------------------------------
Ran 4 tests in 0.119s

OK
</code>```

As you can see from the trace, it fails at the very beginning of the file, in the imports, where I use import myapp.

Project structure:

```<code>/project
  /myapp
    __init__.py
    models.py
  /otherapp
  /anotherapp
  /tests
    test_app.py
  /scripts
    a_script.py
</code>```

What magic is the unittest module doing to make my script load?

How do I execute my script directly?

答:
It fails because when you run with python tests/test_app.pyyour python will look for myappin the local folder relative to the test_app.py or in PYTHONPATH and won't find it. Whereas unittest will handle importing the package while starting from project root folder.

This python documentation link explain how import statement work

When a module named spam is imported, the interpreter first searches
  for a built-in module with that name. If not found, it then searches
  for a file named spam.py in a list of directories given by the
  variable sys.path. sys.path is initialized from these locations:

the directory containing the input script (or the current directory).

PYTHONPATH (a list of directory names, with the same syntax as the
  shell variable PATH).

the installation-dependent default.

After initialization, Python programs can modify sys.path. The directory
  containing the script being run is placed at the beginning of the
  search path, ahead of the standard library path. This means that
  scripts in that directory will be loaded instead of modules of the
  same name in the library directory. This is an error unless the
  replacement is intended. See section Standard Modules for more
  information.

Therefore, to make your script directly executable you need to tell python to find "myapp" using one of the ways described in the documentation. Here's another SO question discussing how to use import (you can find a lot more with a quick search).

Body:
I've got a test script which imports modules from my application. This works when run with python -munittest, but it fails with ModuleNotFoundError if I simply use python tests/test_app.py.

This also happens with other scripts in this project which aren't unit tests.

$ python tests/test_app.py
Traceback (most recent call last):
  File "tests/test_app.py", line 2, in <module>
    import myapp
ModuleNotFoundError: No module named 'myapp'

$ python -munittest tests.test_app
....
----------------------------------------------------------------------
Ran 4 tests in 0.119s

OK

As you can see from the trace, it fails at the very beginning of the file, in the imports, where I use import myapp.

Project structure:

/project
  /myapp
    __init__.py
    models.py
  /otherapp
  /anotherapp
  /tests
    test_app.py
  /scripts
    a_script.py

What magic is the unittest module doing to make my script load?

How do I execute my script directly?


问:
How to nest php inside if statement
Probably a newbie thing but I can't get the meta name="description" row to work. You should close and open PHP-code if its nested, right?

Thanks!
/Robert

```<code><?php
    $blogname = get_bloginfo('name');
    if ($blogname == 'Wobbling Willy') {
        echo '<meta name="description" content="?><?php bloginfo('description'); ?><?php" />'."\n";
        echo '<meta name="keywords" content=”keyword1, keyword2, keyword3” />'."\n";
    }
?>
</code>```

答:
Try this:</p>

```<code><?php
    $blogname = get_bloginfo('name');
    if ($blogname == 'Wobbling Willy') {
        echo '<meta name="description" content="'.bloginfo('description').'"/>\n';
        echo '<meta name="keywords" content="keyword1, keyword2, keyword3"/>\n';
    }
?>
</code>```

Title: How to nest php inside if statement

Body:
Probably a newbie thing but I can't get the meta name="description" row to work. You should close and open PHP-code if its nested, right?

Thanks!
/Robert

<?php
    $blogname = get_bloginfo('name');
    if ($blogname == 'Wobbling Willy') {
        echo '<meta name="description" content="?><?php bloginfo('description'); ?><?php" />'."\n";
        echo '<meta name="keywords" content=”keyword1, keyword2, keyword3” />'."\n";
    }
?>

Body:
Try this:

<?php
    $blogname = get_bloginfo('name');
    if ($blogname == 'Wobbling Willy') {
        echo '<meta name="description" content="'.bloginfo('description').'"/>\n';
        echo '<meta name="keywords" content="keyword1, keyword2, keyword3"/>\n';
    }
?>


问:
Change default rule type in SonarQube 6.4
Is there a way to change the type for rules existing in SonarQube 6.4 (not custom rules). For example, can I change an existing rule from a bug to a vulnerability or a code smell etc.. ?

Thanks in advance

答: Good question SabrinaS... It is needed to change type of rules existing in SonarQube 6.4 .          </p>


问:
Can't register my jQuery script in WordPress
For some reason my jQuery script is not being registered, I believe I am doing it correctly but maybe I'm missing something. Here's my code: </p>

```<code>/*registering script*/
    function register_my_script(){
        wp_register_script('alliance_script', get_template_directory_uri() . '/js/script.js');
    }
    add_action('enqueue_scripts', 'register_my_script');
</code>```

答:
I think the problem is that you're using 'enqueue_scripts' as action, which should be 'wp_enqueue_scripts'.</p>

```<code>function register_my_script(){
    wp_register_script('alliance_script', get_template_directory_uri() . '/js/script.js');
}
add_action('wp_enqueue_scripts', 'register_my_script');
</code>```

Body:
For some reason my jQuery script is not being registered, I believe I am doing it correctly but maybe I'm missing something. Here's my code:

/*registering script*/
    function register_my_script(){
        wp_register_script('alliance_script', get_template_directory_uri() . '/js/script.js');
    }
    add_action('enqueue_scripts', 'register_my_script');

Body:
I think the problem is that you're using 'enqueue_scripts' as action, which should be 'wp_enqueue_scripts'.

function register_my_script(){
    wp_register_script('alliance_script', get_template_directory_uri() . '/js/script.js');
}
add_action('wp_enqueue_scripts', 'register_my_script');


问:
Indexing Between two Matrices
I have two Matrices (V; Vertex Node Coordinates x,y,z & T; List of Triangles showing the nodes (1,2,3) that make up the triangle)

I want to replace the values in T with the coordinates of the corresponding vertex nodes ie:

```<code>V
    1 --- 1.35234 1.2542445 1.32234324
    2 --- 3.42354 1.2521345 1.34325524
    3 --- 2.26434 1.2323345 1.33225324
T
1 2 3

should go to

T_V

1.35234 1.2542445 1.32234324 3.42354 1.2521345 1.34325524 2.26434 1.2323345 1.33225324
</code>```

Title: Indexing Between two Matrices

Body:
I have two Matrices (V; Vertex Node Coordinates x,y,z & T; List of Triangles showing the nodes (1,2,3) that make up the triangle)

I want to replace the values in T with the coordinates of the corresponding vertex nodes ie:

V
    1 --- 1.35234 1.2542445 1.32234324
    2 --- 3.42354 1.2521345 1.34325524
    3 --- 2.26434 1.2323345 1.33225324
T
1 2 3

should go to

T_V

1.35234 1.2542445 1.32234324 3.42354 1.2521345 1.34325524 2.26434 1.2323345 1.33225324

Body:
It T is always a (1x3) array you can try:

T_V=reshape(V(T(:),:)',1,numel(T)*size(V,2))

For a more general case, in case T is a matrix such as, for exampale:

T=[1 2 3;4 5 6]

for  a V matrix such as

V=[
1.35234 1.2542445 1.32234324
3.42354 1.2521345 1.34325524
2.26434 1.2323345 1.33225324
10 20 30
40 50 60
70 80 90]

you can try:

T1=T'
V_T=reshape(V(T1(:),:)',1,numel(T1)*size(V,2))

Edit

In case the expected shape of the T_V matrix is (n_row of T x 9) you can try (I've added some rows on both V and T for test purpose):

V=[
1.35234 1.2542445 1.32234324
3.42354 1.2521345 1.34325524
2.26434 1.2323345 1.33225324
10 20 30
40 50 60
70 80 90]

T=[1 2 3
5 4 6]

T1=T'

T_V=reshape(reshape(V(T1(:),:)',1,numel(T1)*3),size(T,2)*size(V,2),size(T))'

The resulting T_V matrix:

T_V =

    1.3523    1.2542    1.3223    3.4235    1.2521    1.3433    2.2643    1.2323    1.3323
   40.0000   50.0000   60.0000   10.0000   20.0000   30.0000   70.0000   80.0000   90.0000

Notice: tested with Octave


问:
Ruby on Rails: Custom routes for search results
I am building an app for users to submit "adventures" and I would like to have individual pages set up to display adventures by city. I followed this advice (Ruby on Rails 4: Display Search Results on Search Results Page) to have search results display on a separate page and that works very well, but I would like to take it further and have pre-set links to route users to city-specific adventures. I'm not sure how to get the results from http://localhost:3000/adventures/search?utf8=%E2%9C%93&search=Tokyo to display on http://localhost:3000/pages/tokyo. Also, I am very new to Rails; this is my first project.

routes.rb

```<code>  root 'adventures#index'
  resources :adventures do
    collection do
      get :search
    end
  end
</code>```

adventures_controller

```<code>  def search
    if params[:search]
      @adventures = Adventure.search(params[:search]).order("created_at DESC")
    else
      @adventures = Adventure.all.order("created_at DESC")
    end
  end
</code>```

答:
Build a custom route for pages. something like

```<code>get "/pages/:city", to: "pages#display_city", as: "display_city"
</code>```

and redirect to that with the params[:search]

```<code>def search
  if params[:search]
    #this won't be needed here
    #@adventures = Adventure.search(params[:search]).order("created_at DESC")
    redirect_to display_city_path(params[:search])
  else
    @adventures = Adventure.all.order("created_at DESC")
  end
end
</code>```

Have a controller#action and view for that corresponding route.

```<code>#pages_controller

def display_city
  @adventures = Adventure.search(params[:city]).order("created_at DESC")
  ....
  #write the required code
end

app/views/pages/display_city.html.erb
  #your code to display the city
</code>```

Body:
I am building an app for users to submit "adventures" and I would like to have individual pages set up to display adventures by city. I followed this advice (Ruby on Rails 4: Display Search Results on Search Results Page) to have search results display on a separate page and that works very well, but I would like to take it further and have pre-set links to route users to city-specific adventures. I'm not sure how to get the results from http://localhost:3000/adventures/search?utf8=%E2%9C%93&search=Tokyo to display on http://localhost:3000/pages/tokyo. Also, I am very new to Rails; this is my first project.

routes.rb

  root 'adventures#index'
  resources :adventures do
    collection do
      get :search
    end
  end

adventures_controller

  def search
    if params[:search]
      @adventures = Adventure.search(params[:search]).order("created_at DESC")
    else
      @adventures = Adventure.all.order("created_at DESC")
    end
  end

Body:
Build a custom route for pages. something like

get "/pages/:city", to: "pages#display_city", as: "display_city"

and redirect to that with the params[:search]

def search
  if params[:search]
    #this won't be needed here
    #@adventures = Adventure.search(params[:search]).order("created_at DESC")
    redirect_to display_city_path(params[:search])
  else
    @adventures = Adventure.all.order("created_at DESC")
  end
end

Have a controller#action and view for that corresponding route.

#pages_controller

def display_city
  @adventures = Adventure.search(params[:city]).order("created_at DESC")
  ....
  #write the required code
end

app/views/pages/display_city.html.erb
  #your code to display the city


问:
How to line up each word in a list so that entries start at the same point horizontally?
Here's an example I've changed slightly from a previous SO question:
http://jsfiddle.net/tPjQR/72/

ol {
    font-family: Georgia, serif;
}
ol span {
    font-family: Arial, sans-serif;
    font-size: 17px
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ol>
    <li><span>Entry one</span></li>
    <li><span>Entry two</span></li>
    <li><span>Entrye three</span></li>
    <li><span>Entry five</span></li>
    <li><span>Entry six</span></li>
    <li><span>Entry Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long</span></li>
</ol></code>```

I would like to line up the columns so that, no matter how much text is in one column, the first characters of each column will be lined up.

E.g.

not

```<code>Entry one
Entry two
Entrye three
Entry five
Entry six
</code>```

rather

```<code>Entry  one
Entry  two
Entrye three
Entry  five
Entry  six
</code>```

Is there a way to do this with list items, or do I need to use a table?

答:
Use the below code to get that design...

li span {
    display:inline-block;
    width: 25%;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ol>
    <li><span>Entry</span> one</li>
    <li><span>Entry</span> two</li>
    <li><span>Entrye</span> three</li>
    <li><span>Entry</span> five</li>
    <li><span>Entry</span> six</li>
</ol></code>```

Body:
Here's an example I've changed slightly from a previous SO question:
http://jsfiddle.net/tPjQR/72/

ol {
    font-family: Georgia, serif;
}
ol span {
    font-family: Arial, sans-serif;
    font-size: 17px
}

Entry one

Entry two

Entrye three

Entry five

Entry six

Entry Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long

I would like to line up the columns so that, no matter how much text is in one column, the first characters of each column will be lined up.

E.g.

not

Entry one
Entry two
Entrye three
Entry five
Entry six

rather

Entry  one
Entry  two
Entrye three
Entry  five
Entry  six

Is there a way to do this with list items, or do I need to use a table?

Body:
Use the below code to get that design...

li span {
    display:inline-block;
    width: 25%;
}

<ol>
    <li><span>Entry</span> one</li>
    <li><span>Entry</span> two</li>
    <li><span>Entrye</span> three</li>
    <li><span>Entry</span> five</li>
    <li><span>Entry</span> six</li>
</ol>


问:
Spark scala dataframe finding max
I am using following to find the max column value.

```<code>  val d = sqlContext.sql("select max(date), id from myTable group By id")
</code>```

How to do the same query on DataFrame without registering temp table.

thanks,

答:
if you have a dataframe with id and date column, what you can do n spark 2.0.1 is </p>

```<code>from pyspark.sql.functions import max
 mydf.groupBy('date').agg({'id':'max'}).show()
</code>```

Title: Spark scala dataframe finding max

Body:
I am using following to find the max column value.

  val d = sqlContext.sql("select max(date), id from myTable group By id")

How to do the same query on DataFrame without registering temp table.

thanks,

Body:
if you have a dataframe with id and date column, what you can do n spark 2.0.1 is

from pyspark.sql.functions import max
 mydf.groupBy('date').agg({'id':'max'}).show()