Recherche avancée

Médias (0)

Mot : - Tags -/objet éditorial

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

Autres articles (86)

  • Organiser par catégorie

    17 mai 2013, par

    Dans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
    Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
    Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...)

  • Récupération d’informations sur le site maître à l’installation d’une instance

    26 novembre 2010, par

    Utilité
    Sur le site principal, une instance de mutualisation est définie par plusieurs choses : Les données dans la table spip_mutus ; Son logo ; Son auteur principal (id_admin dans la table spip_mutus correspondant à un id_auteur de la table spip_auteurs)qui sera le seul à pouvoir créer définitivement l’instance de mutualisation ;
    Il peut donc être tout à fait judicieux de vouloir récupérer certaines de ces informations afin de compléter l’installation d’une instance pour, par exemple : récupérer le (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

Sur d’autres sites (6035)

  • Compress video FFMPEG doesn't work

    13 février 2018, par Douglas Anunciação

    I’m trying to compress video using FFMPEG and this library : https://github.com/guardianproject/android-ffmpeg-java

    I imported ffmpeglib as a module in my project. This is the code is use to compress :

    public class MainActivity extends Activity {

       private ArrayList&lt;Object&gt; listVideoPaths = new ArrayList&lt;&gt;();<br />
    <br />
       @Override<br />
       protected void onCreate(Bundle savedInstanceState) {<br />
           super.onCreate(savedInstanceState);<br />
           setContentView(R.layout.activity_main);<br />
    <br />
           getGalleryVideos();<br />
    <br />
           File videoFolderFile = new File(&quot;/storage/emulated/0/DCIM/Camera/&quot;);<br />
    <br />
           if(videoFolderFile.exists())<br />
               Log.e(&quot;TEST FFMPEG&quot;, &quot;video folder exist&quot;);<br />
           else<br />
               Log.e(&quot;TEST FFMPEG&quot;, &quot;video folder DON'T exist&quot;);<br />
    <br />
    <br />
           File videoInputFile = new File(listVideoPaths.get(0).toString());<br />
    <br />
           if(videoInputFile.exists())<br />
               Log.e(&quot;TEST FFMPEG&quot;, &quot;video input file exist&quot;);<br />
           else<br />
               Log.e(&quot;TEST FFMPEG&quot;, &quot;video input file DON'T exist&quot;);<br />
    <br />
           File videoOutputFile = new File(videoFolderFile,&quot;output.mp4&quot;);<br />
    <br />
           if(videoOutputFile.exists())<br />
               Log.e(&quot;TEST FFMPEG&quot;, &quot;video output file exist&quot;);<br />
           else<br />
               Log.e(&quot;TEST FFMPEG&quot;, &quot;video output file DON'T exist&quot;);<br />
    <br />
           FfmpegController ffmpegController;<br />
    <br />
           try {<br />
               ffmpegController = new FfmpegController(this,videoFolderFile);<br />
    <br />
               Clip mediaIn = new Clip();<br />
    <br />
               mediaIn.path = videoInputFile.getAbsolutePath();<br />
    <br />
               mediaIn.videoFps =  &quot;25&quot;;<br />
    <br />
               ffmpegController.convertToMPEG(mediaIn, videoOutputFile.getAbsolutePath(), new ShellUtils.ShellCallback() {<br />
    <br />
                   @Override<br />
                   public void shellOut(String shellLine) {<br />
                       Log.e(&quot;TEST FFMPEG&quot;, &quot;shellOut - &quot; + shellLine);<br />
                   }<br />
    <br />
                   @Override<br />
                   public void processComplete(int exitValue) {<br />
                       Log.e(&quot;TEST FFMPEG&quot;, &quot;proccess complete - &quot; + exitValue);<br />
                   }<br />
               });<br />
    <br />
    <br />
           } catch (IOException e) {<br />
               e.printStackTrace();<br />
           } catch (Exception e) {<br />
               e.printStackTrace();<br />
           }finally {<br />
    <br />
               if(videoOutputFile.exists())<br />
                   Log.e(&quot;TEST FFMPEG&quot;, &quot;finished ffmpeg ---&gt; video output file exist&quot;);<br />
               else<br />
                   Log.e(&quot;TEST FFMPEG&quot;, &quot;finished ffmpeg ---&gt; video output file DON'T exist&quot;);<br />
    <br />
           }<br />
       }<br />
    <br />
       private void getGalleryVideos(){<br />
    <br />
           Cursor videoCursor = null;<br />
    <br />
           try {<br />
    <br />
               final String[] columns = { Media.DATA,<br />
                       Media._ID,<br />
                       Media.DATE_ADDED };<br />
    <br />
               final String orderBy = Media.DATE_ADDED;<br />
    <br />
               videoCursor = getContentResolver().query(<br />
                       MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns,<br />
                       null, null, orderBy);<br />
    <br />
               if (videoCursor != null &amp;amp;&amp;amp; videoCursor.getCount() &gt; 0) {<br />
    <br />
                   while (videoCursor.moveToNext()) {<br />
    <br />
                       int dataColumnIndex = videoCursor<br />
                               .getColumnIndex(Media.DATA);<br />
    <br />
                       listVideoPaths.add(videoCursor<br />
                               .getString(dataColumnIndex));<br />
    <br />
                   }<br />
    <br />
               }<br />
    <br />
               Collections.sort(listVideoPaths,new Comparator());<br />
    <br />
           } catch (Exception e) {<br />
    <br />
               e.printStackTrace();<br />
    <br />
           } finally {<br />
    <br />
               if (videoCursor != null) {<br />
    <br />
                   if (!videoCursor.isClosed()) {<br />
    <br />
                       videoCursor.close();<br />
    <br />
                   }<br />
    <br />
               }<br />
    <br />
           }<br />
    <br />
       }<br />
    <br />
    }<br />
    &lt;/code&gt;&lt;/pre&gt;<br />
    <br />
    &lt;p&gt;I get no error but the video doesn't play. The log file is:&lt;/p&gt;<br />
    <br />
    &lt;blockquote&gt;<br />
     &lt;p&gt;3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     video folder exist 07-30 14:31:57.389&lt;br&gt;<br />
     3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     video input file exist 07-30 14:31:57.389&lt;br&gt;<br />
     3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     video output file DON'T exist 07-30 14:31:58.363&lt;br&gt;<br />
     3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -<br />
     /data/data/douglasanunciacao.androidffmpegjavateste/app_bin/ffmpeg -y<br />
     -i /storage/emulated/0/DCIM/Camera/VID_20150730_142330563.mp4 -f mpeg /storage/emulated/0/DCIM/Camera/output.mp4 07-30 14:31:58.385&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - WARNING: linker:<br />
     /data/data/douglasanunciacao.androidffmpegjavateste/app_bin/ffmpeg has<br />
     text relocations. This is wasting memory and prevents security<br />
     hardening. Please fix. 07-30 14:31:58.390&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg<br />
     developers 07-30 14:31:58.391&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   built on Dec 22 2014 12:52:34 with gcc 4.6 20120106<br />
     (prerelease) 07-30 14:31:58.391&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   configuration: --arch=arm --cpu=cortex-a8<br />
     --target-os=linux --enable-runtime-cpudetect --prefix=/data/data/info.guardianproject.ffmpeg/app_opt --enable-pic --disable-shared --enable-static --cross-prefix=/home/n8fr8/dev/android/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-<br />
     --sysroot=/home/n8fr8/dev/android/ndk/platforms/android-16/arch-arm --extra-cflags='-I../x264 -mfloat-abi=softfp -mfpu=neon -fPIE -pie' --extra-ldflags='-L../x264 -fPIE -pie' --enable-version3 --enable-gpl --disable-doc --enable-yasm --enable-decoders --enable-encoders --enable-muxers --enable-demuxers --enable-parsers --enable-protocols --enable-filters --enable-avresample --enable-libfreetype --disable-indevs --enable-indev=lavfi --disable-outdevs --enable-hwaccels --enable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-network --enable-libx264 --enable-zlib 07-30 14:31:58.391&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libavutil      51. 54.100 / 51. 54.100 07-30 14:31:58.391<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libavcodec     54. 23.100 / 54. 23.100 07-30 14:31:58.391<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libavformat    54.  6.100 / 54.  6.100 07-30 14:31:58.391<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libavdevice    54.  0.100 / 54.  0.100 07-30 14:31:58.391<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libavfilter     2. 77.100 /  2. 77.100 07-30 14:31:58.391<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libswscale      2.  1.100 /  2.  1.100 07-30 14:31:58.391<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libswresample   0. 15.100 /  0. 15.100 07-30 14:31:58.391<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   libpostproc    52.  0.100 / 52.  0.100 07-30 14:31:58.868<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - Input #0, mov,mp4,m4a,3gp,3g2,mj2, from<br />
     '/storage/emulated/0/DCIM/Camera/VID_20150730_142330563.mp4': 07-30<br />
     14:31:58.869    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -   Metadata: 07-30 14:31:58.869&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     major_brand     : mp42 07-30 14:31:58.870&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     minor_version   : 0 07-30 14:31:58.871&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     compatible_brands: isommp42 07-30 14:31:58.872&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     creation_time   : 2015-07-30 17:23:34 07-30<br />
     14:31:58.873    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -   Duration: 00:00:01.89, start: 0.000000,<br />
     bitrate: 17571 kb/s 07-30 14:31:58.874&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     Stream #0:0(eng): Video: h264 (High) (avc1 /<br />
     0x31637661), yuv420p, 1920x1080, 15874 kb/s, SAR 65536:65536 DAR 16:9,<br />
     23.90 fps, 23.92 tbr, 90k tbn, 180k tbc 07-30 14:31:58.875    3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     Metadata: 07-30 14:31:58.876&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -       rotate          : 270 07-30 14:31:58.877&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -       creation_time   : 2015-07-30 17:23:34 07-30<br />
     14:31:58.878    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -       handler_name    : VideoHandle 07-30<br />
     14:31:58.878    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -     Stream #0:1(eng): Audio: aac (mp4a /<br />
     0x6134706D), 48000 Hz, stereo, s16, 127 kb/s 07-30 14:31:58.878&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     Metadata: 07-30 14:31:58.878&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -       creation_time   : 2015-07-30 17:23:34 07-30<br />
     14:31:58.878    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -       handler_name    : SoundHandle 07-30<br />
     14:31:58.882    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut - [buffer @ 0xb5cce0a0] w:1920 h:1080<br />
     pixfmt:yuv420p tb:1/90000 sar:65536/65536 sws_param:flags=2 07-30<br />
     14:31:58.882    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut - [buffersink @ 0xb5cce0d0] No opaque field<br />
     provided 07-30 14:31:58.891&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - [mpeg @ 0xb5c3df00] VBV buffer size not set, muxing may<br />
     fail 07-30 14:31:58.892&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - Output #0, mpeg, to<br />
     '/storage/emulated/0/DCIM/Camera/output.mp4': 07-30 14:31:58.894&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   Metadata: 07-30 14:31:58.895&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     major_brand     : mp42 07-30 14:31:58.896&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     minor_version   : 0 07-30 14:31:58.896&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     compatible_brands: isommp42 07-30 14:31:58.897&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     creation_time   : 2015-07-30 17:23:34 07-30<br />
     14:31:58.898    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -     encoder         : Lavf54.6.100 07-30<br />
     14:31:58.898    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -     Stream #0:0(eng): Video: mpeg1video,<br />
     yuv420p, 1920x1080 [SAR 65536:65536 DAR 16:9], q=2-31, 200 kb/s, 90k<br />
     tbn, 23.98 tbc 07-30 14:31:58.899&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     Metadata: 07-30 14:31:58.899&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -       rotate          : 270 07-30 14:31:58.900&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -       creation_time   : 2015-07-30 17:23:34 07-30<br />
     14:31:58.901    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -       handler_name    : VideoHandle 07-30<br />
     14:31:58.906    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -     Stream #0:1(eng): Audio: mp2, 48000 Hz,<br />
     stereo, s16, 128 kb/s 07-30 14:31:58.906&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -     Metadata: 07-30 14:31:58.906&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -       creation_time   : 2015-07-30 17:23:34 07-30<br />
     14:31:58.906    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -       handler_name    : SoundHandle 07-30<br />
     14:31:58.906    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut - Stream mapping: 07-30 14:31:58.906&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut -   Stream #0:0 -&gt; #0:0 (h264 -&gt; mpeg1video) 07-30<br />
     14:31:58.906    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut -   Stream #0:1 -&gt; #0:1 (aac -&gt; mp2) 07-30<br />
     14:31:58.906    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut - Press [q] to stop, [?] for help 07-30<br />
     14:31:59.824    3096-3182/douglasanunciacao.androidffmpegjavateste<br />
     E/TESTE FFMPEG﹕ shellOut - frame=    4 fps=0.0 q=2.0 size=       0kB<br />
     time=00:00:00.08 bitrate=   0.0kbits/s 07-30 14:32:02.029&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=    8 fps=2.7 q=10.5 size=       4kB time=00:00:00.25<br />
     bitrate= 130.9kbits/s 07-30 14:32:02.536&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   13 fps=3.7 q=25.2 size=     696kB time=00:00:00.45<br />
     bitrate=12427.3kbits/s 07-30 14:32:03.045&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   18 fps=4.4 q=31.0 size=     750kB time=00:00:00.66<br />
     bitrate=9206.8kbits/s 07-30 14:32:03.582&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   23 fps=5.0 q=31.0 size=     786kB time=00:00:00.87<br />
     bitrate=7351.4kbits/s 07-30 14:32:04.140&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   28 fps=5.5 q=31.0 size=     862kB time=00:00:01.08<br />
     bitrate=6511.8kbits/s 07-30 14:32:05.239&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   30 fps=4.8 q=31.0 size=     876kB time=00:00:01.16<br />
     bitrate=6144.9kbits/s 07-30 14:32:05.746&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   35 fps=5.2 q=31.0 size=     910kB time=00:00:01.37<br />
     bitrate=5416.2kbits/s 07-30 14:32:06.317&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   41 fps=5.6 q=31.0 size=     972kB time=00:00:01.62<br />
     bitrate=4895.2kbits/s 07-30 14:32:06.832&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - frame=   45 fps=5.7 q=31.0 Lsize=    1022kB<br />
     time=00:00:01.83 bitrate=4562.1kbits/s 07-30 14:32:06.832&lt;br&gt;<br />
     3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     shellOut - video:984kB audio:30kB global headers:0kB muxing overhead<br />
     0.756932% 07-30 14:32:06.858    3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     proccess complete - 0 07-30 14:32:06.858&lt;br&gt;<br />
     3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕<br />
     terminou o ffmpeg ---&gt; video output file exist&lt;/p&gt;<br />
    &lt;/blockquote&gt;<br />
    <br />
    &lt;p&gt;Does anyone knows how to solve this problem? Thanks in advance.&lt;/p&gt;
  • Creating a video using ffmpeg in a PHP script

    30 décembre 2017, par Femzy

    I have been trying to solve this problem for a while now, but i have not got it through please someone should help me..
    My main objective is to collect user’n inputs and convert it to a video with black background, then the input text will be moving from left to right while the video is playing with audio in the background. Currently i was suggested to use "drawtext" but i have not find it working
    This is the code I use just to test the drawtext but the thing is, if i try it 10 times it will create a video file ones in many times i tried and even the video file would have 0 kb in size
    The Below code is my code

    The Below is the Report i got from the not working ffmpeg cmmand

    echo shell_exec('ffmpeg -f lavfi -i testsrc=duration=5:size=800x600:rate=30 -vf drawtext="fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf:textfile=text.txt: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" -preset ultrafast outex.mp4');

    ffmpeg started on 2017-12-29 at 16:43:24

    Report written to "ffmpeg-20171229-164324.log"
    Command line :
    ffmpeg -f test.mp4 -vf "drawtext=fontsize=64:fontcolor=white@0.8:box=1:boxcolor=black@0.75:boxborderw=16:fontfile=OCRA.ttf:text=my_video:x=(w-tw)/2:y=th" textover09.mpg -report
    ffmpeg version git-2017-12-28-be4dfbf Copyright (c) 2000-2017 the FFmpeg developers
    built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18)
    configuration : —prefix=/usr/local/ffmpeg —extra-cflags=-I/usr/local/ffmpeg/include —extra-ldflags=-L/usr/local/ffmpeg/lib —bindir=/usr/local/bin —enable-gpl —enable-nonfree —enable-libfdk_aac —enable-libmp3lame —enable-libopus —enable-libvpx —enable-libx264 —enable-libtheora —enable-filter=drawtext
    libavutil 56. 7.100 / 56. 7.100
    libavcodec 58. 9.100 / 58. 9.100
    libavformat 58. 3.100 / 58. 3.100
    libavdevice 58. 0.100 / 58. 0.100
    libavfilter 7. 8.100 / 7. 8.100
    libswscale 5. 0.101 / 5. 0.101
    libswresample 3. 0.101 / 3. 0.101
    libpostproc 55. 0.100 / 55. 0.100
    Splitting the commandline.
    Reading option ’-f’ ... matched as option ’f’ (force format) with argument ’test.mp4’.
    Reading option ’-vf’ ... matched as option ’vf’ (set video filters) with argument ’drawtext=fontsize=64:fontcolor=white@0.8:box=1:boxcolor=black@0.75:boxborderw=16:fontfile=OCRA.ttf:text=my_video:x=(w-tw)/2:y=th’.
    Reading option ’textover09.mpg’ ... matched as output url.
    Reading option ’-report’ ... matched as option ’report’ (generate a report) with argument ’1’.
    Finished splitting the commandline.
    Parsing a group of options : global .
    Applying option report (generate a report) with argument 1.
    Successfully parsed a group of options.
    Parsing a group of options : output url textover09.mpg.
    Applying option f (force format) with argument test.mp4.
    Applying option vf (set video filters) with argument drawtext=fontsize=64:fontcolor=white@0.8:box=1:boxcolor=black@0.75:boxborderw=16:fontfile=OCRA.ttf:text=my_video:x=(w-tw)/2:y=th.
    Successfully parsed a group of options.
    Opening an output file : textover09.mpg.
    [NULL @ 0x4671e80] Requested output format ’test.mp4’ is not a suitable output format
    textover09.mpg : Invalid argument

    This is Another report i got, in this report it is saying" Drawtext no such filters"

    ffmpeg started on 2017-12-29 at 09:00:43
    Report written to "ffmpeg-20171229-090043.log"
    Command line:
    ffmpeg -i test.mp4 -vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf:textfile=text.txt:reload=1:y=h-line_h-10:x=(W/tw)*n" textover7.mpg -report
    ffmpeg version git-2017-12-28-be4dfbf Copyright (c) 2000-2017 the FFmpeg developers
     built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18)
     configuration: --prefix=/usr/local/ffmpeg --extra-cflags=-I/usr/local/ffmpeg/include --extra-ldflags=-L/usr/local/ffmpeg/lib --bindir=/usr/local/bin --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libtheora --enable-filter=drawtext
     libavutil      56.  7.100 / 56.  7.100
     libavcodec     58.  9.100 / 58.  9.100
     libavformat    58.  3.100 / 58.  3.100
     libavdevice    58.  0.100 / 58.  0.100
     libavfilter     7.  8.100 /  7.  8.100
     libswscale      5.  0.101 /  5.  0.101
     libswresample   3.  0.101 /  3.  0.101
     libpostproc    55.  0.100 / 55.  0.100
    Splitting the commandline.
    Reading option '-i' ... matched as input url with argument 'test.mp4'.
    Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf:textfile=text.txt:reload=1:y=h-line_h-10:x=(W/tw)*n'.
    Reading option 'textover7.mpg' ... matched as output url.
    Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
    Finished splitting the commandline.
    Parsing a group of options: global .
    Applying option report (generate a report) with argument 1.
    Successfully parsed a group of options.
    Parsing a group of options: input url test.mp4.
    Successfully parsed a group of options.
    Opening an input file: test.mp4.
    [NULL @ 0x42d2d80] Opening 'test.mp4' for reading
    [file @ 0x42d3700] Setting default whitelist 'file,crypto'
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] ISO: File Type Major Brand: mp42
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] Unknown dref type 0x206c7275 size 12
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] Processing st: 0, edit list 0 - media time: 0, duration: 13049
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] Unknown dref type 0x206c7275 size 12
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] Before avformat_find_stream_info() pos: 112452 bytes read:141356 seeks:0 nb_streams:2
    [h264 @ 0x42d4640] nal_unit_type: 7, nal_ref_idc: 3
    [h264 @ 0x42d4640] nal_unit_type: 8, nal_ref_idc: 3
    [h264 @ 0x42d4640] nal_unit_type: 5, nal_ref_idc: 3
    [h264 @ 0x42d4640] Format yuv420p chosen by get_format().
    [h264 @ 0x42d4640] Reinit context to 640x368, pix_fmt: yuv420p
    [h264 @ 0x42d4640] nal_unit_type: 1, nal_ref_idc: 2
    [h264 @ 0x42d4640] nal_unit_type: 1, nal_ref_idc: 2
    [h264 @ 0x42d4640] nal_unit_type: 1, nal_ref_idc: 2
    [h264 @ 0x42d4640] nal_unit_type: 1, nal_ref_idc: 2
    [h264 @ 0x42d4640] nal_unit_type: 1, nal_ref_idc: 2
    [h264 @ 0x42d4640] nal_unit_type: 1, nal_ref_idc: 2
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] All info found
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x42d2d80] After avformat_find_stream_info() pos: 159483 bytes read:174124 seeks:0 frames:9
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
     Metadata:
       major_brand     : mp42
       minor_version   : 0
       compatible_brands: isommp42
       creation_time   : 2014-01-19T03:12:30.000000Z
     Duration: 00:07:15.00, start: 0.000000, bitrate: 201 kb/s
       Stream #0:0(und), 8, 1/30: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360, 103 kb/s, 15 fps, 15 tbr, 30 tbn, 30 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(und), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
       Metadata:
         creation_time   : 2014-01-19T03:12:31.000000Z
         handler_name    : IsoMedia File Produced by Google, 5-11-2011
    Successfully opened the file.
    Parsing a group of options: output url textover7.mpg.
    Applying option vf (set video filters) with argument drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf:textfile=text.txt:reload=1:y=h-line_h-10:x=(W/tw)*n.
    Successfully parsed a group of options.
    Opening an output file: textover7.mpg.
    [file @ 0x42e9e40] Setting default whitelist 'file,crypto'
    Successfully opened the file.
    detected 12 logical cores
    [h264 @ 0x43ece00] nal_unit_type: 7, nal_ref_idc: 3
    [h264 @ 0x43ece00] nal_unit_type: 8, nal_ref_idc: 3
    Stream mapping:
     Stream #0:0 -> #0:0 (h264 (native) -> mpeg1video (native))
     Stream #0:1 -> #0:1 (aac (native) -> mp2 (native))
    Press [q] to stop, [?] for help
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x43ece00] nal_unit_type: 5, nal_ref_idc: 3
    [h264 @ 0x43ece00] Format yuv420p chosen by get_format().
    [h264 @ 0x43ece00] Reinit context to 640x368, pix_fmt: yuv420p
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x43f91c0] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x43376c0] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x4339d40] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x43c1840] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x43de0c0] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x439b000] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x445ae80] nal_unit_type: 1, nal_ref_idc: 2
    [graph_1_in_0_1 @ 0x4657a40] Setting 'time_base' to value '1/44100'
    [graph_1_in_0_1 @ 0x4657a40] Setting 'sample_rate' to value '44100'
    [graph_1_in_0_1 @ 0x4657a40] Setting 'sample_fmt' to value 'fltp'
    [graph_1_in_0_1 @ 0x4657a40] Setting 'channel_layout' to value '0x3'
    [graph_1_in_0_1 @ 0x4657a40] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3
    [format_out_0_1 @ 0x4657cc0] Setting 'sample_fmts' to value 's16'
    [format_out_0_1 @ 0x4657cc0] Setting 'sample_rates' to value '44100|48000|32000|22050|24000|16000'
    [format_out_0_1 @ 0x4657cc0] Setting 'channel_layouts' to value '0x4|0x3'
    [format_out_0_1 @ 0x4657cc0] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_1'
    [AVFilterGraph @ 0x42d2c40] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
    [auto_resampler_0 @ 0x4658dc0] [SWR @ 0x4659140] Using fltp internally between filters
    [auto_resampler_0 @ 0x4658dc0] ch:2 chl:stereo fmt:fltp r:44100Hz -> ch:2 chl:stereo fmt:s16 r:44100Hz
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x4477580] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x4493cc0] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x44b0340] nal_unit_type: 1, nal_ref_idc: 2
    cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    [h264 @ 0x44cca80] nal_unit_type: 1, nal_ref_idc: 2
    [AVFilterGraph @ 0x466e4c0] No such filter: 'drawtext'
    Error reinitializing filters!
    Failed to inject frame into filter network: Invalid argument
    Error while processing the decoded data for stream #0:0
    [h264 @ 0x44e91c0] nal_unit_type: 1, nal_ref_idc: 2
    [AVIOContext @ 0x43c0280] Statistics: 0 seeks, 0 writeouts
    [AVIOContext @ 0x42db980] Statistics: 174124 bytes read, 0 seeks
    Conversion failed!
  • Transcoded video stream unplayable in QuickTime player

    30 novembre 2017, par Nikolai Linetskiy

    Currently I’m writing software for transcoding media files using ffmpeg libs. The problem is that in case of H264 QuickTime cannot play result stream and shows black screen. Audio streams work as expected. I have read that QuickTime can deal only with yuv420p pixel format and that is true for encoded video.

    I looked through the ffmpeg examples and ffmpeg source code and could not find anything find any clues where the problem might be. I would really appreciate any help.

    The only thing I managed to get from QuickTime is
    SeqAndPicParamSetFromCFDictionaryRef, bad config record message in console. Same thing is logged by AVPlayer from AVFoundation.

    Here is the initialization of output streams and encoders.

    int status;

    // avformat_alloc_output_context2()
    if ((status = formatContext.open(destFilename)) &lt; 0) {
       return status;
    }

    AVDictionary *fmtOptions = nullptr;
    av_dict_set(&amp;fmtOptions, "movflags", "faststart", 0);
    av_dict_set(&amp;fmtOptions, "brand", "mp42", 0);

    streams.resize(input->getStreamsCount());
    for (int i = 0; i &lt; input->getStreamsCount(); ++i) {
       AVStream *inputStream = input->getStreamAtIndex(i);
       CodecContext &amp;decoderContext = input->getDecoderAtIndex(i);

       // retrieve output codec by codec id
       auto encoderCodecId = decoderContext.getCodecID();;
       if (decoderContext.getCodecType() == AVMEDIA_TYPE_VIDEO || decoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO) {
           int codecIdKey = decoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO ? IPROC_KEY_INT(TargetAudioCodecID) : IPROC_KEY_INT(TargetVideoCodecID);
           auto codecIdParam = static_cast<avcodecid>(params[codecIdKey]);
           if (codecIdParam != AV_CODEC_ID_NONE) {
               encoderCodecId = codecIdParam;
           }
       }
       AVCodec *encoder = nullptr;
       if ((encoder = avcodec_find_encoder(encoderCodecId)) == nullptr) {
           status = AVERROR_ENCODER_NOT_FOUND;
           return status;
       }

       // create stream with specific codec and format
       AVStream *outputStream = nullptr;
       // avformat_new_stream()
       if ((outputStream = formatContext.newStream(encoder)) == nullptr) {
           return AVERROR(ENOMEM);
       }


       CodecContext encoderContext;
       // avcodec_alloc_context3()
       if ((status = encoderContext.init(encoder)) &lt; 0) {
           return status;
       }

       outputStream->disposition = inputStream->disposition;
       encoderContext.getRawCtx()->chroma_sample_location = decoderContext.getRawCtx()->chroma_sample_location;

       if (encoderContext.getCodecType() == AVMEDIA_TYPE_VIDEO) {
           auto lang = av_dict_get(input->getStreamAtIndex(i)->metadata, "language", nullptr, 0);
           if (lang) {
               av_dict_set(&amp;outputStream->metadata, "language", lang->value, 0);
           }

           // prepare encoder context
           int targetWidth = params[IPROC_KEY_INT(TargetVideoWidth)];
           int targetHeight = params[IPROC_KEY_INT(TargetVideHeight)];



           encoderContext.width() = targetWidth > 0 ? targetWidth : decoderContext.width();
           encoderContext.height() = targetHeight > 0 ? targetHeight : decoderContext.height();
           encoderContext.pixelFormat() = encoder->pix_fmts ? encoder->pix_fmts[0] : decoderContext.pixelFormat();;
           encoderContext.timeBase() = decoderContext.timeBase();
           encoderContext.getRawCtx()->level = 31;
           encoderContext.getRawCtx()->gop_size = 25;

           double far = static_cast<double>(encoderContext.getRawCtx()->width) / encoderContext.getRawCtx()->height;
           double dar = static_cast<double>(decoderContext.width()) / decoderContext.height();
           encoderContext.sampleAspectRatio() = av_d2q(dar / far, 255);


           encoderContext.getRawCtx()->bits_per_raw_sample = FFMIN(decoderContext.getRawCtx()->bits_per_raw_sample,
                                                                   av_pix_fmt_desc_get(encoderContext.pixelFormat())->comp[0].depth);
           encoderContext.getRawCtx()->framerate = inputStream->r_frame_rate;
           outputStream->avg_frame_rate = encoderContext.getRawCtx()->framerate;

           VideoFilterGraphParameters params;
           params.height = encoderContext.height();
           params.width = encoderContext.width();
           params.pixelFormat = encoderContext.pixelFormat();
           if ((status = generateGraph(decoderContext, encoderContext, params, streams[i].filterGraph)) &lt; 0) {
               return status;
           }

       } else if (encoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO) {
           auto lang = av_dict_get(input->getStreamAtIndex(i)->metadata, "language", nullptr, 0);
           if (lang) {
               av_dict_set(&amp;outputStream->metadata, "language", lang->value, 0);
           }

           encoderContext.sampleRate() = params[IPROC_KEY_INT(TargetAudioSampleRate)] ? : decoderContext.sampleRate();
           encoderContext.channels() = params[IPROC_KEY_INT(TargetAudioChannels)] ? : decoderContext.channels();
           auto paramChannelLayout = params[IPROC_KEY_INT(TargetAudioChannelLayout)];
           if (paramChannelLayout) {
               encoderContext.channelLayout() = paramChannelLayout;
           } else {
               encoderContext.channelLayout() = av_get_default_channel_layout(encoderContext.channels());
           }

           AVSampleFormat sampleFormatParam = static_cast<avsampleformat>(params[IPROC_KEY_INT(TargetAudioSampleFormat)]);
           if (sampleFormatParam != AV_SAMPLE_FMT_NONE) {
               encoderContext.sampleFormat() = sampleFormatParam;
           } else if (encoder->sample_fmts) {
               encoderContext.sampleFormat() = encoder->sample_fmts[0];
           } else {
               encoderContext.sampleFormat() = decoderContext.sampleFormat();
           }

           encoderContext.timeBase().num = 1;
           encoderContext.timeBase().den = encoderContext.sampleRate();

           AudioFilterGraphParameters params;
           params.channelLayout = encoderContext.channelLayout();
           params.channels = encoderContext.channels();
           params.format = encoderContext.sampleFormat();
           params.sampleRate = encoderContext.sampleRate();
           if ((status = generateGraph(decoderContext, encoderContext, params, streams[i].filterGraph)) &lt; 0) {
               return status;
           }
       }

       // before using encoder, we should open it and update its parameters
       printf("Codec bits per sample %d\n", av_get_bits_per_sample(encoderCodecId));
       AVDictionary *options = nullptr;
       // avcodec_open2()
       if ((status = encoderContext.open(encoder, &amp;options)) &lt; 0) {
           return status;
       }
       if (streams[i].filterGraph) {
           streams[i].filterGraph.setOutputFrameSize(encoderContext.getFrameSize());
       }
       // avcodec_parameters_from_context()
       if ((status = encoderContext.fillParamters(outputStream->codecpar)) &lt; 0) {
           return status;
       }
       outputStream->codecpar->format = encoderContext.getRawCtx()->pix_fmt;

       if (formatContext.getRawCtx()->oformat->flags &amp; AVFMT_GLOBALHEADER) {
           encoderContext.getRawCtx()->flags |= CODEC_FLAG_GLOBAL_HEADER;
       }

       if (encoderContext.getRawCtx()->nb_coded_side_data) {
           int i;

           for (i = 0; i &lt; encoderContext.getRawCtx()->nb_coded_side_data; i++) {
               const AVPacketSideData *sd_src = &amp;encoderContext.getRawCtx()->coded_side_data[i];
               uint8_t *dst_data;

               dst_data = av_stream_new_side_data(outputStream, sd_src->type, sd_src->size);
               if (!dst_data)
                   return AVERROR(ENOMEM);
               memcpy(dst_data, sd_src->data, sd_src->size);
           }
       }

       /*
        * Add global input side data. For now this is naive, and copies it
        * from the input stream's global side data. All side data should
        * really be funneled over AVFrame and libavfilter, then added back to
        * packet side data, and then potentially using the first packet for
        * global side data.
        */
       for (int i = 0; i &lt; inputStream->nb_side_data; i++) {
           AVPacketSideData *sd = &amp;inputStream->side_data[i];
           uint8_t *dst = av_stream_new_side_data(outputStream, sd->type, sd->size);
           if (!dst)
               return AVERROR(ENOMEM);
           memcpy(dst, sd->data, sd->size);
       }

       // copy timebase while removing common factors
       if (outputStream->time_base.num &lt;= 0 || outputStream->time_base.den &lt;= 0) {
           outputStream->time_base = av_add_q(encoderContext.timeBase(), (AVRational){0, 1});
       }

       // copy estimated duration as a hint to the muxer
       if (outputStream->duration &lt;= 0 &amp;&amp; inputStream->duration > 0) {
           outputStream->duration = av_rescale_q(inputStream->duration, inputStream->time_base, outputStream->time_base);
       }

       streams[i].codecType = encoderContext.getRawCtx()->codec_type;
       streams[i].codec = std::move(encoderContext);
       streams[i].streamIndex = i;
    }

    // avio_open() and avformat_write_header()
    if ((status = formatContext.writeHeader(fmtOptions)) &lt; 0) {
       return status;
    }

    formatContext.dumpFormat();
    </avsampleformat></double></double></avcodecid>

    Reading from stream.

    int InputProcessor::performStep() {
       int status;

       Packet nextPacket;
       if ((status = input->getFormatContext().readFrame(nextPacket)) &lt; 0) {
           return status;
       }
       ++streams[nextPacket.getStreamIndex()].readPackets;
       int streamIndex = nextPacket.getStreamIndex();
       CodecContext &amp;decoder = input->getDecoderAtIndex(streamIndex);
       AVStream *inputStream = input->getStreamAtIndex(streamIndex);

       if (streams[nextPacket.getStreamIndex()].readPackets == 1) {
           for (int i = 0; i &lt; inputStream->nb_side_data; ++i) {
               AVPacketSideData *src_sd = &amp;inputStream->side_data[i];
               uint8_t *dst_data;

               if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX) {
                   continue;
               }
               if (av_packet_get_side_data(nextPacket.getRawPtr(), src_sd->type, nullptr)) {
                   continue;
               }
               dst_data = av_packet_new_side_data(nextPacket.getRawPtr(), src_sd->type, src_sd->size);
               if (!dst_data) {
                   return AVERROR(ENOMEM);
               }
               memcpy(dst_data, src_sd->data, src_sd->size);
           }
       }

       nextPacket.rescaleTimestamps(inputStream->time_base, decoder.timeBase());

       status = decodePacket(&amp;nextPacket, nextPacket.getStreamIndex());
       if (status &lt; 0 &amp;&amp; status != AVERROR(EAGAIN)) {
           return status;
       }
       return 0;
    }

    Here is decoding/encoding code.

    int InputProcessor::decodePacket(Packet *packet, int streamIndex) {
       int status;
       int sendStatus;

       auto &amp;decoder = input->getDecoderAtIndex(streamIndex);

       do {
           if (packet == nullptr) {

               sendStatus = decoder.flushDecodedFrames();
           } else {
               sendStatus = decoder.sendPacket(*packet);
           }

           if (sendStatus &lt; 0 &amp;&amp; sendStatus != AVERROR(EAGAIN) &amp;&amp; sendStatus != AVERROR_EOF) {
               return sendStatus;
           }
           if (sendStatus == 0 &amp;&amp; packet) {
               ++streams[streamIndex].decodedPackets;
           }

           Frame decodedFrame;
           while (true) {
               if ((status = decoder.receiveFrame(decodedFrame)) &lt; 0) {
                   break;
               }
               ++streams[streamIndex].decodedFrames;
               if ((status = filterAndWriteFrame(&amp;decodedFrame, streamIndex)) &lt; 0) {
                   break;
               }
               decodedFrame.unref();
           }
       } while (sendStatus == AVERROR(EAGAIN));

    return status;
    }

    int InputProcessor::encodeAndWriteFrame(Frame *frame, int streamIndex) {
       assert(input->isValid());
       assert(formatContext);

       int status = 0;
       int sendStatus;

       Packet packet;

       CodecContext &amp;encoderContext = streams[streamIndex].codec;

       do {
           if (frame) {
               sendStatus = encoderContext.sendFrame(*frame);
           } else {
               sendStatus = encoderContext.flushEncodedPackets();
           }
           if (sendStatus &lt; 0 &amp;&amp; sendStatus != AVERROR(EAGAIN) &amp;&amp; sendStatus != AVERROR_EOF) {
               return status;
           }
           if (sendStatus == 0 &amp;&amp; frame) {
               ++streams[streamIndex].encodedFrames;
           }

           while (true) {
               if ((status = encoderContext.receivePacket(packet)) &lt; 0) {
                   break;
               }
               ++streams[streamIndex].encodedPackets;
               packet.setStreamIndex(streamIndex);
               auto sourceTimebase = encoderContext.timeBase();
               auto dstTimebase = formatContext.getStreams()[streamIndex]->time_base;
               packet.rescaleTimestamps(sourceTimebase, dstTimebase);
               if ((status = formatContext.writeFrameInterleaved(packet)) &lt; 0) {
                   return status;
               }
               packet.unref();
           }
       } while (sendStatus == AVERROR(EAGAIN));

       if (status != AVERROR(EAGAIN)) {
           return status;
       }

       return 0;
    }

    FFprobe output for original video.

    Input #0, matroska,webm, from 'testvideo':
     Metadata:
       title           : TestVideo
       encoder         : libebml v1.3.0 + libmatroska v1.4.0
       creation_time   : 2014-12-23T03:38:05.000000Z
     Duration: 00:02:29.25, start: 0.000000, bitrate: 79549 kb/s
       Stream #0:0(rus): Video: h264 (High 4:4:4 Predictive), yuv444p10le(pc, bt709, progressive), 2048x858 [SAR 1:1 DAR 1024:429], 24 fps, 24 tbr, 1k tbn, 48 tbc (default)
       Stream #0:1(rus): Audio: pcm_s24le, 48000 Hz, 6 channels, s32 (24 bit), 6912 kb/s (default)

    Transcoded :

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '123.mp4':
     Metadata:
       major_brand     : mp42
       minor_version   : 512
       compatible_brands: isomiso2avc1mp41
       encoder         : Lavf57.71.100
     Duration: 00:02:29.27, start: 0.000000, bitrate: 4282 kb/s
       Stream #0:0(rus): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 192:143 DAR 1024:429], 3940 kb/s, 24.01 fps, 24 tbr, 12288 tbn, 96 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(rus): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 336 kb/s (default)
       Metadata:
         handler_name    : SoundHandler