Recherche avancée

Médias (1)

Mot : - Tags -/musée

Autres articles (73)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • Création définitive du canal

    12 mars 2010, par

    Lorsque votre demande est validée, vous pouvez alors procéder à la création proprement dite du canal. Chaque canal est un site à part entière placé sous votre responsabilité. Les administrateurs de la plateforme n’y ont aucun accès.
    A la validation, vous recevez un email vous invitant donc à créer votre canal.
    Pour ce faire il vous suffit de vous rendre à son adresse, dans notre exemple "http://votre_sous_domaine.mediaspip.net".
    A ce moment là un mot de passe vous est demandé, il vous suffit d’y (...)

  • Demande de création d’un canal

    12 mars 2010, par

    En fonction de la configuration de la plateforme, l’utilisateur peu avoir à sa disposition deux méthodes différentes de demande de création de canal. La première est au moment de son inscription, la seconde, après son inscription en remplissant un formulaire de demande.
    Les deux manières demandent les mêmes choses fonctionnent à peu près de la même manière, le futur utilisateur doit remplir une série de champ de formulaire permettant tout d’abord aux administrateurs d’avoir des informations quant à (...)

Sur d’autres sites (5055)

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

    



    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.

    



    Below is an example of what I am doing :

    



    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


    



    This results in a media info of :

    



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

Audio #2
ID                                       : 3
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : A_AAC-2
Duration                                 : 1 h 50 min
Bit rate                                 : 3 545 kb/s
Channel(s)                               : 8 channels
Channel layout                           : C L R Ls Rs Lb Rb LFE
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 2.73 GiB (29%)
Title                                    : AAC 5.1
Writing library                          : Lavc58.62.100 aac
Language                                 : English
Default                                  : Yes
Forced                                   : No


    



    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.

    



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

    



    Thanks in advance.

    



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

    



    ffmpeg started on 2019-12-04 at 14:31:25
Report written to "ffmpeg-20191204-143125.log"
Log level: 48
Command line:
"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
ffmpeg version git-2019-11-18-d831edc Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20191010
  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
  libavutil      56. 36.100 / 56. 36.100
  libavcodec     58. 62.100 / 58. 62.100
  libavformat    58. 35.100 / 58. 35.100
  libavdevice    58.  9.101 / 58.  9.101
  libavfilter     7. 66.100 /  7. 66.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'input.mkv'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-map_chapters' ... matched as option 'map_chapters' (set chapters mapping) with argument '0'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:v'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-c:s' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:a'.
Reading option '-c:a:0' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:a'.
Reading option '-c:a:1' ... matched as option 'c' (codec name) with argument 'aac'.
Reading option 'destination.mkv' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url input.mkv.
Successfully parsed a group of options.
Opening an input file: input.mkv.
[NULL @ 000001b290ddad00] Opening 'input.mkv' for reading
[file @ 000001b290ddbe00] Setting default whitelist 'file,crypto'
[matroska,webm @ 000001b290ddad00] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
st:1 removing common factor 1000000 from timebase
[matroska,webm @ 000001b290ddad00] Before avformat_find_stream_info() pos: 5080 bytes read:32768 seeks:0 nb_streams:2
[hevc @ 000001b290ddeb80] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b290ddeb80] Decoding VPS
[hevc @ 000001b290ddeb80] Main 10 profile bitstream
[hevc @ 000001b290ddeb80] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b290ddeb80] Decoding SPS
[hevc @ 000001b290ddeb80] Main 10 profile bitstream
[hevc @ 000001b290ddeb80] Decoding VUI
[hevc @ 000001b290ddeb80] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b290ddeb80] Decoding PPS
[hevc @ 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b290ddeb80] Decoding SEI
[hevc @ 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b290ddeb80] Decoding SEI
[hevc @ 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b290ddeb80] Decoding SEI
[hevc @ 000001b290ddeb80] Skipped PREFIX SEI 5
[matroska,webm @ 000001b290ddad00] All info found
[matroska,webm @ 000001b290ddad00] After avformat_find_stream_info() pos: 10219 bytes read:32768 seeks:0 frames:4
Input #0, matroska,webm, from 'input.mkv':
  Metadata:
    title           : input
    ENCODER         : Lavf58.35.100
  Duration: 01:50:06.89, start: 0.000000, bitrate: 11569 kb/s
    Chapter #0:0: start 0.000000, end 308.766792
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 308.766792, end 679.720708
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 679.720708, end 904.820583
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 904.820583, end 1282.781500
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 1282.781500, end 1487.736250
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 1487.736250, end 1846.177667
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 1846.177667, end 2116.531083
    Metadata:
      title           : Chapter 07
    Chapter #0:7: start 2116.531083, end 2443.858083
    Metadata:
      title           : Chapter 08
    Chapter #0:8: start 2443.858083, end 2731.979250
    Metadata:
      title           : Chapter 09
    Chapter #0:9: start 2731.979250, end 3178.383542
    Metadata:
      title           : Chapter 10
    Chapter #0:10: start 3178.383542, end 3636.507875
    Metadata:
      title           : Chapter 11
    Chapter #0:11: start 3636.507875, end 3867.488625
    Metadata:
      title           : Chapter 12
    Chapter #0:12: start 3867.488625, end 4208.037167
    Metadata:
      title           : Chapter 13
    Chapter #0:13: start 4208.037167, end 4502.372875
    Metadata:
      title           : Chapter 14
    Chapter #0:14: start 4502.372875, end 4853.431917
    Metadata:
      title           : Chapter 15
    Chapter #0:15: start 4853.431917, end 5267.470542
    Metadata:
      title           : Chapter 16
    Chapter #0:16: start 5267.470542, end 5543.329458
    Metadata:
      title           : Chapter 17
    Chapter #0:17: start 5543.329458, end 5847.132958
    Metadata:
      title           : Chapter 18
    Chapter #0:18: start 5847.132958, end 6150.269125
    Metadata:
      title           : Chapter 19
    Chapter #0:19: start 6150.269125, end 6606.891958
    Metadata:
      title           : Chapter 20
    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
    Metadata:
      title           : input
      ENCODER         : Lavc58.62.100 libx265
      DURATION        : 01:50:06.891000000
    Stream #0:1(eng), 1, 1/1000: Audio: truehd, 48000 Hz, 7.1, s32 (24 bit) (default)
    Metadata:
      title           : input
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      BPS-eng         : 3544728
      DURATION-eng    : 01:50:06.893000000
      NUMBER_OF_FRAMES-eng: 7928271
      NUMBER_OF_BYTES-eng: 2927455224
      _STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 ('Old Town Road + Pony') 64-bit
      _STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25
      DURATION        : 01:50:06.893000000
Successfully opened the file.
Parsing a group of options: output url destination.mkv.
Applying option map_chapters (set chapters mapping) with argument 0.
Applying option map (set input stream mapping) with argument 0:v.
Applying option c:v (codec name) with argument copy.
Applying option c:s (codec name) with argument copy.
Applying option map (set input stream mapping) with argument 0:a.
Applying option c:a:0 (codec name) with argument copy.
Applying option map (set input stream mapping) with argument 0:a.
Applying option c:a:1 (codec name) with argument aac.
Successfully parsed a group of options.
Opening an output file: destination.mkv.
[file @ 000001b290ea7e40] Setting default whitelist 'file,crypto'
Successfully opened the file.
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:1 -> #0:2 (truehd (native) -> aac (native))
Press [q] to stop, [?] for help
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
detected 12 logical cores
[graph_0_in_0_1 @ 000001b290dda840] Setting 'time_base' to value '1/48000'
[graph_0_in_0_1 @ 000001b290dda840] Setting 'sample_rate' to value '48000'
[graph_0_in_0_1 @ 000001b290dda840] Setting 'sample_fmt' to value 's32'
[graph_0_in_0_1 @ 000001b290dda840] Setting 'channel_layout' to value '0x63f'
[graph_0_in_0_1 @ 000001b290dda840] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x63f
[format_out_0_2 @ 000001b290e0ea00] Setting 'sample_fmts' to value 'fltp'
[format_out_0_2 @ 000001b290e0ea00] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[format_out_0_2 @ 000001b290e0ea00] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_2'
[AVFilterGraph @ 000001b290e1b3c0] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 000001b290e0fe80] [SWR @ 000001b291232000] Using fltp internally between filters
[auto_resampler_0 @ 000001b290e0fe80] ch:8 chl:7.1 fmt:s32 r:48000Hz -> ch:8 chl:7.1 fmt:fltp r:48000Hz
[matroska @ 000001b290dfba40] get_metadata_duration returned: 6606893000
[matroska @ 000001b290dfba40] Write early duration from metadata = 6606893
Output #0, matroska, to 'destination.mkv':
  Metadata:
    title           : input
    encoder         : Lavf58.35.100
    Chapter #0:0: start 0.000000, end 308.766792
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 308.766792, end 679.720708
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 679.720708, end 904.820583
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 904.820583, end 1282.781500
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 1282.781500, end 1487.736250
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 1487.736250, end 1846.177667
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 1846.177667, end 2116.531083
    Metadata:
      title           : Chapter 07
    Chapter #0:7: start 2116.531083, end 2443.858083
    Metadata:
      title           : Chapter 08
    Chapter #0:8: start 2443.858083, end 2731.979250
    Metadata:
      title           : Chapter 09
    Chapter #0:9: start 2731.979250, end 3178.383542
    Metadata:
      title           : Chapter 10
    Chapter #0:10: start 3178.383542, end 3636.507875
    Metadata:
      title           : Chapter 11
    Chapter #0:11: start 3636.507875, end 3867.488625
    Metadata:
      title           : Chapter 12
    Chapter #0:12: start 3867.488625, end 4208.037167
    Metadata:
      title           : Chapter 13
    Chapter #0:13: start 4208.037167, end 4502.372875
    Metadata:
      title           : Chapter 14
    Chapter #0:14: start 4502.372875, end 4853.431917
    Metadata:
      title           : Chapter 15
    Chapter #0:15: start 4853.431917, end 5267.470542
    Metadata:
      title           : Chapter 16
    Chapter #0:16: start 5267.470542, end 5543.329458
    Metadata:
      title           : Chapter 17
    Chapter #0:17: start 5543.329458, end 5847.132958
    Metadata:
      title           : Chapter 18
    Chapter #0:18: start 5847.132958, end 6150.269125
    Metadata:
      title           : Chapter 19
    Chapter #0:19: start 6150.269125, end 6606.891958
    Metadata:
      title           : Chapter 20
    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
    Metadata:
      title           : input
      ENCODER         : Lavc58.62.100 libx265
      DURATION        : 01:50:06.891000000
    Stream #0:1(eng), 0, 1/1000: Audio: truehd ([255][255][255][255] / 0xFFFFFFFF), 48000 Hz, 7.1, s32 (24 bit) (default)
    Metadata:
      title           : input
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      BPS-eng         : 3544728
      DURATION-eng    : 01:50:06.893000000
      NUMBER_OF_FRAMES-eng: 7928271
      NUMBER_OF_BYTES-eng: 2927455224
      _STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 ('Old Town Road + Pony') 64-bit
      _STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25
      DURATION        : 01:50:06.893000000
    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)
    Metadata:
      title           : input
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      BPS-eng         : 3544728
      DURATION-eng    : 01:50:06.893000000
      NUMBER_OF_FRAMES-eng: 7928271
      NUMBER_OF_BYTES-eng: 2927455224
      _STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 ('Old Town Road + Pony') 64-bit
      _STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25
      DURATION        : 01:50:06.893000000
      encoder         : Lavc58.62.100 aac
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)

....................
....................
[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
[matroska @ 000001b290dfba40] end duration = 6606914
[matroska @ 000001b290dfba40] stream 0 end duration = 6606912
[matroska @ 000001b290dfba40] stream 1 end duration = 6606914
[matroska @ 000001b290dfba40] stream 2 end duration = 6606914
frame=158407 fps=357 q=-1.0 Lsize= 9708475kB time=01:50:06.91 bitrate=12037.7kbits/s speed=14.9x    
video:6416483kB audio:3234397kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.596787%
Input file #0 (input.mkv):
  Input stream #0:0 (video): 158407 packets read (6570478730 bytes); 
  Input stream #0:1 (audio): 7928271 packets read (2927455224 bytes); 7928271 frames decoded (317130840 samples); 
  Total: 8086678 packets (9497933954 bytes) demuxed
Output file #0 (destination.mkv):
  Output stream #0:0 (video): 158407 packets muxed (6570478730 bytes); 
  Output stream #0:1 (audio): 7928271 packets muxed (2927455224 bytes); 
  Output stream #0:2 (audio): 309699 frames encoded (317130840 samples); 309700 packets muxed (384567176 bytes); 
  Total: 8396378 packets (9882501130 bytes) muxed
7928271 frames successfully decoded, 0 decoding errors
[AVIOContext @ 000001b291230100] Statistics: 8 seeks, 39676 writeouts
[aac @ 000001b290dff3c0] Qavg: 3839.668
[AVIOContext @ 000001b290de4080] Statistics: 9554742230 bytes read, 0 seeks


    


  • Converting mkv to mp4 with ffmpeg sometimes loses video

    9 décembre 2019, par RobertW

    How can I create a universal as possible command line to convert mkv to mp4 ?

    I fixed an issue where sometimes I’d lose audio (I think) and now I’m losing video.
    This is the command I currently use (I’ve used a few, including -analyzeduration 1G -probesize 50M but I always end up with broken videos at some point) :

    if [[ $(pgrep -i ffmpeg) ]] ; then
     echo "FFMPEG IS ALREADY RUNNING!"
    else
     echo "Starting mkv to mp4 conversion...";
       for i in /var/www/html/uploads/Videos/*/*/*/*.mkv;
         do name=$(echo "${i//.mkv/}");
         echo "$name";
         ffmpeg -n -i "$i" -c copy -c:a aac -movflags +faststart "${name}.mp4"; rm -v -f "${name}.mkv";
       done
    fi

    Output of running that on the specific videos I’m losing picture on :

    Starting mkv to mp4 conversion...
    /var/www/html/uploads/Videos/TV/Avatar The Last Airbender/Season 1/Avatar The Last Airbender - S01E02 - The Avatar Returns WEBDL-1080p
    ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
     built with gcc 9 (GCC)
     configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/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 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --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      56. 31.100 / 56. 31.100
     libavcodec     58. 54.100 / 58. 54.100
     libavformat    58. 29.100 / 58. 29.100
     libavdevice    58.  8.100 / 58.  8.100
     libavfilter     7. 57.100 /  7. 57.100
     libavresample   4.  0.  0 /  4.  0.  0
     libswscale      5.  5.100 /  5.  5.100
     libswresample   3.  5.100 /  3.  5.100
     libpostproc    55.  5.100 / 55.  5.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/uploads/Videos/TV/Avatar The Last Airbender/Season 1/Avatar The Last Airbender - S01E02 - The Avatar Returns WEBDL-1080p.mkv':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       encoder         : Lavf58.29.100
     Duration: 00:23:59.11, start: 0.000000, bitrate: 1258 kb/s
       Stream #0:0(und): Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv), 1440x1080, 1124 kb/s, SAR 1:1 DAR 4:3, 23.98 fps, 23.98 tbr, 16k tbn, 23.98 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
    Stream mapping:
     Stream #0:0 -> #0:0 (copy)
     Stream #0:1 -> #0:1 (aac (native) -> aac (native))
    Press [q] to stop, [?] for help
    Output #0, mp4, to '/var/www/html/uploads/Videos/TV/Avatar The Last Airbender/Season 1/Avatar The Last Airbender - S01E02 - The Avatar Returns WEBDL-1080p.mp4':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       encoder         : Lavf58.29.100
       Stream #0:0(und): Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv), 1440x1080 [SAR 1:1 DAR 4:3], q=2-31, 1124 kb/s, 23.98 fps, 23.98 tbr, 16k tbn, 16k tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
         encoder         : Lavc58.54.100 aac
    [mp4 @ 0x5583e9bdb8c0] Starting second pass: moving the moov atom to the beginning of the file
    frame=34504 fps=1260 q=-1.0 Lsize=  221105kB time=00:23:59.08 bitrate=1258.6kbits/s speed=52.5x
    video:197477kB audio:22515kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.506059%
    [aac @ 0x5583e9b3f140] Qavg: 562.538

    Edit :

    The below command worked on similar files which the above command did not :

     ffmpeg -n -i "$i" -c:v libx264 -c:a aac -movflags +faststart

    Output :

    Starting mkv to mp4 conversion...
    /var/www/html/uploads/Videos/TV/Avatar The Last Airbender/Season 1/Avatar The Last Airbender - S01E03 - The Southern Air Temple WEBDL-1080p
    ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
     built with gcc 9 (GCC)
     configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/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 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --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      56. 31.100 / 56. 31.100
     libavcodec     58. 54.100 / 58. 54.100
     libavformat    58. 29.100 / 58. 29.100
     libavdevice    58.  8.100 / 58.  8.100
     libavfilter     7. 57.100 /  7. 57.100
     libavresample   4.  0.  0 /  4.  0.  0
     libswscale      5.  5.100 /  5.  5.100
     libswresample   3.  5.100 /  3.  5.100
     libpostproc    55.  5.100 / 55.  5.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/uploads/Videos/TV/Avatar The Last Airbender/Season 1/Avatar The Last Airbender - S01E03 - The Southern Air Temple WEBDL-1080p.mkv':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       encoder         : Lavf58.29.100
     Duration: 00:24:10.74, start: 0.000000, bitrate: 1354 kb/s
       Stream #0:0(und): Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv), 1440x1080, 1124 kb/s, SAR 1:1 DAR 4:3, 23.98 fps, 23.98 tbr, 16k tbn, 23.98 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(eng): Audio: eac3 (ec-3 / 0x332D6365), 48000 Hz, stereo, fltp, 224 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
       Side data:
         audio service type: main
    Stream mapping:
     Stream #0:0 -> #0:0 (hevc (native) -> h264 (libx264))
     Stream #0:1 -> #0:1 (eac3 (native) -> aac (native))
    Press [q] to stop, [?] for help
    [libx264 @ 0x563ef7ad5a40] using SAR=1/1
    [libx264 @ 0x563ef7ad5a40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
    [libx264 @ 0x563ef7ad5a40] profile High 10, level 4.0, 4:2:0, 10-bit
    [libx264 @ 0x563ef7ad5a40] 264 - core 157 r2980 34c06d1 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - 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=34 lookahead_threads=5 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=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=81 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to '/var/www/html/uploads/Videos/TV/Avatar The Last Airbender/Season 1/Avatar The Last Airbender - S01E03 - The Southern Air Temple WEBDL-1080p.mp4':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       encoder         : Lavf58.29.100
       Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p10le, 1440x1080 [SAR 1:1 DAR 4:3], q=-1--1, 23.98 fps, 24k tbn, 23.98 tbc (default)
       Metadata:
         handler_name    : VideoHandler
         encoder         : Lavc58.54.100 libx264
       Side data:
         cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
       Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
         encoder         : Lavc58.54.100 aac
       Side data:
         audio service type: main
    frame=   37 fps=0.0 q=0.0 size=       0kB time=00:00:02.09 bitrate=   0.2kbits/sframe=   72 fps= 72 q=0.0 size=       0kB time=00:00:03.54 bitrate=   0.1kbits/sframe=  103 fps= 68 q=40.0 size=       0kB time=00:00:04.84 bitrate=   0.1kbits/frame=  128 fps= 64 q=40.0 size=       0kB time=00:00:05.90 bitrate=   0.1kbits/frame=  169 fps= 66 q=40.0 size=     256kB time=00:00:07.59 bitrate= 276.2kbits/frame=  194 fps= 63 q=40.0 size=     512kB time=00:00:08.66 bitrate= 484.3kbits/frame=  241 fps= 68 q=40.0 size=     512kB time=00:00:10.60 bitrate= 395.6kbits/frame=  262 fps= 64 q=40.0 size=     512kB time=00:00:11.47 bitrate= 365.5kbits/frame=  284 fps= 62 q=40.0 size=     768kB time=00:00:12.37 bitrate= 508.5kbits/frame=  312 fps= 61 q=40.0 size=     768kB time=00:00:13.54 bitrate= 464.5kbits/frame=  341 fps= 61 q=40.0 size=    1024kB time=00:00:14.74 bitrate= 569.1kbits/frame=  373 fps= 61 q=40.0 size=    1280kB time=00:00:16.10 bitrate= 651.0kbits/frame=  398 fps= 60 q=40.0 size=    1280kB time=00:00:17.13 bitrate= 612.1kbits/frame=  419 fps= 59 q=40.0 size=    1536kB time=00:00:18.02 bitrate= 698.0kbits/frame=  433 fps= 56 q=40.0 size=    1792kB time=00:00:18.60 bitrate= 789.2kbits/frame=  456 fps= 55 q=40.0 size=    2048kB time=00:00:19.56 bitrate= 857.6kbits/frame=  469 fps= 53 q=40.0 size=    2304kB time=00:00:20.11 bitrate= 938.2kbits/frame=  486 fps= 52 q=40.0 size=    2816kB time=00:00:20.82 bitrate=1108.0kbits/frame=  504 fps= 51 q=40.0 size=    3328kB time=00:00:21.58 bitrate=1262.8kbits/frame=  522 fps= 51 q=40.0 size=    4096kB time=00:00:22.31 bitrate=1503.7kbits/frame=  545 fps= 50 q=40.0 size=    4608kB time=00:00:23.27 bitrate=1621.9kbits/frame=  570 fps= 50 q=40.0 size=    5120kB time=00:00:24.34 bitrate=1723.1kbits/frame=  597 fps= 50 q=40.0 size=    5632kB time=00:00:25.45 bitrate=1812.8kbits/frame=  619 fps= 50 q=40.0 size=    5888kB time=00:00:26.38 bitrate=1827.8kbits/frame=  650 fps= 50 q=40.0 size=    6400kB time=00:00:27.66 bitrate=1894.8kbits/frame=  674 fps= 50 q=40.0 size=    6656kB time=00:00:28.65 bitrate=1903.1kbits/frame=  701 fps= 50 q=40.0 size=    6656kB time=00:00:29.78 bitrate=1830.9kbits/frame=  734 fps= 51 q=40.0 size=    6912kB time=00:00:31.12 bitrate=1819.2kbits/frame=  754 fps= 50 q=40.0 size=    7168kB time=00:00:31.97 bitrate=1836.2kbits/frame=  778 fps= 50 q=40.0 size=    7168kB time=00:00:33.00 --SNIPPED--
    bitrate=1518.4kbits/frame=34775 fps= 58 q=40.0 size=  268800kB time=00:24:10.64 bitrate=1518.0kbits/[mp4 @ 0x563ef7ad45c0] Starting second pass: moving the moov atom to the beginning of the file
    frame=34783 fps= 58 q=-1.0 Lsize=  269967kB time=00:24:10.68 bitrate=1524.5kbits/s speed= 2.4x
    video:246310kB audio:22689kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.359968%
    [libx264 @ 0x563ef7ad5a40] frame I:651   Avg QP:27.80  size: 60711
    [libx264 @ 0x563ef7ad5a40] frame P:10705 Avg QP:32.02  size: 14279
    [libx264 @ 0x563ef7ad5a40] frame B:23427 Avg QP:37.64  size:  2554
    [libx264 @ 0x563ef7ad5a40] consecutive B-frames:  6.9%  8.1%  5.5% 79.6%
    [libx264 @ 0x563ef7ad5a40] mb I  I16..4: 29.6% 60.8%  9.6%
    [libx264 @ 0x563ef7ad5a40] mb P  I16..4:  7.7% 10.0%  1.1%  P16..4: 20.4%  3.8%  2.2%  0.0%  0.0%    skip:54.8%
    [libx264 @ 0x563ef7ad5a40] mb B  I16..4:  0.6%  0.6%  0.1%  B16..8: 13.6%  1.0%  0.2%  direct: 0.7%  skip:83.3%  L0:41.6% L1:55.3% BI: 3.1%
    [libx264 @ 0x563ef7ad5a40] 8x8 transform intra:54.2% inter:75.7%
    [libx264 @ 0x563ef7ad5a40] coded y,uvDC,uvAC intra: 29.1% 50.3% 11.9% inter: 3.4% 4.5% 0.1%
    [libx264 @ 0x563ef7ad5a40] i16 v,h,dc,p: 25% 29%  9% 38%
    [libx264 @ 0x563ef7ad5a40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 18% 25%  4%  5%  5%  5%  5%  5%
    [libx264 @ 0x563ef7ad5a40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 14% 17%  7%  8%  9%  6%  7%  4%
    [libx264 @ 0x563ef7ad5a40] i8c dc,h,v,p: 51% 22% 19%  9%
    [libx264 @ 0x563ef7ad5a40] Weighted P-Frames: Y:2.7% UV:2.1%
    [libx264 @ 0x563ef7ad5a40] ref P L0: 74.1% 16.9%  8.9%  0.1%
    [libx264 @ 0x563ef7ad5a40] ref B L0: 85.8% 11.6%  2.6%
    [libx264 @ 0x563ef7ad5a40] ref B L1: 96.8%  3.2%
    [libx264 @ 0x563ef7ad5a40] kb/s:1390.85
    [aac @ 0x563ef7ade100] Qavg: 572.905
    removed '/var/www/html/uploads/Videos/TV/Avatar The Last Airbender/Season 1/Avatar The Last Airbender - S01E03 - The Southern Air Temple WEBDL-1080p.mkv'
    Done transcoding!
  • 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.