Recherche avancée

Médias (16)

Mot : - Tags -/mp3

Autres articles (62)

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

  • Librairies et binaires spécifiques au traitement vidéo et sonore

    31 janvier 2010, par

    Les logiciels et librairies suivantes sont utilisées par SPIPmotion d’une manière ou d’une autre.
    Binaires obligatoires FFMpeg : encodeur principal, permet de transcoder presque tous les types de fichiers vidéo et sonores dans les formats lisibles sur Internet. CF ce tutoriel pour son installation ; Oggz-tools : outils d’inspection de fichiers ogg ; Mediainfo : récupération d’informations depuis la plupart des formats vidéos et sonores ;
    Binaires complémentaires et facultatifs flvtool2 : (...)

Sur d’autres sites (8549)

  • AVPlayer currentTime not match with the displayed frame after many seeking. (HLS Stream)

    26 août 2022, par D.Bence

    I have a m3u8 file which i want to use with HLS.
link to m3u8 file

    


    My problem is that when i seek many times, the currentTime not match with the displayed frame. I experience that, the more seeking there is more difference. (it's like a constant +offset)

    


    Our use case is very timing sensitive, we need to stop the videos at specific positions. For this we use the following code :

    


    [_player addBoundaryTimeObserverForTimes:times
      queue:dispatch_get_main_queue()
      usingBlock:^{
            weakSelf.player.rate = 0.0;
            // The time is correct here, but the displayed frame is not sync with this time
            CMTimeShow(weakSelf.player.currentTime);
      }
]   


    


    I read that AVURLAssetPreferPreciseDurationAndTimingKey can help, but the currentTime still wrong.

    


    NSDictionary<nsstring> *options = @{AVURLAssetPreferPreciseDurationAndTimingKey:@YES};&#xA;AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:options];&#xA;AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:urlAsset];&#xA;</nsstring>

    &#xA;

    I also read that there is a problem with the m3u8 itself. (for example wrong GOP size.)

    &#xA;

    What is the reason for the incorrect currentTime, and how can i fix this ?

    &#xA;

    ffprobe m3u8 :

    &#xA;

    ffprobe https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized.m3u8&#xA;ffprobe version 5.1 Copyright (c) 2007-2022 the FFmpeg developers&#xA;  built with Apple clang version 13.1.6 (clang-1316.0.21.2.5)&#xA;  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon&#xA;  libavutil      57. 28.100 / 57. 28.100&#xA;  libavcodec     59. 37.100 / 59. 37.100&#xA;  libavformat    59. 27.100 / 59. 27.100&#xA;  libavdevice    59.  7.100 / 59.  7.100&#xA;  libavfilter     8. 44.100 /  8. 44.100&#xA;  libswscale      6.  7.100 /  6.  7.100&#xA;  libswresample   4.  7.100 /  4.  7.100&#xA;  libpostproc    56.  6.100 / 56.  6.100&#xA;[hls @ 0x152f04280] Skip (&#x27;#EXT-X-VERSION:3&#x27;)&#xA;[hls @ 0x152f04280] Skip (&#x27;#EXT-X-INDEPENDENT-SEGMENTS&#x27;)&#xA;[hls @ 0x152f04280] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1080p_6000000bitrate.m3u8&#x27; for reading&#xA;[hls @ 0x152f04280] Skip (&#x27;#EXT-X-VERSION:3&#x27;)&#xA;[https @ 0x154045000] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1080p_15000000bitrate.m3u8&#x27; for reading&#xA;[hls @ 0x152f04280] Skip (&#x27;#EXT-X-VERSION:3&#x27;)&#xA;[https @ 0x154045000] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1520p_33000000bitrate.m3u8&#x27; for reading&#xA;[hls @ 0x152f04280] Skip (&#x27;#EXT-X-VERSION:3&#x27;)&#xA;[hls @ 0x152f04280] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1080p_6000000bitrate_00001.ts&#x27; for reading&#xA;[hls @ 0x152f04280] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1080p_6000000bitrate_00002.ts&#x27; for reading&#xA;[hls @ 0x152f04280] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1080p_15000000bitrate_00001.ts&#x27; for reading&#xA;[hls @ 0x152f04280] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1080p_15000000bitrate_00002.ts&#x27; for reading&#xA;[hls @ 0x152f04280] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1520p_33000000bitrate_00001.ts&#x27; for reading&#xA;[hls @ 0x152f04280] Opening &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized1520p_33000000bitrate_00002.ts&#x27; for reading&#xA;Input #0, hls, from &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/released/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized.m3u8&#x27;:&#xA;  Duration: 00:49:43.00, start: 2.033367, bitrate: 0 kb/s&#xA;  Program 0&#xA;    Metadata:&#xA;      variant_bitrate : 8133826&#xA;  Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn&#xA;    Metadata:&#xA;      variant_bitrate : 8133826&#xA;  Program 1&#xA;    Metadata:&#xA;      variant_bitrate : 18870392&#xA;  Stream #0:1: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn&#xA;    Metadata:&#xA;      variant_bitrate : 18870392&#xA;  Program 2&#xA;    Metadata:&#xA;      variant_bitrate : 40776144&#xA;  Stream #0:2: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 2704x1520 [SAR 1:1 DAR 169:95], 29.97 fps, 29.97 tbr, 90k tbn&#xA;    Metadata:&#xA;      variant_bitrate : 40776144&#xA;

    &#xA;

    ffprobe original mp4 :

    &#xA;

    ffprobe https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/finalized/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized.mp4&#xA;ffprobe version 5.1 Copyright (c) 2007-2022 the FFmpeg developers&#xA;  built with Apple clang version 13.1.6 (clang-1316.0.21.2.5)&#xA;  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon&#xA;  libavutil      57. 28.100 / 57. 28.100&#xA;  libavcodec     59. 37.100 / 59. 37.100&#xA;  libavformat    59. 27.100 / 59. 27.100&#xA;  libavdevice    59.  7.100 / 59.  7.100&#xA;  libavfilter     8. 44.100 /  8. 44.100&#xA;  libswscale      6.  7.100 /  6.  7.100&#xA;  libswresample   4.  7.100 /  4.  7.100&#xA;  libpostproc    56.  6.100 / 56.  6.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;https://mrkresz-content-bucket.s3.eu-central-1.amazonaws.com/applicationData/extended-path-videos/4b0046fd-0be7-4a07-bc7c-c1a0069116b1/finalized/50816bc9-6118-4dd1-a90e-fb72652bb06f-final-from-anonymized.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : isom&#xA;    minor_version   : 512&#xA;    compatible_brands: isomiso2avc1mp41&#xA;    encoder         : Lavf58.76.100&#xA;  Duration: 00:49:42.81, start: 0.000000, bitrate: 36142 kb/s&#xA;  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 2486x1398, 36138 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)&#xA;    Metadata:&#xA;      handler_name    : VideoHandler&#xA;      vendor_id       : [0][0][0][0]&#xA;

    &#xA;

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

    &#xA;

    The bash command is :

    &#xA;

    ffmpeg -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&#xA;

    &#xA;

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

    &#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;Input #0, image2, from &#x27;*.png&#x27;:&#xA;  Duration: 00:16:39.00, start: 0.000000, bitrate: N/A&#xA;    Stream #0:0: Video: png, rgba(pc), 895x332 [SAR 3937:3937 DAR 895:332], 1 fps, 1 tbr, 1 tbn, 1 tbc&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))&#xA;Press [q] to stop, [?] for help&#xA;[libx264 @ 0x55726ab95d00] using SAR=1/1&#xA;[libx264 @ 0x55726ab95d00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512&#xA;[libx264 @ 0x55726ab95d00] profile High, level 2.2&#xA;[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&#xA;Output #0, mp4, to &#x27;out.mp4&#x27;:&#xA;  Metadata:&#xA;    encoder         : Lavf58.29.100&#xA;    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&#xA;    Metadata:&#xA;      encoder         : Lavc58.54.100 libx264&#xA;    Side data:&#xA;      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1&#xA;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    &#xA;video:4974kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.241361%&#xA;[libx264 @ 0x55726ab95d00] frame I:4     Avg QP: 6.12  size: 24072&#xA;[libx264 @ 0x55726ab95d00] frame P:346   Avg QP:12.94  size:  5708&#xA;[libx264 @ 0x55726ab95d00] frame B:649   Avg QP:18.19  size:  4655&#xA;[libx264 @ 0x55726ab95d00] consecutive B-frames:  5.8% 16.0% 20.1% 58.1%&#xA;[libx264 @ 0x55726ab95d00] mb I  I16..4: 59.1% 10.6% 30.4%&#xA;[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%&#xA;[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%&#xA;[libx264 @ 0x55726ab95d00] 8x8 transform intra:5.9% inter:10.4%&#xA;[libx264 @ 0x55726ab95d00] coded y,uvDC,uvAC intra: 20.1% 18.3% 17.3% inter: 4.7% 4.7% 4.6%&#xA;[libx264 @ 0x55726ab95d00] i16 v,h,dc,p: 66% 33%  1%  0%&#xA;[libx264 @ 0x55726ab95d00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18%  8% 73%  0%  0%  0%  0%  0%  0%&#xA;[libx264 @ 0x55726ab95d00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 31% 31%  2%  3%  2%  4%  2%  3%&#xA;[libx264 @ 0x55726ab95d00] i8c dc,h,v,p: 73% 23%  3%  0%&#xA;[libx264 @ 0x55726ab95d00] Weighted P-Frames: Y:0.0% UV:0.0%&#xA;[libx264 @ 0x55726ab95d00] ref P L0: 57.2%  1.5% 24.3% 17.0%&#xA;[libx264 @ 0x55726ab95d00] ref B L0: 69.6% 24.8%  5.6%&#xA;[libx264 @ 0x55726ab95d00] ref B L1: 92.4%  7.6%&#xA;[libx264 @ 0x55726ab95d00] kb/s:40.78&#xA;

    &#xA;

    In my python script I tried the following solutions :

    &#xA;

    video_cmd = """ffmpeg -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"""&#xA;&#xA;subprocess.run(shlex.split(video_cmd), shell=False, cwd=path_viz, stderr=subprocess.STDOUT, check=True, text=False)&#xA;&#xA;subprocess.run(video_cmd, shell=True, cwd=path_viz, stderr=subprocess.STDOUT, check=True, text=False)&#xA;

    &#xA;

    as well as the solution proposed for this similar question

    &#xA;

    subprocess.Popen(video_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)&#xA;

    &#xA;

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

    &#xA;

    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;

    &#xA;

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

    &#xA;

    fmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers&#xA;  built with gcc 7.3.0 (crosstool-NG 1.23.0.449-a04d0)&#xA;  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&#xA;  libavutil      56. 51.100 / 56. 51.100&#xA;  libavcodec     58. 91.100 / 58. 91.100&#xA;  libavformat    58. 45.100 / 58. 45.100&#xA;  libavdevice    58. 10.100 / 58. 10.100&#xA;  libavfilter     7. 85.100 /  7. 85.100&#xA;  libavresample   4.  0.  0 /  4.  0.  0&#xA;  libswscale      5.  7.100 /  5.  7.100&#xA;  libswresample   3.  7.100 /  3.  7.100&#xA;Input #0, image2, from &#x27;*.png&#x27;:&#xA;  Duration: 00:16:39.00, start: 0.000000, bitrate: N/A&#xA;    Stream #0:0: Video: png, rgba(pc), 895x332 [SAR 3937:3937 DAR 895:332], 1 fps, 1 tbr, 1 tbn, 1 tbc&#xA;

    &#xA;

    but it then pops up the following error :

    &#xA;

    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;

  • Getting shifted timestamps when encoding a fragmented h264 mp4 with ffmpeg

    14 septembre 2022, par Martin Castin

    I am trying to encode a fragmented h264 mp4 with ffmpeg. I tried the following command :

    &#xA;

    ffmpeg -i input.mp4 -movflags &#x2B;frag_keyframe&#x2B;separate_moof&#x2B;omit_tfhd_offset&#x2B;empty_moov output.mp4&#xA;

    &#xA;

    It does give me a fragmented mp4 but the timestamps of the frames seem to be shifted by 0.04s when I read the video with mpv. The first frame has a timestamp of 0.04s instead of 0s, as in the input video (1920x1080, 50 fps). I encountered the problem both with ffmpeg 5.1 and ffmpeg 3.4.11.

    &#xA;

    I tried to add several flags, as -avoid_negative_ts make_zero or -copyts -output_ts_offset -0.04, but it did not help.

    &#xA;

    I am also trying to achieve this using the ffmpeg libav libraries in C++ but did not get to better result. Here are the code fragments I used.

    &#xA;

     avformat_alloc_output_context2(&amp;oc, NULL, NULL, filename);&#xA;&#xA; if (oc_->oformat->flags &amp; AVFMT_GLOBALHEADER) {&#xA;    codecCtx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA; }&#xA;...&#xA; AVDictionary* opts = NULL;&#xA;&#xA; av_dict_set(&amp;opts, "movflags", "frag_keyframe&#x2B;separate_moof&#x2B;omit_tfhd_offset&#x2B;empty_moov", 0);&#xA;&#xA; ret = avformat_write_header(oc_, &amp;opts);&#xA;

    &#xA;

    Do you know how to avoid this behaviour of shifted timestamps for fragmented mp4, either with ffmpeg or libav ?

    &#xA;

    Edit : example videos and complete code example

    &#xA;

    I also tried with the following ffmpeg build

    &#xA;

    ffmpeg version 5.0.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2022 the FFmpeg developers&#xA;built with gcc 8 (Debian 8.3.0-6)&#xA;configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg&#xA;libavutil      57. 17.100 / 57. 17.100&#xA;libavcodec     59. 18.100 / 59. 18.100&#xA;libavformat    59. 16.100 / 59. 16.100&#xA;libavdevice    59.  4.100 / 59.  4.100&#xA;libavfilter     8. 24.100 /  8. 24.100&#xA;libswscale      6.  4.100 /  6.  4.100&#xA;libswresample   4.  3.100 /  4.  3.100&#xA;libpostproc    56.  3.100 / 56.  3.100&#xA;

    &#xA;

    and with the sintel trailer as input video, which is 24fps, and I thus get a timeshift of 83ms. Here is the output I get.

    &#xA;

    Here is a complete code example, slightly adapted from the muxing.c ffmpeg example (audio removed and adapted for c++). This code shows exactly the same problem.

    &#xA;

    You can just comment the line 383 (that is calling av_dict_set) to switch back to a not fragmented mp4 that will not have the timestamp shift.

    &#xA;

    /*&#xA; * Copyright (c) 2003 Fabrice Bellard&#xA; *&#xA; * Permission is hereby granted, free of charge, to any person obtaining a copy&#xA; * of this software and associated documentation files (the "Software"), to deal&#xA; * in the Software without restriction, including without limitation the rights&#xA; * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell&#xA; * copies of the Software, and to permit persons to whom the Software is&#xA; * furnished to do so, subject to the following conditions:&#xA; *&#xA; * The above copyright notice and this permission notice shall be included in&#xA; * all copies or substantial portions of the Software.&#xA; *&#xA; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR&#xA; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,&#xA; * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL&#xA; * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER&#xA; * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,&#xA; * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN&#xA; * THE SOFTWARE.&#xA; */&#xA;&#xA;/**&#xA; * @file&#xA; * libavformat API example.&#xA; *&#xA; * Output a media file in any supported libavformat format. The default&#xA; * codecs are used.&#xA; * @example muxing.c&#xA; */&#xA;&#xA;#include <cstdlib>&#xA;#include <cstdio>&#xA;#include <cstring>&#xA;#include <cmath>&#xA;&#xA;extern "C"&#xA;{&#xA;#define __STDC_CONSTANT_MACROS&#xA;#include <libavutil></libavutil>avassert.h>&#xA;#include <libavutil></libavutil>channel_layout.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavutil></libavutil>mathematics.h>&#xA;#include <libavutil></libavutil>timestamp.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include <libswresample></libswresample>swresample.h>&#xA;}&#xA;&#xA;#define STREAM_DURATION   10.0&#xA;#define STREAM_FRAME_RATE 25 /* 25 images/s */&#xA;#define STREAM_PIX_FMT    AV_PIX_FMT_YUV420P /* default pix_fmt */&#xA;&#xA;#define SCALE_FLAGS SWS_BICUBIC&#xA;&#xA;// a wrapper around a single output AVStream&#xA;typedef struct OutputStream {&#xA;  AVStream *st;&#xA;  AVCodecContext *enc;&#xA;&#xA;  /* pts of the next frame that will be generated */&#xA;  int64_t next_pts;&#xA;  int samples_count;&#xA;&#xA;  AVFrame *frame;&#xA;  AVFrame *tmp_frame;&#xA;&#xA;  AVPacket *tmp_pkt;&#xA;&#xA;  float t, tincr, tincr2;&#xA;&#xA;  struct SwsContext *sws_ctx;&#xA;  struct SwrContext *swr_ctx;&#xA;} OutputStream;&#xA;&#xA;static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt)&#xA;{&#xA;  AVRational *time_base = &amp;fmt_ctx->streams[pkt->stream_index]->time_base;&#xA;&#xA;//  printf("pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\n",&#xA;//         av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, time_base),&#xA;//         av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, time_base),&#xA;//         av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, time_base),&#xA;//         pkt->stream_index);&#xA;}&#xA;&#xA;static int write_frame(AVFormatContext *fmt_ctx, AVCodecContext *c,&#xA;                       AVStream *st, AVFrame *frame, AVPacket *pkt)&#xA;{&#xA;  int ret;&#xA;&#xA;  // send the frame to the encoder&#xA;  ret = avcodec_send_frame(c, frame);&#xA;  if (ret &lt; 0) {&#xA;    fprintf(stderr, "Error sending a frame to the encoder");&#xA;    exit(1);&#xA;  }&#xA;&#xA;  while (ret >= 0) {&#xA;    ret = avcodec_receive_packet(c, pkt);&#xA;    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;      break;&#xA;    else if (ret &lt; 0) {&#xA;      fprintf(stderr, "Error encoding a frame\n");&#xA;      exit(1);&#xA;    }&#xA;&#xA;    /* rescale output packet timestamp values from codec to stream timebase */&#xA;    av_packet_rescale_ts(pkt, c->time_base, st->time_base);&#xA;    pkt->stream_index = st->index;&#xA;&#xA;    /* Write the compressed frame to the media file. */&#xA;    log_packet(fmt_ctx, pkt);&#xA;    ret = av_interleaved_write_frame(fmt_ctx, pkt);&#xA;    /* pkt is now blank (av_interleaved_write_frame() takes ownership of&#xA;     * its contents and resets pkt), so that no unreferencing is necessary.&#xA;     * This would be different if one used av_write_frame(). */&#xA;    if (ret &lt; 0) {&#xA;      fprintf(stderr, "Error while writing output packet\n");&#xA;      exit(1);&#xA;    }&#xA;  }&#xA;&#xA;  return ret == AVERROR_EOF ? 1 : 0;&#xA;}&#xA;&#xA;/* Add an output stream. */&#xA;static void add_stream(OutputStream *ost, AVFormatContext *oc,&#xA;                       const AVCodec **codec,&#xA;                       enum AVCodecID codec_id)&#xA;{&#xA;  AVCodecContext *c;&#xA;  int i;&#xA;&#xA;  /* find the encoder */&#xA;  *codec = avcodec_find_encoder(codec_id);&#xA;  if (!(*codec)) {&#xA;    fprintf(stderr, "Could not find encoder for &#x27;%s&#x27;\n",&#xA;            avcodec_get_name(codec_id));&#xA;    exit(1);&#xA;  }&#xA;&#xA;  ost->tmp_pkt = av_packet_alloc();&#xA;  if (!ost->tmp_pkt) {&#xA;    fprintf(stderr, "Could not allocate AVPacket\n");&#xA;    exit(1);&#xA;  }&#xA;&#xA;  ost->st = avformat_new_stream(oc, NULL);&#xA;  if (!ost->st) {&#xA;    fprintf(stderr, "Could not allocate stream\n");&#xA;    exit(1);&#xA;  }&#xA;  ost->st->id = oc->nb_streams-1;&#xA;  c = avcodec_alloc_context3(*codec);&#xA;  if (!c) {&#xA;    fprintf(stderr, "Could not alloc an encoding context\n");&#xA;    exit(1);&#xA;  }&#xA;  ost->enc = c;&#xA;&#xA;  switch ((*codec)->type) {&#xA;    case AVMEDIA_TYPE_VIDEO:&#xA;      c->codec_id = codec_id;&#xA;&#xA;      c->bit_rate = 400000;&#xA;      /* Resolution must be a multiple of two. */&#xA;      c->width    = 352;&#xA;      c->height   = 288;&#xA;      /* timebase: This is the fundamental unit of time (in seconds) in terms&#xA;       * of which frame timestamps are represented. For fixed-fps content,&#xA;       * timebase should be 1/framerate and timestamp increments should be&#xA;       * identical to 1. */&#xA;      ost->st->time_base = (AVRational){ 1, STREAM_FRAME_RATE };&#xA;      c->time_base       = ost->st->time_base;&#xA;&#xA;      c->gop_size      = 12; /* emit one intra frame every twelve frames at most */&#xA;      c->pix_fmt       = STREAM_PIX_FMT;&#xA;      if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {&#xA;        /* just for testing, we also add B-frames */&#xA;        c->max_b_frames = 2;&#xA;      }&#xA;      if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {&#xA;        /* Needed to avoid using macroblocks in which some coeffs overflow.&#xA;         * This does not happen with normal video, it just happens here as&#xA;         * the motion of the chroma plane does not match the luma plane. */&#xA;        c->mb_decision = 2;&#xA;      }&#xA;      break;&#xA;&#xA;    default:&#xA;      break;&#xA;  }&#xA;&#xA;  /* Some formats want stream headers to be separate. */&#xA;  if (oc->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;    c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;}&#xA;&#xA;/**************************************************************/&#xA;/* video output */&#xA;&#xA;static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, int width, int height)&#xA;{&#xA;  AVFrame *picture;&#xA;  int ret;&#xA;&#xA;  picture = av_frame_alloc();&#xA;  if (!picture)&#xA;    return NULL;&#xA;&#xA;  picture->format = pix_fmt;&#xA;  picture->width  = width;&#xA;  picture->height = height;&#xA;&#xA;  /* allocate the buffers for the frame data */&#xA;  ret = av_frame_get_buffer(picture, 0);&#xA;  if (ret &lt; 0) {&#xA;    fprintf(stderr, "Could not allocate frame data.\n");&#xA;    exit(1);&#xA;  }&#xA;&#xA;  return picture;&#xA;}&#xA;&#xA;static void open_video(AVFormatContext *oc, const AVCodec *codec,&#xA;                       OutputStream *ost, AVDictionary *opt_arg)&#xA;{&#xA;  int ret;&#xA;  AVCodecContext *c = ost->enc;&#xA;  AVDictionary *opt = NULL;&#xA;&#xA;  av_dict_copy(&amp;opt, opt_arg, 0);&#xA;&#xA;  /* open the codec */&#xA;  ret = avcodec_open2(c, codec, &amp;opt);&#xA;  av_dict_free(&amp;opt);&#xA;  if (ret &lt; 0) {&#xA;    fprintf(stderr, "Could not open video codec\n");&#xA;    exit(1);&#xA;  }&#xA;&#xA;  /* allocate and init a re-usable frame */&#xA;  ost->frame = alloc_picture(c->pix_fmt, c->width, c->height);&#xA;  if (!ost->frame) {&#xA;    fprintf(stderr, "Could not allocate video frame\n");&#xA;    exit(1);&#xA;  }&#xA;&#xA;  /* If the output format is not YUV420P, then a temporary YUV420P&#xA;   * picture is needed too. It is then converted to the required&#xA;   * output format. */&#xA;  ost->tmp_frame = NULL;&#xA;  if (c->pix_fmt != AV_PIX_FMT_YUV420P) {&#xA;    ost->tmp_frame = alloc_picture(AV_PIX_FMT_YUV420P, c->width, c->height);&#xA;    if (!ost->tmp_frame) {&#xA;      fprintf(stderr, "Could not allocate temporary picture\n");&#xA;      exit(1);&#xA;    }&#xA;  }&#xA;&#xA;  /* copy the stream parameters to the muxer */&#xA;  ret = avcodec_parameters_from_context(ost->st->codecpar, c);&#xA;  if (ret &lt; 0) {&#xA;    fprintf(stderr, "Could not copy the stream parameters\n");&#xA;    exit(1);&#xA;  }&#xA;}&#xA;&#xA;/* Prepare a dummy image. */&#xA;static void fill_yuv_image(AVFrame *pict, int frame_index,&#xA;                           int width, int height)&#xA;{&#xA;  int x, y, i;&#xA;&#xA;  i = frame_index;&#xA;&#xA;  /* Y */&#xA;  for (y = 0; y &lt; height; y&#x2B;&#x2B;)&#xA;    for (x = 0; x &lt; width; x&#x2B;&#x2B;)&#xA;      pict->data[0][y * pict->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;&#xA;  /* Cb and Cr */&#xA;  for (y = 0; y &lt; height / 2; y&#x2B;&#x2B;) {&#xA;    for (x = 0; x &lt; width / 2; x&#x2B;&#x2B;) {&#xA;      pict->data[1][y * pict->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;      pict->data[2][y * pict->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;    }&#xA;  }&#xA;}&#xA;&#xA;static AVFrame *get_video_frame(OutputStream *ost)&#xA;{&#xA;  AVCodecContext *c = ost->enc;&#xA;&#xA;  /* check if we want to generate more frames */&#xA;  if (av_compare_ts(ost->next_pts, c->time_base,&#xA;                    STREAM_DURATION, (AVRational){ 1, 1 }) > 0)&#xA;    return NULL;&#xA;&#xA;  /* when we pass a frame to the encoder, it may keep a reference to it&#xA;   * internally; make sure we do not overwrite it here */&#xA;  if (av_frame_make_writable(ost->frame) &lt; 0)&#xA;    exit(1);&#xA;&#xA;  if (c->pix_fmt != AV_PIX_FMT_YUV420P) {&#xA;    /* as we only generate a YUV420P picture, we must convert it&#xA;     * to the codec pixel format if needed */&#xA;    if (!ost->sws_ctx) {&#xA;      ost->sws_ctx = sws_getContext(c->width, c->height,&#xA;                                    AV_PIX_FMT_YUV420P,&#xA;                                    c->width, c->height,&#xA;                                    c->pix_fmt,&#xA;                                    SCALE_FLAGS, NULL, NULL, NULL);&#xA;      if (!ost->sws_ctx) {&#xA;        fprintf(stderr,&#xA;                "Could not initialize the conversion context\n");&#xA;        exit(1);&#xA;      }&#xA;    }&#xA;    fill_yuv_image(ost->tmp_frame, ost->next_pts, c->width, c->height);&#xA;    sws_scale(ost->sws_ctx, (const uint8_t * const *) ost->tmp_frame->data,&#xA;              ost->tmp_frame->linesize, 0, c->height, ost->frame->data,&#xA;              ost->frame->linesize);&#xA;  } else {&#xA;    fill_yuv_image(ost->frame, ost->next_pts, c->width, c->height);&#xA;  }&#xA;&#xA;  ost->frame->pts = ost->next_pts&#x2B;&#x2B;;&#xA;&#xA;  return ost->frame;&#xA;}&#xA;&#xA;/*&#xA; * encode one video frame and send it to the muxer&#xA; * return 1 when encoding is finished, 0 otherwise&#xA; */&#xA;static int write_video_frame(AVFormatContext *oc, OutputStream *ost)&#xA;{&#xA;  return write_frame(oc, ost->enc, ost->st, get_video_frame(ost), ost->tmp_pkt);&#xA;}&#xA;&#xA;static void close_stream(AVFormatContext *oc, OutputStream *ost)&#xA;{&#xA;  avcodec_free_context(&amp;ost->enc);&#xA;  av_frame_free(&amp;ost->frame);&#xA;  av_frame_free(&amp;ost->tmp_frame);&#xA;  av_packet_free(&amp;ost->tmp_pkt);&#xA;  sws_freeContext(ost->sws_ctx);&#xA;  swr_free(&amp;ost->swr_ctx);&#xA;}&#xA;&#xA;/**************************************************************/&#xA;/* media file output */&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;  OutputStream video_st = { 0 }, audio_st = { 0 };&#xA;  const AVOutputFormat *fmt;&#xA;  const char *filename;&#xA;  AVFormatContext *oc;&#xA;  const AVCodec *audio_codec, *video_codec;&#xA;  int ret;&#xA;  int have_video = 0, have_audio = 0;&#xA;  int encode_video = 0, encode_audio = 0;&#xA;  AVDictionary *opt = NULL;&#xA;  int i;&#xA;&#xA;  if (argc &lt; 2) {&#xA;    printf("usage: %s output_file\n"&#xA;           "API example program to output a media file with libavformat.\n"&#xA;           "This program generates a synthetic audio and video stream, encodes and\n"&#xA;           "muxes them into a file named output_file.\n"&#xA;           "The output format is automatically guessed according to the file extension.\n"&#xA;           "Raw images can also be output by using &#x27;%%d&#x27; in the filename.\n"&#xA;           "\n", argv[0]);&#xA;    return 1;&#xA;  }&#xA;&#xA;  filename = argv[1];&#xA;&#xA;  av_dict_set(&amp;opt, "movflags", "frag_keyframe&#x2B;separate_moof&#x2B;omit_tfhd_offset&#x2B;empty_moov", 0);&#xA;&#xA;  /* allocate the output media context */&#xA;  avformat_alloc_output_context2(&amp;oc, NULL, NULL, filename);&#xA;  if (!oc) {&#xA;    printf("Could not deduce output format from file extension: using MPEG.\n");&#xA;    avformat_alloc_output_context2(&amp;oc, NULL, "mpeg", filename);&#xA;  }&#xA;  if (!oc)&#xA;    return 1;&#xA;&#xA;  fmt = oc->oformat;&#xA;&#xA;  /* Add the audio and video streams using the default format codecs&#xA;   * and initialize the codecs. */&#xA;  if (fmt->video_codec != AV_CODEC_ID_NONE) {&#xA;    add_stream(&amp;video_st, oc, &amp;video_codec, fmt->video_codec);&#xA;    have_video = 1;&#xA;    encode_video = 1;&#xA;  }&#xA;&#xA;  /* Now that all the parameters are set, we can open the audio and&#xA;   * video codecs and allocate the necessary encode buffers. */&#xA;  if (have_video)&#xA;    open_video(oc, video_codec, &amp;video_st, opt);&#xA;&#xA;&#xA;  av_dump_format(oc, 0, filename, 1);&#xA;&#xA;  /* open the output file, if needed */&#xA;  if (!(fmt->flags &amp; AVFMT_NOFILE)) {&#xA;    ret = avio_open(&amp;oc->pb, filename, AVIO_FLAG_WRITE);&#xA;    if (ret &lt; 0) {&#xA;      fprintf(stderr, "Could not open &#x27;%s&#x27;\n", filename);&#xA;      return 1;&#xA;    }&#xA;  }&#xA;&#xA;  /* Write the stream header, if any. */&#xA;  ret = avformat_write_header(oc, &amp;opt);&#xA;  if (ret &lt; 0) {&#xA;    fprintf(stderr, "Error occurred when opening output file\n");&#xA;    return 1;&#xA;  }&#xA;&#xA;  while (encode_video || encode_audio) {&#xA;    /* select the stream to encode */&#xA;    if (encode_video &amp;&amp;&#xA;        (!encode_audio || av_compare_ts(video_st.next_pts, video_st.enc->time_base,&#xA;                                        audio_st.next_pts, audio_st.enc->time_base) &lt;= 0)) {&#xA;      encode_video = !write_video_frame(oc, &amp;video_st);&#xA;    }&#xA;  }&#xA;&#xA;  av_write_trailer(oc);&#xA;&#xA;  /* Close each codec. */&#xA;  if (have_video)&#xA;    close_stream(oc, &amp;video_st);&#xA;  if (have_audio)&#xA;    close_stream(oc, &amp;audio_st);&#xA;&#xA;  if (!(fmt->flags &amp; AVFMT_NOFILE))&#xA;    /* Close the output file. */&#xA;    avio_closep(&amp;oc->pb);&#xA;&#xA;  /* free the stream */&#xA;  avformat_free_context(oc);&#xA;&#xA;  return 0;&#xA;}&#xA;</cmath></cstring></cstdio></cstdlib>

    &#xA;