Recherche avancée

Médias (1)

Mot : - Tags -/wave

Autres articles (62)

  • 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 (...)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Le plugin : Gestion de la mutualisation

    2 mars 2010, par

    Le plugin de Gestion de mutualisation permet de gérer les différents canaux de mediaspip depuis un site maître. Il a pour but de fournir une solution pure SPIP afin de remplacer cette ancienne solution.
    Installation basique
    On installe les fichiers de SPIP sur le serveur.
    On ajoute ensuite le plugin "mutualisation" à la racine du site comme décrit ici.
    On customise le fichier mes_options.php central comme on le souhaite. Voilà pour l’exemple celui de la plateforme mediaspip.net :
    < ?php (...)

Sur d’autres sites (4469)

  • MKV Video Faster Plays Faster

    4 avril 2014, par Ankush

    I have C# program which screenshots 3 times per second & adds this to mkv ( VP8 ) video, set FPS to 3,encoded video works but plays faster, the total length of video player shows is wrong & while playing it doesn't plays smooth it jumps like from 1sec -> 3sec -> 5sec means instread of 1 -> 2 ->3..

    There is something wrong with pts value,

    if ( codecContext->coded_frame->pts != AV_NOPTS_VALUE )
    {
    packet.pts = av_rescale_q( packet.pts, codecContext->time_base, pVideoStream->time_base );
    }

    if ( codecContext->coded_frame->pkt_dts != AV_NOPTS_VALUE )
    {
    packet.dts = av_rescale_q( packet.dts, codecContext->time_base, pVideoStream->time_base );
    }

    while debugging codecContext->time_base shows 3FPS ( num=1 den=3 ) & pVideoStream->time_base shows ( num=1 den=1000) & packet.pts & packet.dts shows 0 ( everytime )

    Whats wrong ? Anyone please give me some hint atleast.

  • FFmpeg media info incorrect when encoding aac audio track

    11 janvier 2023, par user2028936

    I recently dipped my feet into encoding with FFmpeg. It's been working fine for me apart form 1 issues I have noticed recently. When I try and re-encode an audio track to acc the media info tags are somewhat wrong. Bitrate, streamsize etc seems to be copied form the source as opposed to reading it from the new track.

    &#xA;&#xA;

    Essentially I want to copy the source video, audio and subtitles and also create an AAC version of the soundtrack for playback on devices that don't support HD audio.

    &#xA;&#xA;

    Below is an example of what I am doing :

    &#xA;&#xA;

    ffmpeg -i source.mkv -map_chapters 0 -map 0:v -c:v copy -c:s copy -map 0:a -c:a:0 copy -map 0:a c:a:1 aac destination.mkv&#xA;

    &#xA;&#xA;

    This results in a media info of :

    &#xA;&#xA;

    Audio #1&#xA;ID                                       : 2&#xA;Format                                   : MLP FBA 16-ch&#xA;Format/Info                              : Meridian Lossless Packing FBA with 16-channel presentation&#xA;Commercial name                          : Dolby TrueHD with Dolby Atmos&#xA;Codec ID                                 : A_TRUEHD&#xA;Duration                                 : 1 h 50 min&#xA;Bit rate mode                            : Variable&#xA;Bit rate                                 : 3 545 kb/s&#xA;Maximum bit rate                         : 5 826 kb/s&#xA;Channel(s)                               : 8 channels&#xA;Channel layout                           : L R C LFE Ls Rs Lb Rb&#xA;Sampling rate                            : 48.0 kHz&#xA;Frame rate                               : 1 200.000 FPS (40 SPF)&#xA;Bit depth                                : 24 bits&#xA;Compression mode                         : Lossless&#xA;Delay relative to video                  : 21 ms&#xA;Stream size                              : 2.73 GiB (29%)&#xA;Title                                    : Dolby TrueHD 7.1 (Atmos)&#xA;Language                                 : English&#xA;Default                                  : Yes&#xA;Forced                                   : No&#xA;Number of dynamic objects                : 11&#xA;Bed channel count                        : 1 channel&#xA;Bed channel configuration                : LFE&#xA;&#xA;Audio #2&#xA;ID                                       : 3&#xA;Format                                   : AAC LC&#xA;Format/Info                              : Advanced Audio Codec Low Complexity&#xA;Codec ID                                 : A_AAC-2&#xA;Duration                                 : 1 h 50 min&#xA;Bit rate                                 : 3 545 kb/s&#xA;Channel(s)                               : 8 channels&#xA;Channel layout                           : C L R Ls Rs Lb Rb LFE&#xA;Sampling rate                            : 48.0 kHz&#xA;Frame rate                               : 46.875 FPS (1024 SPF)&#xA;Compression mode                         : Lossy&#xA;Stream size                              : 2.73 GiB (29%)&#xA;Title                                    : AAC 5.1&#xA;Writing library                          : Lavc58.62.100 aac&#xA;Language                                 : English&#xA;Default                                  : Yes&#xA;Forced                                   : No&#xA;

    &#xA;&#xA;

    As you can see the bit rate, stream size, etc is copied from the source track which is incorrect. I've tried the -map_metadata -1 but that removes the metadata without creating a new one and also removed it from all video and audio tracks which I don't want.

    &#xA;&#xA;

    Any other ideas what I am doing wrong or is this just a quirk of the software ?

    &#xA;&#xA;

    Thanks in advance.

    &#xA;&#xA;

    Adding -report output trimming the lines "Writing block of size..." as the file is huge :

    &#xA;&#xA;

    ffmpeg started on 2019-12-04 at 14:31:25&#xA;Report written to "ffmpeg-20191204-143125.log"&#xA;Log level: 48&#xA;Command line:&#xA;"C:\\ffmpeg\\ffmpeg-20191118-d831edc-win64-static\\bin\\ffmpeg" -i input.mkv -report -map_chapters 0 -map 0:v -c:v copy -c:s copy -map 0:a -c:a:0 copy -map 0:a -c:a:1 aac destination.mkv&#xA;ffmpeg version git-2019-11-18-d831edc Copyright (c) 2000-2019 the FFmpeg developers&#xA;  built with gcc 9.2.1 (GCC) 20191010&#xA;  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf&#xA;  libavutil      56. 36.100 / 56. 36.100&#xA;  libavcodec     58. 62.100 / 58. 62.100&#xA;  libavformat    58. 35.100 / 58. 35.100&#xA;  libavdevice    58.  9.101 / 58.  9.101&#xA;  libavfilter     7. 66.100 /  7. 66.100&#xA;  libswscale      5.  6.100 /  5.  6.100&#xA;  libswresample   3.  6.100 /  3.  6.100&#xA;  libpostproc    55.  6.100 / 55.  6.100&#xA;Splitting the commandline.&#xA;Reading option &#x27;-i&#x27; ... matched as input url with argument &#x27;input.mkv&#x27;.&#xA;Reading option &#x27;-report&#x27; ... matched as option &#x27;report&#x27; (generate a report) with argument &#x27;1&#x27;.&#xA;Reading option &#x27;-map_chapters&#x27; ... matched as option &#x27;map_chapters&#x27; (set chapters mapping) with argument &#x27;0&#x27;.&#xA;Reading option &#x27;-map&#x27; ... matched as option &#x27;map&#x27; (set input stream mapping) with argument &#x27;0:v&#x27;.&#xA;Reading option &#x27;-c:v&#x27; ... matched as option &#x27;c&#x27; (codec name) with argument &#x27;copy&#x27;.&#xA;Reading option &#x27;-c:s&#x27; ... matched as option &#x27;c&#x27; (codec name) with argument &#x27;copy&#x27;.&#xA;Reading option &#x27;-map&#x27; ... matched as option &#x27;map&#x27; (set input stream mapping) with argument &#x27;0:a&#x27;.&#xA;Reading option &#x27;-c:a:0&#x27; ... matched as option &#x27;c&#x27; (codec name) with argument &#x27;copy&#x27;.&#xA;Reading option &#x27;-map&#x27; ... matched as option &#x27;map&#x27; (set input stream mapping) with argument &#x27;0:a&#x27;.&#xA;Reading option &#x27;-c:a:1&#x27; ... matched as option &#x27;c&#x27; (codec name) with argument &#x27;aac&#x27;.&#xA;Reading option &#x27;destination.mkv&#x27; ... matched as output url.&#xA;Finished splitting the commandline.&#xA;Parsing a group of options: global .&#xA;Applying option report (generate a report) with argument 1.&#xA;Successfully parsed a group of options.&#xA;Parsing a group of options: input url input.mkv.&#xA;Successfully parsed a group of options.&#xA;Opening an input file: input.mkv.&#xA;[NULL @ 000001b290ddad00] Opening &#x27;input.mkv&#x27; for reading&#xA;[file @ 000001b290ddbe00] Setting default whitelist &#x27;file,crypto&#x27;&#xA;[matroska,webm @ 000001b290ddad00] Format matroska,webm probed with size=2048 and score=100&#xA;st:0 removing common factor 1000000 from timebase&#xA;st:1 removing common factor 1000000 from timebase&#xA;[matroska,webm @ 000001b290ddad00] Before avformat_find_stream_info() pos: 5080 bytes read:32768 seeks:0 nb_streams:2&#xA;[hevc @ 000001b290ddeb80] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0&#xA;[hevc @ 000001b290ddeb80] Decoding VPS&#xA;[hevc @ 000001b290ddeb80] Main 10 profile bitstream&#xA;[hevc @ 000001b290ddeb80] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0&#xA;[hevc @ 000001b290ddeb80] Decoding SPS&#xA;[hevc @ 000001b290ddeb80] Main 10 profile bitstream&#xA;[hevc @ 000001b290ddeb80] Decoding VUI&#xA;[hevc @ 000001b290ddeb80] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0&#xA;[hevc @ 000001b290ddeb80] Decoding PPS&#xA;[hevc @ 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0&#xA;[hevc @ 000001b290ddeb80] Decoding SEI&#xA;[hevc @ 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0&#xA;[hevc @ 000001b290ddeb80] Decoding SEI&#xA;[hevc @ 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0&#xA;[hevc @ 000001b290ddeb80] Decoding SEI&#xA;[hevc @ 000001b290ddeb80] Skipped PREFIX SEI 5&#xA;[matroska,webm @ 000001b290ddad00] All info found&#xA;[matroska,webm @ 000001b290ddad00] After avformat_find_stream_info() pos: 10219 bytes read:32768 seeks:0 frames:4&#xA;Input #0, matroska,webm, from &#x27;input.mkv&#x27;:&#xA;  Metadata:&#xA;    title           : input&#xA;    ENCODER         : Lavf58.35.100&#xA;  Duration: 01:50:06.89, start: 0.000000, bitrate: 11569 kb/s&#xA;    Chapter #0:0: start 0.000000, end 308.766792&#xA;    Metadata:&#xA;      title           : Chapter 01&#xA;    Chapter #0:1: start 308.766792, end 679.720708&#xA;    Metadata:&#xA;      title           : Chapter 02&#xA;    Chapter #0:2: start 679.720708, end 904.820583&#xA;    Metadata:&#xA;      title           : Chapter 03&#xA;    Chapter #0:3: start 904.820583, end 1282.781500&#xA;    Metadata:&#xA;      title           : Chapter 04&#xA;    Chapter #0:4: start 1282.781500, end 1487.736250&#xA;    Metadata:&#xA;      title           : Chapter 05&#xA;    Chapter #0:5: start 1487.736250, end 1846.177667&#xA;    Metadata:&#xA;      title           : Chapter 06&#xA;    Chapter #0:6: start 1846.177667, end 2116.531083&#xA;    Metadata:&#xA;      title           : Chapter 07&#xA;    Chapter #0:7: start 2116.531083, end 2443.858083&#xA;    Metadata:&#xA;      title           : Chapter 08&#xA;    Chapter #0:8: start 2443.858083, end 2731.979250&#xA;    Metadata:&#xA;      title           : Chapter 09&#xA;    Chapter #0:9: start 2731.979250, end 3178.383542&#xA;    Metadata:&#xA;      title           : Chapter 10&#xA;    Chapter #0:10: start 3178.383542, end 3636.507875&#xA;    Metadata:&#xA;      title           : Chapter 11&#xA;    Chapter #0:11: start 3636.507875, end 3867.488625&#xA;    Metadata:&#xA;      title           : Chapter 12&#xA;    Chapter #0:12: start 3867.488625, end 4208.037167&#xA;    Metadata:&#xA;      title           : Chapter 13&#xA;    Chapter #0:13: start 4208.037167, end 4502.372875&#xA;    Metadata:&#xA;      title           : Chapter 14&#xA;    Chapter #0:14: start 4502.372875, end 4853.431917&#xA;    Metadata:&#xA;      title           : Chapter 15&#xA;    Chapter #0:15: start 4853.431917, end 5267.470542&#xA;    Metadata:&#xA;      title           : Chapter 16&#xA;    Chapter #0:16: start 5267.470542, end 5543.329458&#xA;    Metadata:&#xA;      title           : Chapter 17&#xA;    Chapter #0:17: start 5543.329458, end 5847.132958&#xA;    Metadata:&#xA;      title           : Chapter 18&#xA;    Chapter #0:18: start 5847.132958, end 6150.269125&#xA;    Metadata:&#xA;      title           : Chapter 19&#xA;    Chapter #0:19: start 6150.269125, end 6606.891958&#xA;    Metadata:&#xA;      title           : Chapter 20&#xA;    Stream #0:0, 3, 1/1000: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x1600 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc&#xA;    Metadata:&#xA;      title           : input&#xA;      ENCODER         : Lavc58.62.100 libx265&#xA;      DURATION        : 01:50:06.891000000&#xA;    Stream #0:1(eng), 1, 1/1000: Audio: truehd, 48000 Hz, 7.1, s32 (24 bit) (default)&#xA;    Metadata:&#xA;      title           : input&#xA;      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES&#xA;      BPS-eng         : 3544728&#xA;      DURATION-eng    : 01:50:06.893000000&#xA;      NUMBER_OF_FRAMES-eng: 7928271&#xA;      NUMBER_OF_BYTES-eng: 2927455224&#xA;      _STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 (&#x27;Old Town Road &#x2B; Pony&#x27;) 64-bit&#xA;      _STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25&#xA;      DURATION        : 01:50:06.893000000&#xA;Successfully opened the file.&#xA;Parsing a group of options: output url destination.mkv.&#xA;Applying option map_chapters (set chapters mapping) with argument 0.&#xA;Applying option map (set input stream mapping) with argument 0:v.&#xA;Applying option c:v (codec name) with argument copy.&#xA;Applying option c:s (codec name) with argument copy.&#xA;Applying option map (set input stream mapping) with argument 0:a.&#xA;Applying option c:a:0 (codec name) with argument copy.&#xA;Applying option map (set input stream mapping) with argument 0:a.&#xA;Applying option c:a:1 (codec name) with argument aac.&#xA;Successfully parsed a group of options.&#xA;Opening an output file: destination.mkv.&#xA;[file @ 000001b290ea7e40] Setting default whitelist &#x27;file,crypto&#x27;&#xA;Successfully opened the file.&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (copy)&#xA;  Stream #0:1 -> #0:1 (copy)&#xA;  Stream #0:1 -> #0:2 (truehd (native) -> aac (native))&#xA;Press [q] to stop, [?] for help&#xA;cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;detected 12 logical cores&#xA;[graph_0_in_0_1 @ 000001b290dda840] Setting &#x27;time_base&#x27; to value &#x27;1/48000&#x27;&#xA;[graph_0_in_0_1 @ 000001b290dda840] Setting &#x27;sample_rate&#x27; to value &#x27;48000&#x27;&#xA;[graph_0_in_0_1 @ 000001b290dda840] Setting &#x27;sample_fmt&#x27; to value &#x27;s32&#x27;&#xA;[graph_0_in_0_1 @ 000001b290dda840] Setting &#x27;channel_layout&#x27; to value &#x27;0x63f&#x27;&#xA;[graph_0_in_0_1 @ 000001b290dda840] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x63f&#xA;[format_out_0_2 @ 000001b290e0ea00] Setting &#x27;sample_fmts&#x27; to value &#x27;fltp&#x27;&#xA;[format_out_0_2 @ 000001b290e0ea00] Setting &#x27;sample_rates&#x27; to value &#x27;96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350&#x27;&#xA;[format_out_0_2 @ 000001b290e0ea00] auto-inserting filter &#x27;auto_resampler_0&#x27; between the filter &#x27;Parsed_anull_0&#x27; and the filter &#x27;format_out_0_2&#x27;&#xA;[AVFilterGraph @ 000001b290e1b3c0] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed&#xA;[auto_resampler_0 @ 000001b290e0fe80] [SWR @ 000001b291232000] Using fltp internally between filters&#xA;[auto_resampler_0 @ 000001b290e0fe80] ch:8 chl:7.1 fmt:s32 r:48000Hz -> ch:8 chl:7.1 fmt:fltp r:48000Hz&#xA;[matroska @ 000001b290dfba40] get_metadata_duration returned: 6606893000&#xA;[matroska @ 000001b290dfba40] Write early duration from metadata = 6606893&#xA;Output #0, matroska, to &#x27;destination.mkv&#x27;:&#xA;  Metadata:&#xA;    title           : input&#xA;    encoder         : Lavf58.35.100&#xA;    Chapter #0:0: start 0.000000, end 308.766792&#xA;    Metadata:&#xA;      title           : Chapter 01&#xA;    Chapter #0:1: start 308.766792, end 679.720708&#xA;    Metadata:&#xA;      title           : Chapter 02&#xA;    Chapter #0:2: start 679.720708, end 904.820583&#xA;    Metadata:&#xA;      title           : Chapter 03&#xA;    Chapter #0:3: start 904.820583, end 1282.781500&#xA;    Metadata:&#xA;      title           : Chapter 04&#xA;    Chapter #0:4: start 1282.781500, end 1487.736250&#xA;    Metadata:&#xA;      title           : Chapter 05&#xA;    Chapter #0:5: start 1487.736250, end 1846.177667&#xA;    Metadata:&#xA;      title           : Chapter 06&#xA;    Chapter #0:6: start 1846.177667, end 2116.531083&#xA;    Metadata:&#xA;      title           : Chapter 07&#xA;    Chapter #0:7: start 2116.531083, end 2443.858083&#xA;    Metadata:&#xA;      title           : Chapter 08&#xA;    Chapter #0:8: start 2443.858083, end 2731.979250&#xA;    Metadata:&#xA;      title           : Chapter 09&#xA;    Chapter #0:9: start 2731.979250, end 3178.383542&#xA;    Metadata:&#xA;      title           : Chapter 10&#xA;    Chapter #0:10: start 3178.383542, end 3636.507875&#xA;    Metadata:&#xA;      title           : Chapter 11&#xA;    Chapter #0:11: start 3636.507875, end 3867.488625&#xA;    Metadata:&#xA;      title           : Chapter 12&#xA;    Chapter #0:12: start 3867.488625, end 4208.037167&#xA;    Metadata:&#xA;      title           : Chapter 13&#xA;    Chapter #0:13: start 4208.037167, end 4502.372875&#xA;    Metadata:&#xA;      title           : Chapter 14&#xA;    Chapter #0:14: start 4502.372875, end 4853.431917&#xA;    Metadata:&#xA;      title           : Chapter 15&#xA;    Chapter #0:15: start 4853.431917, end 5267.470542&#xA;    Metadata:&#xA;      title           : Chapter 16&#xA;    Chapter #0:16: start 5267.470542, end 5543.329458&#xA;    Metadata:&#xA;      title           : Chapter 17&#xA;    Chapter #0:17: start 5543.329458, end 5847.132958&#xA;    Metadata:&#xA;      title           : Chapter 18&#xA;    Chapter #0:18: start 5847.132958, end 6150.269125&#xA;    Metadata:&#xA;      title           : Chapter 19&#xA;    Chapter #0:19: start 6150.269125, end 6606.891958&#xA;    Metadata:&#xA;      title           : Chapter 20&#xA;    Stream #0:0, 0, 1/1000: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x1600 [SAR 1:1 DAR 12:5], q=2-31, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc&#xA;    Metadata:&#xA;      title           : input&#xA;      ENCODER         : Lavc58.62.100 libx265&#xA;      DURATION        : 01:50:06.891000000&#xA;    Stream #0:1(eng), 0, 1/1000: Audio: truehd ([255][255][255][255] / 0xFFFFFFFF), 48000 Hz, 7.1, s32 (24 bit) (default)&#xA;    Metadata:&#xA;      title           : input&#xA;      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES&#xA;      BPS-eng         : 3544728&#xA;      DURATION-eng    : 01:50:06.893000000&#xA;      NUMBER_OF_FRAMES-eng: 7928271&#xA;      NUMBER_OF_BYTES-eng: 2927455224&#xA;      _STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 (&#x27;Old Town Road &#x2B; Pony&#x27;) 64-bit&#xA;      _STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25&#xA;      DURATION        : 01:50:06.893000000&#xA;    Stream #0:2(eng), 0, 1/1000: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, 7.1, fltp (24 bit), 469 kb/s (default)&#xA;    Metadata:&#xA;      title           : input&#xA;      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES&#xA;      BPS-eng         : 3544728&#xA;      DURATION-eng    : 01:50:06.893000000&#xA;      NUMBER_OF_FRAMES-eng: 7928271&#xA;      NUMBER_OF_BYTES-eng: 2927455224&#xA;      _STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 (&#x27;Old Town Road &#x2B; Pony&#x27;) 64-bit&#xA;      _STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25&#xA;      DURATION        : 01:50:06.893000000&#xA;      encoder         : Lavc58.62.100 aac&#xA;cur_dts is invalid st:2 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;&#xA;....................&#xA;....................&#xA;[matroska @ 000001b290dfba40] Writing block of size 168 with pts 6606913, dts 6606913, duration 1 at relative offset 550755 in cluster at offset 9940898622. TrackNumber 2, keyframe 1&#xA;[matroska @ 000001b290dfba40] end duration = 6606914&#xA;[matroska @ 000001b290dfba40] stream 0 end duration = 6606912&#xA;[matroska @ 000001b290dfba40] stream 1 end duration = 6606914&#xA;[matroska @ 000001b290dfba40] stream 2 end duration = 6606914&#xA;frame=158407 fps=357 q=-1.0 Lsize= 9708475kB time=01:50:06.91 bitrate=12037.7kbits/s speed=14.9x    &#xA;video:6416483kB audio:3234397kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.596787%&#xA;Input file #0 (input.mkv):&#xA;  Input stream #0:0 (video): 158407 packets read (6570478730 bytes); &#xA;  Input stream #0:1 (audio): 7928271 packets read (2927455224 bytes); 7928271 frames decoded (317130840 samples); &#xA;  Total: 8086678 packets (9497933954 bytes) demuxed&#xA;Output file #0 (destination.mkv):&#xA;  Output stream #0:0 (video): 158407 packets muxed (6570478730 bytes); &#xA;  Output stream #0:1 (audio): 7928271 packets muxed (2927455224 bytes); &#xA;  Output stream #0:2 (audio): 309699 frames encoded (317130840 samples); 309700 packets muxed (384567176 bytes); &#xA;  Total: 8396378 packets (9882501130 bytes) muxed&#xA;7928271 frames successfully decoded, 0 decoding errors&#xA;[AVIOContext @ 000001b291230100] Statistics: 8 seeks, 39676 writeouts&#xA;[aac @ 000001b290dff3c0] Qavg: 3839.668&#xA;[AVIOContext @ 000001b290de4080] Statistics: 9554742230 bytes read, 0 seeks&#xA;

    &#xA;

  • 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) &lt; 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(&amp;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 &amp; AVFMT_NOFILE)) {
       int r = avio_open(&amp;rtmp_format_context_->pb, uri.c_str(), AVIO_FLAG_WRITE);
       if (r &lt; 0) {
           throw std::runtime_error("unable to open " + uri + " : " + av_err2str(r));
       }
    }

    if (avformat_write_header(rtmp_format_context_.get(), NULL) &lt; 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 &lt; 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 &lt; 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 &lt; 0 ) {
               std::cerr &lt;&lt; av_err2str(rval) &lt;&lt; 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.