Recherche avancée

Médias (1)

Mot : - Tags -/publicité

Autres articles (61)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

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

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

Sur d’autres sites (8797)

  • HTML5 Video Chrome - ffmpeg - mp4 working in all but Chrome

    16 octobre 2014, par IIIOXIII

    I have successfully encoded a file to .mp4 using ffmpeg which will play in all tested devices (Safari on PC, IE on PC, Android Browser, Andriod Video Player, and Safari iPad), except for Chrome.

    As a work-around, I had planned to simply list the .ogg source prior to the .mp4 source so that chrome would play the .ogg source without even seeing the .mp4 source, however, I ran into the issue mentioned here.

    Basically, I am after the proper ffmpeg command which will encode an .mp4 video to standards which will play in Chrome - of course without losing playback functionality on any of the other previously mentioned platforms.

    I have tried several combinations, such as :

    ffmpeg -i [filename].wmv -vprofile baseline -level 30 -vf scale=640:-1 -movflags faststart [filename].mp4

    etc. but have not yet found the winning one.

    EDIT : I tried :

    ffmpeg_new -i [filename].wmv -strict experimental –acodec libvo_aacenc -ac 2 -ab 160k -vcodec libx264 -vf scale=640:-1 -pix_fmt yuv420p -preset slow -profile:v baseline -level 30 -maxrate 10000000 -bufsize 10000000 -b 1200k -f mp4 -threads 0 [filename].mp4

    And here is the ffmpeg output :

    ffmpeg version N-54207-ge59fb3f Copyright (c) 2000-2013 the FFmpeg developers built on Jun 25 2013 21:55:00 with gcc 4.7.3 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
    ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
    ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
    amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
    enable-libxvid --enable-zlib
     libavutil      52. 37.101 / 52. 37.101
     libavcodec     55. 17.100 / 55. 17.100
     libavformat    55. 10.100 / 55. 10.100
     libavdevice    55.  2.100 / 55.  2.100
     libavfilter     3. 77.101 /  3. 77.101
     libswscale      2.  3.100 /  2.  3.100
     libswresample   0. 17.102 /  0. 17.102
     libpostproc    52.  3.100 / 52.  3.100
    [asf @ 000000000254f9e0] Stream #0: not enough frames to estimate rate; consider
    increasing probesize
    Guessed Channel Layout for  Input Stream #0.0 : stereo
    Input #0, asf, from 'C:\vidtests\Wildlife.wmv':
     Metadata:
       SfOriginalFPS   : 299700
       WMFSDKVersion   : 11.0.6001.7000
       WMFSDKNeeded    : 0.0.0.0000
       comment         : Footage: Small World Productions, Inc; Tourism New Zealand
    | Producer: Gary F. Spradling | Music: Steve Ball
       title           : Wildlife in HD
       copyright       : ┬⌐ 2008 Microsoft Corporation
       IsVBR           : 0
       DeviceConformanceTemplate: AP@L3
     Duration: 00:00:30.09, start: 0.000000, bitrate: 6977 kb/s
       Stream #0:0(eng): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, stereo, fltp
    , 192 kb/s
       Stream #0:1(eng): Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 1280x7
    20, 5942 kb/s, 29.97 tbr, 1k tbn, 1k tbc
    Please use -b:a or -b:v, -b is ambiguous
    [libx264 @ 000000000264faa0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64

    [libx264 @ 000000000264faa0] profile Constrained Baseline, level 3.0
    [libx264 @ 000000000264faa0] 264 - core 133 r2334 a3ac64b - H.264/MPEG-4 AVC cod
    ec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=0 r
    ef=5 deblock=1:0:0 analyse=0x1:0x111 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed
    _ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pski
    p=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 deci
    mate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyi
    nt=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=abr mbtree=1
    bitrate=1200 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=10000
    vbv_bufsize=10000 nal_hrd=none ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'C:\vidtests\Wildlife_SE1.mp4':
     Metadata:
       SfOriginalFPS   : 299700
       WMFSDKVersion   : 11.0.6001.7000
       WMFSDKNeeded    : 0.0.0.0000
       comment         : Footage: Small World Productions, Inc; Tourism New Zealand
    | Producer: Gary F. Spradling | Music: Steve Ball
       title           : Wildlife in HD
       copyright       : ┬⌐ 2008 Microsoft Corporation
       IsVBR           : 0
       DeviceConformanceTemplate: AP@L3
       encoder         : Lavf55.10.100
       Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 6
    40x360, q=-1--1, 1200 kb/s, 30k tbn, 29.97 tbc
       Stream #0:1(eng): Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100
    Hz, stereo, s16, 160 kb/s
    Stream mapping:
     Stream #0:1 -> #0:0 (vc1 -> libx264)
     Stream #0:0 -> #0:1 (wmav2 -> libvo_aacenc)
    Press [q] to stop, [?] for help
    frame=   59 fps= 55 q=32.0 size=       0kB time=00:00:00.16 bitrate=   2.3kbits/
    frame=   66 fps= 42 q=31.0 size=       0kB time=00:00:00.40 bitrate=   1.0kbits/
    frame=   75 fps= 35 q=31.0 size=       0kB time=00:00:00.70 bitrate=   0.5kbits/
    frame=   84 fps= 31 q=31.0 size=       0kB time=00:00:01.00 bitrate=   0.4kbits/
    frame=   93 fps= 29 q=31.0 size=       0kB time=00:00:01.30 bitrate=   0.3kbits/
    frame=  102 fps= 27 q=31.0 size=       0kB time=00:00:01.60 bitrate=   0.2kbits/
    frame=  111 fps= 26 q=31.0 size=      38kB time=00:00:01.90 bitrate= 165.1kbits/
    Queue input is backward in time
    [mp4 @ 000000000264f2c0] Non-monotonous DTS in output stream 0:1; previous: 7616
    , current: 7063; changing to 7617. This may result in incorrect timestamps in th
    e output file.
    frame=  120 fps= 25 q=31.0 size=     107kB time=00:00:02.20 bitrate= 397.7kbits/
    frame=  128 fps= 24 q=31.0 size=     161kB time=00:00:02.46 bitrate= 534.1kbits/
    frame=  137 fps= 23 q=31.0 size=     194kB time=00:00:02.76 bitrate= 572.6kbits/
    frame=  145 fps= 23 q=31.0 size=     219kB time=00:00:03.03 bitrate= 592.1kbits/
    frame=  153 fps= 22 q=31.0 size=     273kB time=00:00:03.30 bitrate= 677.8kbits/
    frame=  162 fps= 22 q=31.0 size=     317kB time=00:00:03.60 bitrate= 720.8kbits/
    frame=  170 fps= 21 q=31.0 size=     366kB time=00:00:03.87 bitrate= 775.2kbits/
    frame=  177 fps= 21 q=31.0 size=     451kB time=00:00:04.10 bitrate= 900.2kbits/
    frame=  193 fps= 21 q=31.0 size=     602kB time=00:00:04.63 bitrate=1062.7kbits/
    frame=  208 fps= 22 q=30.0 size=     755kB time=00:00:05.13 bitrate=1204.2kbits/
    frame=  219 fps= 22 q=30.0 size=     769kB time=00:00:05.50 bitrate=1143.6kbits/
    frame=  228 fps= 21 q=30.0 size=     790kB time=00:00:05.80 bitrate=1114.5kbits/
    frame=  234 fps= 21 q=31.0 size=     806kB time=00:00:06.00 bitrate=1098.7kbits/
    frame=  243 fps= 21 q=31.0 size=     806kB time=00:00:06.30 bitrate=1046.4kbits/
    frame=  251 fps= 21 q=31.0 size=     831kB time=00:00:06.57 bitrate=1035.6kbits/
    frame=  260 fps= 20 q=31.0 size=     860kB time=00:00:06.87 bitrate=1024.6kbits/
    frame=  273 fps= 21 q=31.0 size=     934kB time=00:00:07.30 bitrate=1046.7kbits/
    frame=  288 fps= 21 q=30.0 size=    1019kB time=00:00:07.80 bitrate=1068.7kbits/
    frame=  302 fps= 21 q=30.0 size=    1066kB time=00:00:08.27 bitrate=1055.8kbits/
    frame=  314 fps= 21 q=29.0 size=    1146kB time=00:00:08.67 bitrate=1082.1kbits/
    frame=  328 fps= 21 q=28.0 size=    1189kB time=00:00:09.14 bitrate=1065.6kbits/
    frame=  341 fps= 21 q=28.0 size=    1247kB time=00:00:09.57 bitrate=1066.7kbits/
    frame=  352 fps= 22 q=27.0 size=    1274kB time=00:00:09.94 bitrate=1049.3kbits/
    frame=  365 fps= 22 q=27.0 size=    1298kB time=00:00:10.37 bitrate=1024.7kbits/
    frame=  376 fps= 22 q=27.0 size=    1349kB time=00:00:10.74 bitrate=1028.7kbits/
    frame=  388 fps= 22 q=26.0 size=    1378kB time=00:00:11.14 bitrate=1012.9kbits/
    frame=  401 fps= 22 q=26.0 size=    1415kB time=00:00:11.57 bitrate=1001.4kbits/
    frame=  412 fps= 22 q=26.0 size=    1454kB time=00:00:11.94 bitrate= 996.9kbits/
    frame=  421 fps= 22 q=27.0 size=    1489kB time=00:00:12.24 bitrate= 996.2kbits/
    frame=  431 fps= 21 q=27.0 size=    1509kB time=00:00:12.57 bitrate= 982.7kbits/
    frame=  441 fps= 21 q=28.0 size=    1555kB time=00:00:12.91 bitrate= 986.6kbits/
    frame=  450 fps= 21 q=28.0 size=    1599kB time=00:00:13.21 bitrate= 991.7kbits/
    frame=  460 fps= 21 q=28.0 size=    1621kB time=00:00:13.54 bitrate= 980.4kbits/
    frame=  470 fps= 21 q=28.0 size=    1660kB time=00:00:13.88 bitrate= 979.9kbits/
    frame=  480 fps= 21 q=28.0 size=    1734kB time=00:00:14.21 bitrate= 999.2kbits/
    frame=  489 fps= 21 q=29.0 size=    1834kB time=00:00:14.51 bitrate=1035.3kbits/
    frame=  499 fps= 21 q=29.0 size=    1890kB time=00:00:14.84 bitrate=1042.8kbits/
    frame=  508 fps= 21 q=29.0 size=    1962kB time=00:00:15.14 bitrate=1060.8kbits/
    frame=  519 fps= 21 q=29.0 size=    2061kB time=00:00:15.51 bitrate=1087.9kbits/
    frame=  531 fps= 21 q=29.0 size=    2189kB time=00:00:15.91 bitrate=1126.6kbits/
    frame=  540 fps= 21 q=29.0 size=    2329kB time=00:00:16.21 bitrate=1176.4kbits/
    frame=  551 fps= 21 q=29.0 size=    2439kB time=00:00:16.58 bitrate=1204.8kbits/
    frame=  562 fps= 21 q=29.0 size=    2569kB time=00:00:16.95 bitrate=1241.8kbits/
    frame=  575 fps= 21 q=29.0 size=    2688kB time=00:00:17.38 bitrate=1266.9kbits/
    frame=  581 fps= 21 q=29.0 size=    2749kB time=00:00:17.58 bitrate=1280.6kbits/
    frame=  589 fps= 21 q=29.0 size=    2785kB time=00:00:17.85 bitrate=1278.1kbits/
    frame=  595 fps= 21 q=30.0 size=    2808kB time=00:00:18.05 bitrate=1274.5kbits/
    frame=  602 fps= 20 q=30.0 size=    2903kB time=00:00:18.28 bitrate=1300.7kbits/
    frame=  610 fps= 20 q=31.0 size=    3008kB time=00:00:18.55 bitrate=1328.2kbits/
    frame=  616 fps= 20 q=31.0 size=    3128kB time=00:00:18.75 bitrate=1366.6kbits/
    frame=  625 fps= 20 q=31.0 size=    3238kB time=00:00:19.05 bitrate=1392.5kbits/
    frame=  633 fps= 20 q=31.0 size=    3320kB time=00:00:19.31 bitrate=1407.9kbits/
    frame=  642 fps= 20 q=31.0 size=    3397kB time=00:00:19.61 bitrate=1418.4kbits/
    frame=  652 fps= 20 q=31.0 size=    3437kB time=00:00:19.95 bitrate=1411.1kbits/
    frame=  661 fps= 20 q=31.0 size=    3511kB time=00:00:20.25 bitrate=1420.3kbits/
    frame=  669 fps= 20 q=31.0 size=    3578kB time=00:00:20.52 bitrate=1428.2kbits/
    frame=  679 fps= 20 q=31.0 size=    3606kB time=00:00:20.85 bitrate=1416.6kbits/
    frame=  691 fps= 20 q=32.0 size=    3670kB time=00:00:21.25 bitrate=1414.5kbits/
    frame=  701 fps= 20 q=32.0 size=    3798kB time=00:00:21.58 bitrate=1441.2kbits/
    frame=  713 fps= 20 q=32.0 size=    3901kB time=00:00:21.98 bitrate=1453.3kbits/
    frame=  723 fps= 20 q=32.0 size=    3969kB time=00:00:22.32 bitrate=1456.6kbits/
    frame=  735 fps= 20 q=32.0 size=    4027kB time=00:00:22.72 bitrate=1451.7kbits/
    frame=  744 fps= 20 q=32.0 size=    4102kB time=00:00:23.02 bitrate=1459.6kbits/
    frame=  755 fps= 20 q=32.0 size=    4135kB time=00:00:23.39 bitrate=1448.3kbits/
    frame=  764 fps= 20 q=32.0 size=    4172kB time=00:00:23.69 bitrate=1442.7kbits/
    frame=  776 fps= 20 q=32.0 size=    4216kB time=00:00:24.09 bitrate=1433.5kbits/
    frame=  787 fps= 20 q=32.0 size=    4254kB time=00:00:24.45 bitrate=1424.8kbits/
    frame=  802 fps= 20 q=32.0 size=    4337kB time=00:00:24.95 bitrate=1423.6kbits/
    frame=  815 fps= 20 q=32.0 size=    4369kB time=00:00:25.39 bitrate=1409.6kbits/
    frame=  828 fps= 20 q=32.0 size=    4450kB time=00:00:25.82 bitrate=1411.5kbits/
    frame=  840 fps= 20 q=32.0 size=    4467kB time=00:00:26.22 bitrate=1395.3kbits/
    frame=  852 fps= 20 q=32.0 size=    4550kB time=00:00:26.62 bitrate=1399.8kbits/
    frame=  865 fps= 20 q=32.0 size=    4594kB time=00:00:27.06 bitrate=1390.7kbits/
    frame=  877 fps= 20 q=32.0 size=    4629kB time=00:00:27.46 bitrate=1380.9kbits/
    frame=  889 fps= 20 q=32.0 size=    4689kB time=00:00:27.86 bitrate=1378.6kbits/
    frame=  900 fps= 20 q=32.0 size=    4740kB time=00:00:28.22 bitrate=1375.6kbits/
    frame=  901 fps= 19 q=-1.0 Lsize=    5203kB time=00:00:30.10 bitrate=1416.0kbits
    /s
    video:4586kB audio:590kB subtitle:0 global headers:0kB muxing overhead 0.532558%

    [libx264 @ 000000000264faa0] frame I:8     Avg QP:22.98  size: 31700
    [libx264 @ 000000000264faa0] frame P:893   Avg QP:27.55  size:  4974
    [libx264 @ 000000000264faa0] mb I  I16..4: 34.6%  0.0% 65.4%
    [libx264 @ 000000000264faa0] mb P  I16..4:  0.8%  0.0%  1.5%  P16..4: 41.4% 18.8
    %  8.5%  0.0%  0.0%    skip:29.0%
    [libx264 @ 000000000264faa0] final ratefactor: 24.50
    [libx264 @ 000000000264faa0] coded y,uvDC,uvAC intra: 64.3% 76.0% 36.7% inter: 2
    3.5% 19.6% 0.7%
    [libx264 @ 000000000264faa0] i16 v,h,dc,p: 34% 33% 11% 22%
    [libx264 @ 000000000264faa0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 16% 12%  9% 12%
    11% 12%  7%  8%
    [libx264 @ 000000000264faa0] i8c dc,h,v,p: 55% 23% 14%  7%
    [libx264 @ 000000000264faa0] ref P L0: 72.3% 12.0%  8.1%  3.7%  3.9%
    [libx264 @ 000000000264faa0] kb/s:1249.53

    But still no luck. The .mp4 will play in every compatible device/browser combination I have tried except for chrome.. Any advice ?

    TIA.

  • send h264 video to nginx-rtmp server using ffmpeg API

    11 décembre 2019, par Glen

    I have C++ code that grabs frames from a GigE camera and writes them out to a file. I’m using the libx264 codec and ffmpeg version 4.0.

    Writing to the file works fine, however I would also like to send the video to nginx configured with the nginx-rtmp plug-in to make the video available live via HLS.

    I can use the ffmpeg command line program to stream one of my previously captured files to my nginx server and rebroadcast as HLS, however if I try to stream from my C++ code the nginx server closes the connection after one or two frames are sent.

    To test further, I used the ffmpeg command line program to receive a rtmp stream and write it out to a file. I am able to send video to ffmpeg from my C++ program with rtmp, however every frame generates a warning like this :

    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1771, current: 53; changing to 1772. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1772, current: 53; changing to 1773. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1773, current: 53; changing to 1774. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1774, current: 53; changing to 1775. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1775, current: 53; changing to 1776. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1776, current: 53; changing to 1777. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1777, current: 53; changing to 1778. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1778, current: 53; changing to 1779. This may result in incorrect timestamps in the output file.
    [avi @ 0x1b6b6f0] Non-monotonous DTS in output stream 0:0; previous: 1779, current: 53; changing to 1780. This may result in incorrect timestamps in the output file.

    I printed PTS and DTS for my packet before writing it, and the numbers were monotonous (for example, in this last frame the pts and dts printed from my code were 1780, not the ’current : 53’ that ffmpeg reports>

    also, unless I tell ffmpeg what the output framerate should be I end up with a file that plays 2x speed.

    After ffmpeg receives the rtmp stream and writes it to the file, I am then able to successfully send that file to my nginx server using ffmpeg.

    here is some relevant code :

    //configuring the codec context
    // make sure that config.codec is something we support
    // for now we are only supporting LIBX264
    if (config.codec() != codecs::LIBX264) {
       throw std::invalid_argument("currently only libx264 codec is supported");
    }

    // lookup specified codec
    ffcodec_ = avcodec_find_encoder_by_name(config.codec().c_str());
    if (!ffcodec_) {
       throw std::invalid_argument("unable to get codec " + config.codec());
    }

    // unique_ptr to manage the codec_context
    codec_context_ = av_pointer::codec_context(avcodec_alloc_context3(ffcodec_));

    if (!codec_context_) {
       throw std::runtime_error("unable to initialize AVCodecContext");
    }

    // setup codec_context_
    codec_context_->width = frame_width;
    codec_context_->height = frame_height;
    codec_context_->time_base = (AVRational){1, config.target_fps()};
    codec_context_->framerate = (AVRational){config.target_fps(), 1};
    codec_context_->global_quality = 0;
    codec_context_->compression_level = 0;
    codec_context_->bits_per_raw_sample = 8;
    codec_context_->gop_size = 1;
    codec_context_->max_b_frames = 1;
    codec_context_->pix_fmt = AV_PIX_FMT_YUV420P;

    // x264 only settings
    if (config.codec() == codecs::LIBX264) {
       av_opt_set(codec_context_->priv_data, "preset", config.compression_target().c_str(), 0);
       av_opt_set(codec_context_->priv_data, "crf", std::to_string(config.crf()).c_str(), 0);
    }

    // Open up the codec
    if (avcodec_open2(codec_context_.get(), ffcodec_, NULL) < 0) {
       throw std::runtime_error("unable to open ffmpeg codec");
    }

    // setup the output format context and stream for RTMP
    AVFormatContext *tmp_f_context;
    avformat_alloc_output_context2(&tmp_f_context, NULL, "flv", uri.c_str());
    rtmp_format_context_ = av_pointer::format_context(tmp_f_context);
    rtmp_stream_ = avformat_new_stream(rtmp_format_context_.get(), ffcodec_);
    avcodec_parameters_from_context(rtmp_stream_->codecpar, codec_context_.get());
    rtmp_stream_->time_base = codec_context_->time_base;
    rtmp_stream_->r_frame_rate = codec_context_->framerate;

    /* open the output file */
    if (!(rtmp_format_context_->flags & AVFMT_NOFILE)) {
       int r = avio_open(&rtmp_format_context_->pb, uri.c_str(), AVIO_FLAG_WRITE);
       if (r < 0) {
           throw std::runtime_error("unable to open " + uri + " : " + av_err2str(r));
       }
    }

    if (avformat_write_header(rtmp_format_context_.get(), NULL) < 0) {
       throw std::runtime_error("unable to write header");
    }

    av_dump_format(rtmp_format_context_.get(), 0,uri.c_str() , 1);

    at this point the av_dump_format produces this output :

    Output #0, flv, to 'rtmp://[MY URI]':
     Metadata:
       encoder         : Lavf58.12.100
       Stream #0:0, 0, 1/1000: Video: h264 (libx264), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 800x800 (0x0), 0/1, q=-1--1, 30 tbr, 1k tbn

    encoding and writing the frame :

    // send the frame to the encoder, filtering first if necessary
    void VideoWriter::Encode(AVFrame *frame)
    {
       int rval;
       if (!apply_filter_) {
           //send frame to encoder
           rval = avcodec_send_frame(codec_context_.get(), frame);
           if (rval < 0) {
               throw std::runtime_error("error sending frame for encoding");
           }
       } else {
           // push frame to filter
           // REMOVED, currently testing without filtering
       }

       // get packets from encoder
       while (rval >= 0) {
           // create smart pointer to allocated packet
           av_pointer::packet pkt(av_packet_alloc());
           if (!pkt) {
               throw std::runtime_error("unable to allocate packet");
           }

           rval = avcodec_receive_packet(codec_context_.get(), pkt.get());
           if (rval == AVERROR(EAGAIN) || rval == AVERROR_EOF) {
               return;
           } else if (rval < 0) {
               throw std::runtime_error("error during encoding");
           }

           // if I print pkt->pts and pkt->dts here, I see sequential numbers

           // write packet
           rval = av_interleaved_write_frame(rtmp_format_context_.get(), pkt.get());
           if (rval < 0 ) {
               std::cerr << av_err2str(rval) << std::endl;
           }
       }
    }

    Since I am able to send video from a previously recorded file to nginx with the ffmpeg command line program, I believe the problem is in my code and not my nginx configuration.

    EDIT : I think it may have to do with SPS/PPS as I see a bunch of these error messages in the nginx log before it closes the stream

    2019/12/11 11:11:31 [error] 10180#0: *4 hls: failed to read 5 byte(s), client: XXX, server: 0.0.0.0:1935
    2019/12/11 11:11:31 [error] 10180#0: *4 hls: error appenging SPS/PPS NALs, client: XXX, server: 0.0.0.0:1935

    As I mentioned, this code works fine if I set it up to write to an avi file rather stream to rtmp, and I can stream to ffmpeg listening for rtmp but with lots of warnings about the DTS but if I try to send to nginx, it closes the connection almost immediately. My first thought was that there was something wrong with the frame timestamps, but when I print pts and dts prior to writing the packet to the stream they look okay to me.

    My end goal is to capture video to a file, and also be able to turn on the rtmp stream on demand — but for now I’m just trying to get the rtmp stream working continuously (without writing to a file)

    Thanks for any insights.

  • Best way to diagnose VideoCapture not opening the rtmp stream

    8 janvier 2021, par Greg0ry

    I am pulling my hair off for a few days and I'm out of ideas.

    


    I have two rtmp streams

    


      

    • first stream is transcoded directly by myself (I use ffmpeg to transcode) and then I attach to that stream with opencv - VideoCapture can open the stream with no problem
    • 


    • second stream is transcoded by 3rd party system (this system captures video through WebRTC and then encodes to h264) - this stream cannot be opened by VideCapture no matter what I do
    • 


    


    I can attach with pure ffmpeg to that dodgy stream and I can restream - but this is not ideal as introduces extra network traffic and latency.

    


    I was playing with OPENCV_FFMPEG_CAPTURE_OPTIONS environmental variable (I was trying to remove audio stream, change the video codec, playing with rtmp options like this OPENCV_FFMPEG_CAPTURE_OPTIONS="loglevel;debug" python my_script.py) - no joy

    


    So I figured I am trying to solve this problem from wrong end. I should somehow collect underlying ffmpeg logs that should be available when calling VideoCapture. So I tried to set OPENCV_FFMPEG_CAPTURE_OPTIONS="v;debug" but I can see no ffmpeg output when calling VideoCapture.

    


    This is very simple python3 script I was using during tests :

    


    import cv2 as cv
dodgy_cap = cv.VideoCapture()
dodgy_cap.open('rtmp://my_local_ip_address/rtmp/dodgy_stream_name')
print(dodgy_cap.isOpened())  # always returns False
healthy_cap = cv.VideoCapture()
healthy_cap.open('rtmp://my_local_ip_address/rtmp/healthy_stream_name')
print(healthy_cap.isOpened())  # always returns True


    


    I collected information about both streams with ffprobe, but even though they look different I cannot see what would be the difference that prevents opencv from opening VideoCapture for dodgy stream..

    


    This is a fragment from (very) verbose log for healthy stream :

    


    RTMP_ClientPacket, received: notify 254 bytes                                                                                                                                                                                               
(object begin)                                                                                                                                                                                                                              
Property:                                                                                                                                                                                  
Property:                                                                                                                                                                                             
(object begin)                                                                                                                                                                                                                              
Property:                                                                                                                                                                                        
Property:                                                                                                                                                                                     
Property:                                                                                                                                                                                     
Property:                                                                                                                                                                                        
Property:                                                                                                                                                                                        
Property:                                                                                                                                                                                        
Property:                                                                                                                                                               
Property:                                                                                                                                                                         
Property:                                                                                                                                                                               
Property:                                                                                                                                                                                        
(object end)                                                                                                                                                                                                                                
(object end)                                                                                                                                                                                                                                
Metadata:
  duration              0.00
  width                 2048.00
  height                1536.00
  videodatarate         0.00
  framerate             6.00
  videocodecid          7.00
  title                 Session streamed by "preview"
  comment               h264Preview_01_main
  encoder               Lavf58.20.100
  filesize              0.00

(... raw network packets ...)

Input #0, flv, from 'rtmp://my_local_ip_address/rtmp/healthy_stream_name':
  Metadata:
    title           : Session streamed by "preview"
    comment         : h264Preview_01_main
    encoder         : Lavf58.20.100
  Duration: 00:00:00.00, start: 159.743000, bitrate: N/A
    Stream #0:0, 41, 1/1000: Video: h264 (High), 1 reference frame, yuv420p(progressive), 2048x1536, 0/1, 6 fps, 6 tbr, 1k tbn



    


    And this is the fragment for dodgy stream :

    


    RTMP_ClientPacket, received: notify 205 bytes                                                                                                                                                                                               
(object begin)                                                                                                                                                                                                                              
Property:                                                                                                                                                                                                 
(object begin)                                                                                                                                                                                                                              
Property:                                                                                                                                                                                
Property:                                                                                                                                                                            
Property:                                                                                                                                                                                       
Property:                                                                                                                                                                                       
Property:                                                                                                                                                                                       
Property:                                                                                                                                                                                    
Property:                                                                                                                                                                                        
Property:                                                                                                                                                                                      
Property:                                                                                                                                                                                      
(object end)                                                                                                                                                                                                                                
(object end)                                                                                                                                                                                                                                
RTMP_ReadPacket: fd=3                                                                                                                                                                                                                       

(... raw network packets ...)

Input #0, flv, from 'rtmp://my_local_ip_address/rtmp/dodgy_stream_name':
  Duration: N/A, start: 4511.449000, bitrate: N/A
    Stream #0:0, 41, 1/1000: Video: h264 (High), 1 reference frame, yuv420p(progressive, left), 640x480, 0/1, 15.17 fps, 15.08 tbr, 1k tbn, 30 tbc
    Stream #0:1, 124, 1/1000: Audio: aac (LC), 48000 Hz, mono, fltp



    


    Both streams don't require any authentication (they are not exposed to the outside world)

    


    Dodgy stream contains audio but I don't think it is source of problem as I was able to connect to other healthy rtmp streams that contained audio..

    


    I have no more ideas how can I debug this problem, please help..

    



    


    I found in VideoCap documentation that I can enable exception mode, however it did not help much (it says where it failed but it does not say why) :

    


    >>> dodgy_stream = cv.VideoCapture()&#xA;>>> dodgy_stream.setExceptionMode(True)&#xA;>>> dodgy_stream.open("rtmp://my_local_ip_address/rtmp/dodgy_stream_name")&#xA;Traceback (most recent call last):&#xA;  File "<stdin>", line 1, in <module>&#xA;cv2.error: OpenCV(4.5.0) /tmp/pip-req-build-s_nildlw/opencv/modules/videoio/src/cap.cpp:177: error: (-2:Unspecified error) could not open &#x27;rtmp://my_local_ip_address/rtmp/dodgy_stream_name&#x27; in function &#x27;open&#x27;&#xA;</module></stdin>

    &#xA;