Recherche avancée

Médias (3)

Mot : - Tags -/pdf

Autres articles (80)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Le plugin : Gestion de la mutualisation

    2 mars 2010, par

    Le plugin de Gestion de mutualisation permet de gérer les différents canaux de mediaspip depuis un site maître. Il a pour but de fournir une solution pure SPIP afin de remplacer cette ancienne solution.
    Installation basique
    On installe les fichiers de SPIP sur le serveur.
    On ajoute ensuite le plugin "mutualisation" à la racine du site comme décrit ici.
    On customise le fichier mes_options.php central comme on le souhaite. Voilà pour l’exemple celui de la plateforme mediaspip.net :
    < ?php (...)

Sur d’autres sites (4608)

  • Why does the frame count change when scaling with FFmpeg ?

    22 octobre 2016, par ajmicek

    I use this to scale 1920x1080 H.264 videos :

    ffmpeg -i IMG_1438.MOV -threads 2 -vf scale=-2:600 IMG_1438_scaledTo600.MOV

    And it works great ! But here is my question : most of the time, the frame rate stays exactly the same between the original file and the scaled file. For example :

    $ mediainfo -F IMG_1426.MOV | grep Frame\ rate
    Frame rate                               : 29.970
    Frame rate                               : 29.970 FPS
    Frame rate mode                          : VFR
    Frame rate mode                          : Variable
    Frame rate                               : 29.970
    Frame rate                               : 29.970 (29970/1000) FPS

    $ mediainfo -F IMG_1426_scaledTo600.MOV | grep Frame\ rate
    Frame rate                               : 29.970
    Frame rate                               : 29.970 FPS
    Frame rate mode                          : CFR
    Frame rate mode                          : Constant
    Frame rate                               : 29.970
    Frame rate                               : 29.970 (30000/1001) FPS

    But sometimes, the frame rate increases dramatically :

    $ mediainfo -F IMG_1438.MOV | grep Frame\ rate
    Frame rate                               : 25.044
    Frame rate                               : 25.044 FPS
    Frame rate mode                          : VFR
    Frame rate mode                          : Variable
    Frame rate                               : 25.044
    Frame rate                               : 25.044 FPS

    $ mediainfo -F IMG_1438_scaledTo600.MOV | grep Frame\ rate
    Frame rate                               : 120.000
    Frame rate                               : 120.000 FPS
    Frame rate mode                          : CFR
    Frame rate mode                          : Constant
    Frame rate                               : 120.000
    Frame rate                               : 120.000 FPS

    What should I know about FFmpeg or libx264 or libswscale that will help me understand why this happens ? (Hoping to hear from LordNeckbeard, in particular).

    mediainfo IMG_1438.MOV --Full outputs :

    General
    Count                                    : 327
    Count of stream of this kind             : 1
    Kind of stream                           : General
    Kind of stream                           : General
    Stream identifier                        : 0
    Count of video streams                   : 1
    Count of audio streams                   : 1
    OtherCount                               : 2
    Video_Format_List                        : AVC
    Video_Format_WithHint_List               : AVC
    Codecs Video                             : AVC
    Audio_Format_List                        : AAC
    Audio_Format_WithHint_List               : AAC
    Audio codecs                             : AAC LC
    Complete name                            : IMG_1438.MOV
    File name                                : IMG_1438
    File extension                           : MOV
    Format                                   : MPEG-4
    Format                                   : MPEG-4
    Format/Extensions usually used           : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v
    Commercial name                          : MPEG-4
    Format profile                           : QuickTime
    Internet media type                      : video/mp4
    Codec ID                                 : qt  
    Codec ID                                 : qt   0000.00 (qt  )
    Codec ID/Url                             : http://www.apple.com/quicktime/download/standalone.html
    CodecID_Version                          : 0000.00
    CodecID_Compatible                       : qt  
    Codec                                    : MPEG-4
    Codec                                    : MPEG-4
    Codec/Extensions usually used            : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v
    File size                                : 113990140
    File size                                : 109 MiB
    File size                                : 109 MiB
    File size                                : 109 MiB
    File size                                : 109 MiB
    File size                                : 108.7 MiB
    Duration                                 : 52268
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 00:00:52.268
    Duration                                 : 00:00:52:09
    Duration                                 : 00:00:52.268 (00:00:52:09)
    Overall bit rate                         : 17447026
    Overall bit rate                         : 17.4 Mb/s
    Frame rate                               : 25.044
    Frame rate                               : 25.044 FPS
    Frame count                              : 1309
    Stream size                              : 56670
    Stream size                              : 55.3 KiB (0%)
    Stream size                              : 55 KiB
    Stream size                              : 55 KiB
    Stream size                              : 55.3 KiB
    Stream size                              : 55.34 KiB
    Stream size                              : 55.3 KiB (0%)
    Proportion of this stream                : 0.00050
    HeaderSize                               : 28
    DataSize                                 : 113966271
    FooterSize                               : 23841
    IsStreamable                             : No
    Encoded date                             : UTC 2016-10-08 22:51:19
    Tagged date                              : UTC 2016-10-08 22:52:12
    File last modification date              : UTC 2016-10-08 22:51:19
    File last modification date (local)      : 2016-10-08 17:51:19
    Writing library                          : Apple QuickTime
    Writing library                          : Apple QuickTime
    Encoded_Library_Name                     : Apple QuickTime
    com.apple.quicktime.make                 : Apple
    com.apple.quicktime.model                : iPhone 5
    com.apple.quicktime.software             : 10.0.2
    com.apple.quicktime.creationdate         : 2016-10-08T17:51:19-0500

    Video
    Count                                    : 334
    Count of stream of this kind             : 1
    Kind of stream                           : Video
    Kind of stream                           : Video
    Stream identifier                        : 0
    StreamOrder                              : 0
    ID                                       : 1
    ID                                       : 1
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format/Url                               : http://developers.videolan.org/x264.html
    Commercial name                          : AVC
    Format profile                           : High@L4.1
    Format settings                          : CABAC / 1 Ref Frames
    Format settings, CABAC                   : Yes
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 1
    Format settings, ReFrames                : 1 frame
    Internet media type                      : video/H264
    Codec ID                                 : avc1
    Codec ID/Info                            : Advanced Video Coding
    Codec ID/Url                             : http://www.apple.com/quicktime/download/standalone.html
    Codec                                    : AVC
    Codec                                    : AVC
    Codec/Family                             : AVC
    Codec/Info                               : Advanced Video Codec
    Codec/Url                                : http://developers.videolan.org/x264.html
    Codec/CC                                 : avc1
    Codec profile                            : High@L4.1
    Codec settings                           : CABAC / 1 Ref Frames
    Codec settings, CABAC                    : Yes
    Codec_Settings_RefFrames                 : 1
    Duration                                 : 52268
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 00:00:52.268
    Duration                                 : 00:00:52:09
    Duration                                 : 00:00:52.268 (00:00:52:09)
    Bit rate                                 : 17375530
    Bit rate                                 : 17.4 Mb/s
    Width                                    : 1920
    Width                                    : 1 920 pixels
    Height                                   : 1080
    Height                                   : 1 080 pixels
    Stored_Height                            : 1088
    Sampled_Width                            : 1920
    Sampled_Height                           : 1080
    Pixel aspect ratio                       : 1.000
    Display aspect ratio                     : 1.778
    Display aspect ratio                     : 16:9
    Rotation                                 : 90.000
    Rotation                                 : 90°
    Frame rate mode                          : VFR
    Frame rate mode                          : Variable
    Frame rate                               : 25.044
    Frame rate                               : 25.044 FPS
    Minimum frame rate                       : 23.077
    Minimum frame rate                       : 23.077 FPS
    Maximum frame rate                       : 30.000
    Maximum frame rate                       : 30.000 FPS
    Frame count                              : 1309
    Resolution                               : 8
    Resolution                               : 8 bits
    Colorimetry                              : 4:2:0
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Scan type                                : Progressive
    Interlacement                            : PPF
    Interlacement                            : Progressive
    Bits/(Pixel*Frame)                       : 0.335
    Stream size                              : 113523046
    Stream size                              : 108 MiB (100%)
    Stream size                              : 108 MiB
    Stream size                              : 108 MiB
    Stream size                              : 108 MiB
    Stream size                              : 108.3 MiB
    Stream size                              : 108 MiB (100%)
    Proportion of this stream                : 0.99590
    Title                                    : Core Media Video
    Encoded date                             : UTC 2016-10-08 22:51:19
    Tagged date                              : UTC 2016-10-08 22:52:12
    Color range                              : Limited
    colour_description_present               : Yes
    Color primaries                          : BT.709
    Transfer characteristics                 : BT.709
    Matrix coefficients                      : BT.709

    Audio
    Count                                    : 272
    Count of stream of this kind             : 1
    Kind of stream                           : Audio
    Kind of stream                           : Audio
    Stream identifier                        : 0
    StreamOrder                              : 1
    ID                                       : 2
    ID                                       : 2
    Format                                   : AAC
    Format/Info                              : Advanced Audio Codec
    Commercial name                          : AAC
    Format profile                           : LC
    Codec ID                                 : 40
    Codec                                    : AAC LC
    Codec                                    : AAC LC
    Codec/Family                             : AAC
    Codec/CC                                 : 40
    Duration                                 : 52268
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 00:00:52.268
    Duration                                 : 00:00:52:15
    Duration                                 : 00:00:52.268 (00:00:52:15)
    Source duration                          : 52338
    Source duration                          : 52 s 338 ms
    Source duration                          : 52 s 338 ms
    Source duration                          : 52 s 338 ms
    Source duration                          : 00:00:52.338
    Bit rate mode                            : CBR
    Bit rate mode                            : Constant
    Bit rate                                 : 64000
    Bit rate                                 : 64.0 kb/s
    Channel(s)                               : 1
    Channel(s)                               : 1 channel
    Channel positions                        : Front: C
    Channel positions                        : 1/0/0
    ChannelLayout                            : C
    Samples per frame                        : 1024
    Sampling rate                            : 44100
    Sampling rate                            : 44.1 kHz
    Samples count                            : 2305019
    Frame rate                               : 43.066
    Frame rate                               : 43.066 FPS (1024 spf)
    Frame count                              : 2251
    Source frame count                       : 2254
    Compression mode                         : Lossy
    Compression mode                         : Lossy
    Stream size                              : 410424
    Stream size                              : 401 KiB (0%)
    Stream size                              : 401 KiB
    Stream size                              : 401 KiB
    Stream size                              : 401 KiB
    Stream size                              : 400.8 KiB
    Stream size                              : 401 KiB (0%)
    Proportion of this stream                : 0.00360
    Source stream size                       : 410894
    Source stream size                       : 401 KiB (0%)
    Source stream size                       : 401 KiB
    Source stream size                       : 401 KiB
    Source stream size                       : 401 KiB
    Source stream size                       : 401.3 KiB
    Source stream size                       : 401 KiB (0%)
    Source_StreamSize_Proportion             : 0.00360
    Title                                    : Core Media Audio
    Encoded date                             : UTC 2016-10-08 22:51:19
    Tagged date                              : UTC 2016-10-08 22:52:12

    Other #1
    Count                                    : 112
    Count of stream of this kind             : 2
    Kind of stream                           : Other
    Kind of stream                           : Other
    Stream identifier                        : 0
    Stream identifier                        : 1
    Type                                     : meta
    Duration                                 : 52268
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 00:00:52.268
    Duration                                 : 00:00:52.268
    Frame count                              : 6
    Bit rate mode                            : VBR

    Other #2
    Count                                    : 112
    Count of stream of this kind             : 2
    Kind of stream                           : Other
    Kind of stream                           : Other
    Stream identifier                        : 1
    Stream identifier                        : 2
    Type                                     : meta
    Duration                                 : 52268
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 52 s 268 ms
    Duration                                 : 00:00:52.268
    Duration                                 : 00:00:52.268
    Frame count                              : 1
    Bit rate mode                            : CBR

    and ffprobe IMG_1438.MOV outputs :

    ffprobe version 3.1.3 Copyright (c) 2007-2016 the FFmpeg developers
     built with Apple LLVM version 7.3.0 (clang-703.0.31)
     configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --disable-lzma --enable-vda
     libavutil      55. 28.100 / 55. 28.100
     libavcodec     57. 48.101 / 57. 48.101
     libavformat    57. 41.100 / 57. 41.100
     libavdevice    57.  0.101 / 57.  0.101
     libavfilter     6. 47.100 /  6. 47.100
     libavresample   3.  0.  0 /  3.  0.  0
     libswscale      4.  1.100 /  4.  1.100
     libswresample   2.  1.100 /  2.  1.100
     libpostproc    54.  0.100 / 54.  0.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'IMG_1438.MOV':
     Metadata:
       major_brand     : qt  
       minor_version   : 0
       compatible_brands: qt  
       creation_time   : 2016-10-08 22:51:19
       com.apple.quicktime.make: Apple
       com.apple.quicktime.model: iPhone 5
       com.apple.quicktime.software: 10.0.2
       com.apple.quicktime.creationdate: 2016-10-08T17:51:19-0500
     Duration: 00:00:52.27, start: 0.000000, bitrate: 17446 kb/s
       Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 17375 kb/s, 25.04 fps, 120 tbr, 600 tbn, 1200 tbc (default)
       Metadata:
         rotate          : 90
         creation_time   : 2016-10-08 22:51:19
         handler_name    : Core Media Data Handler
         encoder         : H.264
       Side data:
         displaymatrix: rotation of -90.00 degrees
       Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 62 kb/s (default)
       Metadata:
         creation_time   : 2016-10-08 22:51:19
         handler_name    : Core Media Data Handler
       Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
       Metadata:
         creation_time   : 2016-10-08 22:51:19
         handler_name    : Core Media Data Handler
       Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
       Metadata:
         creation_time   : 2016-10-08 22:51:19
         handler_name    : Core Media Data Handler
    Unsupported codec with id 0 for input stream 2
    Unsupported codec with id 0 for input stream 3

    UPDATE
    To clarify : my video above, the one with the high framerate (120 FPS) output after scaling, plays perfectly before and after scaling with FFmpeg (no sync issues, and 120 FPS is only about 14% larger in file size), I am simply trying to understand why this increase in framerate happens (just a little beyond Mulvya’s note that the framerate stored in the container is wrong).

    From a programming perspective, the initial issue I ran into was that I was using frame= from FFmpeg’s sterr console output to determine progress, which reports erroneous results when the frame count increases dramatically on output ("I’m 372% done encoding ?!") ; I have since read another stackoverflow answer and changed my code to use time=, which appears to be a more robust way for me to display FFmpeg progress. (Also, there is FFmpeg’s -progress option, of course).

    Improving on the original command

    My new command to scale, preserve a useful framerate, and optimize threads :

    ffmpeg -i IMG_1438.MOV -vf scale=-2:600 -r 30 -vsync 0 IMG_1438_scaledTo600.MOV

    Where 30 is the "Maximum frame rate" from mediainfo.

    Thanks to help in the comments, I now know I do not fully understand FFmpeg’s use of three different time bases for timestamps : tbn, tbc, and tbr.
    They were explained by Robert Swain in 2009 and his explanation was also used to answer a Stackoverflow question about tbn, tbc, tbr.

    It sounds to me, as I’m pulling together comments from Mulvya below and Michael Rampe at another forum, that tbr is guessed ; it is frequently but not always the best value to use when changing from a variable to a constant frame rate video.

    Which leaves these 2 questions...

    (1) tbr is incorrect when "field rate and frame rate" differ ? Does this happen a lot ?
    (2) Is -r 30 where 30 is the maximum frame rate reported by mediainfo the best way to do it for most codec/container combinations ? (Or should I only use this method when I am scaling a H.264/MPEG-4 AVC video ?)

  • Libav (ffmpeg) copying decoded video timestamps to encoder

    31 octobre 2016, par Jason C

    I am writing an application that decodes a single video stream from an input file (any codec, any container), does a bunch of image processing, and encodes the results to an output file (single video stream, Quicktime RLE, MOV). I am using ffmpeg’s libav 3.1.5 (Windows build for now, but the application will be cross-platform).

    There is a 1:1 correspondence between input and output frames and I want the frame timing in the output to be identical to the input. I am having a really, really hard time accomplishing this. So my general question is : How do I reliably (as in, in all cases of inputs) set the output frame timing identical to the input ?

    It took me a very long time to slog through the API and get to the point I am at now. I put together a minimal test program to work with :

    #include <cstdio>

    extern "C" {
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libavutil></libavutil>avutil.h>
    #include <libavutil></libavutil>imgutils.h>
    #include <libswscale></libswscale>swscale.h>
    }

    using namespace std;


    struct DecoderStuff {
       AVFormatContext *formatx;
       int nstream;
       AVCodec *codec;
       AVStream *stream;
       AVCodecContext *codecx;
       AVFrame *rawframe;
       AVFrame *rgbframe;
       SwsContext *swsx;
    };


    struct EncoderStuff {
       AVFormatContext *formatx;
       AVCodec *codec;
       AVStream *stream;
       AVCodecContext *codecx;
    };


    template <typename t="t">
    static void dump_timebase (const char *what, const T *o) {
       if (o)
           printf("%s timebase: %d/%d\n", what, o->time_base.num, o->time_base.den);
       else
           printf("%s timebase: null object\n", what);
    }


    // reads next frame into d.rawframe and d.rgbframe. returns false on error/eof.
    static bool read_frame (DecoderStuff &amp;d) {

       AVPacket packet;
       int err = 0, haveframe = 0;

       // read
       while (!haveframe &amp;&amp; err >= 0 &amp;&amp; ((err = av_read_frame(d.formatx, &amp;packet)) >= 0)) {
          if (packet.stream_index == d.nstream) {
              err = avcodec_decode_video2(d.codecx, d.rawframe, &amp;haveframe, &amp;packet);
          }
          av_packet_unref(&amp;packet);
       }

       // error output
       if (!haveframe &amp;&amp; err != AVERROR_EOF) {
           char buf[500];
           av_strerror(err, buf, sizeof(buf) - 1);
           buf[499] = 0;
           printf("read_frame: %s\n", buf);
       }

       // convert to rgb
       if (haveframe) {
           sws_scale(d.swsx, d.rawframe->data, d.rawframe->linesize, 0, d.rawframe->height,
                     d.rgbframe->data, d.rgbframe->linesize);
       }

       return haveframe;

    }


    // writes an output frame, returns false on error.
    static bool write_frame (EncoderStuff &amp;e, AVFrame *inframe) {

       // see note in so post about outframe here
       AVFrame *outframe = av_frame_alloc();
       outframe->format = inframe->format;
       outframe->width = inframe->width;
       outframe->height = inframe->height;
       av_image_alloc(outframe->data, outframe->linesize, outframe->width, outframe->height,
                      AV_PIX_FMT_RGB24, 1);
       //av_frame_copy(outframe, inframe);
       static int count = 0;
       for (int n = 0; n &lt; outframe->width * outframe->height; ++ n) {
           outframe->data[0][n*3+0] = ((n+count) % 100) ? 0 : 255;
           outframe->data[0][n*3+1] = ((n+count) % 100) ? 0 : 255;
           outframe->data[0][n*3+2] = ((n+count) % 100) ? 0 : 255;
       }
       ++ count;

       AVPacket packet;
       av_init_packet(&amp;packet);
       packet.size = 0;
       packet.data = NULL;

       int err, havepacket = 0;
       if ((err = avcodec_encode_video2(e.codecx, &amp;packet, outframe, &amp;havepacket)) >= 0 &amp;&amp; havepacket) {
           packet.stream_index = e.stream->index;
           err = av_interleaved_write_frame(e.formatx, &amp;packet);
       }

       if (err &lt; 0) {
           char buf[500];
           av_strerror(err, buf, sizeof(buf) - 1);
           buf[499] = 0;
           printf("write_frame: %s\n", buf);
       }

       av_packet_unref(&amp;packet);
       av_freep(&amp;outframe->data[0]);
       av_frame_free(&amp;outframe);

       return err >= 0;

    }


    int main (int argc, char *argv[]) {

       const char *infile = "wildlife.wmv";
       const char *outfile = "test.mov";
       DecoderStuff d = {};
       EncoderStuff e = {};

       av_register_all();

       // decoder
       avformat_open_input(&amp;d.formatx, infile, NULL, NULL);
       avformat_find_stream_info(d.formatx, NULL);
       d.nstream = av_find_best_stream(d.formatx, AVMEDIA_TYPE_VIDEO, -1, -1, &amp;d.codec, 0);
       d.stream = d.formatx->streams[d.nstream];
       d.codecx = avcodec_alloc_context3(d.codec);
       avcodec_parameters_to_context(d.codecx, d.stream->codecpar);
       avcodec_open2(d.codecx, NULL, NULL);
       d.rawframe = av_frame_alloc();
       d.rgbframe = av_frame_alloc();
       d.rgbframe->format = AV_PIX_FMT_RGB24;
       d.rgbframe->width = d.codecx->width;
       d.rgbframe->height = d.codecx->height;
       av_frame_get_buffer(d.rgbframe, 1);
       d.swsx = sws_getContext(d.codecx->width, d.codecx->height, d.codecx->pix_fmt,
                               d.codecx->width, d.codecx->height, AV_PIX_FMT_RGB24,
                               SWS_POINT, NULL, NULL, NULL);
       //av_dump_format(d.formatx, 0, infile, 0);
       dump_timebase("in stream", d.stream);
       dump_timebase("in stream:codec", d.stream->codec); // note: deprecated
       dump_timebase("in codec", d.codecx);

       // encoder
       avformat_alloc_output_context2(&amp;e.formatx, NULL, NULL, outfile);
       e.codec = avcodec_find_encoder(AV_CODEC_ID_QTRLE);
       e.stream = avformat_new_stream(e.formatx, e.codec);
       e.codecx = avcodec_alloc_context3(e.codec);
       e.codecx->bit_rate = 4000000; // arbitrary for qtrle
       e.codecx->width = d.codecx->width;
       e.codecx->height = d.codecx->height;
       e.codecx->gop_size = 30; // 99% sure this is arbitrary for qtrle
       e.codecx->pix_fmt = AV_PIX_FMT_RGB24;
       e.codecx->time_base = d.stream->time_base; // ???
       e.codecx->flags |= (e.formatx->flags &amp; AVFMT_GLOBALHEADER) ? AV_CODEC_FLAG_GLOBAL_HEADER : 0;
       avcodec_open2(e.codecx, NULL, NULL);
       avcodec_parameters_from_context(e.stream->codecpar, e.codecx);
       //av_dump_format(e.formatx, 0, outfile, 1);
       dump_timebase("out stream", e.stream);
       dump_timebase("out stream:codec", e.stream->codec); // note: deprecated
       dump_timebase("out codec", e.codecx);

       // open file and write header
       avio_open(&amp;e.formatx->pb, outfile, AVIO_FLAG_WRITE);
       avformat_write_header(e.formatx, NULL);

       // frames
       while (read_frame(d) &amp;&amp; write_frame(e, d.rgbframe))
           ;

       // write trailer and close file
       av_write_trailer(e.formatx);
       avio_closep(&amp;e.formatx->pb);

    }
    </typename></cstdio>

    A few notes about that :

    • Since all of my attempts at frame timing so far have failed, I’ve removed almost all timing-related stuff from this code to start with a clean slate.
    • Almost all error checking and cleanup omitted for brevity.
    • The reason I allocate a new output frame with a new buffer in write_frame, rather than using inframe directly, is because this is more representative of what my real application is doing. My real app also uses RGB24 internally, hence the conversions here.
    • The reason I generate a weird pattern in outframe, rather than using e.g. av_copy_frame, is because I just wanted a test pattern that compressed well with Quicktime RLE (my test input ends up generating a 1.7GB output file otherwise).
    • The input video I am using, "wildlife.wmv", can be found here. I’ve hard-coded the filenames.
    • I am aware that avcodec_decode_video2 and avcodec_encode_video2 are deprecated, but don’t care. They work fine, I’ve already struggled too much getting my head around the latest version of the API, ffmpeg changes their API with nearly every release, and I really don’t feel like dealing with avcodec_send_* and avcodec_receive_* right now.
    • I think I’m supposed to be finishing off by passing a NULL frame to avcodec_encode_video2 to flush some buffers or something but I’m a bit confused about that. Unless somebody feels like explaining that let’s ignore it for now, it’s a separate question. The docs are as vague about this point as they are about everything else.
    • My test input file’s frame rate is 29.97.

    Now, as for my current attempts. The following timing related fields are present in the above code, with details/confusion in bold. There’s a lot of them, because the API is mind-bogglingly convoluted :

    • main: d.stream->time_base : Input video stream time base. For my test input file this is 1/1000.
    • main: d.stream->codec->time_base : Not sure what this is (I never could make sense of why AVStream has an AVCodecContext field when you always use your own new context anyways) and also the codec field is deprecated. For my test input file this is 1/1000.
    • main: d.codecx->time_base : Input codec context time-base. For my test input file this is 0/1. Am I supposed to set it ?
    • main: e.stream->time_base : Time base of the output stream I create. What do I set this to ?
    • main: e.stream->codec->time_base : Time base of the deprecated and mysterious codec field of the output stream I create. Do I set this to anything ?
    • main: e.codecx->time_base : Time base of the encoder context I create. What do I set this to ?
    • read_frame: packet.dts : Decoding timestamp of packet read.
    • read_frame: packet.pts : Presentation timestamp of packet read.
    • read_frame: packet.duration : Duration of packet read.
    • read_frame: d.rawframe->pts : Presentation timestamp of raw frame decoded. This is always 0. Why isn’t it read by the decoder...?
    • read_frame: d.rgbframe->pts / write_frame: inframe->pts : Presentation timestamp of decoded frame converted to RGB. Not set to anything currently.
    • read_frame: d.rawframe->pkt_* : Fields copied from packet, discovered after reading this post. They are set correctly but I don’t know if they are useful.
    • write_frame: outframe->pts : Presentation timestamp of frame being encoded. Should I set this to something ?
    • write_frame: outframe->pkt_* : Timing fields from a packet. Should I set these ? They seem to be ignored by the encoder.
    • write_frame: packet.dts : Decoding timestamp of packet being encoded. What do I set it to ?
    • write_frame: packet.pts : Presentation timestamp of packet being encoded. What do I set it to ?
    • write_frame: packet.duration : Duration of packet being encoded. What do I set it to ?

    I have tried the following, with the described results. Note that inframe is d.rgbframe :

    1.  
      • Init e.stream->time_base = d.stream->time_base
      • Init e.codecx->time_base = d.codecx->time_base
      • Set d.rgbframe->pts = packet.dts in read_frame
      • Set outframe->pts = inframe->pts in write_frame
      • Result : Warning that encoder time base is not set (since d.codecx->time_base was 0/1), seg fault.
    2.  
      • Init e.stream->time_base = d.stream->time_base
      • Init e.codecx->time_base = d.stream->time_base
      • Set d.rgbframe->pts = packet.dts in read_frame
      • Set outframe->pts = inframe->pts in write_frame
      • Result : No warnings, but VLC reports frame rate as 480.048 (no idea where this number came from) and file plays too fast. Also the encoder sets all the timing fields in packet to 0, which was not what I expected. (Edit : Turns out this is because av_interleaved_write_frame, unlike av_write_frame, takes ownership of the packet and swaps it with a blank one, and I was printing the values after that call. So they are not ignored.)
    3.  
      • Init e.stream->time_base = d.stream->time_base
      • Init e.codecx->time_base = d.stream->time_base
      • Set d.rgbframe->pts = packet.dts in read_frame
      • Set any of pts/dts/duration in packet in write_frame to anything.
      • Result : Warnings about packet timestamps not set. Encoder seems to reset all packet timing fields to 0, so none of this has any effect.
    4.  
      • Init e.stream->time_base = d.stream->time_base
      • Init e.codecx->time_base = d.stream->time_base
      • I found these fields, pkt_pts, pkt_dts, and pkt_duration in AVFrame after reading this post, so I tried copying those all the way through to outframe.
      • Result : Really had my hopes up, but ended up with same results as attempt 3 (packet timestamp not set warning, incorrect results).

    I tried various other hand-wavey permutations of the above and nothing worked. What I want to do is create an output file that plays back with the same timing and frame rate as the input (29.97 constant frame rate in this case).

    So how do I do this ? Of the zillions of timing related fields here, what do I do to make the output be the same as the input ? And how do I do it in such a way that handles arbitrary video input formats that may store their time stamps and time bases in different places ? I need this to always work.


    For reference, here is a table of all the packet and frame timestamps read from the video stream of my test input file, to give a sense of what my test file looks like. None of the input packet pts’ are set, same with frame pts, and for some reason the duration of the first 108 frames is 0. VLC plays the file fine and reports the frame rate as 29.9700089 :

  • ffmpeg - convert image sequence to video with reversed order

    8 avril 2017, par 0__

    Looking at the docs, it is not apparent to me whether ffmpeg would allow me to convert an image sequence to a video in reverse order, for example using this sequence :

    frame-1000.jpg
    frame-999.jpg
    frame-998.jpg
    ...
    frame-1.jpg

    Is it possible to give a "step direction" for the frame indices ?