Recherche avancée

Médias (1)

Mot : - Tags -/epub

Autres articles (9)

  • Déploiements possibles

    31 janvier 2010, par

    Deux types de déploiements sont envisageable dépendant de deux aspects : La méthode d’installation envisagée (en standalone ou en ferme) ; Le nombre d’encodages journaliers et la fréquentation envisagés ;
    L’encodage de vidéos est un processus lourd consommant énormément de ressources système (CPU et RAM), il est nécessaire de prendre tout cela en considération. Ce système n’est donc possible que sur un ou plusieurs serveurs dédiés.
    Version mono serveur
    La version mono serveur consiste à n’utiliser qu’une (...)

  • Gestion des droits de création et d’édition des objets

    8 février 2011, par

    Par défaut, beaucoup de fonctionnalités sont limitées aux administrateurs mais restent configurables indépendamment pour modifier leur statut minimal d’utilisation notamment : la rédaction de contenus sur le site modifiables dans la gestion des templates de formulaires ; l’ajout de notes aux articles ; l’ajout de légendes et d’annotations sur les images ;

  • Qu’est ce qu’un éditorial

    21 juin 2013, par

    Ecrivez votre de point de vue dans un article. Celui-ci sera rangé dans une rubrique prévue à cet effet.
    Un éditorial est un article de type texte uniquement. Il a pour objectif de ranger les points de vue dans une rubrique dédiée. Un seul éditorial est placé à la une en page d’accueil. Pour consulter les précédents, consultez la rubrique dédiée.
    Vous pouvez personnaliser le formulaire de création d’un éditorial.
    Formulaire de création d’un éditorial Dans le cas d’un document de type éditorial, les (...)

Sur d’autres sites (3016)

  • Live video in facebook is lagging while using ffmpeg from video link

    1er septembre 2022, par Isteyak Ali

    Livevideo in facebook is working fine for local device video(case 1) but its having lagging issue from video link(case 2) using FFMPEG.

    


    Please find command for the same and log.

    


    Case 1 - Command : ffmpeg -re -i videoplayback.mp4 -c:v libx264 -c:a aac -f flv "rtmps ://live-api-s.facebook.com:443/rtmp/5162241770554550 ?s_bl=1&s_oil=2&s_psm=1&s_sw=0&s_tids=1&s_vt=api-s&a=Aby_ZWutqdUZR26F"

    


    Log -
2022-09-01 18:27:19.683 frame= 9 fps=0.0 q=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A dup=21 drop=0 speed= 0x
    
2022-09-01 18:27:20.163 frame= 19 fps= 19 q=0.0 q=33.0 size= 0kB time=00:00:00.44 bitrate= 8.7kbits/s dup=44 drop=0 speed=0.437x
    
2022-09-01 18:27:20.879 frame= 32 fps= 21 q=0.0 q=33.0 size= 0kB time=00:00:00.92 bitrate= 4.1kbits/s dup=74 drop=0 speed=0.616x
    
2022-09-01 18:27:21.374 frame= 47 fps= 22 q=0.0 q=33.0 size= 0kB time=00:00:01.41 bitrate= 2.7kbits/s dup=109 drop=0 speed=0.651x
    
2022-09-01 18:27:21.940 frame= 58 fps= 21 q=29.0 q=33.0 size= 40kB time=00:00:01.90 bitrate= 174.2kbits/s dup=135 drop=0 speed=0.703x
    
2022-09-01 18:27:22.530 frame= 69 fps= 21 q=29.0 q=33.0 size= 101kB time=00:00:01.92 bitrate= 429.9kbits/s dup=161 drop=0 speed=0.585x
    
2022-09-01 18:27:23.003 frame= 83 fps= 22 q=29.0 q=33.0 size= 165kB time=00:00:02.39 bitrate= 566.5kbits/s dup=193 drop=0 speed=0.623x
    
2022-09-01 18:27:23.567 frame= 97 fps= 22 q=29.0 q=33.0 size= 235kB time=00:00:02.90 bitrate= 661.9kbits/s dup=226 drop=0 speed=0.667x
    
2022-09-01 18:27:24.133 frame= 111 fps= 23 q=29.0 q=33.0 size= 315kB time=00:00:03.36 bitrate= 765.8kbits/s dup=259 drop=0 speed=0.693x
    
2022-09-01 18:27:24.715 frame= 125 fps= 23 q=29.0 q=30.0 size= 385kB time=00:00:03.85 bitrate= 817.5kbits/s dup=291 drop=0 speed=0.703x
    
2022-09-01 18:27:25.227 frame= 142 fps= 24 q=29.0 q=33.0 size= 486kB time=00:00:04.83 bitrate= 824.6kbits/s dup=331 drop=0 speed=0.802x
    
2022-09-01 18:27:25.712 frame= 158 fps= 24 q=29.0 q=33.0 size= 563kB time=00:00:05.31 bitrate= 867.6kbits/s dup=368 drop=0 speed=0.811x
    
2022-09-01 18:27:26.262 frame= 173 fps= 24 q=29.0 q=33.0 size= 634kB time=00:00:05.78 bitrate= 897.8kbits/s dup=403 drop=0 speed=0.819x
    
2022-09-01 18:27:26.796 frame= 191 fps= 25 q=29.0 q=33.0 size= 718kB time=00:00:06.24 bitrate= 941.7kbits/s dup=445 drop=0 speed=0.82x
    
2022-09-01 18:27:27.337 frame= 211 fps= 26 q=29.0 q=33.0 size= 806kB time=00:00:07.17 bitrate= 920.7kbits/s dup=492 drop=0 speed=0.882x
    
2022-09-01 18:27:27.816 frame= 233 fps= 27 q=29.0 q=33.0 size= 921kB time=00:00:07.64 bitrate= 987.4kbits/s dup=543 drop=0 speed=0.881x
    
2022-09-01 18:27:28.348 frame= 251 fps= 27 q=29.0 q=30.0 size= 1031kB time=00:00:08.42 bitrate=1001.9kbits/s dup=585 drop=0 speed=0.919x
    
2022-09-01 18:27:28.868 frame= 274 fps= 28 q=29.0 q=33.0 size= 1141kB time=00:00:09.03 bitrate=1035.2kbits/s dup=639 drop=0 speed=0.933x
    
2022-09-01 18:27:29.393 frame= 293 fps= 29 q=29.0 q=33.0 size= 1283kB time=00:00:09.49 bitrate=1106.5kbits/s dup=683 drop=0 speed=0.932x
    
2022-09-01 18:27:29.870 frame= 313 fps= 29 q=29.0 q=33.0 size= 1433kB time=00:00:10.42 bitrate=1125.6kbits/s dup=730 drop=0 speed=0.975x
    
2022-09-01 18:27:30.356 frame= 331 fps= 30 q=29.0 q=33.0 size= 1557kB time=00:00:10.89 bitrate=1170.9kbits/s dup=772 drop=0 speed=0.973x
    
2022-09-01 18:27:30.843 frame= 346 fps= 30 q=29.0 q=33.0 size= 1627kB time=00:00:11.35 bitrate=1174.1kbits/s dup=807 drop=0 speed=0.971x
    
2022-09-01 18:27:31.357 frame= 361 fps= 30 q=29.0 q=33.0 size= 1711kB time=00:00:11.81 bitrate=1186.2kbits/s dup=842 drop=0 speed=0.969x
    
2022-09-01 18:27:31.862 frame= 376 fps= 30 q=29.0 q=33.0 size= 1789kB time=00:00:12.28 bitrate=1193.3kbits/s dup=877 drop=0 speed=0.967x
    
2022-09-01 18:27:32.371 frame= 391 fps= 30 q=29.0 q=33.0 size= 1870kB time=00:00:12.74 bitrate=1201.8kbits/s dup=912 drop=0 speed=0.965x
    
2022-09-01 18:27:32.908 frame= 406 fps= 30 q=29.0 q=33.0 size= 1959kB time=00:00:13.67 bitrate=1173.3kbits/s dup=947 drop=0 speed=0.997x
    
2022-09-01 18:27:33.109 frame= 422 fps= 30 q=29.0 q=33.0 size= 2061kB time=00:00:14.14 bitrate=1193.8kbits/s dup=984 drop=0 speed=0.992x

    


    Case 2 - Command : ffmpeg -re -i "https://rr1---sn-o58g5ob-nu8e.googlevideo.com/videoplayback?expire=1662057728&ei=n6gQY-D9OLSA4-EPzJKYyA0&ip=103.11.117.194&id=o-AOgjPoKU_GiUy425eSSF6tHEIQvoHpsUyyIHnHERk6YS&itag=22&source=youtube&requiressl=yes&mh=6k&mm=31%2C29&mn=sn-o58g5ob-nu8e%2Csn-cvhelnls&ms=au%2Crdu&mv=m&mvi=1&pcm2cms=yes&pl=24&initcwndbps=867500&vprv=1&mime=video%2Fmp4&ns=z8jzAKb15xkjMcyG0dBthZQH&ratebypass=yes&dur=256.116&lmt=1649507860591021&mt=1662035606&fvip=3&fexp=24001373%2C24007246&c=WEB&rbqsm=fr&txp=4532434&n=PSC3ywazY86ChDwPP2&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAI-aPoysSukxGNgmlsn-4bgCG84gQnILTkGJR8WQnK_bAiEArwSM0z-GYO4SinkzgdGG5qZJtoiP3ROYneg88sOjhv4%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIhAJb7JQbSPhhH2jte8pE0G0iWf1LtRlEzQgSy-2pBGPg3AiBWX0P27KU2xwazMGLiBaQanUOeytB0jPgFsJleM8DO-w%3D%3D" -c:v libx264 -c:a aac -f flv "rtmps ://live-api-s.facebook.com:443/rtmp/5162241770554550 ?s_bl=1&s_oil=2&s_psm=1&s_sw=0&s_tids=1&s_vt=api-s&a=Aby_ZWutqdUZR26F"

    


    Log -

    


    2022-09-01 18:24:23.080 frame= 9 fps=0.0 q=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A dup=21 drop=0 speed= 0x
    
2022-09-01 18:24:23.579 frame= 23 fps= 22 q=0.0 q=33.0 size= 0kB time=00:00:00.44 bitrate= 8.7kbits/s dup=53 drop=0 speed=0.427x
    
2022-09-01 18:24:24.177 frame= 33 fps= 21 q=0.0 q=33.0 size= 0kB time=00:00:00.92 bitrate= 4.1kbits/s dup=77 drop=0 speed=0.589x
    
2022-09-01 18:24:24.872 frame= 39 fps= 18 q=0.0 q=33.0 size= 0kB time=00:00:00.99 bitrate= 3.9kbits/s dup=91 drop=0 speed=0.458x
    
2022-09-01 18:24:25.513 frame= 46 fps= 16 q=0.0 q=33.0 size= 0kB time=00:00:01.41 bitrate= 2.7kbits/s dup=107 drop=0 speed=0.497x
    
2022-09-01 18:24:26.070 frame= 52 fps= 15 q=0.0 q=33.0 size= 0kB time=00:00:01.41 bitrate= 2.7kbits/s dup=121 drop=0 speed=0.41x
    
2022-09-01 18:24:26.602 frame= 58 fps= 14 q=29.0 q=33.0 size= 40kB time=00:00:01.90 bitrate= 174.2kbits/s dup=135 drop=0 speed=0.468x
    
2022-09-01 18:24:27.341 frame= 63 fps= 14 q=29.0 q=33.0 size= 72kB time=00:00:01.90 bitrate= 311.6kbits/s dup=147 drop=0 speed=0.417x
    
2022-09-01 18:24:27.957 frame= 71 fps= 13 q=29.0 q=33.0 size= 115kB time=00:00:02.39 bitrate= 392.6kbits/s dup=165 drop=0 speed=0.448x
    
2022-09-01 18:24:28.621 frame= 78 fps= 13 q=29.0 q=33.0 size= 141kB time=00:00:02.39 bitrate= 483.2kbits/s dup=182 drop=0 speed=0.409x
    
2022-09-01 18:24:29.277 frame= 82 fps= 12 q=29.0 q=33.0 size= 154kB time=00:00:02.39 bitrate= 527.3kbits/s dup=191 drop=0 speed=0.363x
    
2022-09-01 18:24:29.851 frame= 89 fps= 12 q=29.0 q=33.0 size= 197kB time=00:00:02.87 bitrate= 560.9kbits/s dup=207 drop=0 speed=0.397x
    
2022-09-01 18:24:30.385 frame= 96 fps= 12 q=29.0 q=33.0 size= 233kB time=00:00:02.87 bitrate= 662.2kbits/s dup=224 drop=0 speed=0.371x
    
2022-09-01 18:24:31.119 frame= 100 fps= 12 q=29.0 q=33.0 size= 253kB time=00:00:03.36 bitrate= 615.5kbits/s dup=233 drop=0 speed=0.402x
    
2022-09-01 18:24:31.449 frame= 110 fps= 12 q=29.0 q=33.0 size= 309kB time=00:00:03.36 bitrate= 750.7kbits/s dup=256 drop=0 speed=0.378x
    
2022-09-01 18:24:32.062 frame= 111 fps= 12 q=29.0 q=33.0 size= 315kB time=00:00:03.83 bitrate= 672.9kbits/s dup=259 drop=0 speed=0.405x
    
2022-09-01 18:24:32.696 frame= 122 fps= 12 q=29.0 q=33.0 size= 371kB time=00:00:03.85 bitrate= 787.6kbits/s dup=284 drop=0 speed=0.383x
    
2022-09-01 18:24:33.374 frame= 130 fps= 12 q=29.0 q=33.0 size= 410kB time=00:00:04.34 bitrate= 773.0kbits/s dup=303 drop=0 speed=0.407x
    
2022-09-01 18:24:33.987 frame= 139 fps= 12 q=29.0 q=33.0 size= 475kB time=00:00:04.34 bitrate= 895.9kbits/s dup=324 drop=0 speed=0.383x
    
2022-09-01 18:24:34.445 frame= 146 fps= 12 q=29.0 q=33.0 size= 508kB time=00:00:04.83 bitrate= 861.9kbits/s dup=340 drop=0 speed=0.404x
    
2022-09-01 18:24:35.218 frame= 153 fps= 12 q=29.0 q=33.0 size= 540kB time=00:00:05.03 bitrate= 878.1kbits/s dup=357 drop=0 speed=0.405x
    
2022-09-01 18:24:35.558 frame= 163 fps= 12 q=29.0 q=33.0 size= 580kB time=00:00:05.31 bitrate= 893.8kbits/s dup=380 drop=0 speed=0.408x
    
2022-09-01 18:24:36.220 frame= 167 fps= 12 q=29.0 q=33.0 size= 609kB time=00:00:05.31 bitrate= 938.0kbits/s dup=389 drop=0 speed=0.392x
    
2022-09-01 18:24:36.821 frame= 172 fps= 12 q=29.0 q=33.0 size= 630kB time=00:00:05.78 bitrate= 892.5kbits/s dup=401 drop=0 speed=0.408x
    
2022-09-01 18:24:37.428 frame= 179 fps= 12 q=29.0 q=33.0 size= 666kB time=00:00:05.78 bitrate= 943.1kbits/s dup=417 drop=0 speed=0.394x
    
2022-09-01 18:24:37.812 frame= 185 fps= 12 q=29.0 q=30.0 size= 689kB time=00:00:06.24 bitrate= 903.2kbits/s dup=431 drop=0 speed=0.41x
    
2022-09-01 18:24:38.368 frame= 190 fps= 12 q=29.0 q=33.0 size= 711kB time=00:00:06.24 bitrate= 932.5kbits/s dup=443 drop=0 speed=0.396x
    
2022-09-01 18:24:38.979 frame= 195 fps= 12 q=29.0 q=33.0 size= 737kB time=00:00:06.52 bitrate= 925.4kbits/s dup=455 drop=0 speed=0.399x
    
2022-09-01 18:24:39.706 frame= 204 fps= 12 q=29.0 q=33.0 size= 778kB time=00:00:06.71 bitrate= 949.8kbits/s dup=476 drop=0 speed=0.398x
    
2022-09-01 18:24:40.252 frame= 212 fps= 12 q=29.0 q=33.0 size= 808kB time=00:00:07.17 bitrate= 922.8kbits/s dup=494 drop=0 speed=0.407x
    
2022-09-01 18:24:40.977 frame= 220 fps= 12 q=29.0 q=33.0 size= 841kB time=00:00:07.17 bitrate= 960.6kbits/s dup=513 drop=0 speed=0.395x
    
2022-09-01 18:24:41.926 frame= 226 fps= 12 q=29.0 q=33.0 size= 886kB time=00:00:07.64 bitrate= 949.8kbits/s dup=527 drop=0 speed=0.404x
    
2022-09-01 18:24:42.470 frame= 233 fps= 12 q=29.0 q=33.0 size= 921kB time=00:00:07.64 bitrate= 987.4kbits/s dup=543 drop=0 speed=0.385x
    
2022-09-01 18:24:43.081 frame= 237 fps= 12 q=29.0 q=33.0 size= 942kB time=00:00:07.66 bitrate=1007.5kbits/s dup=553 drop=0 speed=0.374x
    
2022-09-01 18:24:43.745 frame= 241 fps= 11 q=29.0 q=33.0 size= 971kB time=00:00:08.10 bitrate= 981.5kbits/s dup=562 drop=0 speed=0.384x
    
2022-09-01 18:24:44.270 frame= 248 fps= 11 q=29.0 q=33.0 size= 1011kB time=00:00:08.10 bitrate=1021.5kbits/s dup=578 drop=0 speed=0.373x
    
2022-09-01 18:24:45.085 frame= 251 fps= 11 q=29.0 q=30.0 size= 1031kB time=00:00:08.10 bitrate=1042.1kbits/s dup=585 drop=0 speed=0.364x

    


    As per my knowledge we have to add such type of delay or late stream video using some command.

    


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

    


    ffmpeg -i input.mp4 -movflags +frag_keyframe+separate_moof+omit_tfhd_offset+empty_moov output.mp4


    


    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.

    


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

    


    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.

    


     avformat_alloc_output_context2(&oc, NULL, NULL, filename);

 if (oc_->oformat->flags & AVFMT_GLOBALHEADER) {
    codecCtx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 }
...
 AVDictionary* opts = NULL;

 av_dict_set(&opts, "movflags", "frag_keyframe+separate_moof+omit_tfhd_offset+empty_moov", 0);

 ret = avformat_write_header(oc_, &opts);


    


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

    


    Edit : example videos and complete code example

    


    I also tried with the following ffmpeg build

    


    ffmpeg version 5.0.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
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
libavutil      57. 17.100 / 57. 17.100
libavcodec     59. 18.100 / 59. 18.100
libavformat    59. 16.100 / 59. 16.100
libavdevice    59.  4.100 / 59.  4.100
libavfilter     8. 24.100 /  8. 24.100
libswscale      6.  4.100 /  6.  4.100
libswresample   4.  3.100 /  4.  3.100
libpostproc    56.  3.100 / 56.  3.100


    


    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.

    


    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.

    


    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; * 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;

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