问:
Using ffmpeg for streaming video composition from Python : why the sound is cut only when streaming into a mp4 file ?
I am using ffmpeg within Python for automatizing some video compositions. To do so, I am using the subprocess module of Python and run a ffmpeg command with a pipe input. This allows me to stream frame by frame the video composition from my array of raw images (numpy matrices) into ffmpeg. In the following example, I reduced the video composition to a simple video of a duration of 12 seconds. The produced ffmpeg command is :

```<code>ffmpeg -i stream_audio.mp3 -re -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt rgb24 -r 25 -i - -map 0:a -map 1:v -y -strict -2 -f mp4 -pix_fmt yuv420p out.mp4
</code>```

The file stream_audio.mp3 is a well formed mp3 file corresponding to the audio output of the output mp4 file. However, the sound in the output file out.mp4 is cut 3 seconds before the end.

If I am trying to output any other format (for example avi), I do not observe this problem. The following command produces a well formed avi file.

```<code> ffmpeg -i ./stream_audio.mp3 -re -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt rgb24 -r 25 -i - -map 0:a -map 1:v -y -b 4096k -f avi -pix_fmt yuv420p out.avi
</code>```

I tried to reproduce the bug with the most simple ffmpeg command without passing by Python, but did not succeed.The closest I have done is the following :

Building a raw video file with the correct specifications

```<code>ffmpeg -i samplevideo.mp4 -f rawvideo -vcodec rawvideo -acodec none -s 1280x720 -pix_fmt rgb24 -r 25 samplevideo.raw
</code>```

Streaming the  raw video file into the ffmpeg command

```<code>cat samplevideo.raw | ffmpeg -i /tmp/stream_audio.mp3 -re -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt rgb24 -r 25 -i - -map 0:a -map 1:v
-y -strict -2 -f mp4 -pix_fmt yuv420p  -ss 00:00:00 -t 00:00:12 out.mp4
</code>```

Here is the version of ffmpeg I am using :

```<code>ffmpeg version 3.1.9 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.1 (GCC) 20161221 (Red Hat 6.3.1-1)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld' --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --extra-cflags=-I/usr/include/nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Hyper fast Audio and Video encoder
</code>```

The file samplevideo.mp4 can be found here : sample videos, the stream_audio.mp3 file is a simple extraction of the audio track of the samplevideo.mp4 file :

```<code>ffmpeg -i samplevideo.mp4 stream_audio.mp3
</code>```

Thanks for your help.

p.s : Here are the different logs of the ffmpeg commands :

Command generated by my Python script with mp4 :

```<code>Input #0, mp3, from './stream_audio.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:29.59, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc57.48
Input #1, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
    Stream #1:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0xf5cb748ac0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xf5cb748ac0] profile High, level 3.1
[libx264 @ 0xf5cb748ac0] 264 - core 148 r2708 86b7198 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=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
[mp4 @ 0xf5cb7462a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
    Stream #0:0: Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.48.101 aac
    Stream #0:1: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.48.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (native) -> aac (native))
  Stream #1:0 -> #0:1 (rawvideo (native) -> h264 (libx264))
[rawvideo @ 0xf5cb722860] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=   14 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   27 fps= 27 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   40 fps= 26 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   52 fps= 26 q=28.0 size=     113kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   65 fps= 26 q=28.0 size=     188kB time=00:00:00.49 bitrate=3145.8kbits/s speed=0.194x
frame=   77 fps= 25 q=28.0 size=     320kB time=00:00:01.00 bitrate=2615.3kbits/s speed=0.331x
frame=   90 fps= 25 q=28.0 size=     450kB time=00:00:01.51 bitrate=2431.3kbits/s speed=0.428x
frame=  103 fps= 25 q=28.0 size=     592kB time=00:00:02.00 bitrate=2418.9kbits/s speed=0.496x
frame=  116 fps= 25 q=28.0 size=     731kB time=00:00:02.52 bitrate=2376.1kbits/s speed=0.554x
frame=  128 fps= 25 q=28.0 size=     849kB time=00:00:03.02 bitrate=2295.6kbits/s speed=0.599x
frame=  141 fps= 25 q=28.0 size=     931kB time=00:00:03.54 bitrate=2153.0kbits/s speed=0.637x
frame=  153 fps= 25 q=28.0 size=     983kB time=00:00:04.03 bitrate=1996.7kbits/s speed=0.665x
frame=  166 fps= 25 q=28.0 size=    1067kB time=00:00:04.56 bitrate=1914.5kbits/s speed=0.695x
frame=  179 fps= 25 q=28.0 size=    1123kB time=00:00:05.04 bitrate=1824.8kbits/s speed=0.712x
frame=  191 fps= 25 q=28.0 size=    1213kB time=00:00:05.54 bitrate=1791.0kbits/s speed=0.732x
frame=  204 fps= 25 q=28.0 size=    1271kB time=00:00:06.05 bitrate=1718.5kbits/s speed=0.749x
frame=  217 fps= 25 q=28.0 size=    1346kB time=00:00:06.57 bitrate=1678.1kbits/s speed=0.764x
frame=  230 fps= 25 q=28.0 size=    1452kB time=00:00:07.08 bitrate=1678.9kbits/s speed=0.778x
frame=  242 fps= 25 q=28.0 size=    1567kB time=00:00:07.59 bitrate=1690.3kbits/s speed=0.79x
frame=  255 fps= 25 q=28.0 size=    1660kB time=00:00:08.08 bitrate=1682.4kbits/s speed=0.799x
frame=  267 fps= 25 q=28.0 size=    1739kB time=00:00:08.59 bitrate=1657.1kbits/s speed=0.81x
frame=  280 fps= 25 q=28.0 size=    1751kB time=00:00:09.08 bitrate=1578.1kbits/s speed=0.817x
frame=  291 fps= 24 q=-1.0 Lsize=    1864kB time=00:00:11.52 bitrate=1325.7kbits/s speed=0.954x
video:1707kB audio:149kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.437266%
[aac @ 0xf5cb747540] Qavg: 202.422
[libx264 @ 0xf5cb748ac0] frame I:2     Avg QP:15.83  size: 78710
[libx264 @ 0xf5cb748ac0] frame P:183   Avg QP:21.13  size:  7293
[libx264 @ 0xf5cb748ac0] frame B:106   Avg QP:26.82  size:  2406
[libx264 @ 0xf5cb748ac0] consecutive B-frames: 47.8% 10.3%  2.1% 39.9%
[libx264 @ 0xf5cb748ac0] mb I  I16..4: 22.1% 32.5% 45.4%
[libx264 @ 0xf5cb748ac0] mb P  I16..4:  0.8%  1.4%  0.2%  P16..4: 25.3%  6.3%  3.1%  0.0%  0.0%    skip:62.9%
[libx264 @ 0xf5cb748ac0] mb B  I16..4:  0.1%  0.2%  0.0%  B16..8: 39.0%  1.7%  0.2%  direct: 0.4%  skip:58.5%  L0:47.3% L1:49.6% BI: 3.1%
[libx264 @ 0xf5cb748ac0] 8x8 transform intra:50.3% inter:57.9%
[libx264 @ 0xf5cb748ac0] coded y,uvDC,uvAC intra: 49.5% 65.3% 23.0% inter: 7.8% 10.2% 0.5%
[libx264 @ 0xf5cb748ac0] i16 v,h,dc,p: 30% 32% 11% 27%
[libx264 @ 0xf5cb748ac0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 21% 23%  4%  5%  7%  5%  5%  5%
[libx264 @ 0xf5cb748ac0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 15% 11%  8%  8%  9%  7% 12%  7%
[libx264 @ 0xf5cb748ac0] i8c dc,h,v,p: 51% 20% 21%  8%
[libx264 @ 0xf5cb748ac0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0xf5cb748ac0] ref P L0: 79.8% 11.4%  7.6%  1.2%
[libx264 @ 0xf5cb748ac0] ref B L0: 96.9%  2.8%  0.4%
[libx264 @ 0xf5cb748ac0] ref B L1: 97.7%  2.3%
[libx264 @ 0xf5cb748ac0] kb/s:1200.72
Exiting normally, received signal 15.
</code>```

Command generated by my Python script with avi :

```<code>Input #0, mp3, from './stream_audio.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:29.59, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc57.48
Input #1, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
    Stream #1:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
[avi @ 0x82147c30e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, avi, to 'out.avi':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    ISFT            : Lavf57.41.100
    Stream #0:0: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p
    Metadata:
      encoder         : Lavc57.48.101 libmp3lame
    Stream #0:1: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1280x720, q=2-31, 4096 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.48.101 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/4096000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (native) -> mp3 (libmp3lame))
  Stream #1:0 -> #0:1 (rawvideo (native) -> mpeg4 (native))
[rawvideo @ 0x821479f820] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=   14 fps=0.0 q=2.6 size=     553kB time=00:00:00.56 bitrate=8082.6kbits/s speed= 1.1x
frame=   27 fps= 27 q=5.4 size=     858kB time=00:00:01.08 bitrate=6507.5kbits/s speed=1.06x
frame=   40 fps= 26 q=5.9 size=    1089kB time=00:00:01.60 bitrate=5574.9kbits/s speed=1.05x
frame=   52 fps= 26 q=5.5 size=    1332kB time=00:00:02.08 bitrate=5225.6kbits/s speed=1.03x
frame=   65 fps= 26 q=4.9 size=    1582kB time=00:00:02.60 bitrate=4985.6kbits/s speed=1.03x
frame=   78 fps= 26 q=4.3 size=    1816kB time=00:00:03.12 bitrate=4768.1kbits/s speed=1.03x
frame=   90 fps= 25 q=2.8 size=    2035kB time=00:00:03.60 bitrate=4631.7kbits/s speed=1.02x
frame=  103 fps= 25 q=2.3 size=    2288kB time=00:00:04.12 bitrate=4549.8kbits/s speed=1.02x
frame=  116 fps= 25 q=2.4 size=    2558kB time=00:00:04.64 bitrate=4516.3kbits/s speed=1.02x
frame=  128 fps= 25 q=2.3 size=    2835kB time=00:00:05.12 bitrate=4535.4kbits/s speed=1.01x
frame=  141 fps= 25 q=3.1 size=    3103kB time=00:00:05.64 bitrate=4506.6kbits/s speed=1.01x
frame=  154 fps= 25 q=2.8 size=    3381kB time=00:00:06.16 bitrate=4495.9kbits/s speed=1.01x
frame=  166 fps= 25 q=3.4 size=    3648kB time=00:00:06.64 bitrate=4494.9kbits/s speed=1.01x
frame=  179 fps= 25 q=3.3 size=    3894kB time=00:00:07.16 bitrate=4455.7kbits/s speed=1.01x
frame=  192 fps= 25 q=3.2 size=    4128kB time=00:00:07.68 bitrate=4402.9kbits/s speed=1.01x
frame=  204 fps= 25 q=3.4 size=    4404kB time=00:00:08.16 bitrate=4420.9kbits/s speed=1.01x
frame=  217 fps= 25 q=2.0 size=    4592kB time=00:00:08.68 bitrate=4334.0kbits/s speed=1.01x
frame=  230 fps= 25 q=2.0 size=    4657kB time=00:00:09.20 bitrate=4147.2kbits/s speed=1.01x
frame=  242 fps= 25 q=2.0 size=    4736kB time=00:00:09.68 bitrate=4007.9kbits/s speed=1.01x
frame=  255 fps= 25 q=2.0 size=    4830kB time=00:00:10.20 bitrate=3879.0kbits/s speed=1.01x
frame=  267 fps= 25 q=2.0 size=    4953kB time=00:00:10.68 bitrate=3799.5kbits/s speed=1.01x
frame=  280 fps= 25 q=2.0 size=    5093kB time=00:00:11.20 bitrate=3722.3kbits/s speed=1.01x
frame=  291 fps= 25 q=2.0 Lsize=    5209kB time=00:00:11.68 bitrate=3650.9kbits/s speed=1.01x
video:4998kB audio:183kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.542552%
Exiting normally, received signal 15.
</code>```

Pure command line for mp4 format :

```<code>Input #0, mp3, from './stream_audio.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:29.59, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc57.48
Input #1, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
    Stream #1:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x75fc583aa0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x75fc583aa0] profile High, level 3.1
[libx264 @ 0x75fc583aa0] 264 - core 148 r2708 86b7198 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=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
[mp4 @ 0x75fc581280] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
    Stream #0:0: Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.48.101 aac
    Stream #0:1: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.48.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (native) -> aac (native))
  Stream #1:0 -> #0:1 (rawvideo (native) -> h264 (libx264))
[rawvideo @ 0x75fc55d840] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=   14 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   27 fps= 27 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   39 fps= 26 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   52 fps= 26 q=28.0 size=     113kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   65 fps= 26 q=28.0 size=     188kB time=00:00:00.48 bitrate=3209.4kbits/s speed=0.191x
frame=   77 fps= 26 q=28.0 size=     320kB time=00:00:01.00 bitrate=2615.3kbits/s speed=0.332x
frame=   90 fps= 26 q=28.0 size=     450kB time=00:00:01.51 bitrate=2431.3kbits/s speed=0.43x
frame=  102 fps= 25 q=28.0 size=     591kB time=00:00:01.98 bitrate=2442.1kbits/s speed=0.493x
frame=  115 fps= 25 q=28.0 size=     731kB time=00:00:02.51 bitrate=2377.6kbits/s speed=0.556x
frame=  128 fps= 25 q=28.0 size=     845kB time=00:00:03.00 bitrate=2307.7kbits/s speed=0.596x
frame=  140 fps= 25 q=28.0 size=     930kB time=00:00:03.52 bitrate=2164.6kbits/s speed=0.636x
frame=  153 fps= 25 q=28.0 size=     983kB time=00:00:04.03 bitrate=1996.7kbits/s speed=0.668x
frame=  165 fps= 25 q=28.0 size=    1063kB time=00:00:04.52 bitrate=1925.2kbits/s speed=0.691x
frame=  178 fps= 25 q=28.0 size=    1122kB time=00:00:05.03 bitrate=1826.2kbits/s speed=0.714x
frame=  191 fps= 25 q=28.0 size=    1203kB time=00:00:05.52 bitrate=1783.6kbits/s speed=0.732x
frame=  203 fps= 25 q=28.0 size=    1270kB time=00:00:06.03 bitrate=1723.7kbits/s speed=0.749x
frame=  216 fps= 25 q=28.0 size=    1339kB time=00:00:06.52 bitrate=1680.5kbits/s speed=0.763x
frame=  228 fps= 25 q=28.0 size=    1443kB time=00:00:07.06 bitrate=1674.1kbits/s speed=0.779x
frame=  241 fps= 25 q=28.0 size=    1558kB time=00:00:07.55 bitrate=1690.0kbits/s speed=0.789x
frame=  254 fps= 25 q=28.0 size=    1654kB time=00:00:08.04 bitrate=1685.0kbits/s speed=0.799x
frame=  266 fps= 25 q=28.0 size=    1738kB time=00:00:08.55 bitrate=1664.6kbits/s speed=0.809x
frame=  279 fps= 25 q=28.0 size=    1750kB time=00:00:09.06 bitrate=1581.2kbits/s speed=0.818x
frame=  291 fps= 25 q=28.0 size=    1765kB time=00:00:09.55 bitrate=1512.7kbits/s speed=0.825x
frame=  300 fps= 25 q=28.0 size=    1779kB time=00:00:11.73 bitrate=1242.1kbits/s speed=0.971x
frame=  300 fps= 24 q=-1.0 Lsize=    1917kB time=00:00:12.01 bitrate=1307.2kbits/s speed=0.955x
video:1720kB audio:188kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.488004%
[aac @ 0x75fc582520] Qavg: 221.585
[libx264 @ 0x75fc583aa0] frame I:2     Avg QP:15.83  size: 78710
[libx264 @ 0x75fc583aa0] frame P:185   Avg QP:21.02  size:  7259
[libx264 @ 0x75fc583aa0] frame B:113   Avg QP:26.59  size:  2298
[libx264 @ 0x75fc583aa0] consecutive B-frames: 46.3% 10.0%  1.0% 42.7%
[libx264 @ 0x75fc583aa0] mb I  I16..4: 22.1% 32.5% 45.4%
[libx264 @ 0x75fc583aa0] mb P  I16..4:  0.8%  1.4%  0.2%  P16..4: 25.2%  6.3%  3.1%  0.0%  0.0%    skip:63.0%
[libx264 @ 0x75fc583aa0] mb B  I16..4:  0.1%  0.2%  0.0%  B16..8: 37.3%  1.6%  0.2%  direct: 0.4%  skip:60.2%  L0:47.3% L1:49.6% BI: 3.0%
[libx264 @ 0x75fc583aa0] 8x8 transform intra:50.5% inter:58.1%
[libx264 @ 0x75fc583aa0] coded y,uvDC,uvAC intra: 49.4% 65.2% 22.9% inter: 7.7% 10.0% 0.5%
[libx264 @ 0x75fc583aa0] i16 v,h,dc,p: 29% 32% 11% 28%
[libx264 @ 0x75fc583aa0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 21% 23%  4%  5%  6%  5%  5%  5%
[libx264 @ 0x75fc583aa0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 15% 11%  8%  8%  9%  7% 12%  7%
[libx264 @ 0x75fc583aa0] i8c dc,h,v,p: 51% 20% 21%  8%
[libx264 @ 0x75fc583aa0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x75fc583aa0] ref P L0: 79.7% 11.4%  7.7%  1.2%
[libx264 @ 0x75fc583aa0] ref B L0: 96.8%  2.9%  0.4%
[libx264 @ 0x75fc583aa0] ref B L1: 97.7%  2.3%
[libx264 @ 0x75fc583aa0] kb/s:1173.39
</code>```

答:
I finally found the trouble. In python, the ffmpeg command was ran using the subprocess module. Each image of the input video was put in a pipe to ffmpeg. At the end of the iteration, the process was killed.

However, the audio and video encoding were not performed in parallel : the audio encoding was not terminated at the end of the video encoding. As a result, the ffmpeg command was killed before the audio was terminated.

Body:
I am using ffmpeg within Python for automatizing some video compositions. To do so, I am using the subprocess module of Python and run a ffmpeg command with a pipe input. This allows me to stream frame by frame the video composition from my array of raw images (numpy matrices) into ffmpeg. In the following example, I reduced the video composition to a simple video of a duration of 12 seconds. The produced ffmpeg command is :

ffmpeg -i stream_audio.mp3 -re -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt rgb24 -r 25 -i - -map 0:a -map 1:v -y -strict -2 -f mp4 -pix_fmt yuv420p out.mp4

The file stream_audio.mp3 is a well formed mp3 file corresponding to the audio output of the output mp4 file. However, the sound in the output file out.mp4 is cut 3 seconds before the end.

If I am trying to output any other format (for example avi), I do not observe this problem. The following command produces a well formed avi file.

 ffmpeg -i ./stream_audio.mp3 -re -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt rgb24 -r 25 -i - -map 0:a -map 1:v -y -b 4096k -f avi -pix_fmt yuv420p out.avi

I tried to reproduce the bug with the most simple ffmpeg command without passing by Python, but did not succeed.The closest I have done is the following :

Building a raw video file with the correct specifications

ffmpeg -i samplevideo.mp4 -f rawvideo -vcodec rawvideo -acodec none -s 1280x720 -pix_fmt rgb24 -r 25 samplevideo.raw

Streaming the  raw video file into the ffmpeg command

cat samplevideo.raw | ffmpeg -i /tmp/stream_audio.mp3 -re -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt rgb24 -r 25 -i - -map 0:a -map 1:v
-y -strict -2 -f mp4 -pix_fmt yuv420p  -ss 00:00:00 -t 00:00:12 out.mp4

Here is the version of ffmpeg I am using :

ffmpeg version 3.1.9 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.1 (GCC) 20161221 (Red Hat 6.3.1-1)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld' --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --extra-cflags=-I/usr/include/nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Hyper fast Audio and Video encoder

The file samplevideo.mp4 can be found here : sample videos, the stream_audio.mp3 file is a simple extraction of the audio track of the samplevideo.mp4 file :

ffmpeg -i samplevideo.mp4 stream_audio.mp3

Thanks for your help.

p.s : Here are the different logs of the ffmpeg commands :

Command generated by my Python script with mp4 :

Input #0, mp3, from './stream_audio.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:29.59, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc57.48
Input #1, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
    Stream #1:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0xf5cb748ac0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xf5cb748ac0] profile High, level 3.1
[libx264 @ 0xf5cb748ac0] 264 - core 148 r2708 86b7198 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=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
[mp4 @ 0xf5cb7462a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
    Stream #0:0: Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.48.101 aac
    Stream #0:1: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.48.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (native) -> aac (native))
  Stream #1:0 -> #0:1 (rawvideo (native) -> h264 (libx264))
[rawvideo @ 0xf5cb722860] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=   14 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   27 fps= 27 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   40 fps= 26 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   52 fps= 26 q=28.0 size=     113kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   65 fps= 26 q=28.0 size=     188kB time=00:00:00.49 bitrate=3145.8kbits/s speed=0.194x
frame=   77 fps= 25 q=28.0 size=     320kB time=00:00:01.00 bitrate=2615.3kbits/s speed=0.331x
frame=   90 fps= 25 q=28.0 size=     450kB time=00:00:01.51 bitrate=2431.3kbits/s speed=0.428x
frame=  103 fps= 25 q=28.0 size=     592kB time=00:00:02.00 bitrate=2418.9kbits/s speed=0.496x
frame=  116 fps= 25 q=28.0 size=     731kB time=00:00:02.52 bitrate=2376.1kbits/s speed=0.554x
frame=  128 fps= 25 q=28.0 size=     849kB time=00:00:03.02 bitrate=2295.6kbits/s speed=0.599x
frame=  141 fps= 25 q=28.0 size=     931kB time=00:00:03.54 bitrate=2153.0kbits/s speed=0.637x
frame=  153 fps= 25 q=28.0 size=     983kB time=00:00:04.03 bitrate=1996.7kbits/s speed=0.665x
frame=  166 fps= 25 q=28.0 size=    1067kB time=00:00:04.56 bitrate=1914.5kbits/s speed=0.695x
frame=  179 fps= 25 q=28.0 size=    1123kB time=00:00:05.04 bitrate=1824.8kbits/s speed=0.712x
frame=  191 fps= 25 q=28.0 size=    1213kB time=00:00:05.54 bitrate=1791.0kbits/s speed=0.732x
frame=  204 fps= 25 q=28.0 size=    1271kB time=00:00:06.05 bitrate=1718.5kbits/s speed=0.749x
frame=  217 fps= 25 q=28.0 size=    1346kB time=00:00:06.57 bitrate=1678.1kbits/s speed=0.764x
frame=  230 fps= 25 q=28.0 size=    1452kB time=00:00:07.08 bitrate=1678.9kbits/s speed=0.778x
frame=  242 fps= 25 q=28.0 size=    1567kB time=00:00:07.59 bitrate=1690.3kbits/s speed=0.79x
frame=  255 fps= 25 q=28.0 size=    1660kB time=00:00:08.08 bitrate=1682.4kbits/s speed=0.799x
frame=  267 fps= 25 q=28.0 size=    1739kB time=00:00:08.59 bitrate=1657.1kbits/s speed=0.81x
frame=  280 fps= 25 q=28.0 size=    1751kB time=00:00:09.08 bitrate=1578.1kbits/s speed=0.817x
frame=  291 fps= 24 q=-1.0 Lsize=    1864kB time=00:00:11.52 bitrate=1325.7kbits/s speed=0.954x
video:1707kB audio:149kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.437266%
[aac @ 0xf5cb747540] Qavg: 202.422
[libx264 @ 0xf5cb748ac0] frame I:2     Avg QP:15.83  size: 78710
[libx264 @ 0xf5cb748ac0] frame P:183   Avg QP:21.13  size:  7293
[libx264 @ 0xf5cb748ac0] frame B:106   Avg QP:26.82  size:  2406
[libx264 @ 0xf5cb748ac0] consecutive B-frames: 47.8% 10.3%  2.1% 39.9%
[libx264 @ 0xf5cb748ac0] mb I  I16..4: 22.1% 32.5% 45.4%
[libx264 @ 0xf5cb748ac0] mb P  I16..4:  0.8%  1.4%  0.2%  P16..4: 25.3%  6.3%  3.1%  0.0%  0.0%    skip:62.9%
[libx264 @ 0xf5cb748ac0] mb B  I16..4:  0.1%  0.2%  0.0%  B16..8: 39.0%  1.7%  0.2%  direct: 0.4%  skip:58.5%  L0:47.3% L1:49.6% BI: 3.1%
[libx264 @ 0xf5cb748ac0] 8x8 transform intra:50.3% inter:57.9%
[libx264 @ 0xf5cb748ac0] coded y,uvDC,uvAC intra: 49.5% 65.3% 23.0% inter: 7.8% 10.2% 0.5%
[libx264 @ 0xf5cb748ac0] i16 v,h,dc,p: 30% 32% 11% 27%
[libx264 @ 0xf5cb748ac0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 21% 23%  4%  5%  7%  5%  5%  5%
[libx264 @ 0xf5cb748ac0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 15% 11%  8%  8%  9%  7% 12%  7%
[libx264 @ 0xf5cb748ac0] i8c dc,h,v,p: 51% 20% 21%  8%
[libx264 @ 0xf5cb748ac0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0xf5cb748ac0] ref P L0: 79.8% 11.4%  7.6%  1.2%
[libx264 @ 0xf5cb748ac0] ref B L0: 96.9%  2.8%  0.4%
[libx264 @ 0xf5cb748ac0] ref B L1: 97.7%  2.3%
[libx264 @ 0xf5cb748ac0] kb/s:1200.72
Exiting normally, received signal 15.

Command generated by my Python script with avi :

Input #0, mp3, from './stream_audio.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:29.59, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc57.48
Input #1, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
    Stream #1:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
[avi @ 0x82147c30e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, avi, to 'out.avi':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    ISFT            : Lavf57.41.100
    Stream #0:0: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p
    Metadata:
      encoder         : Lavc57.48.101 libmp3lame
    Stream #0:1: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1280x720, q=2-31, 4096 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.48.101 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/4096000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (native) -> mp3 (libmp3lame))
  Stream #1:0 -> #0:1 (rawvideo (native) -> mpeg4 (native))
[rawvideo @ 0x821479f820] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=   14 fps=0.0 q=2.6 size=     553kB time=00:00:00.56 bitrate=8082.6kbits/s speed= 1.1x
frame=   27 fps= 27 q=5.4 size=     858kB time=00:00:01.08 bitrate=6507.5kbits/s speed=1.06x
frame=   40 fps= 26 q=5.9 size=    1089kB time=00:00:01.60 bitrate=5574.9kbits/s speed=1.05x
frame=   52 fps= 26 q=5.5 size=    1332kB time=00:00:02.08 bitrate=5225.6kbits/s speed=1.03x
frame=   65 fps= 26 q=4.9 size=    1582kB time=00:00:02.60 bitrate=4985.6kbits/s speed=1.03x
frame=   78 fps= 26 q=4.3 size=    1816kB time=00:00:03.12 bitrate=4768.1kbits/s speed=1.03x
frame=   90 fps= 25 q=2.8 size=    2035kB time=00:00:03.60 bitrate=4631.7kbits/s speed=1.02x
frame=  103 fps= 25 q=2.3 size=    2288kB time=00:00:04.12 bitrate=4549.8kbits/s speed=1.02x
frame=  116 fps= 25 q=2.4 size=    2558kB time=00:00:04.64 bitrate=4516.3kbits/s speed=1.02x
frame=  128 fps= 25 q=2.3 size=    2835kB time=00:00:05.12 bitrate=4535.4kbits/s speed=1.01x
frame=  141 fps= 25 q=3.1 size=    3103kB time=00:00:05.64 bitrate=4506.6kbits/s speed=1.01x
frame=  154 fps= 25 q=2.8 size=    3381kB time=00:00:06.16 bitrate=4495.9kbits/s speed=1.01x
frame=  166 fps= 25 q=3.4 size=    3648kB time=00:00:06.64 bitrate=4494.9kbits/s speed=1.01x
frame=  179 fps= 25 q=3.3 size=    3894kB time=00:00:07.16 bitrate=4455.7kbits/s speed=1.01x
frame=  192 fps= 25 q=3.2 size=    4128kB time=00:00:07.68 bitrate=4402.9kbits/s speed=1.01x
frame=  204 fps= 25 q=3.4 size=    4404kB time=00:00:08.16 bitrate=4420.9kbits/s speed=1.01x
frame=  217 fps= 25 q=2.0 size=    4592kB time=00:00:08.68 bitrate=4334.0kbits/s speed=1.01x
frame=  230 fps= 25 q=2.0 size=    4657kB time=00:00:09.20 bitrate=4147.2kbits/s speed=1.01x
frame=  242 fps= 25 q=2.0 size=    4736kB time=00:00:09.68 bitrate=4007.9kbits/s speed=1.01x
frame=  255 fps= 25 q=2.0 size=    4830kB time=00:00:10.20 bitrate=3879.0kbits/s speed=1.01x
frame=  267 fps= 25 q=2.0 size=    4953kB time=00:00:10.68 bitrate=3799.5kbits/s speed=1.01x
frame=  280 fps= 25 q=2.0 size=    5093kB time=00:00:11.20 bitrate=3722.3kbits/s speed=1.01x
frame=  291 fps= 25 q=2.0 Lsize=    5209kB time=00:00:11.68 bitrate=3650.9kbits/s speed=1.01x
video:4998kB audio:183kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.542552%
Exiting normally, received signal 15.

Pure command line for mp4 format :

Input #0, mp3, from './stream_audio.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:29.59, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc57.48
Input #1, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
    Stream #1:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x75fc583aa0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x75fc583aa0] profile High, level 3.1
[libx264 @ 0x75fc583aa0] 264 - core 148 r2708 86b7198 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=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
[mp4 @ 0x75fc581280] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
    Stream #0:0: Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.48.101 aac
    Stream #0:1: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.48.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (native) -> aac (native))
  Stream #1:0 -> #0:1 (rawvideo (native) -> h264 (libx264))
[rawvideo @ 0x75fc55d840] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=   14 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   27 fps= 27 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   39 fps= 26 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   52 fps= 26 q=28.0 size=     113kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   65 fps= 26 q=28.0 size=     188kB time=00:00:00.48 bitrate=3209.4kbits/s speed=0.191x
frame=   77 fps= 26 q=28.0 size=     320kB time=00:00:01.00 bitrate=2615.3kbits/s speed=0.332x
frame=   90 fps= 26 q=28.0 size=     450kB time=00:00:01.51 bitrate=2431.3kbits/s speed=0.43x
frame=  102 fps= 25 q=28.0 size=     591kB time=00:00:01.98 bitrate=2442.1kbits/s speed=0.493x
frame=  115 fps= 25 q=28.0 size=     731kB time=00:00:02.51 bitrate=2377.6kbits/s speed=0.556x
frame=  128 fps= 25 q=28.0 size=     845kB time=00:00:03.00 bitrate=2307.7kbits/s speed=0.596x
frame=  140 fps= 25 q=28.0 size=     930kB time=00:00:03.52 bitrate=2164.6kbits/s speed=0.636x
frame=  153 fps= 25 q=28.0 size=     983kB time=00:00:04.03 bitrate=1996.7kbits/s speed=0.668x
frame=  165 fps= 25 q=28.0 size=    1063kB time=00:00:04.52 bitrate=1925.2kbits/s speed=0.691x
frame=  178 fps= 25 q=28.0 size=    1122kB time=00:00:05.03 bitrate=1826.2kbits/s speed=0.714x
frame=  191 fps= 25 q=28.0 size=    1203kB time=00:00:05.52 bitrate=1783.6kbits/s speed=0.732x
frame=  203 fps= 25 q=28.0 size=    1270kB time=00:00:06.03 bitrate=1723.7kbits/s speed=0.749x
frame=  216 fps= 25 q=28.0 size=    1339kB time=00:00:06.52 bitrate=1680.5kbits/s speed=0.763x
frame=  228 fps= 25 q=28.0 size=    1443kB time=00:00:07.06 bitrate=1674.1kbits/s speed=0.779x
frame=  241 fps= 25 q=28.0 size=    1558kB time=00:00:07.55 bitrate=1690.0kbits/s speed=0.789x
frame=  254 fps= 25 q=28.0 size=    1654kB time=00:00:08.04 bitrate=1685.0kbits/s speed=0.799x
frame=  266 fps= 25 q=28.0 size=    1738kB time=00:00:08.55 bitrate=1664.6kbits/s speed=0.809x
frame=  279 fps= 25 q=28.0 size=    1750kB time=00:00:09.06 bitrate=1581.2kbits/s speed=0.818x
frame=  291 fps= 25 q=28.0 size=    1765kB time=00:00:09.55 bitrate=1512.7kbits/s speed=0.825x
frame=  300 fps= 25 q=28.0 size=    1779kB time=00:00:11.73 bitrate=1242.1kbits/s speed=0.971x
frame=  300 fps= 24 q=-1.0 Lsize=    1917kB time=00:00:12.01 bitrate=1307.2kbits/s speed=0.955x
video:1720kB audio:188kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.488004%
[aac @ 0x75fc582520] Qavg: 221.585
[libx264 @ 0x75fc583aa0] frame I:2     Avg QP:15.83  size: 78710
[libx264 @ 0x75fc583aa0] frame P:185   Avg QP:21.02  size:  7259
[libx264 @ 0x75fc583aa0] frame B:113   Avg QP:26.59  size:  2298
[libx264 @ 0x75fc583aa0] consecutive B-frames: 46.3% 10.0%  1.0% 42.7%
[libx264 @ 0x75fc583aa0] mb I  I16..4: 22.1% 32.5% 45.4%
[libx264 @ 0x75fc583aa0] mb P  I16..4:  0.8%  1.4%  0.2%  P16..4: 25.2%  6.3%  3.1%  0.0%  0.0%    skip:63.0%
[libx264 @ 0x75fc583aa0] mb B  I16..4:  0.1%  0.2%  0.0%  B16..8: 37.3%  1.6%  0.2%  direct: 0.4%  skip:60.2%  L0:47.3% L1:49.6% BI: 3.0%
[libx264 @ 0x75fc583aa0] 8x8 transform intra:50.5% inter:58.1%
[libx264 @ 0x75fc583aa0] coded y,uvDC,uvAC intra: 49.4% 65.2% 22.9% inter: 7.7% 10.0% 0.5%
[libx264 @ 0x75fc583aa0] i16 v,h,dc,p: 29% 32% 11% 28%
[libx264 @ 0x75fc583aa0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 21% 23%  4%  5%  6%  5%  5%  5%
[libx264 @ 0x75fc583aa0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 15% 11%  8%  8%  9%  7% 12%  7%
[libx264 @ 0x75fc583aa0] i8c dc,h,v,p: 51% 20% 21%  8%
[libx264 @ 0x75fc583aa0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x75fc583aa0] ref P L0: 79.7% 11.4%  7.7%  1.2%
[libx264 @ 0x75fc583aa0] ref B L0: 96.8%  2.9%  0.4%
[libx264 @ 0x75fc583aa0] ref B L1: 97.7%  2.3%
[libx264 @ 0x75fc583aa0] kb/s:1173.39


来源: stackexchange

问:
Ajax form submit and get query strings and append to new page and redirect
I am looking for a way to submit a form using ajax, redirect to a URL and send the data on it, and also get the query strings on the URL. Basically, a normal GET request, This is what I tried

$('#searchform').submit(function(event) {
  $.ajax({
    type: "get",
    url: "/list",
    data: $("#searchform").serialize(),
    beforeSend: function() {
      $(".loader").show();
    },
    success: function(data) {
      location.href = "/list"; //redirect to list
      $("#ajaxcontent").empty(); //try to append data on this div, not sure how
      $("#ajaxcontent").append(data);
    }
  });
  event.preventDefault();
});
```

<p>I want to get the query string as such</p>

```/list?input1=thisinput&input2=anotherinput
```

<p>Same things as you receive from a GET request.</p>

<p>All in all, my only purpose of using ajax on this is to show the preloader.  </p>

<p>Will someone be kind and patient enough to help me explain how should I make my ajax request. I hope I have made myself understandable. </p>

<p>This is the form</p>

```<form method="GET" action="list" id="searchform" name="searchform">

    <input type="text" name="search1">
    <input type="text" name="search2">
    <input type="text" name="search3">
<button type="submit" id="submitz">Submit</button>
  </form>
```

答:
The problem here is that you're using two ways of communication with \list.

At first, you're sending an ajax request at \list (with the .ajax() function), this request contact \list, give it your form data, and send some data back (in the success function).

Next, you use a simple javascript redirection to \list without any data.

So you have to make a choice, either :

-keeping the ajax request (just drop the location.href = "/list"; then), but you'll stay on the same page (you are appending data just fine btw). It will require some content returned from \list, use and abuse of console.log(data); to see what you got here.

-dropping the ajax request for the simple redirection, but then the loader will be nearly invisible, since the page change will be quite fast. So you'll be better off without any JS. To test it :

```<code>$('#searchform').submit(function(event) {
  $(".loader").show();
  location.href = "/list?"+$("#searchform").serialize(); //redirect to list
  event.preventDefault();
});
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I am looking for a way to submit a form using ajax, redirect to a URL and send the data on it, and also get the query strings on the URL. Basically, a normal GET request, This is what I tried

$('#searchform').submit(function(event) {
  $.ajax({
    type: "get",
    url: "/list",
    data: $("#searchform").serialize(),
    beforeSend: function() {
      $(".loader").show();
    },
    success: function(data) {
      location.href = "/list"; //redirect to list
      $("#ajaxcontent").empty(); //try to append data on this div, not sure how
      $("#ajaxcontent").append(data);
    }
  });
  event.preventDefault();
});

I want to get the query string as such

/list?input1=thisinput&input2=anotherinput

Same things as you receive from a GET request.

All in all, my only purpose of using ajax on this is to show the preloader.

Will someone be kind and patient enough to help me explain how should I make my ajax request. I hope I have made myself understandable.

This is the form

<form method="GET" action="list" id="searchform" name="searchform">

    <input type="text" name="search1">
    <input type="text" name="search2">
    <input type="text" name="search3">
<button type="submit" id="submitz">Submit</button>
  </form>

Body:
The problem here is that you're using two ways of communication with \list.

At first, you're sending an ajax request at \list (with the .ajax() function), this request contact \list, give it your form data, and send some data back (in the success function).

Next, you use a simple javascript redirection to \list without any data.

So you have to make a choice, either :

-keeping the ajax request (just drop the location.href = "/list"; then), but you'll stay on the same page (you are appending data just fine btw). It will require some content returned from \list, use and abuse of console.log(data); to see what you got here.

-dropping the ajax request for the simple redirection, but then the loader will be nearly invisible, since the page change will be quite fast. So you'll be better off without any JS. To test it :

$('#searchform').submit(function(event) {
  $(".loader").show();
  location.href = "/list?"+$("#searchform").serialize(); //redirect to list
  event.preventDefault();
});


问:
Obtain relevant data from dictionaries in list
I'm trying to obtain information about my videos with certain tags on Vimeo. I've read through the API, but I can't find anything about requesting your videos which contain a certain tag. It only offers a tag search for public videos and a get all function for your own videos. So the only option it leaves me is to request all videos, then search through the dictionary for the relevant data.

However, Vimeo only allows you to request 100 videos at a time. Since there are more than 100 videos on my account I have to create a list of dictionaries to obtain all videos. This is the simplified list of dictionaries I'm talking about:

```<code>[{'data': [{'download': [{'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 360,
                      'link': 'https://player.vimeo.com/play/884123433?s=245200119_1512117636_a70a08b2710ec2c731c9d39729895c76&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights164.mp4',
                      'md5': 'f87ad14ecf73f27bc4fd2ff537f9cf9b',
                      'quality': 'sd',
                      'size': 128905331,
                      'type': 'video/mp4',
                      'width': 520},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884123432?s=245200119_1512117636_ffaf6e2eb391b06cff5e534dfd026204&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights169.mp4',
                      'md5': 'fe06de889adf38dceb92089427c4a0cc',
                      'quality': 'hd',
                      'size': 1072969191,
                      'type': 'video/mp4',
                      'width': 1560},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 720,
                      'link': 'https://player.vimeo.com/play/884123428?s=245200119_1512117636_4f7665421693d392a0e7caabb331c075&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights174.mp4',
                      'md5': '6b62e4aaa044f8802f6ba30c29047b69',
                      'quality': 'hd',
                      'size': 562614988,
                      'type': 'video/mp4',
                      'width': 1040},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 540,
                      'link': 'https://player.vimeo.com/play/884123427?s=245200119_1512117636_a1718ab65d37637e0406c8ab099f8f50&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights165.mp4',
                      'md5': '4d014ea00d0c8620869f5ad4c5b4e404',
                      'quality': 'sd',
                      'size': 364759333,
                      'type': 'video/mp4',
                      'width': 780},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884123417?s=245200119_1512117636_9c7ad015a30585c3cedb9429ffd0c9f2&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights175.mp4',
                      'md5': 'd73682a6385154a83fe1653176bf17ab',
                      'quality': 'hd',
                      'size': 1071546729,
                      'type': 'video/mp4',
                      'width': 1560},
                     {'created_time': '2017-11-30T14:51:00+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884114225?s=245200119_1512117636_034586db598d6b398ecf86fe7bb50fb7&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlightssource.webm',
                      'md5': '76bcb8c1cd19b7ffa4d59f7961bb3076',
                      'quality': 'source',
                      'size': 1429585788,
                      'type': 'source',
                      'width': 1560}],
        'tags': []},
    {'download': [{'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 540,
                      'link': 'https://player.vimeo.com/play/880414686?s=244460915_1512117636_e99e772d06f2be1f3e792e2eaf9649ab&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying165.mp4',
                      'md5': '8e920c971257c4578ce9a23bcd532b2a',
                      'quality': 'sd',
                      'size': 1913433310,
                      'type': 'video/mp4',
                      'width': 960},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 720,
                      'link': 'https://player.vimeo.com/play/880414685?s=244460915_1512117636_219ce4f61b0c8169d06951488b07a242&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying174.mp4',
                      'md5': 'c4a58556df95ca0ee2283793b6f099cb',
                      'quality': 'hd',
                      'size': 3090734703,
                      'type': 'video/mp4',
                      'width': 1280},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414684?s=244460915_1512117636_5ade2bfdffc7932dd0598bfff9f7ea58&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying169.mp4',
                      'md5': '019552bae7ca1c71e5964c54dbdf8949',
                      'quality': 'hd',
                      'size': 5891693868,
                      'type': 'video/mp4',
                      'width': 1920},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 360,
                      'link': 'https://player.vimeo.com/play/880414679?s=244460915_1512117636_4d1dc529cad10c2753b967987b3c6b06&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying164.mp4',
                      'md5': '3daca0303792d0b7506b3247e7b6ee99',
                      'quality': 'sd',
                      'size': 719988849,
                      'type': 'video/mp4',
                      'width': 640},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414677?s=244460915_1512117636_49c3975dd10c202fddd9e4e3418a150d&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying175.mp4',
                      'md5': 'f1f38a8aa8612d9fa1331410a3a153f1',
                      'quality': 'hd',
                      'size': 5883105557,
                      'type': 'video/mp4',
                      'width': 1920},
                     {'created_time': '2017-11-25T18:11:34+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414164?s=244460915_1512117636_4a9ae40250b8d5f1ab803973cb4617cc&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifyingsource.',
                      'md5': '21425a206698038bc9e8114698a187e9',
                      'quality': 'source',
                      'size': 7026953324,
                      'type': 'source',
                      'width': 1920}],
        'tags': [{'canonical': 'foo',
                  'metadata': {'connections': {'videos': {'options': ['GET'],
                                                          'total': 109,
                                                          'uri': '/tags/foo/videos'}}},
                  'name': 'Foo',
                  'resource_key': '3b4ab793385a07c695ef0081210c8fd586e2d890',
                  'tag': 'Foo',
                  'uri': '/tags/foo'},
                 {'canonical': '2017',
                  'metadata': {'connections': {'videos': {'options': ['GET'],
                                                          'total': 158765,
                                                          'uri': '/tags/2017/videos'}}},
                  'name': '2017',
                  'resource_key': 'a5c9f20cc79135f49b431c20b779e7b93bd26415',
                  'tag': '2017',
                  'uri': '/tags/2017'}]}]
},"second_dict"]
</code>```

What I want: I want to find all videos which contain the tag Foo, then get the download link from 'type': 'source'. So I want to end up with ["data"]["download"]["link"] where 'type':'source'.

I tried writing a bit of code which checks for tags and then creates a list with only the videos containing the 'Foo' tag:

```<code>videosFiltered = []
for entry in videos:
    for subentry in entry["data"]:
        if subentry["tags"] and subentry["tags"][0]["name"] == "Foo":
            videosFiltered.append()
</code>```

But as you can see I'm failing miserably, since I'm just writing terrifying nests of for loops and if loops. I'm pretty sure I will eventually get what I want, but I was hoping you could help me find a more elegant solution to this problem.

答:
/tags/:word/videos is the resource you're looking for. Hitting /tags/foo/videos should return a paginated list of videos that have the "foo" tag.

https://developer.vimeo.com/api/endpoints/tags#GET/tags/{word}/videos

Body:
I'm trying to obtain information about my videos with certain tags on Vimeo. I've read through the API, but I can't find anything about requesting your videos which contain a certain tag. It only offers a tag search for public videos and a get all function for your own videos. So the only option it leaves me is to request all videos, then search through the dictionary for the relevant data.

However, Vimeo only allows you to request 100 videos at a time. Since there are more than 100 videos on my account I have to create a list of dictionaries to obtain all videos. This is the simplified list of dictionaries I'm talking about:

[{'data': [{'download': [{'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 360,
                      'link': 'https://player.vimeo.com/play/884123433?s=245200119_1512117636_a70a08b2710ec2c731c9d39729895c76&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights164.mp4',
                      'md5': 'f87ad14ecf73f27bc4fd2ff537f9cf9b',
                      'quality': 'sd',
                      'size': 128905331,
                      'type': 'video/mp4',
                      'width': 520},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884123432?s=245200119_1512117636_ffaf6e2eb391b06cff5e534dfd026204&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights169.mp4',
                      'md5': 'fe06de889adf38dceb92089427c4a0cc',
                      'quality': 'hd',
                      'size': 1072969191,
                      'type': 'video/mp4',
                      'width': 1560},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 720,
                      'link': 'https://player.vimeo.com/play/884123428?s=245200119_1512117636_4f7665421693d392a0e7caabb331c075&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights174.mp4',
                      'md5': '6b62e4aaa044f8802f6ba30c29047b69',
                      'quality': 'hd',
                      'size': 562614988,
                      'type': 'video/mp4',
                      'width': 1040},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 540,
                      'link': 'https://player.vimeo.com/play/884123427?s=245200119_1512117636_a1718ab65d37637e0406c8ab099f8f50&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights165.mp4',
                      'md5': '4d014ea00d0c8620869f5ad4c5b4e404',
                      'quality': 'sd',
                      'size': 364759333,
                      'type': 'video/mp4',
                      'width': 780},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884123417?s=245200119_1512117636_9c7ad015a30585c3cedb9429ffd0c9f2&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights175.mp4',
                      'md5': 'd73682a6385154a83fe1653176bf17ab',
                      'quality': 'hd',
                      'size': 1071546729,
                      'type': 'video/mp4',
                      'width': 1560},
                     {'created_time': '2017-11-30T14:51:00+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884114225?s=245200119_1512117636_034586db598d6b398ecf86fe7bb50fb7&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlightssource.webm',
                      'md5': '76bcb8c1cd19b7ffa4d59f7961bb3076',
                      'quality': 'source',
                      'size': 1429585788,
                      'type': 'source',
                      'width': 1560}],
        'tags': []},
    {'download': [{'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 540,
                      'link': 'https://player.vimeo.com/play/880414686?s=244460915_1512117636_e99e772d06f2be1f3e792e2eaf9649ab&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying165.mp4',
                      'md5': '8e920c971257c4578ce9a23bcd532b2a',
                      'quality': 'sd',
                      'size': 1913433310,
                      'type': 'video/mp4',
                      'width': 960},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 720,
                      'link': 'https://player.vimeo.com/play/880414685?s=244460915_1512117636_219ce4f61b0c8169d06951488b07a242&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying174.mp4',
                      'md5': 'c4a58556df95ca0ee2283793b6f099cb',
                      'quality': 'hd',
                      'size': 3090734703,
                      'type': 'video/mp4',
                      'width': 1280},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414684?s=244460915_1512117636_5ade2bfdffc7932dd0598bfff9f7ea58&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying169.mp4',
                      'md5': '019552bae7ca1c71e5964c54dbdf8949',
                      'quality': 'hd',
                      'size': 5891693868,
                      'type': 'video/mp4',
                      'width': 1920},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 360,
                      'link': 'https://player.vimeo.com/play/880414679?s=244460915_1512117636_4d1dc529cad10c2753b967987b3c6b06&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying164.mp4',
                      'md5': '3daca0303792d0b7506b3247e7b6ee99',
                      'quality': 'sd',
                      'size': 719988849,
                      'type': 'video/mp4',
                      'width': 640},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414677?s=244460915_1512117636_49c3975dd10c202fddd9e4e3418a150d&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying175.mp4',
                      'md5': 'f1f38a8aa8612d9fa1331410a3a153f1',
                      'quality': 'hd',
                      'size': 5883105557,
                      'type': 'video/mp4',
                      'width': 1920},
                     {'created_time': '2017-11-25T18:11:34+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414164?s=244460915_1512117636_4a9ae40250b8d5f1ab803973cb4617cc&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifyingsource.',
                      'md5': '21425a206698038bc9e8114698a187e9',
                      'quality': 'source',
                      'size': 7026953324,
                      'type': 'source',
                      'width': 1920}],
        'tags': [{'canonical': 'foo',
                  'metadata': {'connections': {'videos': {'options': ['GET'],
                                                          'total': 109,
                                                          'uri': '/tags/foo/videos'}}},
                  'name': 'Foo',
                  'resource_key': '3b4ab793385a07c695ef0081210c8fd586e2d890',
                  'tag': 'Foo',
                  'uri': '/tags/foo'},
                 {'canonical': '2017',
                  'metadata': {'connections': {'videos': {'options': ['GET'],
                                                          'total': 158765,
                                                          'uri': '/tags/2017/videos'}}},
                  'name': '2017',
                  'resource_key': 'a5c9f20cc79135f49b431c20b779e7b93bd26415',
                  'tag': '2017',
                  'uri': '/tags/2017'}]}]
},"second_dict"]

What I want: I want to find all videos which contain the tag Foo, then get the download link from 'type': 'source'. So I want to end up with ["data"]["download"]["link"] where 'type':'source'.

I tried writing a bit of code which checks for tags and then creates a list with only the videos containing the 'Foo' tag:

videosFiltered = []
for entry in videos:
    for subentry in entry["data"]:
        if subentry["tags"] and subentry["tags"][0]["name"] == "Foo":
            videosFiltered.append()

But as you can see I'm failing miserably, since I'm just writing terrifying nests of for loops and if loops. I'm pretty sure I will eventually get what I want, but I was hoping you could help me find a more elegant solution to this problem.


问:
Manage datepicker dates with material ui
I have to date pickers, start date and end date. what I want to do with the end date is that if you choose the start date to be December 15 (for example) then when you choose the end date all the previous days to December 15 should be disable.

The thing is that I don't know how to pass to my end date the selected start date.

This is my code.

```<code>import React from 'react';
import DatePicker from 'material-ui/DatePicker';
import Divider from 'material-ui/Divider';

import cr from '../styles/general.css';

export default class DatePickers extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      startDate: '',
      endDate: ''
    };
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event, index, value) {this.setState({value});}

  render() {

    const today = new Date();
    today.setDate(today.getDate() + 1);

    return (
      <div className={cr.container}>
        <div className ={cr.boton}>
          <Divider/>
        </div>
        <div className={cr.rows}>
          <div>
            <div>
              <DatePicker
                hintText="Start Date"
                minDate = {today}
              />
              <br/>
              <DatePicker
                hintText="End Date"
              />
            </div>
          </div>
        </div>

      </div>
    );
  }
}
</code>```

Any help on this??

Regards..

答:
Looking at their documentation you can use minDate to set the value you need and DatePicker takes care of disabling unnecessary dates automatically for you.

<DatePicker minDate={yourDateValue} />

In order to manipulate dates, you can use state for example and, on every date change, you update it accordingly:

```<code><DatePicker
  onChange={(_, date) => this.setState({ startDate: date })}
  value={this.state.startDate}
/>
</code>```

Body:
I have to date pickers, start date and end date. what I want to do with the end date is that if you choose the start date to be December 15 (for example) then when you choose the end date all the previous days to December 15 should be disable.

The thing is that I don't know how to pass to my end date the selected start date.

This is my code.

import React from 'react';
import DatePicker from 'material-ui/DatePicker';
import Divider from 'material-ui/Divider';

import cr from '../styles/general.css';

export default class DatePickers extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      startDate: '',
      endDate: ''
    };
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event, index, value) {this.setState({value});}

  render() {

    const today = new Date();
    today.setDate(today.getDate() + 1);

    return (

          <Divider/>

              <DatePicker
                hintText="Start Date"
                minDate = {today}
              />

              <DatePicker
                hintText="End Date"
              />

    );
  }
}

Any help on this??

Regards..

Body:
Looking at their documentation you can use minDate to set the value you need and DatePicker takes care of disabling unnecessary dates automatically for you.

<DatePicker minDate={yourDateValue} />

In order to manipulate dates, you can use state for example and, on every date change, you update it accordingly:

<DatePicker
  onChange={(_, date) => this.setState({ startDate: date })}
  value={this.state.startDate}
/>


问:
Alter css keyframe properties at runtime
I have a simple keyframe animation which grows a dot and transforms the background into blue. How can I dynamically alter this background color?

```<code>@keyframes growDot {
    100% {
        background-color: #23b7e5;
        -webkit-transform: scale3d(0.9, 0.9, 0.9);
        transform: scale3d(0.9, 0.9, 0.9);
    }
}
</code>```

Obviously, something like $('keyframes growDot').css("background-color", "#FF00B0"); is not working.

答:
I would recommend using css transition for things like this.

They are more robust in cases that you need to abort animations or blend between them. Also animations will not "hold" the assigned value after they are finished.

(see code snippets the animation part will cut to the original color after finishing. also if you switch the animation mid way, the new animation will start from the original color)

document.getElementById('b1').addEventListener('click', function(){
  document.getElementById('test').style.backgroundColor = '#f33';
})
document.getElementById('b2').addEventListener('click', function(){
  document.getElementById('test').style.backgroundColor = '#3f3';
})
document.getElementById('b3').addEventListener('click', function(){
  document.getElementById('test').style.backgroundColor = '#33f';
})

document.getElementById('bb1').addEventListener('click', function(){
  document.getElementById('test2').classList.remove('blue', 'green', 'red')
  document.getElementById('test2').classList.add('red')
})
document.getElementById('bb2').addEventListener('click', function(){
  document.getElementById('test2').classList.remove('blue', 'green', 'red')
  document.getElementById('test2').classList.add('green')
})
document.getElementById('bb3').addEventListener('click', function(){
  document.getElementById('test2').classList.remove('blue', 'green', 'red')
  document.getElementById('test2').classList.add('blue')
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#test, #test2{
  transition: background-color 2s;
  background: #aaa;
  width:150px;
  height:30px;
}

.red{
  animation-name: red_anim;
    animation-duration: 2s;
}
.green{
  animation-name: green_anim;
    animation-duration: 2s;
}
.blue{
  animation-name: blue_anim;
    animation-duration: 2s;
}

@keyframes red_anim {100% {background-color: #f33;}}
@keyframes green_anim {100% {background-color: #3f3;}}
@keyframes blue_anim {100% { background-color: #33f; } }</code>```

Transition

<button id="b1">red</button>
<button id="b2">green</button>
<button id="b3">blue</button>

Animation

<button id="bb1">red</button>
<button id="bb2">green</button>
<button id="bb3">blue</button>```

Body:
I have a simple keyframe animation which grows a dot and transforms the background into blue. How can I dynamically alter this background color?

@keyframes growDot {
    100% {
        background-color: #23b7e5;
        -webkit-transform: scale3d(0.9, 0.9, 0.9);
        transform: scale3d(0.9, 0.9, 0.9);
    }
}

Obviously, something like $('keyframes growDot').css("background-color", "#FF00B0"); is not working.

Body:
I would recommend using css transition for things like this.

They are more robust in cases that you need to abort animations or blend between them. Also animations will not "hold" the assigned value after they are finished.

(see code snippets the animation part will cut to the original color after finishing. also if you switch the animation mid way, the new animation will start from the original color)

document.getElementById('b1').addEventListener('click', function(){
  document.getElementById('test').style.backgroundColor = '#f33';
})
document.getElementById('b2').addEventListener('click', function(){
  document.getElementById('test').style.backgroundColor = '#3f3';
})
document.getElementById('b3').addEventListener('click', function(){
  document.getElementById('test').style.backgroundColor = '#33f';
})

document.getElementById('bb1').addEventListener('click', function(){
  document.getElementById('test2').classList.remove('blue', 'green', 'red')
  document.getElementById('test2').classList.add('red')
})
document.getElementById('bb2').addEventListener('click', function(){
  document.getElementById('test2').classList.remove('blue', 'green', 'red')
  document.getElementById('test2').classList.add('green')
})
document.getElementById('bb3').addEventListener('click', function(){
  document.getElementById('test2').classList.remove('blue', 'green', 'red')
  document.getElementById('test2').classList.add('blue')
})

#test, #test2{
  transition: background-color 2s;
  background: #aaa;
  width:150px;
  height:30px;
}

.red{
  animation-name: red_anim;
    animation-duration: 2s;
}
.green{
  animation-name: green_anim;
    animation-duration: 2s;
}
.blue{
  animation-name: blue_anim;
    animation-duration: 2s;
}

@keyframes red_anim {100% {background-color: #f33;}}
@keyframes green_anim {100% {background-color: #3f3;}}
@keyframes blue_anim {100% { background-color: #33f; } }

Transition
<div id="test"></div>

<button id="b1">red</button>
<button id="b2">green</button>
<button id="b3">blue</button>

<br>
<br>

Animation
<div id="test2"></div>

<button id="bb1">red</button>
<button id="bb2">green</button>
<button id="bb3">blue</button>


问:
Java keytool max pass length
I want to use this command from Java's keytool to create a keystore:

```<code>keytool -genkey -alias clientprivate -keystore client.private -storetype PKCS12 -keyalg rsa -storepass password -keypass password
</code>```

Then use the resulting keystore for a java program. But when calling clientKeyStore.load(loader.clientpublic(), "password".toCharArray());

I get the error java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big.

I believe that it's because I used a quite long password of 109 characters. So my question is, what is the maximum allowed password length?

答:
Turned out I made a stupid mistake;
I had the certificates all included in a resource package with a resource loader, and the methods clientpublic() clientprivate() serverpublic() and serverprivate().

I was still messing with the resources and I managed to get it to work, but I'd forgotten to set the methods to their respective certificates, they were all pointing to the private client certificate :). Changing that solved the issue.

Title: Java keytool max pass length

Body:
I want to use this command from Java's keytool to create a keystore:

keytool -genkey -alias clientprivate -keystore client.private -storetype PKCS12 -keyalg rsa -storepass password -keypass password

Then use the resulting keystore for a java program. But when calling clientKeyStore.load(loader.clientpublic(), "password".toCharArray());

I get the error java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big.

I believe that it's because I used a quite long password of 109 characters. So my question is, what is the maximum allowed password length?


问:
Spawning an interactive process
How can a Java application spawn a new interactive application (e.g. an command line editor) from Java/Scala?

When I use Runtime.getRuntime().exec("vim test"), I would only get a Process instance, while vim would be running in the background; rather then appear to the user.

答:
MMmmm. Try this:

```<code>scala.sys.Process("vim test").run(true)
</code>```

Oops, that's only on the Scala trunk -- possibly Scala 2.9.

ContentLicense: CC BY-SA 2.5

Title: Spawning an interactive process

Body:
MMmmm. Try this:

scala.sys.Process("vim test").run(true)

Oops, that's only on the Scala trunk -- possibly Scala 2.9.


问:
How to make HTML perfect on Print view with CSS and javascript?
I have some problems with the Print view on the browser.
While looking perfect for Web browser view, it is not same in the Print view.
For example, Setting the margin or Padding on Print View is not working for me.
Also, rotating the table on Print view(vertical align) is pretty unfamiliar to me.
How can I deal with the problems using HTML, CSS, and javascript?</p>

答:
```<code><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>        body {
            margin: 0;
            padding: 0;
            background-color: #FAFAFA;
            font: 12pt "Tahoma";
        }
        * {
            box-sizing: border-box;
            -moz-box-sizing: border-box;
        }
        .page {
            width: 21cm;
            min-height: 29.7cm;
            padding: 2cm;
            margin: 1cm auto;
            border: 1px #D3D3D3 solid;
            border-radius: 5px;
            background: white;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }
        .subpage {
            padding: 1cm;
            border: 5px red solid;
            height: 256mm;
            outline: 2cm #FFEAEA solid;
        }

        @page {
            size: A4;
            margin: 0;
        }
        @media print {
            .page {
                margin: 0;
                border: initial;
                border-radius: initial;
                width: initial;
                min-height: initial;
                box-shadow: initial;
                background: initial;
                page-break-after: always;
            }
        }</code>```

Page 1/2

Page 2/2

```
</div>
</div>

</code>```

Body:
        body {
            margin: 0;
            padding: 0;
            background-color: #FAFAFA;
            font: 12pt "Tahoma";
        }
        * {
            box-sizing: border-box;
            -moz-box-sizing: border-box;
        }
        .page {
            width: 21cm;
            min-height: 29.7cm;
            padding: 2cm;
            margin: 1cm auto;
            border: 1px #D3D3D3 solid;
            border-radius: 5px;
            background: white;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }
        .subpage {
            padding: 1cm;
            border: 5px red solid;
            height: 256mm;
            outline: 2cm #FFEAEA solid;
        }

        @page {
            size: A4;
            margin: 0;
        }
        @media print {
            .page {
                margin: 0;
                border: initial;
                border-radius: initial;
                width: initial;
                min-height: initial;
                box-shadow: initial;
                background: initial;
                page-break-after: always;
            }
        }

    <div class="book">
        <div class="page">
            <div class="subpage">Page 1/2</div>
        </div>
        <div class="page">
            <div class="subpage">Page 2/2</div>
        </div>
    </div>


问:
Icecast - Moving listeners from autodj to live stream without resetting the stream
I have Icecast server and I have /autodj.mp3 and another mountpoint called /stream.mp3

When I broadcast Live I am broadcasting to /stream.mp3

But when I'm listening and I start broadcasting Live it does not automatically switch to Live, unless I reload the page with the stream, then it works

Any ideas?

Icecast.xml

```<code>    <mount>
<mount-name>/autodj.mp3</mount-name>
<stream-name>Niall FM AutoDJ</stream-name>
</mount>
<mount>
<mount-name>/stream.mp3</mount-name>
<fallback-mount>/autodj.mp3</fallback-mount>
<fallback-override>1</fallback-override>
<stream-name>Niall FM</stream-name>
    <public>1</public>
</mount>
</code>```

答:
Out of band discussion on IRC with the user revealed that they were streaming Ogg/Vorbis content to /autodj.mp3 and Icecast consequently refused to move listeners to a MP3 stream logging in at /stream.mp3.

Icecast enforces a very high level compatibility, but actually to ensure largest possible listener software compatibility it is highly recommended to closely match all stream and codec parameters between streams that fall back to each other.

Body:
I have Icecast server and I have /autodj.mp3 and another mountpoint called /stream.mp3

When I broadcast Live I am broadcasting to /stream.mp3

But when I'm listening and I start broadcasting Live it does not automatically switch to Live, unless I reload the page with the stream, then it works

Any ideas?

Icecast.xml

    <mount>
<mount-name>/autodj.mp3</mount-name>
<stream-name>Niall FM AutoDJ</stream-name>
</mount>
<mount>
<mount-name>/stream.mp3</mount-name>
<fallback-mount>/autodj.mp3</fallback-mount>
<fallback-override>1</fallback-override>
<stream-name>Niall FM</stream-name>
    <public>1</public>
</mount>


问:
Copy all values from a column of one Table to a specific column of another Table
I want to copy all values from column course_id of table Student to the column subj_id of table Subject.

```<code>    Student
-----------------
id      |course_id
----------------
1       |A
2       |B
3       |C
4       |D
</code>```

desired result below:

```<code>    Subject
-----------------
uniqueid|subj_id
----------------
        |A
        |B
        |C
        |D
</code>```

Below is the query

```<code>INSERT INTO `Subject`(uniqueid,`subject_id`) values ((SELECT `course_id` FROM `Student`))
</code>```

Note that uniqueid on Subject table is PK, non null, the problem I'm having is query returns more than one result.

答:
Use insert . . . select, not insert . . . values:

```<code>INSERT INTO Subject(`subject_id`)
    SELECT `course_id`
    FROM `Student`;
</code>```

Body:
I want to copy all values from column course_id of table Student to the column subj_id of table Subject.

    Student
-----------------
id      |course_id
----------------
1       |A
2       |B
3       |C
4       |D

desired result below:

    Subject
-----------------
uniqueid|subj_id
----------------
        |A
        |B
        |C
        |D

Below is the query

INSERT INTO `Subject`(uniqueid,`subject_id`) values ((SELECT `course_id` FROM `Student`))

Note that uniqueid on Subject table is PK, non null, the problem I'm having is query returns more than one result.

Body:
Use insert . . . select, not insert . . . values:

INSERT INTO Subject(`subject_id`)
    SELECT `course_id`
    FROM `Student`;


问:
Is it possible to obtain the spoken language from youtube-dl?
I'm using youtube-dl to download videos from youtube that we query using words from a target foreign language, but there's no guarantee that the video is in the target language. Is there any way to know what is the spoken language in a video when using youtube-dl? I figure youtube must know this info since it generates captions for some videos.
Thanks!</p>

答:
I am not sure if you can use youtube-dl to get the video language, but if you use the Youtube Data API it is possible.

The documentation here shows that you can get the video language in multiple ways:

Video title / description language: snippet.defaultLanguage

spoken language in default audio track: snippet.defaultAudioLanguage

The option for you would be to call the Youtube Data API and check if snippet.defaultAudioLanguage matches your desired language.


问:
Get IIS bindings at runtime
I wonder how to get the IIS binding settings of the current site (host name, port, IP address) at runtime using ASP.NET.
Does .NET provide any way to get these information?

Edit: I need a way to get the http and https ports configured to redirect to the right port when switching from http to https, and back from https to http if other ports then 80/443 are used. Is there a way to do this without extended privileges?

Regards

答:
You should be able to accomplish this by accessing the IIS metabase, using the System.DirectoryServices assembly.

For example, here you can enumerate through all of your sites and property configurations contained within those sites.

Add this reference to your project:

using System.DirectoryServices

```<code>// Assuming your Server Id is 1, and you are connecting to your local IIS.
DirectoryEntry de = new DirectoryEntry(@"IIS://localhost/W3SVC/1/Root");
foreach (DirectoryEntry entry in de.Children)
{
   foreach (PropertyValueCollection property in entry.Properties)
   {
      Console.WriteLine("Name: {0}, Value {1}",property.PropertyName, property.Value);
   }
}
</code>```

Title: Get IIS bindings at runtime

Body:
You should be able to accomplish this by accessing the IIS metabase, using the System.DirectoryServices assembly.

For example, here you can enumerate through all of your sites and property configurations contained within those sites.

Add this reference to your project:

using System.DirectoryServices

// Assuming your Server Id is 1, and you are connecting to your local IIS.
DirectoryEntry de = new DirectoryEntry(@"IIS://localhost/W3SVC/1/Root");
foreach (DirectoryEntry entry in de.Children)
{
   foreach (PropertyValueCollection property in entry.Properties)
   {
      Console.WriteLine("Name: {0}, Value {1}",property.PropertyName, property.Value);
   }
}


问:
wrap everything between hr elements
Trying to find a way to wrap all between hr tags in code, but nogo so far. Any advise on the code?

Here's what I'm doing right now (also as a fiddle):

$('hr').each(function() {
  $(this).next('hr').wrapAll('

');
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code>Text
<hr>
Text1
Text2
<hr>
Text3
<hr>
Text4
Text5
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></code>```

答:
jQuery doesn't do a lot to help you around text nodes (other than contents). Simplest thing here is probably to just use the DOM itself to find following sibling nodes (including text nodes), and then wrap them in the div; see comments:

$('hr').each(function() {
  // Build an array of all nodes (including text nodes)
  // up to and not including the next HR if any
  var nodes = [];
  var n = this.nextSibling;
  while (n && n.nodeName != "HR") {
    nodes.push(n);
    n = n.nextSibling;
  }
  // Wrap them in a div
  $(nodes).wrapAll('

');
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code>Text
<hr>
Text1
Text2
<hr>
Text3
<hr>
Text4
Text5
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></code>```

Title: wrap everything between hr elements

Body:
Trying to find a way to wrap all between hr tags in code, but nogo so far. Any advise on the code?

Here's what I'm doing right now (also as a fiddle):

$('hr').each(function() {
  $(this).next('hr').wrapAll('

');
});

Text

Text1
Text2

Text3

Text4
Text5

Body:
jQuery doesn't do a lot to help you around text nodes (other than contents). Simplest thing here is probably to just use the DOM itself to find following sibling nodes (including text nodes), and then wrap them in the div; see comments:

$('hr').each(function() {
  // Build an array of all nodes (including text nodes)
  // up to and not including the next HR if any
  var nodes = [];
  var n = this.nextSibling;
  while (n && n.nodeName != "HR") {
    nodes.push(n);
    n = n.nextSibling;
  }
  // Wrap them in a div
  $(nodes).wrapAll('<div style="background-color:yellow"></div>');
});

Text
<hr>
Text1
Text2
<hr>
Text3
<hr>
Text4
Text5
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


问:
Using form authentication and Azure AD login in same mvc application
I am using mvc application with azure AD login option(OpenId Authentication). i need to provide impersonation option for Admins. so i have decided to use form authentication for this impersonation login. now my problem is when enabling form authentication in webconfig affects azure AD login. once added form authentication it will show redirect continously with the belo url,
http://localhost:9666/members/logon?ReturnUrl=%2fmembers%2flogonusingazure%3freturnUrl%3d%2f&returnUrl=/

code used in web config for form authentication.

```<code><authentication mode="Forms">
      <forms loginUrl="~/members/logon" cookieless="UseCookies" name="MvcForumAuth" slidingExpiration="true" timeout="432000" />
    </authentication>
</code>```

Thanks,
Nagaraj M.

答:
Following Nan Yu suggestion above,
sometimes the application try to do an Azure Ad / OpenId login before get to identity login page.
I can't figure out why, but configuring to forms authentication seems to work fine </p>

```<code><authentication mode="Forms">
      <forms loginUrl="~/Account/Login/" timeout="2880"/>
</authentication>
</code>```

Body:
I am using mvc application with azure AD login option(OpenId Authentication). i need to provide impersonation option for Admins. so i have decided to use form authentication for this impersonation login. now my problem is when enabling form authentication in webconfig affects azure AD login. once added form authentication it will show redirect continously with the belo url,
http://localhost:9666/members/logon?ReturnUrl=%2fmembers%2flogonusingazure%3freturnUrl%3d%2f&returnUrl=/

code used in web config for form authentication.

<authentication mode="Forms">
      <forms loginUrl="~/members/logon" cookieless="UseCookies" name="MvcForumAuth" slidingExpiration="true" timeout="432000" />
    </authentication>

Thanks,
Nagaraj M.

Body:
Following Nan Yu suggestion above,
sometimes the application try to do an Azure Ad / OpenId login before get to identity login page.
I can't figure out why, but configuring to forms authentication seems to work fine

<authentication mode="Forms">
      <forms loginUrl="~/Account/Login/" timeout="2880"/>
</authentication>


问:
Questions on using synchronized and Transaction Management together
I was doing a code review and I found a code piece like below where a Java method processDataInTransaction uses both Synchronized and Transaction Management together and makes a call to createOrUpdateGroupData method

```<code>  private synchronized void processDataInTransaction(final Map<String, List<ListGroup>> groupMap,
            final GroupMetadata grpMetadata)
    {
        TransactionDefinition transactionDefinition = new DefaultTransactionAttribute(
                TransactionDefinition.PROPAGATION_REQUIRES_NEW);

        new TransactionTemplate(transactionManager, transactionDefinition)
                .execute(new TransactionCallbackWithoutResult()
                {
                    @Override
                    protected void doInTransactionWithoutResult(TransactionStatus status)
                    {
                        createOrUpdateGroupData(groupMap, grpMetadata);
                    }
                });
    }

    // createOrUpdateGroupData

        protected void createOrUpdateGroupData (Map<String, List<ListGroup>> map,
                                                GroupMetadata grpData)
{  // Code omitted for clarity

}
</code>```

Now my questions are

can I not simply put @Transactional on processDataInTransaction and remove synchronized ?

and use @Transactional(propagation=Propagation.MANDATORY) on createOrUpdateGroupData ?

答:
The answer depends on the following.

Synchronized make sure that the method processDataInTransaction will be synchronized in an  multithreaded context, if there is no concurency execution of your method then you can remove the syncronized.

if you want to use @Transactionnal, make you that your service is enhanced via AOP, if that is the case, then you can go for @Transactional.

Last thing,   as createOrUpdateGroupData is a protected method, the proxy pattern might not take effect; so use @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS ) to make sure that internal method call are proxied.

Body:
I was doing a code review and I found a code piece like below where a Java method processDataInTransaction uses both Synchronized and Transaction Management together and makes a call to createOrUpdateGroupData method

  private synchronized void processDataInTransaction(final Map<String, List<ListGroup>> groupMap,
            final GroupMetadata grpMetadata)
    {
        TransactionDefinition transactionDefinition = new DefaultTransactionAttribute(
                TransactionDefinition.PROPAGATION_REQUIRES_NEW);

        new TransactionTemplate(transactionManager, transactionDefinition)
                .execute(new TransactionCallbackWithoutResult()
                {
                    @Override
                    protected void doInTransactionWithoutResult(TransactionStatus status)
                    {
                        createOrUpdateGroupData(groupMap, grpMetadata);
                    }
                });
    }

    // createOrUpdateGroupData

        protected void createOrUpdateGroupData (Map<String, List<ListGroup>> map,
                                                GroupMetadata grpData)
{  // Code omitted for clarity

}

Now my questions are

can I not simply put @Transactional on processDataInTransaction and remove synchronized ?

and use @Transactional(propagation=Propagation.MANDATORY) on createOrUpdateGroupData ?