Recherche avancée

Médias (1)

Mot : - Tags -/Rennes

Autres articles (47)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Les vidéos

    21 avril 2011, par

    Comme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
    Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
    Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...)

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

Sur d’autres sites (7626)

  • Font setting for ffmpeg not working when adding subtitles from .srt file

    29 septembre 2022, par asdfgh

    I've been trying to use the ffmpeg-subtitles
option like this

    


    ffmpeg -i demo.mp4 -vf "subtitles=demo.srt:fontsdir=/usr/share/fonts/truetype/dejavu:force_style='Fontsize=24px,PrimaryColour=&H000000FF,force_style=Fontname=DejaVuSerif'" out.mp4


    


    but it seems to me that some default config file is overriding font argument from command line because it is ignored (the other things like generating video with subtitle and text coloring works fine), as per this line

    


    fontselect: (Arial, 400, 0) -> /usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf, 0, LiberationSans


    


    no matter what I give as fontsdir or Fontname, ffmpeg always uses LiberationSans. Here is the full output of the command above :

    


    ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'demo.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:17.27, start: 0.000000, bitrate: 752 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 410x358 [SAR 3529:3532 DAR 723445:632228], 751 kb/s, SAR 8234:8241 DAR 230:201, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
File 'out.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 2.3.1 (COMPLEX)
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Bold.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Oblique.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-BoldItalic.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuMathTeXGyre.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Italic.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Loading font file '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-BoldOblique.ttf'
[Parsed_subtitles_0 @ 0x5589d9ca5a40] Using font provider fontconfig
[Parsed_subtitles_0 @ 0x5589d9ca5a40] fontselect: (Arial, 400, 0) -> /usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf, 0, LiberationSans
[libx264 @ 0x5589d9b4cb40] using SAR=3529/3532
[libx264 @ 0x5589d9b4cb40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5589d9b4cb40] profile High, level 2.1
[libx264 @ 0x5589d9b4cb40] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 410x358 [SAR 8234:8241 DAR 230:201], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.35.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=  518 fps=216 q=-1.0 Lsize=     936kB time=00:00:17.16 bitrate= 446.7kbits/s speed=7.15x    
video:929kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.716306%
[libx264 @ 0x5589d9b4cb40] frame I:3     Avg QP:22.06  size:  9804
[libx264 @ 0x5589d9b4cb40] frame P:169   Avg QP:25.02  size:  3412
[libx264 @ 0x5589d9b4cb40] frame B:346   Avg QP:27.47  size:   997
[libx264 @ 0x5589d9b4cb40] consecutive B-frames:  7.7%  6.6%  9.3% 76.4%
[libx264 @ 0x5589d9b4cb40] mb I  I16..4: 14.3% 63.4% 22.2%
[libx264 @ 0x5589d9b4cb40] mb P  I16..4:  9.9% 16.4%  2.6%  P16..4: 41.8% 17.3%  5.2%  0.0%  0.0%    skip: 6.7%
[libx264 @ 0x5589d9b4cb40] mb B  I16..4:  1.6%  2.3%  0.3%  B16..8: 43.9%  5.7%  0.6%  direct: 2.2%  skip:43.4%  L0:50.8% L1:44.1% BI: 5.0%
[libx264 @ 0x5589d9b4cb40] 8x8 transform intra:56.4% inter:82.5%
[libx264 @ 0x5589d9b4cb40] coded y,uvDC,uvAC intra: 41.7% 64.7% 6.3% inter: 14.9% 20.9% 0.0%
[libx264 @ 0x5589d9b4cb40] i16 v,h,dc,p: 15% 27%  9% 49%
[libx264 @ 0x5589d9b4cb40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 23% 17%  6%  7%  6%  8%  7%  6%
[libx264 @ 0x5589d9b4cb40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 27% 11%  5%  9%  8%  9%  5%  4%
[libx264 @ 0x5589d9b4cb40] i8c dc,h,v,p: 54% 22% 14%  9%
[libx264 @ 0x5589d9b4cb40] Weighted P-Frames: Y:18.9% UV:5.9%
[libx264 @ 0x5589d9b4cb40] ref P L0: 62.8% 16.2% 15.4%  4.9%  0.8%
[libx264 @ 0x5589d9b4cb40] ref B L0: 91.0%  7.4%  1.6%
[libx264 @ 0x5589d9b4cb40] ref B L1: 97.4%  2.6%
[libx264 @ 0x5589d9b4cb40] kb/s:440.62


    


  • FFMPEG command runs in terminal but not by subprocess

    1er septembre 2022, par Basilique

    I am trying to run a bash command using the subprocess module from within python 3.10.

    


    The bash command is :

    


    ffmpeg -framerate 1 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p -vf "crop=trunc(iw/2)*2:trunc(ih/2)*2" out.mp4


    


    In terminal the command runs fine. Here is the output :

    


    ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  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, image2, from '*.png':
  Duration: 00:16:39.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 895x332 [SAR 3937:3937 DAR 895:332], 1 fps, 1 tbr, 1 tbn, 1 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x55726ab95d00] using SAR=1/1
[libx264 @ 0x55726ab95d00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
[libx264 @ 0x55726ab95d00] profile High, level 2.2
[libx264 @ 0x55726ab95d00] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=10 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=1 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
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 894x332 [SAR 1:1 DAR 447:166], q=-1--1, 1 fps, 16384 tbn, 1 tbc
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=  173 fps=0.0 q=17.0 size=     512kB time=00:01:56.00 bitrate=  36.2kbits/frame=  351 fps=350 q=17.0 size=    1536kB time=00:04:54.00 bitrate=  42.8kbits/frame=  517 fps=343 q=17.0 size=    2560kB time=00:07:40.00 bitrate=  45.6kbits/frame=  725 fps=361 q=17.0 size=    3328kB time=00:11:08.00 bitrate=  40.8kbits/frame=  913 fps=364 q=17.0 size=    4352kB time=00:14:16.00 bitrate=  41.6kbits/frame=  999 fps=361 q=-1.0 Lsize=    4986kB time=00:16:36.00 bitrate=  41.0kbits/s speed= 360x    
video:4974kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.241361%
[libx264 @ 0x55726ab95d00] frame I:4     Avg QP: 6.12  size: 24072
[libx264 @ 0x55726ab95d00] frame P:346   Avg QP:12.94  size:  5708
[libx264 @ 0x55726ab95d00] frame B:649   Avg QP:18.19  size:  4655
[libx264 @ 0x55726ab95d00] consecutive B-frames:  5.8% 16.0% 20.1% 58.1%
[libx264 @ 0x55726ab95d00] mb I  I16..4: 59.1% 10.6% 30.4%
[libx264 @ 0x55726ab95d00] mb P  I16..4:  5.6%  0.6%  2.2%  P16..4: 10.5%  4.3%  2.3%  0.0%  0.0%    skip:74.5%
[libx264 @ 0x55726ab95d00] mb B  I16..4:  2.2%  0.1%  1.7%  B16..8: 16.9%  4.8%  1.6%  direct: 1.1%  skip:71.5%  L0:50.9% L1:45.2% BI: 3.9%
[libx264 @ 0x55726ab95d00] 8x8 transform intra:5.9% inter:10.4%
[libx264 @ 0x55726ab95d00] coded y,uvDC,uvAC intra: 20.1% 18.3% 17.3% inter: 4.7% 4.7% 4.6%
[libx264 @ 0x55726ab95d00] i16 v,h,dc,p: 66% 33%  1%  0%
[libx264 @ 0x55726ab95d00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18%  8% 73%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x55726ab95d00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 31% 31%  2%  3%  2%  4%  2%  3%
[libx264 @ 0x55726ab95d00] i8c dc,h,v,p: 73% 23%  3%  0%
[libx264 @ 0x55726ab95d00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x55726ab95d00] ref P L0: 57.2%  1.5% 24.3% 17.0%
[libx264 @ 0x55726ab95d00] ref B L0: 69.6% 24.8%  5.6%
[libx264 @ 0x55726ab95d00] ref B L1: 92.4%  7.6%
[libx264 @ 0x55726ab95d00] kb/s:40.78


    


    In my python script I tried the following solutions :

    


    video_cmd = """ffmpeg -framerate 1 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p -vf "crop=trunc(iw/2)*2:trunc(ih/2)*2" out.mp4"""

subprocess.run(shlex.split(video_cmd), shell=False, cwd=path_viz, stderr=subprocess.STDOUT, check=True, text=False)

subprocess.run(video_cmd, shell=True, cwd=path_viz, stderr=subprocess.STDOUT, check=True, text=False)


    


    as well as the solution proposed for this similar question

    


    subprocess.Popen(video_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)


    


    None of them worked. Apparently, the right command is run (output of the check_out function) :

    


    Command 'ffmpeg -y -framerate 1 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p -vf "crop=trunc(iw/2)*2:trunc(ih/2)*2" out.mp4' returned non-zero exit status 1.


    


    the first part of the job (up to Stream mapping:) is done also correctly :

    


    fmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7.3.0 (crosstool-NG 1.23.0.449-a04d0)
  configuration: --prefix=/home/rsghazanfari/anaconda3/envs/_cuda --cc=/opt/conda/conda-bld/ffmpeg_1597178665428/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc --disable-doc --disable-openssl --enable-avresample --enable-gnutls --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-pic --enable-pthreads --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libmp3lame
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
Input #0, image2, from '*.png':
  Duration: 00:16:39.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 895x332 [SAR 3937:3937 DAR 895:332], 1 fps, 1 tbr, 1 tbn, 1 tbc


    


    but it then pops up the following error :

    


    Unknown encoder &#x27;libx264&#x27;&#xA;Traceback (most recent call last):&#xA;  File "/home/rsgh/anaconda3/envs/_cuda/lib/python3.10/code.py", line 90, in runcode&#xA;    exec(code, self.locals)&#xA;  File "<input />", line 1, in <module>&#xA;  File "/home/rsgh/anaconda3/envs/_cuda/lib/python3.10/subprocess.py", line 524, in run&#xA;    raise CalledProcessError(retcode, process.args,&#xA;&#xA;subprocess.CalledProcessError: Command &#x27;ffmpeg -y -framerate 1 -pattern_type glob -i &#x27;*.png&#x27; -c:v libx264 -pix_fmt yuv420p -vf "crop=trunc(iw/2)*2:trunc(ih/2)*2" out.mp4&#x27; returned non-zero exit status 1.&#xA;</module>

    &#xA;

    Any ideas of why this error is produced in python while in terminal it runs fine ? Thank you in advance.

    &#xA;

    PS : ffmpeg -version outputs :

    &#xA;

    ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers&#xA;built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)&#xA;configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared&#xA;libavutil      56. 31.100 / 56. 31.100&#xA;libavcodec     58. 54.100 / 58. 54.100&#xA;libavformat    58. 29.100 / 58. 29.100&#xA;libavdevice    58.  8.100 / 58.  8.100&#xA;libavfilter     7. 57.100 /  7. 57.100&#xA;libavresample   4.  0.  0 /  4.  0.  0&#xA;libswscale      5.  5.100 /  5.  5.100&#xA;libswresample   3.  5.100 /  3.  5.100&#xA;libpostproc    55.  5.100 / 55.  5.100&#xA;

    &#xA;

    ubuntu version :

    &#xA;

    Distributor ID: Ubuntu&#xA;Description:    Ubuntu 20.04.4 LTS&#xA;Release:    20.04&#xA;Codename:   focal&#xA;

    &#xA;

  • ffmpeg : libavformat/libswresample to transcode and resample at same time

    21 février 2024, par whatdoido

    I want to transcode and down/re-sample the audio for output using ffmpeg's libav*/libswresample - I am using ffmpeg's (4.x) transcode_aac.c and resample_audio.c as reference - but the code produces audio with glitches that is clearly not what ffmpeg itself would produce (ie ffmpeg -i foo.wav -ar 22050 foo.m4a)

    &#xA;

    Based on the ffmpeg examples, to resample audio it appears that I need to set the output AVAudioContext and SwrContext sample_rate to what I desire and ensure the swr_convert() is provided with the correct number of output samples based av_rescale_rnd( swr_delay(), ...) once I have an decoded input audio. I've taken care to ensure all the relevant calculations of samples for output are taken into account in the merged code (below) :

    &#xA;

      &#xA;
    • open_output_file() - AVCodecContext.sample_rate (avctx variable) set to our target (down sampled) sample_rate
    • &#xA;

    • read_decode_convert_and_store() is where the work happens : input audio is decoded to an AVFrame and this input frame is converted before being encoded.&#xA;
        &#xA;
      • init_converted_samples() and av_samples_alloc() uses the input frame's nb_samples
      • &#xA;

      • ADDED : calc the number of output samples via av_rescale_rnd() and swr_delay()
      • &#xA;

      • UPDATED : convert_samples() and swr_convert() uses the input frame's samples and our calculated output samples as parameters
      • &#xA;

      &#xA;

    • &#xA;

    &#xA;

    However the resulting audio file is produced with audio glitches. Does the community know of any references for how transcode AND resample should be done or what is missing in this example ?

    &#xA;

        /* compile and run:&#xA;         gcc -I/usr/include/ffmpeg  transcode-swr-aac.c  -lavformat -lavutil -lavcodec -lswresample -lm&#xA;         ./a.out foo.wav foo.m4a&#xA;    */&#xA;&#xA;/*&#xA; * Copyright (c) 2013-2018 Andreas Unterweger&#xA; *  &#xA; * This file is part of FFmpeg.                                                 &#xA; ...                                                                       ...&#xA; *   &#xA; * @example transcode_aac.c                                                    &#xA; * Convert an input audio file to AAC in an MP4 container using FFmpeg.         &#xA; * Formats other than MP4 are supported based on the output file extension.                            &#xA; * @author Andreas Unterweger (xxxx@xxxxx.com)&#xA; */  &#xA;    #include &#xA; &#xA;&#xA;    #include "libavformat/avformat.h"&#xA;    #include "libavformat/avio.h"&#xA;    &#xA;    #include "libavcodec/avcodec.h"&#xA;    &#xA;    #include "libavutil/audio_fifo.h"&#xA;    #include "libavutil/avassert.h"&#xA;    #include "libavutil/avstring.h"&#xA;    #include "libavutil/channel_layout.h"&#xA;    #include "libavutil/frame.h"&#xA;    #include "libavutil/opt.h"&#xA;    &#xA;    #include "libswresample/swresample.h"&#xA;    &#xA;    #define OUTPUT_BIT_RATE 128000&#xA;    #define OUTPUT_CHANNELS 2&#xA;    &#xA;    static int open_input_file(const char *filename,&#xA;                               AVFormatContext **input_format_context,&#xA;                               AVCodecContext **input_codec_context)&#xA;    {&#xA;        AVCodecContext *avctx;&#xA;        const AVCodec *input_codec;&#xA;        const AVStream *stream;&#xA;        int error;&#xA;    &#xA;        if ((error = avformat_open_input(input_format_context, filename, NULL,&#xA;                                         NULL)) &lt; 0) {&#xA;            fprintf(stderr, "Could not open input file &#x27;%s&#x27; (error &#x27;%s&#x27;)\n",&#xA;                    filename, av_err2str(error));&#xA;            *input_format_context = NULL;&#xA;            return error;&#xA;        }&#xA;    &#xA;&#xA;        if ((error = avformat_find_stream_info(*input_format_context, NULL)) &lt; 0) {&#xA;            fprintf(stderr, "Could not open find stream info (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            avformat_close_input(input_format_context);&#xA;            return error;&#xA;        }&#xA;    &#xA;        if ((*input_format_context)->nb_streams != 1) {&#xA;            fprintf(stderr, "Expected one audio input stream, but found %d\n",&#xA;                    (*input_format_context)->nb_streams);&#xA;            avformat_close_input(input_format_context);&#xA;            return AVERROR_EXIT;&#xA;        }&#xA;    &#xA;        stream = (*input_format_context)->streams[0];&#xA;    &#xA;        if (!(input_codec = avcodec_find_decoder(stream->codecpar->codec_id))) {&#xA;            fprintf(stderr, "Could not find input codec\n");&#xA;            avformat_close_input(input_format_context);&#xA;            return AVERROR_EXIT;&#xA;        }&#xA;    &#xA;        avctx = avcodec_alloc_context3(input_codec);&#xA;        if (!avctx) {&#xA;            fprintf(stderr, "Could not allocate a decoding context\n");&#xA;            avformat_close_input(input_format_context);&#xA;            return AVERROR(ENOMEM);&#xA;        }&#xA;    &#xA;        /* Initialize the stream parameters with demuxer information. */&#xA;        error = avcodec_parameters_to_context(avctx, stream->codecpar);&#xA;        if (error &lt; 0) {&#xA;            avformat_close_input(input_format_context);&#xA;            avcodec_free_context(&amp;avctx);&#xA;            return error;&#xA;        }&#xA;    &#xA;        /* Open the decoder for the audio stream to use it later. */&#xA;        if ((error = avcodec_open2(avctx, input_codec, NULL)) &lt; 0) {&#xA;            fprintf(stderr, "Could not open input codec (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            avcodec_free_context(&amp;avctx);&#xA;            avformat_close_input(input_format_context);&#xA;            return error;&#xA;        }&#xA;    &#xA;        /* Set the packet timebase for the decoder. */&#xA;        avctx->pkt_timebase = stream->time_base;&#xA;    &#xA;        /* Save the decoder context for easier access later. */&#xA;        *input_codec_context = avctx;&#xA;    &#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int open_output_file(const char *filename,&#xA;                                AVCodecContext *input_codec_context,&#xA;                                AVFormatContext **output_format_context,&#xA;                                AVCodecContext **output_codec_context)&#xA;    {&#xA;        AVCodecContext *avctx          = NULL;&#xA;        AVIOContext *output_io_context = NULL;&#xA;        AVStream *stream               = NULL;&#xA;        const AVCodec *output_codec    = NULL;&#xA;        int error;&#xA;    &#xA;&#xA;        if ((error = avio_open(&amp;output_io_context, filename,&#xA;                               AVIO_FLAG_WRITE)) &lt; 0) {&#xA;            fprintf(stderr, "Could not open output file &#x27;%s&#x27; (error &#x27;%s&#x27;)\n",&#xA;                    filename, av_err2str(error));&#xA;            return error;&#xA;        }&#xA;    &#xA;&#xA;        if (!(*output_format_context = avformat_alloc_context())) {&#xA;            fprintf(stderr, "Could not allocate output format context\n");&#xA;            return AVERROR(ENOMEM);&#xA;        }&#xA;    &#xA;&#xA;        (*output_format_context)->pb = output_io_context;&#xA;    &#xA;&#xA;        if (!((*output_format_context)->oformat = av_guess_format(NULL, filename,&#xA;                                                                  NULL))) {&#xA;            fprintf(stderr, "Could not find output file format\n");&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;        if (!((*output_format_context)->url = av_strdup(filename))) {&#xA;            fprintf(stderr, "Could not allocate url.\n");&#xA;            error = AVERROR(ENOMEM);&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;&#xA;        if (!(output_codec = avcodec_find_encoder(AV_CODEC_ID_AAC))) {&#xA;            fprintf(stderr, "Could not find an AAC encoder.\n");&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;        /* Create a new audio stream in the output file container. */&#xA;        if (!(stream = avformat_new_stream(*output_format_context, NULL))) {&#xA;            fprintf(stderr, "Could not create new stream\n");&#xA;            error = AVERROR(ENOMEM);&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;        avctx = avcodec_alloc_context3(output_codec);&#xA;        if (!avctx) {&#xA;            fprintf(stderr, "Could not allocate an encoding context\n");&#xA;            error = AVERROR(ENOMEM);&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;   /* Set the basic encoder parameters.&#xA;    * SET OUR DESIRED output sample_rate here&#xA;    */&#xA;        avctx->channels       = OUTPUT_CHANNELS;&#xA;        avctx->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);&#xA;        // avctx->sample_rate    = input_codec_context->sample_rate;&#xA;        avctx->sample_rate    = 22050;&#xA;        avctx->sample_fmt     = output_codec->sample_fmts[0];&#xA;        avctx->bit_rate       = OUTPUT_BIT_RATE;&#xA;    &#xA;        avctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;&#xA;    &#xA;        /* Set the sample rate for the container. */&#xA;        stream->time_base.den = avctx->sample_rate;&#xA;        stream->time_base.num = 1;&#xA;    &#xA;        if ((*output_format_context)->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;            avctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    &#xA;        if ((error = avcodec_open2(avctx, output_codec, NULL)) &lt; 0) {&#xA;            fprintf(stderr, "Could not open output codec (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;        error = avcodec_parameters_from_context(stream->codecpar, avctx);&#xA;        if (error &lt; 0) {&#xA;            fprintf(stderr, "Could not initialize stream parameters\n");&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;        /* Save the encoder context for easier access later. */&#xA;        *output_codec_context = avctx;&#xA;    &#xA;        return 0;&#xA;    &#xA;    cleanup:&#xA;        avcodec_free_context(&amp;avctx);&#xA;        avio_closep(&amp;(*output_format_context)->pb);&#xA;        avformat_free_context(*output_format_context);&#xA;        *output_format_context = NULL;&#xA;        return error &lt; 0 ? error : AVERROR_EXIT;&#xA;    }&#xA;    &#xA;    /**&#xA;     * Initialize one data packet for reading or writing.&#xA;     */&#xA;    static int init_packet(AVPacket **packet)&#xA;    {&#xA;        if (!(*packet = av_packet_alloc())) {&#xA;            fprintf(stderr, "Could not allocate packet\n");&#xA;            return AVERROR(ENOMEM);&#xA;        }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int init_input_frame(AVFrame **frame)&#xA;    {&#xA;        if (!(*frame = av_frame_alloc())) {&#xA;            fprintf(stderr, "Could not allocate input frame\n");&#xA;            return AVERROR(ENOMEM);&#xA;        }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int init_resampler(AVCodecContext *input_codec_context,&#xA;                              AVCodecContext *output_codec_context,&#xA;                              SwrContext **resample_context)&#xA;    {&#xA;            int error;&#xA;&#xA;  /**&#xA;   * create the resample, including ref to the desired output sample rate&#xA;   */&#xA;            *resample_context = swr_alloc_set_opts(NULL,&#xA;                                                  av_get_default_channel_layout(output_codec_context->channels),&#xA;                                                  output_codec_context->sample_fmt,&#xA;                                                  output_codec_context->sample_rate,&#xA;                              av_get_default_channel_layout(input_codec_context->channels),&#xA;                                                  input_codec_context->sample_fmt,&#xA;                                                  input_codec_context->sample_rate,&#xA;                                                  0, NULL);&#xA;            if (!*resample_context &lt; 0) {&#xA;                fprintf(stderr, "Could not allocate resample context\n");&#xA;            return AVERROR(ENOMEM);&#xA;            }&#xA;    &#xA;            if ((error = swr_init(*resample_context)) &lt; 0) {&#xA;                fprintf(stderr, "Could not open resample context\n");&#xA;                swr_free(resample_context);&#xA;                return error;&#xA;            }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int init_fifo(AVAudioFifo **fifo, AVCodecContext *output_codec_context)&#xA;    {&#xA;        if (!(*fifo = av_audio_fifo_alloc(output_codec_context->sample_fmt,&#xA;                                          output_codec_context->channels, 1))) {&#xA;            fprintf(stderr, "Could not allocate FIFO\n");&#xA;            return AVERROR(ENOMEM);&#xA;        }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int write_output_file_header(AVFormatContext *output_format_context)&#xA;    {&#xA;        int error;&#xA;        if ((error = avformat_write_header(output_format_context, NULL)) &lt; 0) {&#xA;            fprintf(stderr, "Could not write output file header (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            return error;&#xA;        }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int decode_audio_frame(AVFrame *frame,&#xA;                                  AVFormatContext *input_format_context,&#xA;                                  AVCodecContext *input_codec_context,&#xA;                                  int *data_present, int *finished)&#xA;    {&#xA;        AVPacket *input_packet;&#xA;        int error;&#xA;    &#xA;        error = init_packet(&amp;input_packet);&#xA;        if (error &lt; 0)&#xA;            return error;&#xA;    &#xA;        *data_present = 0;&#xA;        *finished = 0;&#xA;&#xA;        if ((error = av_read_frame(input_format_context, input_packet)) &lt; 0) {&#xA;            if (error == AVERROR_EOF)&#xA;                *finished = 1;&#xA;            else {&#xA;                fprintf(stderr, "Could not read frame (error &#x27;%s&#x27;)\n",&#xA;                        av_err2str(error));&#xA;                goto cleanup;&#xA;            }&#xA;        }&#xA;    &#xA;        if ((error = avcodec_send_packet(input_codec_context, input_packet)) &lt; 0) {&#xA;            fprintf(stderr, "Could not send packet for decoding (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;        error = avcodec_receive_frame(input_codec_context, frame);&#xA;        if (error == AVERROR(EAGAIN)) {&#xA;            error = 0;&#xA;            goto cleanup;&#xA;        } else if (error == AVERROR_EOF) {&#xA;            *finished = 1;&#xA;            error = 0;&#xA;            goto cleanup;&#xA;        } else if (error &lt; 0) {&#xA;            fprintf(stderr, "Could not decode frame (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            goto cleanup;&#xA;        } else {&#xA;            *data_present = 1;&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;    cleanup:&#xA;        av_packet_free(&amp;input_packet);&#xA;        return error;&#xA;    }&#xA;    &#xA;    static int init_converted_samples(uint8_t ***converted_input_samples,&#xA;                                      AVCodecContext *output_codec_context,&#xA;                                      int frame_size)&#xA;    {&#xA;        int error;&#xA;    &#xA;        if (!(*converted_input_samples = calloc(output_codec_context->channels,&#xA;                                                sizeof(**converted_input_samples)))) {&#xA;            fprintf(stderr, "Could not allocate converted input sample pointers\n");&#xA;            return AVERROR(ENOMEM);&#xA;        }&#xA;    &#xA;&#xA;        if ((error = av_samples_alloc(*converted_input_samples, NULL,&#xA;                                      output_codec_context->channels,&#xA;                                      frame_size,&#xA;                                      output_codec_context->sample_fmt, 0)) &lt; 0) {&#xA;            fprintf(stderr,&#xA;                    "Could not allocate converted input samples (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            av_freep(&amp;(*converted_input_samples)[0]);&#xA;            free(*converted_input_samples);&#xA;            return error;&#xA;        }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int convert_samples(const uint8_t **input_data, const int input_nb_samples,&#xA;                               uint8_t **converted_data, const int output_nb_samples,&#xA;                               SwrContext *resample_context)&#xA;    {&#xA;        int error;&#xA;    &#xA;        if ((error = swr_convert(resample_context,&#xA;                                 converted_data, output_nb_samples,&#xA;                                 input_data    , input_nb_samples)) &lt; 0) {&#xA;            fprintf(stderr, "Could not convert input samples (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            return error;&#xA;        }&#xA;    &#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int add_samples_to_fifo(AVAudioFifo *fifo,&#xA;                                   uint8_t **converted_input_samples,&#xA;                                   const int frame_size)&#xA;    {&#xA;        int error;&#xA;    &#xA;        if ((error = av_audio_fifo_realloc(fifo, av_audio_fifo_size(fifo) &#x2B; frame_size)) &lt; 0) {&#xA;            fprintf(stderr, "Could not reallocate FIFO\n");&#xA;            return error;&#xA;        }&#xA;    &#xA;        if (av_audio_fifo_write(fifo, (void **)converted_input_samples,&#xA;                                frame_size) &lt; frame_size) {&#xA;            fprintf(stderr, "Could not write data to FIFO\n");&#xA;            return AVERROR_EXIT;&#xA;        }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    static int read_decode_convert_and_store(AVAudioFifo *fifo,&#xA;                                             AVFormatContext *input_format_context,&#xA;                                             AVCodecContext *input_codec_context,&#xA;                                             AVCodecContext *output_codec_context,&#xA;                                             SwrContext *resampler_context,&#xA;                                             int *finished)&#xA;    {&#xA;        AVFrame *input_frame = NULL;&#xA;        uint8_t **converted_input_samples = NULL;&#xA;        int data_present;&#xA;        int ret = AVERROR_EXIT;&#xA;    &#xA;&#xA;        if (init_input_frame(&amp;input_frame))&#xA;            goto cleanup;&#xA;&#xA;        if (decode_audio_frame(input_frame, input_format_context,&#xA;                               input_codec_context, &amp;data_present, finished))&#xA;            goto cleanup;&#xA;&#xA;        if (*finished) {&#xA;            ret = 0;&#xA;            goto cleanup;&#xA;        }&#xA;&#xA;        if (data_present) {&#xA;            /* Initialize the temporary storage for the converted input samples. */&#xA;            if (init_converted_samples(&amp;converted_input_samples, output_codec_context,&#xA;                                       input_frame->nb_samples))&#xA;                goto cleanup;&#xA; &#xA;    /* figure out how many samples are required for target sample_rate incl&#xA;     * any items left in the swr buffer&#xA;     */   &#xA;            int  output_nb_samples = av_rescale_rnd(&#xA;                                       swr_get_delay(resampler_context, input_codec_context->sample_rate) &#x2B; input_frame->nb_samples,&#xA;                                       output_codec_context->sample_rate, &#xA;                                        input_codec_context->sample_rate,&#xA;                                       AV_ROUND_UP);&#xA; &#xA;            /* ignore, just to ensure we&#x27;ve got enough buffer alloc&#x27;d for conversion buffer */&#xA;            av_assert1(input_frame->nb_samples > output_nb_samples);&#xA;   &#xA;    /* Convert the input samples to the desired output sample format, via swr_convert().&#xA;     */&#xA;            if (convert_samples((const uint8_t**)input_frame->extended_data, input_frame->nb_samples,&#xA;                        converted_input_samples, output_nb_samples,&#xA;                    resampler_context))&#xA;                goto cleanup;&#xA;    &#xA;            /* Add the converted input samples to the FIFO buffer for later processing. */&#xA;            if (add_samples_to_fifo(fifo, converted_input_samples,&#xA;                                    output_nb_samples))&#xA;                goto cleanup;&#xA;            ret = 0;&#xA;        }&#xA;        ret = 0;&#xA;    &#xA;    cleanup:&#xA;        if (converted_input_samples) {&#xA;            av_freep(&amp;converted_input_samples[0]);&#xA;            free(converted_input_samples);&#xA;        }&#xA;        av_frame_free(&amp;input_frame);&#xA;    &#xA;        return ret;&#xA;    }&#xA;    &#xA;    static int init_output_frame(AVFrame **frame,&#xA;                                 AVCodecContext *output_codec_context,&#xA;                                 int frame_size)&#xA;    {&#xA;        int error;&#xA;    &#xA;        if (!(*frame = av_frame_alloc())) {&#xA;            fprintf(stderr, "Could not allocate output frame\n");&#xA;            return AVERROR_EXIT;&#xA;        }&#xA;    &#xA;        /* Set the frame&#x27;s parameters, especially its size and format.&#xA;         * av_frame_get_buffer needs this to allocate memory for the&#xA;         * audio samples of the frame.&#xA;         * Default channel layouts based on the number of channels&#xA;         * are assumed for simplicity. */&#xA;        (*frame)->nb_samples     = frame_size;&#xA;        (*frame)->channel_layout = output_codec_context->channel_layout;&#xA;        (*frame)->format         = output_codec_context->sample_fmt;&#xA;        (*frame)->sample_rate    = output_codec_context->sample_rate;&#xA;    &#xA;        /* Allocate the samples of the created frame. This call will make&#xA;         * sure that the audio frame can hold as many samples as specified. */&#xA;        if ((error = av_frame_get_buffer(*frame, 0)) &lt; 0) {&#xA;            fprintf(stderr, "Could not allocate output frame samples (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            av_frame_free(frame);&#xA;            return error;&#xA;        }&#xA;    &#xA;        return 0;&#xA;    }&#xA;    &#xA;    /* Global timestamp for the audio frames. */&#xA;    static int64_t pts = 0;&#xA;    &#xA;    /**&#xA;     * Encode one frame worth of audio to the output file.&#xA;     */&#xA;    static int encode_audio_frame(AVFrame *frame,&#xA;                                  AVFormatContext *output_format_context,&#xA;                                  AVCodecContext *output_codec_context,&#xA;                                  int *data_present)&#xA;    {&#xA;        AVPacket *output_packet;&#xA;        int error;&#xA;    &#xA;        error = init_packet(&amp;output_packet);&#xA;        if (error &lt; 0)&#xA;            return error;&#xA;    &#xA;        /* Set a timestamp based on the sample rate for the container. */&#xA;        if (frame) {&#xA;            frame->pts = pts;&#xA;            pts &#x2B;= frame->nb_samples;&#xA;        }&#xA;    &#xA;        *data_present = 0;&#xA;        error = avcodec_send_frame(output_codec_context, frame);&#xA;        if (error &lt; 0 &amp;&amp; error != AVERROR_EOF) {&#xA;          fprintf(stderr, "Could not send packet for encoding (error &#x27;%s&#x27;)\n",&#xA;                  av_err2str(error));&#xA;          goto cleanup;&#xA;        }&#xA;    &#xA;&#xA;        error = avcodec_receive_packet(output_codec_context, output_packet);&#xA;        if (error == AVERROR(EAGAIN)) {&#xA;            error = 0;&#xA;            goto cleanup;&#xA;        } else if (error == AVERROR_EOF) {&#xA;            error = 0;&#xA;            goto cleanup;&#xA;        } else if (error &lt; 0) {&#xA;            fprintf(stderr, "Could not encode frame (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            goto cleanup;&#xA;        } else {&#xA;            *data_present = 1;&#xA;        }&#xA;    &#xA;        /* Write one audio frame from the temporary packet to the output file. */&#xA;        if (*data_present &amp;&amp;&#xA;            (error = av_write_frame(output_format_context, output_packet)) &lt; 0) {&#xA;            fprintf(stderr, "Could not write frame (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            goto cleanup;&#xA;        }&#xA;    &#xA;    cleanup:&#xA;        av_packet_free(&amp;output_packet);&#xA;        return error;&#xA;    }&#xA;    &#xA;    /**&#xA;     * Load one audio frame from the FIFO buffer, encode and write it to the&#xA;     * output file.&#xA;     */&#xA;    static int load_encode_and_write(AVAudioFifo *fifo,&#xA;                                     AVFormatContext *output_format_context,&#xA;                                     AVCodecContext *output_codec_context)&#xA;    {&#xA;        AVFrame *output_frame;&#xA;        /* Use the maximum number of possible samples per frame.&#xA;         * If there is less than the maximum possible frame size in the FIFO&#xA;         * buffer use this number. Otherwise, use the maximum possible frame size. */&#xA;        const int frame_size = FFMIN(av_audio_fifo_size(fifo),&#xA;                                     output_codec_context->frame_size);&#xA;        int data_written;&#xA;    &#xA;        if (init_output_frame(&amp;output_frame, output_codec_context, frame_size))&#xA;            return AVERROR_EXIT;&#xA;    &#xA;        /* Read as many samples from the FIFO buffer as required to fill the frame.&#xA;         * The samples are stored in the frame temporarily. */&#xA;        if (av_audio_fifo_read(fifo, (void **)output_frame->data, frame_size) &lt; frame_size) {&#xA;            fprintf(stderr, "Could not read data from FIFO\n");&#xA;            av_frame_free(&amp;output_frame);&#xA;            return AVERROR_EXIT;&#xA;        }&#xA;    &#xA;        /* Encode one frame worth of audio samples. */&#xA;        if (encode_audio_frame(output_frame, output_format_context,&#xA;                               output_codec_context, &amp;data_written)) {&#xA;            av_frame_free(&amp;output_frame);&#xA;            return AVERROR_EXIT;&#xA;        }&#xA;        av_frame_free(&amp;output_frame);&#xA;        return 0;&#xA;    }&#xA;    &#xA;    /**&#xA;     * Write the trailer of the output file container.&#xA;     */&#xA;    static int write_output_file_trailer(AVFormatContext *output_format_context)&#xA;    {&#xA;        int error;&#xA;        if ((error = av_write_trailer(output_format_context)) &lt; 0) {&#xA;            fprintf(stderr, "Could not write output file trailer (error &#x27;%s&#x27;)\n",&#xA;                    av_err2str(error));&#xA;            return error;&#xA;        }&#xA;        return 0;&#xA;    }&#xA;    &#xA;    int main(int argc, char **argv)&#xA;    {&#xA;        AVFormatContext *input_format_context = NULL, *output_format_context = NULL;&#xA;        AVCodecContext *input_codec_context = NULL, *output_codec_context = NULL;&#xA;        SwrContext *resample_context = NULL;&#xA;        AVAudioFifo *fifo = NULL;&#xA;        int ret = AVERROR_EXIT;&#xA;    &#xA;        if (argc != 3) {&#xA;            fprintf(stderr, "Usage: %s <input file="file" /> <output file="file">\n", argv[0]);&#xA;            exit(1);&#xA;        }&#xA;    &#xA;&#xA;        if (open_input_file(argv[1], &amp;input_format_context,&#xA;                            &amp;input_codec_context))&#xA;            goto cleanup;&#xA;&#xA;        if (open_output_file(argv[2], input_codec_context,&#xA;                             &amp;output_format_context, &amp;output_codec_context))&#xA;            goto cleanup;&#xA;&#xA;        if (init_resampler(input_codec_context, output_codec_context,&#xA;                           &amp;resample_context))&#xA;            goto cleanup;&#xA;&#xA;        if (init_fifo(&amp;fifo, output_codec_context))&#xA;            goto cleanup;&#xA;&#xA;        if (write_output_file_header(output_format_context))&#xA;            goto cleanup;&#xA;    &#xA;        while (1) {&#xA;            /* Use the encoder&#x27;s desired frame size for processing. */&#xA;            const int output_frame_size = output_codec_context->frame_size;&#xA;            int finished                = 0;&#xA;    &#xA;            while (av_audio_fifo_size(fifo) &lt; output_frame_size) {&#xA;                /* Decode one frame worth of audio samples, convert it to the&#xA;                 * output sample format and put it into the FIFO buffer. */&#xA;                if (read_decode_convert_and_store(fifo, input_format_context,&#xA;                                                  input_codec_context,&#xA;                                                  output_codec_context,&#xA;                                                  resample_context, &amp;finished))&#xA;                    goto cleanup;&#xA;    &#xA;                if (finished)&#xA;                    break;&#xA;            }&#xA;    &#xA;            while (av_audio_fifo_size(fifo) >= output_frame_size ||&#xA;                   (finished &amp;&amp; av_audio_fifo_size(fifo) > 0))&#xA;                if (load_encode_and_write(fifo, output_format_context,&#xA;                                          output_codec_context))&#xA;                    goto cleanup;&#xA;    &#xA;            if (finished) {&#xA;                int data_written;&#xA;                do {&#xA;                    if (encode_audio_frame(NULL, output_format_context,&#xA;                                           output_codec_context, &amp;data_written))&#xA;                        goto cleanup;&#xA;                } while (data_written);&#xA;                break;&#xA;            }&#xA;        }&#xA;    &#xA;        if (write_output_file_trailer(output_format_context))&#xA;            goto cleanup;&#xA;        ret = 0;&#xA;    &#xA;    cleanup:&#xA;        if (fifo)&#xA;            av_audio_fifo_free(fifo);&#xA;        swr_free(&amp;resample_context);&#xA;        if (output_codec_context)&#xA;            avcodec_free_context(&amp;output_codec_context);&#xA;        if (output_format_context) {&#xA;            avio_closep(&amp;output_format_context->pb);&#xA;            avformat_free_context(output_format_context);&#xA;        }&#xA;        if (input_codec_context)&#xA;            avcodec_free_context(&amp;input_codec_context);&#xA;        if (input_format_context)&#xA;            avformat_close_input(&amp;input_format_context);&#xA;    &#xA;        return ret;&#xA;    }&#xA;</output>

    &#xA;