Recherche avancée

Médias (0)

Mot : - Tags -/xmlrpc

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (28)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

  • 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" ;

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

Sur d’autres sites (4349)

  • Using ffmpeg for streaming video composition from Python : why the sound is cut only when streaming into a mp4 file ?

    4 décembre 2017, par redantlabs

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

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

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

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

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

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

    Building a raw video file with the correct specifications

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

    Streaming the raw video file into the ffmpeg command

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

    Here is the version of ffmpeg I am using :

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

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

    ffmpeg -i samplevideo.mp4 stream_audio.mp3

    Thanks for your help.

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

    Command generated by my Python script with mp4 :

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

    Command generated by my Python script with avi :

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

    Pure command line for mp4 format :

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

    27 février 2020, par michpohl

    I am trying to decode am MP3 file to a raw PCM stream using FFMpeg via JNI on Android. I have compiled the latest FFMpeg version (4.2) and added it to my app. This did not make any problems.
    The goal is to be able to use mp3 files from the device’s storage for playback with oboe

    Since I am relatively inexperienced with both C++ and FFMpeg, my approach is based upon this :
    oboe’s RhythmGame example

    I have based my FFMpegExtractorclass on the one found in the example here. With the help of StackOverflow the AAssetManageruse was removed and instead a MediaSource helper class now serves as a wrapper for my stream (see here)

    But unfortunately, creating the AVFormatContext doesn’t work right - and I can’t seem to understand why. Since I have very limited understanding of correct pointer usage and C++ memory management, I suspect it’s most likely I’m doing something wrong in that area. But honestly, I have no idea.

    This is my FFMpegExtractor.h :

    #define MYAPP_FFMPEGEXTRACTOR_H

    extern "C" {
    #include <libavformat></libavformat>avformat.h>
    #include <libswresample></libswresample>swresample.h>
    #include <libavutil></libavutil>opt.h>
    }

    #include <cstdint>
    #include <android></android>asset_manager.h>
    #include
    #include <fstream>
    #include "MediaSource.cpp"


    class FFMpegExtractor {
    public:

       FFMpegExtractor();

       ~FFMpegExtractor();

       int64_t decode2(char *filepath, uint8_t *targetData, AudioProperties targetProperties);

    private:
       MediaSource *mSource;

       bool createAVFormatContext(AVIOContext *avioContext, AVFormatContext **avFormatContext);

       bool openAVFormatContext(AVFormatContext *avFormatContext);

       int32_t cleanup(AVIOContext *avioContext, AVFormatContext *avFormatContext);

       bool getStreamInfo(AVFormatContext *avFormatContext);

       AVStream *getBestAudioStream(AVFormatContext *avFormatContext);

       AVCodec *findCodec(AVCodecID id);

       void printCodecParameters(AVCodecParameters *params);

       bool createAVIOContext2(const std::string &amp;filePath, uint8_t *buffer, uint32_t bufferSize,
                               AVIOContext **avioContext);
    };


    #endif //MYAPP_FFMPEGEXTRACTOR_H
    </fstream></cstdint>

    This is FFMPegExtractor.cpp :

    #include <memory>
    #include <oboe></oboe>Definitions.h>
    #include "FFMpegExtractor.h"
    #include "logging.h"
    #include <fstream>

    FFMpegExtractor::FFMpegExtractor() {
       mSource = new MediaSource;
    }

    FFMpegExtractor::~FFMpegExtractor() {
       delete mSource;
    }

    constexpr int kInternalBufferSize = 1152; // Use MP3 block size. https://wiki.hydrogenaud.io/index.php?title=MP3

    /**
    * Reads from an IStream into FFmpeg.
    *
    * @param ptr       A pointer to the user-defined IO data structure.
    * @param buf       A buffer to read into.
    * @param buf_size  The size of the buffer buff.
    *
    * @return The number of bytes read into the buffer.
    */


    // If FFmpeg needs to read the file, it will call this function.
    // We need to fill the buffer with file's data.
    int read(void *opaque, uint8_t *buffer, int buf_size) {
       MediaSource *source = (MediaSource *) opaque;
       return source->read(buffer, buf_size);
    }

    // If FFmpeg needs to seek in the file, it will call this function.
    // We need to change the read pos.
    int64_t seek(void *opaque, int64_t offset, int whence) {
       MediaSource *source = (MediaSource *) opaque;
       return source->seek(offset, whence);
    }


    // Create and save a MediaSource instance.
    bool FFMpegExtractor::createAVIOContext2(const std::string &amp;filepath, uint8_t *buffer, uint32_t bufferSize,
                                            AVIOContext **avioContext) {

       mSource = new MediaSource;
       mSource->open(filepath);
       constexpr int isBufferWriteable = 0;

       *avioContext = avio_alloc_context(
               buffer, // internal buffer for FFmpeg to use
               bufferSize, // For optimal decoding speed this should be the protocol block size
               isBufferWriteable,
               mSource, // Will be passed to our callback functions as a (void *)
               read, // Read callback function
               nullptr, // Write callback function (not used)
               seek); // Seek callback function

       if (*avioContext == nullptr) {
           LOGE("Failed to create AVIO context");
           return false;
       } else {
           return true;
       }
    }

    bool
    FFMpegExtractor::createAVFormatContext(AVIOContext *avioContext,
                                          AVFormatContext **avFormatContext) {

       *avFormatContext = avformat_alloc_context();
       (*avFormatContext)->pb = avioContext;

       if (*avFormatContext == nullptr) {
           LOGE("Failed to create AVFormatContext");
           return false;
       } else {
           LOGD("Successfully created AVFormatContext");
           return true;
       }
    }

    bool FFMpegExtractor::openAVFormatContext(AVFormatContext *avFormatContext) {

       int result = avformat_open_input(&amp;avFormatContext,
                                        "", /* URL is left empty because we're providing our own I/O */
                                        nullptr /* AVInputFormat *fmt */,
                                        nullptr /* AVDictionary **options */
       );

       if (result == 0) {
           return true;
       } else {
           LOGE("Failed to open file. Error code %s", av_err2str(result));
           return false;
       }
    }

    bool FFMpegExtractor::getStreamInfo(AVFormatContext *avFormatContext) {

       int result = avformat_find_stream_info(avFormatContext, nullptr);
       if (result == 0) {
           return true;
       } else {
           LOGE("Failed to find stream info. Error code %s", av_err2str(result));
           return false;
       }
    }

    AVStream *FFMpegExtractor::getBestAudioStream(AVFormatContext *avFormatContext) {

       int streamIndex = av_find_best_stream(avFormatContext, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0);

       if (streamIndex &lt; 0) {
           LOGE("Could not find stream");
           return nullptr;
       } else {
           return avFormatContext->streams[streamIndex];
       }
    }

    int64_t FFMpegExtractor::decode2(
           char* filepath,
           uint8_t *targetData,
           AudioProperties targetProperties) {

       LOGD("Decode SETUP");
       int returnValue = -1; // -1 indicates error

       // Create a buffer for FFmpeg to use for decoding (freed in the custom deleter below)
       auto buffer = reinterpret_cast(av_malloc(kInternalBufferSize));


       // Create an AVIOContext with a custom deleter
       std::unique_ptr ioContext{
               nullptr,
               [](AVIOContext *c) {
                   av_free(c->buffer);
                   avio_context_free(&amp;c);
               }
       };
       {
           AVIOContext *tmp = nullptr;
           if (!createAVIOContext2(filepath, buffer, kInternalBufferSize, &amp;tmp)) {
               LOGE("Could not create an AVIOContext");
               return returnValue;
           }
           ioContext.reset(tmp);
       }
       // Create an AVFormatContext using the avformat_free_context as the deleter function
       std::unique_ptr formatContext{
               nullptr,
               &amp;avformat_free_context
       };

       {
           AVFormatContext *tmp;
           if (!createAVFormatContext(ioContext.get(), &amp;tmp)) return returnValue;
           formatContext.reset(tmp);
       }
       if (!openAVFormatContext(formatContext.get())) return returnValue;
       LOGD("172");

       if (!getStreamInfo(formatContext.get())) return returnValue;
       LOGD("175");

       // Obtain the best audio stream to decode
       AVStream *stream = getBestAudioStream(formatContext.get());
       if (stream == nullptr || stream->codecpar == nullptr) {
           LOGE("Could not find a suitable audio stream to decode");
           return returnValue;
       }
       LOGD("183");

       printCodecParameters(stream->codecpar);

       // Find the codec to decode this stream
       AVCodec *codec = avcodec_find_decoder(stream->codecpar->codec_id);
       if (!codec) {
           LOGE("Could not find codec with ID: %d", stream->codecpar->codec_id);
           return returnValue;
       }

       // Create the codec context, specifying the deleter function
       std::unique_ptr codecContext{
               nullptr,
               [](AVCodecContext *c) { avcodec_free_context(&amp;c); }
       };
       {
           AVCodecContext *tmp = avcodec_alloc_context3(codec);
           if (!tmp) {
               LOGE("Failed to allocate codec context");
               return returnValue;
           }
           codecContext.reset(tmp);
       }

       // Copy the codec parameters into the context
       if (avcodec_parameters_to_context(codecContext.get(), stream->codecpar) &lt; 0) {
           LOGE("Failed to copy codec parameters to codec context");
           return returnValue;
       }

       // Open the codec
       if (avcodec_open2(codecContext.get(), codec, nullptr) &lt; 0) {
           LOGE("Could not open codec");
           return returnValue;
       }

       // prepare resampler
       int32_t outChannelLayout = (1 &lt;&lt; targetProperties.channelCount) - 1;
       LOGD("Channel layout %d", outChannelLayout);

       SwrContext *swr = swr_alloc();
       av_opt_set_int(swr, "in_channel_count", stream->codecpar->channels, 0);
       av_opt_set_int(swr, "out_channel_count", targetProperties.channelCount, 0);
       av_opt_set_int(swr, "in_channel_layout", stream->codecpar->channel_layout, 0);
       av_opt_set_int(swr, "out_channel_layout", outChannelLayout, 0);
       av_opt_set_int(swr, "in_sample_rate", stream->codecpar->sample_rate, 0);
       av_opt_set_int(swr, "out_sample_rate", targetProperties.sampleRate, 0);
       av_opt_set_int(swr, "in_sample_fmt", stream->codecpar->format, 0);
       av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
       av_opt_set_int(swr, "force_resampling", 1, 0);

       // Check that resampler has been inited
       int result = swr_init(swr);
       if (result != 0) {
           LOGE("swr_init failed. Error: %s", av_err2str(result));
           return returnValue;
       };
       if (!swr_is_initialized(swr)) {
           LOGE("swr_is_initialized is false\n");
           return returnValue;
       }

       // Prepare to read data
       int bytesWritten = 0;
       AVPacket avPacket; // Stores compressed audio data
       av_init_packet(&amp;avPacket);
       AVFrame *decodedFrame = av_frame_alloc(); // Stores raw audio data
       int bytesPerSample = av_get_bytes_per_sample((AVSampleFormat) stream->codecpar->format);

       LOGD("Bytes per sample %d", bytesPerSample);

       // While there is more data to read, read it into the avPacket
       while (av_read_frame(formatContext.get(), &amp;avPacket) == 0) {

           if (avPacket.stream_index == stream->index) {

               while (avPacket.size > 0) {
                   // Pass our compressed data into the codec
                   result = avcodec_send_packet(codecContext.get(), &amp;avPacket);
                   if (result != 0) {
                       LOGE("avcodec_send_packet error: %s", av_err2str(result));
                       goto cleanup;
                   }

                   // Retrieve our raw data from the codec
                   result = avcodec_receive_frame(codecContext.get(), decodedFrame);
                   if (result != 0) {
                       LOGE("avcodec_receive_frame error: %s", av_err2str(result));
                       goto cleanup;
                   }

                   // DO RESAMPLING
                   auto dst_nb_samples = (int32_t) av_rescale_rnd(
                           swr_get_delay(swr, decodedFrame->sample_rate) + decodedFrame->nb_samples,
                           targetProperties.sampleRate,
                           decodedFrame->sample_rate,
                           AV_ROUND_UP);

                   short *buffer1;
                   av_samples_alloc(
                           (uint8_t **) &amp;buffer1,
                           nullptr,
                           targetProperties.channelCount,
                           dst_nb_samples,
                           AV_SAMPLE_FMT_FLT,
                           0);
                   int frame_count = swr_convert(
                           swr,
                           (uint8_t **) &amp;buffer1,
                           dst_nb_samples,
                           (const uint8_t **) decodedFrame->data,
                           decodedFrame->nb_samples);

                   int64_t bytesToWrite = frame_count * sizeof(float) * targetProperties.channelCount;
                   memcpy(targetData + bytesWritten, buffer1, (size_t) bytesToWrite);
                   bytesWritten += bytesToWrite;
                   av_freep(&amp;buffer1);

                   avPacket.size = 0;
                   avPacket.data = nullptr;
               }
           }
       }

       av_frame_free(&amp;decodedFrame);

       returnValue = bytesWritten;

       cleanup:
       return returnValue;
    }

    void FFMpegExtractor::printCodecParameters(AVCodecParameters *params) {

       LOGD("Stream properties");
       LOGD("Channels: %d", params->channels);
       LOGD("Channel layout: %"
                    PRId64, params->channel_layout);
       LOGD("Sample rate: %d", params->sample_rate);
       LOGD("Format: %s", av_get_sample_fmt_name((AVSampleFormat) params->format));
       LOGD("Frame size: %d", params->frame_size);
    }
    </fstream></memory>

    And this is the MediaSource.cpp :

    #ifndef MYAPP_MEDIASOURCE_CPP
    #define MYAPP_MEDIASOURCE_CPP

    extern "C" {
    #include <libavformat></libavformat>avformat.h>
    #include <libswresample></libswresample>swresample.h>
    #include <libavutil></libavutil>opt.h>
    }

    #include <cstdint>
    #include <android></android>asset_manager.h>
    #include
    #include <fstream>
    #include "logging.h"

    // wrapper class for file stream
    class MediaSource {
    public:

       MediaSource() {
       }

       ~MediaSource() {
           source.close();
       }

       void open(const std::string &amp;filePath) {
           const char *x = filePath.c_str();
           LOGD("Opened %s", x);
           source.open(filePath, std::ios::in | std::ios::binary);
       }

       int read(uint8_t *buffer, int buf_size) {
           // read data to buffer
           source.read((char *) buffer, buf_size);
           // return how many bytes were read
           return source.gcount();
       }

       int64_t seek(int64_t offset, int whence) {
           if (whence == AVSEEK_SIZE) {
               // FFmpeg needs file size.
               int oldPos = source.tellg();
               source.seekg(0, std::ios::end);
               int64_t length = source.tellg();
               // seek to old pos
               source.seekg(oldPos);
               return length;
           } else if (whence == SEEK_SET) {
               // set pos to offset
               source.seekg(offset);
           } else if (whence == SEEK_CUR) {
               // add offset to pos
               source.seekg(offset, std::ios::cur);
           } else {
               // do not support other flags, return -1
               return -1;
           }
           // return current pos
           return source.tellg();
       }

    private:
       std::ifstream source;
    };

    #endif //MYAPP_MEDIASOURCE_CPP
    </fstream></cstdint>

    When the code is executed, I can see that I submit the correct file path, so I assume the resource mp3 is there.
    When this code is executed the app crashes in line 103 of FFMpegExtractor.cpp, at formatContext.reset(tmp);

    This is what Android Studio logs when the app crashes :

    --------- beginning of crash
    2020-02-27 14:31:26.341 9852-9945/com.user.myapp A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7fffffff0 in tid 9945 (chaelpohl.loopy), pid 9852 (user.myapp)

    This is the (sadly very short) output I get with ndk-stack :

    ********** Crash dump: **********
    Build fingerprint: 'samsung/dreamltexx/dreamlte:9/PPR1.180610.011/G950FXXU6DSK9:user/release-keys'
    #00 0x0000000000016c50 /data/app/com.user.myapp-D7dBCgHF-vdQNNSald4lWA==/lib/arm64/libavformat.so (avformat_free_context+260)
                                                                                                            avformat_free_context
                                                                                                            ??:0:0
    Crash dump is completed

    I tested a bit around, and every call to my formatContext crashes the app. So I assume there is something wrong with the input I provide to build it but I have no clue how to debug this.

    Any help is appreciated ! (Happy to provide additional resources if something crucial is missing).

  • Stream ffmpeg transcoding result to S3

    7 juin 2019, par mabead

    I want to transcode a large file using FFMPEG and store the result directly on AWS S3. This will be done inside of an AWS Lambda that has limited tmp space so I can’t store the transcoding result locally and then upload it to S3 in a second step. I won’t have enough tmp space. I therefore want to store the FFMPEG output directly on S3.

    I therefore created a S3 pre-signed url that allows ’PUT’ :

    var outputPath = s3Client.GetPreSignedURL(new Amazon.S3.Model.GetPreSignedUrlRequest
    {
       BucketName = "my-bucket",
       Expires = DateTime.UtcNow.AddMinutes(5),
       Key = "output.mp3",
       Verb = HttpVerb.PUT,
    });

    I then called ffmpeg with the resulting pre-signed url :

    ffmpeg -i C:\input.wav -y -vn -ar 44100 -ac 2 -ab 192k -f mp3 https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550427237&amp;Signature=%2BE8Wc%2F%2FQYrvGxzc%2FgXnsvauKnac%3D

    FFMPEG returns an exit code of 1 with the following output :

    ffmpeg version N-93120-ga84af760b8 Copyright (c) 2000-2019 the FFmpeg developers
     built with gcc 8.2.1 (GCC) 20190212
     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-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
     libavutil      56. 26.100 / 56. 26.100
     libavcodec     58. 47.100 / 58. 47.100
     libavformat    58. 26.101 / 58. 26.101
     libavdevice    58.  6.101 / 58.  6.101
     libavfilter     7. 48.100 /  7. 48.100
     libswscale      5.  4.100 /  5.  4.100
     libswresample   3.  4.100 /  3.  4.100
     libpostproc    55.  4.100 / 55.  4.100
    Guessed Channel Layout for Input Stream #0.0 : stereo
    Input #0, wav, from 'C:\input.wav':
     Duration: 00:04:16.72, bitrate: 3072 kb/s
       Stream #0:0: Audio: pcm_s32le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s32, 3072 kb/s
    Stream mapping:
     Stream #0:0 -> #0:0 (pcm_s32le (native) -> mp3 (libmp3lame))
    Press [q] to stop, [?] for help
    Output #0, mp3, to 'https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550427237&amp;Signature=%2BE8Wc%2F%2FQYrvGxzc%2FgXnsvauKnac%3D':
     Metadata:
       TSSE            : Lavf58.26.101
       Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s32p, 192 kb/s
       Metadata:
         encoder         : Lavc58.47.100 libmp3lame
    size=     577kB time=00:00:24.58 bitrate= 192.2kbits/s speed=49.1x    
    size=    1109kB time=00:00:47.28 bitrate= 192.1kbits/s speed=47.2x    
    [tls @ 000001d73d786b00] Error in the push function.
    av_interleaved_write_frame(): I/O error
    Error writing trailer of https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550427237&amp;Signature=%2BE8Wc%2F%2FQYrvGxzc%2FgXnsvauKnac%3D: I/O error
    size=    1143kB time=00:00:48.77 bitrate= 192.0kbits/s speed=  47x    
    video:0kB audio:1144kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    [tls @ 000001d73d786b00] The specified session has been invalidated for some reason.
    [tls @ 000001d73d786b00] Error in the pull function.
    [https @ 000001d73d784fc0] URL read error:  -5
    Conversion failed!

    As you can see, I have a URL read error. This is a little surprising to me since I want to output to this url and not read it.

    Anybody know how I can store directly my FFMPEG output directly to S3 without having to store it locally first ?

    Edit 1
    I then tried to use the -method PUT parameter and use http instead of https to remove TLS from the equation. Here’s the output that I got when running ffmpeg with the -v trace option.

    ffmpeg version N-93120-ga84af760b8 Copyright (c) 2000-2019 the FFmpeg developers
     built with gcc 8.2.1 (GCC) 20190212
     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-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
     libavutil      56. 26.100 / 56. 26.100
     libavcodec     58. 47.100 / 58. 47.100
     libavformat    58. 26.101 / 58. 26.101
     libavdevice    58.  6.101 / 58.  6.101
     libavfilter     7. 48.100 /  7. 48.100
     libswscale      5.  4.100 /  5.  4.100
     libswresample   3.  4.100 /  3.  4.100
     libpostproc    55.  4.100 / 55.  4.100
    Splitting the commandline.
    Reading option '-i' ... matched as input url with argument 'C:\input.wav'.
    Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
    Reading option '-vn' ... matched as option 'vn' (disable video) with argument '1'.
    Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '44100'.
    Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '2'.
    Reading option '-ab' ... matched as option 'ab' (audio bitrate (please use -b:a)) with argument '192k'.
    Reading option '-f' ... matched as option 'f' (force format) with argument 'mp3'.
    Reading option '-method' ... matched as AVOption 'method' with argument 'PUT'.
    Reading option '-v' ... matched as option 'v' (set logging level) with argument 'trace'.
    Reading option 'https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550695990&amp;Signature=dy3RVqDlX%2BlJ0INlDkl0Lm1Rqb4%3D' ... matched as output url.
    Finished splitting the commandline.
    Parsing a group of options: global .
    Applying option y (overwrite output files) with argument 1.
    Applying option v (set logging level) with argument trace.
    Successfully parsed a group of options.
    Parsing a group of options: input url C:\input.wav.
    Successfully parsed a group of options.
    Opening an input file: C:\input.wav.
    [NULL @ 000001fb37abb180] Opening 'C:\input.wav' for reading
    [file @ 000001fb37abc180] Setting default whitelist 'file,crypto'
    Probing wav score:99 size:2048
    [wav @ 000001fb37abb180] Format wav probed with size=2048 and score=99
    [wav @ 000001fb37abb180] Before avformat_find_stream_info() pos: 54 bytes read:65590 seeks:1 nb_streams:1
    [wav @ 000001fb37abb180] parser not found for codec pcm_s32le, packets or times may be invalid.
       Last message repeated 1 times
    [wav @ 000001fb37abb180] All info found
    [wav @ 000001fb37abb180] stream 0: start_time: -192153584101141.156 duration: 256.716
    [wav @ 000001fb37abb180] format: start_time: -9223372036854.775 duration: 256.716 bitrate=3072 kb/s
    [wav @ 000001fb37abb180] After avformat_find_stream_info() pos: 204854 bytes read:294966 seeks:1 frames:50
    Guessed Channel Layout for Input Stream #0.0 : stereo
    Input #0, wav, from 'C:\input.wav':
     Duration: 00:04:16.72, bitrate: 3072 kb/s
       Stream #0:0, 50, 1/48000: Audio: pcm_s32le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s32, 3072 kb/s
    Successfully opened the file.
    Parsing a group of options: output url https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550695990&amp;Signature=dy3RVqDlX%2BlJ0INlDkl0Lm1Rqb4%3D.
    Applying option vn (disable video) with argument 1.
    Applying option ar (set audio sampling rate (in Hz)) with argument 44100.
    Applying option ac (set number of audio channels) with argument 2.
    Applying option ab (audio bitrate (please use -b:a)) with argument 192k.
    Applying option f (force format) with argument mp3.
    Successfully parsed a group of options.
    Opening an output file: https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550695990&amp;Signature=dy3RVqDlX%2BlJ0INlDkl0Lm1Rqb4%3D.
    [http @ 000001fb37b15140] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
    [tcp @ 000001fb37b16c80] Original list of addresses:
    [tcp @ 000001fb37b16c80] Address 52.216.8.203 port 80
    [tcp @ 000001fb37b16c80] Interleaved list of addresses:
    [tcp @ 000001fb37b16c80] Address 52.216.8.203 port 80
    [tcp @ 000001fb37b16c80] Starting connection attempt to 52.216.8.203 port 80
    [tcp @ 000001fb37b16c80] Successfully connected to 52.216.8.203 port 80
    [http @ 000001fb37b15140] request: PUT /output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550695990&amp;Signature=dy3RVqDlX%2BlJ0INlDkl0Lm1Rqb4%3D HTTP/1.1
    Transfer-Encoding: chunked
    User-Agent: Lavf/58.26.101
    Accept: */*
    Connection: close
    Host: landr-distribution-reportsdev-mb.s3.amazonaws.com
    Icy-MetaData: 1
    Successfully opened the file.
    Stream mapping:
     Stream #0:0 -> #0:0 (pcm_s32le (native) -> mp3 (libmp3lame))
    Press [q] to stop, [?] for help
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    detected 8 logical cores
    [graph_0_in_0_0 @ 000001fb37b21080] Setting 'time_base' to value '1/48000'
    [graph_0_in_0_0 @ 000001fb37b21080] Setting 'sample_rate' to value '48000'
    [graph_0_in_0_0 @ 000001fb37b21080] Setting 'sample_fmt' to value 's32'
    [graph_0_in_0_0 @ 000001fb37b21080] Setting 'channel_layout' to value '0x3'
    [graph_0_in_0_0 @ 000001fb37b21080] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x3
    [format_out_0_0 @ 000001fb37b22cc0] Setting 'sample_fmts' to value 's32p|fltp|s16p'
    [format_out_0_0 @ 000001fb37b22cc0] Setting 'sample_rates' to value '44100'
    [format_out_0_0 @ 000001fb37b22cc0] Setting 'channel_layouts' to value '0x3'
    [format_out_0_0 @ 000001fb37b22cc0] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
    [AVFilterGraph @ 000001fb37b0d940] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
    [auto_resampler_0 @ 000001fb37b251c0] picking s32p out of 3 ref:s32
    [auto_resampler_0 @ 000001fb37b251c0] [SWR @ 000001fb37b252c0] Using fltp internally between filters
    [auto_resampler_0 @ 000001fb37b251c0] ch:2 chl:stereo fmt:s32 r:48000Hz -> ch:2 chl:stereo fmt:s32p r:44100Hz
    Output #0, mp3, to 'https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550695990&amp;Signature=dy3RVqDlX%2BlJ0INlDkl0Lm1Rqb4%3D':
     Metadata:
       TSSE            : Lavf58.26.101
       Stream #0:0, 0, 1/44100: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s32p, delay 1105, 192 kb/s
       Metadata:
         encoder         : Lavc58.47.100 libmp3lame
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
       Last message repeated 6 times
    size=     649kB time=00:00:27.66 bitrate= 192.2kbits/s speed=55.3x    
    size=    1207kB time=00:00:51.48 bitrate= 192.1kbits/s speed=51.5x    
    av_interleaved_write_frame(): Unknown error
    No more output streams to write to, finishing.
    [libmp3lame @ 000001fb37b147c0] Trying to remove 47 more samples than there are in the queue
    Error writing trailer of https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550695990&amp;Signature=dy3RVqDlX%2BlJ0INlDkl0Lm1Rqb4%3D: Error number -10054 occurred
    size=    1251kB time=00:00:53.39 bitrate= 192.0kbits/s speed=51.5x    
    video:0kB audio:1252kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    Input file #0 (C:\input.wav):
     Input stream #0:0 (audio): 5014 packets read (20537344 bytes); 5014 frames decoded (2567168 samples);
     Total: 5014 packets (20537344 bytes) demuxed
    Output file #0 (https://my-bucket.s3.amazonaws.com/output.mp3?AWSAccessKeyId=AKIAJDSGJWM63VQEXHIQ&amp;Expires=1550695990&amp;Signature=dy3RVqDlX%2BlJ0INlDkl0Lm1Rqb4%3D):
     Output stream #0:0 (audio): 2047 frames encoded (2358144 samples); 2045 packets muxed (1282089 bytes);
     Total: 2045 packets (1282089 bytes) muxed
    5014 frames successfully decoded, 0 decoding errors
    [AVIOContext @ 000001fb37b1f440] Statistics: 0 seeks, 2046 writeouts
    [http @ 000001fb37b15140] URL read error:  -10054
    [AVIOContext @ 000001fb37ac4400] Statistics: 20611126 bytes read, 1 seeks
    Conversion failed!

    So it looks like it is able to connect to my S3 pre-signed url but I still have the Error writing trailer error coupled with a URL read error.