Recherche avancée

Médias (1)

Mot : - Tags -/ticket

Autres articles (60)

  • Contribute to documentation

    13 avril 2011

    Documentation is vital to the development of improved technical capabilities.
    MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
    To contribute, register to the project users’ mailing (...)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

Sur d’autres sites (4635)

  • ffmpeg determine correct codec to use

    8 avril 2020, par nha

    I am trying to use .y4m files that I feed into Chrome for playing.
This is the only format that I can use.

    



    I have a set of .y4m files that are working for my use case, taken from here.
For example let's say that I use the file mobile_qcif_7.5fps.y4m.

    



    I also have a .mp4 file (specifically the sample small.mp4 file from techslides ). I know how to convert small.mp4 to small.y4m with the following command :

    



    ffmpeg -y -i small.mp4 small.y4m

    



    I would like the resulting file to be accepted by Chrome, just like the other file.
What options should I use (and how to find them) ?

    



    Additional information

    



    ffprobe gives :

    



    $ ffprobe small.y4m 
avprobe version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2007-2014 the Libav developers
  built on Jul 15 2014 13:48:35 with gcc 4.8.1
[yuv4mpegpipe @ 0x23160c0] Estimating duration from bitrate, this may be inaccurate
Input #0, yuv4mpegpipe, from 'small.y4m':
  Duration: N/A, bitrate: N/A
    Stream #0.0: Video: rawvideo, yuv420p, 560x320, 30 fps, 30 tbr, 30 tbn, 30 tbc


$ ffprobe mobile_qcif_7.5fps.y4m
avprobe version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2007-2014 the Libav developers
  built on Jul 15 2014 13:48:35 with gcc 4.8.1
[yuv4mpegpipe @ 0x1e080c0] max_analyze_duration reached
[yuv4mpegpipe @ 0x1e080c0] Estimating duration from bitrate, this may be inaccurate
Input #0, yuv4mpegpipe, from 'mobile_qcif_7.5fps.y4m':
  Duration: N/A, bitrate: N/A
    Stream #0.0: Video: rawvideo, yuv420p, 176x144, PAR 128:117 DAR 1408:1053, 7.50 fps, 7.50 tbr, 7.50 tbn, 7.50 tbc


    



    OS : I am using ffmpeg in Ubuntu 13.10 from the default repository : I ran sudo apt-get install ffmpeg libavcodec-extra-53

    



    Complete console output

    



    $ ffmpeg -y -i small.mp4 small.y4m
ffmpeg version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2000-2014 the Libav developers
  built on Jul 15 2014 13:48:35 with gcc 4.8.1
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.56, start: 0.000000, bitrate: 551 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc
    Metadata:
      creation_time   : 2010-03-20 21:29:11
    Stream #0.1(eng): Audio: aac, 48000 Hz, mono, s16, 83 kb/s
    Metadata:
      creation_time   : 2010-03-20 21:29:11
[buffer @ 0x7274e0] w:560 h:320 pixfmt:yuv420p
Output #0, yuv4mpegpipe, to 'small.y4m':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : Lavf53.21.1
    Stream #0.0(und): Video: rawvideo, yuv420p, 560x320, q=2-31, 200 kb/s, 90k tbn, 30 tbc
    Metadata:
      creation_time   : 2010-03-20 21:29:11
Stream mapping:
  Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame=  166 fps=  0 q=0.0 Lsize=   43576kB time=5.53 bitrate=64513.5kbits/s    
video:0kB audio:0kB global headers:0kB muxing overhead inf%


    



    Head of the files

    



    Not sure if this is relevant, but the text content of both files begin like that :

    



    mobile_qcif_7.5fps.y4m
YUV4MPEG2 W176 H144 F15:2 Ip A128:117
FRAME

small.y4m (invalid)
YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2
FRAME


    



    Additional experiment

    



    Taking the sample mobile_qcif_7.5fps.y4m, turning it into a .mp4 file and then back into a .y4m produces an invalid file (at least for Chrome).

    



    Answer to comments in the answer of @SirDarius

    



    Following the suggestion of @SirDarius ; I tried the following commands.
They failed to produce a valid file.

    



    # [COMMAND]   # [RESULT] [HEADER]
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv444p -y small_yuv444p.y4m   # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C444 XYSCSS=444
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv422p -y small_yuv422p.y4m   # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C422 XYSCSS=422
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv420p -y small_yuv420p.y4m   # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv411p -y small_yuv411p.y4m   # KO   YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C411 XYSCSS=411

ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p9 -y small_yuv420p9.y4m   # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p9 XYSCSS=420P9
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p12 -y small_yuv420p12.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p12 XYSCSS=420P12
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p14 -y small_yuv420p14.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p14 XYSCSS=420P14
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p16 -y small_yuv420p16.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p16 XYSCSS=420P16


    



    When trying other formats (like yuv420p12be, which was in the output of -pix_fmts), I had the following output (hence my previous trials) :

    



    $  ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv420p12be -y small_yuv420p12be.y4m 
ffmpeg version N-68884-g3ebd76a Copyright (c) 2000-2015 the FFmpeg developers
  built on Jan  6 2015 11:03:21 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
  configuration: 
  libavutil      54. 16.100 / 54. 16.100
  libavcodec     56. 19.100 / 56. 19.100
  libavformat    56. 18.100 / 56. 18.100
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  6.100 /  5.  6.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x21d0220] overread end of atom 'colr' by 1 bytes
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : JVT/AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
[yuv4mpegpipe @ 0x21d8180] ERROR: yuv4mpeg can only handle yuv444p, yuv422p, yuv420p, yuv411p and gray8 pixel formats. And using 'strict -1' also yuv444p9, yuv422p9, yuv420p9, yuv444p10, yuv422p10, yuv420p10, yuv444p12, yuv422p12, yuv420p12, yuv444p14, yuv422p14, yuv420p14, yuv444p16, yuv422p16, yuv420p16 and gray16 pixel formats. Use -pix_fmt to select one.
Output #0, yuv4mpegpipe, to 'small_yuv420p12be.y4m':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf56.18.100
    Stream #0:0(und): Video: rawvideo ([12][11]3Y / 0x59330B0C), yuv420p12be, 560x320, q=2-31, 200 kb/s, 7.50 fps, 7.50 tbn, 7.50 tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : Lavc56.19.100 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Could not write header for output file #0 (incorrect codec parameters ?): Input/output error


    



    After that, I also tried to edit with an hexadecimal editor (bless) the small_yuv420p.y4m file. I replace C420mpeg2 by C420, and the file was accepted by Chrome.
What does the number in 420p[number] correspond to ? It is not explained there.
Is there any way to make ffmpeg output this kind of header files ?

    



    @SirDarius, thank you again for your help.

    



    The question

    



    (in case you forgot after this text blob)

    



    How can I convert the small.mp4 into a small.y4m file that has the same properties as the mobile_qcif_7.5fps.y4m file ?

    


  • ffmpeg : Trying to access Ebur128Context->integrated_loudness but unsuccessful

    12 avril 2019, par Sourabh Jain

    [FFMPEG] Trying to access Ebur128Context->integrated_loudness but unsuccessful

    I am trying to run ebur128Filter on audio file . similar to be doing
    [http://ffmpeg.org/doxygen/2.6/f__ebur128_8c_source.html#l00135]

    ffmpeg -i sample.wav -filter_complex ebur128=peak=true -f null -

    result of which is :

    [Parsed_ebur128_0 @ 0x7f9d38403ec0] Summary:

    Integrated loudness:
    I: -15.5 LUFS
    Threshold: -25.6 LUFS

    Loudness range:
    LRA: 1.5 LU
    Threshold: -35.5 LUFS
    LRA low: -16.3 LUFS
    LRA high: -14.8 LUFS

    True peak:
    Peak: -0.4 dBFS
    /*
    * Copyright (c) 2010 Nicolas George
    * Copyright (c) 2011 Stefano Sabatini
    * Copyright (c) 2012 Clément Bœsch
    *
    * Permission is hereby granted, free of charge, to any person obtaining a copy
    * of this software and associated documentation files (the "Software"), to deal
    * in the Software without restriction, including without limitation the rights
    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    * copies of the Software, and to permit persons to whom the Software is
    * furnished to do so, subject to the following conditions:
    *
    * The above copyright notice and this permission notice shall be included in
    * all copies or substantial portions of the Software.
    *
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    * THE SOFTWARE.
    */

    /**
    * @file
    * API example for audio decoding and filtering
    * @example filtering_audio.c
    */

    #include

    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libavfilter></libavfilter>buffersink.h>
    #include <libavfilter></libavfilter>buffersrc.h>
    #include <libavutil></libavutil>opt.h>

    #define MAX_CHANNELS 63



    static const char *filter_descr = "ebur128=peak=true";

    static AVFormatContext *fmt_ctx;
    static AVCodecContext *dec_ctx;
    AVFilterContext *buffersink_ctx;
    AVFilterContext *buffersrc_ctx;
    AVFilterGraph *filter_graph;
    static int audio_stream_index = -1;

    struct rect { int x, y, w, h; };


    struct hist_entry {
       int count;                      ///&lt; how many times the corresponding value occurred
       double energy;                  ///&lt; E = 10^((L + 0.691) / 10)
       double loudness;                ///&lt; L = -0.691 + 10 * log10(E)
    };


    struct integrator {
       double *cache[MAX_CHANNELS];    ///&lt; window of filtered samples (N ms)
       int cache_pos;                  ///&lt; focus on the last added bin in the cache array
       double sum[MAX_CHANNELS];       ///&lt; sum of the last N ms filtered samples (cache content)
       int filled;                     ///&lt; 1 if the cache is completely filled, 0 otherwise
       double rel_threshold;           ///&lt; relative threshold
       double sum_kept_powers;         ///&lt; sum of the powers (weighted sums) above absolute threshold
       int nb_kept_powers;             ///&lt; number of sum above absolute threshold
       struct hist_entry *histogram;   ///&lt; histogram of the powers, used to compute LRA and I
    };

    typedef struct EBUR128Context {
       const AVClass *class;           ///&lt; AVClass context for log and options purpose

       /* peak metering */
       int peak_mode;                  ///&lt; enabled peak modes
       double *true_peaks;             ///&lt; true peaks per channel
       double *sample_peaks;           ///&lt; sample peaks per channel
       double *true_peaks_per_frame;   ///&lt; true peaks in a frame per channel
    #if CONFIG_SWRESAMPLE
       SwrContext *swr_ctx;            ///&lt; over-sampling context for true peak metering
       double *swr_buf;                ///&lt; resampled audio data for true peak metering
       int swr_linesize;
    #endif

       /* video  */
       int do_video;                   ///&lt; 1 if video output enabled, 0 otherwise
       int w, h;                       ///&lt; size of the video output
       struct rect text;               ///&lt; rectangle for the LU legend on the left
       struct rect graph;              ///&lt; rectangle for the main graph in the center
       struct rect gauge;              ///&lt; rectangle for the gauge on the right
       AVFrame *outpicref;             ///&lt; output picture reference, updated regularly
       int meter;                      ///&lt; select a EBU mode between +9 and +18
       int scale_range;                ///&lt; the range of LU values according to the meter
       int y_zero_lu;                  ///&lt; the y value (pixel position) for 0 LU
       int y_opt_max;                  ///&lt; the y value (pixel position) for 1 LU
       int y_opt_min;                  ///&lt; the y value (pixel position) for -1 LU
       int *y_line_ref;                ///&lt; y reference values for drawing the LU lines in the graph and the gauge

       /* audio */
       int nb_channels;                ///&lt; number of channels in the input
       double *ch_weighting;           ///&lt; channel weighting mapping
       int sample_count;               ///&lt; sample count used for refresh frequency, reset at refresh

       /* Filter caches.
        * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */
       double x[MAX_CHANNELS * 3];     ///&lt; 3 input samples cache for each channel
       double y[MAX_CHANNELS * 3];     ///&lt; 3 pre-filter samples cache for each channel
       double z[MAX_CHANNELS * 3];     ///&lt; 3 RLB-filter samples cache for each channel

    #define I400_BINS  (48000 * 4 / 10)
    #define I3000_BINS (48000 * 3)
       struct integrator i400;         ///&lt; 400ms integrator, used for Momentary loudness  (M), and Integrated loudness (I)
       struct integrator i3000;        ///&lt;    3s integrator, used for Short term loudness (S), and Loudness Range      (LRA)

       /* I and LRA specific */
       double integrated_loudness;     ///&lt; integrated loudness in LUFS (I)
       double loudness_range;          ///&lt; loudness range in LU (LRA)
       double lra_low, lra_high;       ///&lt; low and high LRA values

       /* misc */
       int loglevel;                   ///&lt; log level for frame logging
       int metadata;                   ///&lt; whether or not to inject loudness results in frames
       int dual_mono;                  ///&lt; whether or not to treat single channel input files as dual-mono
       double pan_law;                 ///&lt; pan law value used to calculate dual-mono measurements
       int target;                     ///&lt; target level in LUFS used to set relative zero LU in visualization
       int gauge_type;                 ///&lt; whether gauge shows momentary or short
       int scale;                      ///&lt; display scale type of statistics
    } EBUR128Context;

    void dump_ebur128_context(void *priv);

    static int open_input_file(const char *filename)
    {
       int ret;
       AVCodec *dec;

       if ((ret = avformat_open_input(&amp;fmt_ctx, filename, NULL, NULL)) &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");
           return ret;
       }

       if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
           return ret;
       }

       /* select the audio stream */
       ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, &amp;dec, 0);
       if (ret &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot find an audio stream in the input file\n");
           return ret;
       }
       audio_stream_index = ret;

       /* create decoding context */
       dec_ctx = avcodec_alloc_context3(dec);
       if (!dec_ctx)
           return AVERROR(ENOMEM);
       avcodec_parameters_to_context(dec_ctx, fmt_ctx->streams[audio_stream_index]->codecpar);

       /* init the audio decoder */
       if ((ret = avcodec_open2(dec_ctx, dec, NULL)) &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot open audio decoder\n");
           return ret;
       }

       return 0;
    }

    static int init_filters(const char *filters_descr)
    {
       char args[512];
       int ret = 0;
       const AVFilter *abuffersrc  = avfilter_get_by_name("abuffer");
       const AVFilter *abuffersink = avfilter_get_by_name("abuffersink");
       AVFilterInOut *outputs = avfilter_inout_alloc();
       AVFilterInOut *inputs  = avfilter_inout_alloc();
       static const enum AVSampleFormat out_sample_fmts[] = { AV_SAMPLE_FMT_S16, -1 };
       static const int64_t out_channel_layouts[] = { AV_CH_LAYOUT_MONO, -1 };
       static const int out_sample_rates[] = { 8000, -1 };
       const AVFilterLink *outlink;
       AVRational time_base = fmt_ctx->streams[audio_stream_index]->time_base;

       filter_graph = avfilter_graph_alloc();
       if (!outputs || !inputs || !filter_graph) {
           ret = AVERROR(ENOMEM);
           goto end;
       }

       /* buffer audio source: the decoded frames from the decoder will be inserted here. */
       if (!dec_ctx->channel_layout)
           dec_ctx->channel_layout = av_get_default_channel_layout(dec_ctx->channels);
       snprintf(args, sizeof(args),
               "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%"PRIx64,
                time_base.num, time_base.den, dec_ctx->sample_rate,
                av_get_sample_fmt_name(dec_ctx->sample_fmt), dec_ctx->channel_layout);
       ret = avfilter_graph_create_filter(&amp;buffersrc_ctx, abuffersrc, "in",
                                          args, NULL, filter_graph);
       if (ret &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer source\n");
           goto end;
       }

       /* buffer audio sink: to terminate the filter chain. */
       ret = avfilter_graph_create_filter(&amp;buffersink_ctx, abuffersink, "out",
                                          NULL, NULL, filter_graph);
       if (ret &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer sink\n");
           goto end;
       }

       ret = av_opt_set_int_list(buffersink_ctx, "sample_fmts", out_sample_fmts, -1,
                                 AV_OPT_SEARCH_CHILDREN);
       if (ret &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot set output sample format\n");
           goto end;
       }

       ret = av_opt_set_int_list(buffersink_ctx, "channel_layouts", out_channel_layouts, -1,
                                 AV_OPT_SEARCH_CHILDREN);
       if (ret &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot set output channel layout\n");
           goto end;
       }

       ret = av_opt_set_int_list(buffersink_ctx, "sample_rates", out_sample_rates, -1,
                                 AV_OPT_SEARCH_CHILDREN);
       if (ret &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot set output sample rate\n");
           goto end;
       }

       /*
        * Set the endpoints for the filter graph. The filter_graph will
        * be linked to the graph described by filters_descr.
        */

       /*
        * The buffer source output must be connected to the input pad of
        * the first filter described by filters_descr; since the first
        * filter input label is not specified, it is set to "in" by
        * default.
        */
       outputs->name       = av_strdup("in");
       outputs->filter_ctx = buffersrc_ctx;
       outputs->pad_idx    = 0;
       outputs->next       = NULL;

       /*
        * The buffer sink input must be connected to the output pad of
        * the last filter described by filters_descr; since the last
        * filter output label is not specified, it is set to "out" by
        * default.
        */
       inputs->name       = av_strdup("out");
       inputs->filter_ctx = buffersink_ctx;
       inputs->pad_idx    = 0;
       inputs->next       = NULL;

       if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
                                           &amp;inputs, &amp;outputs, NULL)) &lt; 0)
           goto end;

       if ((ret = avfilter_graph_config(filter_graph, NULL)) &lt; 0)
           goto end;

       /* Print summary of the sink buffer
        * Note: args buffer is reused to store channel layout string */
       outlink = buffersink_ctx->inputs[0];
       av_get_channel_layout_string(args, sizeof(args), -1, outlink->channel_layout);
       av_log(NULL, AV_LOG_INFO, "Output: srate:%dHz fmt:%s chlayout:%s\n",
              (int)outlink->sample_rate,
              (char *)av_x_if_null(av_get_sample_fmt_name(outlink->format), "?"),
              args);

    end:
       avfilter_inout_free(&amp;inputs);
       avfilter_inout_free(&amp;outputs);

       return ret;
    }

    static void print_frame(const AVFrame *frame)
    {
    //    const int n = frame->nb_samples * av_get_channel_layout_nb_channels(frame->channel_layout);
    //    const uint16_t *p     = (uint16_t*)frame->data[0];
    //    const uint16_t *p_end = p + n;
    //
    //    while (p &lt; p_end) {
    //        fputc(*p    &amp; 0xff, stdout);
    //        fputc(*p>>8 &amp; 0xff, stdout);
    //        p++;
    //    }
    //    fflush(stdout);
    }

    int main(int argc, char **argv)
    {
       av_log_set_level(AV_LOG_DEBUG);
       int ret;
       AVPacket packet;
       AVFrame *frame = av_frame_alloc();
       AVFrame *filt_frame = av_frame_alloc();

       if (!frame || !filt_frame) {
           perror("Could not allocate frame");
           exit(1);
       }


       if ((ret = open_input_file(argv[1])) &lt; 0)
           goto end;
       if ((ret = init_filters(filter_descr)) &lt; 0)
           goto end;

       /* read all packets */
       while (1) {
           if ((ret = av_read_frame(fmt_ctx, &amp;packet)) &lt; 0)
               break;

           if (packet.stream_index == audio_stream_index) {
               ret = avcodec_send_packet(dec_ctx, &amp;packet);
               if (ret &lt; 0) {
                   av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
                   break;
               }

               while (ret >= 0) {
                   ret = avcodec_receive_frame(dec_ctx, frame);
                   if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
                       break;
                   } else if (ret &lt; 0) {
                       av_log(NULL, AV_LOG_ERROR, "Error while receiving a frame from the decoder\n");
                       goto end;
                   }

                   if (ret >= 0) {
                       /* push the audio data from decoded frame into the filtergraph */
                       if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) &lt; 0) {
                           av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
                           break;
                       }

                       /* pull filtered audio from the filtergraph */
                       while (1) {
                           ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
                           if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
                               break;
                           if (ret &lt; 0)
                               goto end;
                           print_frame(filt_frame);
                           av_frame_unref(filt_frame);
                       }
                       av_frame_unref(frame);
                   }
               }
           }
           av_packet_unref(&amp;packet);
       }
       if(filter_graph->nb_filters){
       av_log(filter_graph, AV_LOG_INFO, "hello : %d \n",
                   filter_graph->nb_filters);
       int i;
       for (int i = 0; i &lt; filter_graph->nb_filters; i++){
           av_log(filter_graph, AV_LOG_INFO, "name : %s \n",
                           filter_graph->filters[i]->name);
       }
       }

       av_log(filter_graph, AV_LOG_INFO, "name : %s \n",
                               filter_graph->filters[2]->name);
       void* priv = filter_graph->filters[2]->priv;

       dump_ebur128_context(&amp;priv);

    end:


       avfilter_graph_free(&amp;filter_graph);
       avcodec_free_context(&amp;dec_ctx);
       avformat_close_input(&amp;fmt_ctx);
       av_frame_free(&amp;frame);
       av_frame_free(&amp;filt_frame);

       if (ret &lt; 0 &amp;&amp; ret != AVERROR_EOF) {
           fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
           exit(1);
       }

       exit(0);
    }

    void dump_ebur128_context(void *priv){
       EBUR128Context *ebur128 = priv;

       av_log(ebur128, AV_LOG_INFO, "integrated_loudness : %5.1f \n",
                               ebur128->integrated_loudness);
       av_log(ebur128, AV_LOG_INFO, "lra_low : %5.1f \n",
                                   ebur128->lra_low);
       av_log(ebur128, AV_LOG_INFO, "lra_high : %5.1f \n",
                                   ebur128->lra_high);


    }
    program fails while accessing integrated loudness in dump_ebur128_context.

    can someone guide me about , how I should proceed in here.

  • Does H.264 encoded video with BT.709 matrix include any gamma adjustment ?

    27 janvier 2019, par MoDJ

    I have read the BT.709 spec a number of times and the thing that is just not clear is should an encoded H.264 bitstream actually apply any gamma curve to the encoded data ? Note the specific mention of a gamma like formula in the BT.709 spec. Apple provided examples of OpenGL or Metal shaders that read YUV data from CoreVideo provided buffers do not do any sort of gamma adjustment. YUV values are being read and processed as though they are simple linear values. I also examined the source code of ffmpeg and found no gamma adjustments being applied after the BT.709 scaling step. I then created a test video with just two linear grayscale colors 5 and 26 corresponding to 2% and 10% levels. When converted to H.264 with both ffmpeg and iMovie, the output BT.709 values are (YCbCr) (20 128 128) and (38 128 128) and these values exactly match the output of the BT.709 conversion matrix without any gamma adjustment.

    A great piece of background on this topic can be found at Quicktime Gamma Bug. It seems that some historical issues with Quicktime and Adobe encoders were improperly doing different gamma adjustments and the results made video streams look awful on different players. This is really confusing because if you compare to sRGB, it clearly indicates how to apply a gamma encoding and then decode it to convert between sRGB and linear. Why does BT.709 go into so much detail about the same sort of gamma adjustment curve if no gamma adjustment is applied after the matrix step when creating a h.264 data stream ? Are all the color steps in a h.264 stream meant to be coded as straight linear (gamma 1.0) values ?

    In case specific example input would make things more clear, I am attaching 3 color bar images, the exact values of different colors can be displayed in an image editor with these image files.

    This first image is in the sRGB colorspace and is tagged as sRGB.

    sRGB colorspace

    This second image has been converted to the linear RGB colorspace and is tagged with a linear RGB profile.

    linear RGB colorspace

    This third image has been converted to REC.709 profile levels with Rec709-elle-V4-rec709.icc from elles_icc_profiles
    . This seems to be what one would need to do to simulate "camera" gamma as described in BT.709.

    BT.709 colorspace ICC

    Note how the sRGB value in the lower right corner (0x555555) becomes linear RGB (0x171717) and the BT.709 gamma encoded value becomes (0x464646). What is unclear is if I should be passing a linear RGB value into ffmpeg or if I should be passing an already BT.709 gamma encoded value which would then need to be decoded in the client before the linear conversion Matrix step to get back to RGB.

    Update :

    Based on the feedback, I have updated my C based implementation and Metal shader and uploaded to github as an iOS example project MetalBT709Decoder.

    Encoding a normalized linear RGB value is implemented like this :

    static inline
    int BT709_convertLinearRGBToYCbCr(
                               float Rn,
                               float Gn,
                               float Bn,
                               int *YPtr,
                               int *CbPtr,
                               int *CrPtr,
                               int applyGammaMap)
    {
     // Gamma adjustment to non-linear value

     if (applyGammaMap) {
       Rn = BT709_linearNormToNonLinear(Rn);
       Gn = BT709_linearNormToNonLinear(Gn);
       Bn = BT709_linearNormToNonLinear(Bn);
     }

     // https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.709-6-201506-I!!PDF-E.pdf

     float Ey = (Kr * Rn) + (Kg * Gn) + (Kb * Bn);
     float Eb = (Bn - Ey) / Eb_minus_Ey_Range;
     float Er = (Rn - Ey) / Er_minus_Ey_Range;

     // Quant Y to range [16, 235] (inclusive 219 values)
     // Quant Eb, Er to range [16, 240] (inclusive 224 values, centered at 128)

     float AdjEy = (Ey * (YMax-YMin)) + 16;
     float AdjEb = (Eb * (UVMax-UVMin)) + 128;
     float AdjEr = (Er * (UVMax-UVMin)) + 128;

     *YPtr = (int) round(AdjEy);
     *CbPtr = (int) round(AdjEb);
     *CrPtr = (int) round(AdjEr);

     return 0;
    }

    Decoding from YCbCr to linear RGB is implemented like so :

    static inline
    int BT709_convertYCbCrToLinearRGB(
                                int Y,
                                int Cb,
                                int Cr,
                                float *RPtr,
                                float *GPtr,
                                float *BPtr,
                                int applyGammaMap)
    {
     // https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion
     // http://www.niwa.nu/2013/05/understanding-yuv-values/

     // Normalize Y to range [0 255]
     //
     // Note that the matrix multiply will adjust
     // this byte normalized range to account for
     // the limited range [16 235]

     float Yn = (Y - 16) * (1.0f / 255.0f);

     // Normalize Cb and CR with zero at 128 and range [0 255]
     // Note that matrix will adjust to limited range [16 240]

     float Cbn = (Cb - 128) * (1.0f / 255.0f);
     float Crn = (Cr - 128) * (1.0f / 255.0f);

     const float YScale = 255.0f / (YMax-YMin);
     const float UVScale = 255.0f / (UVMax-UVMin);

     const
     float BT709Mat[] = {
       YScale,   0.000f,  (UVScale * Er_minus_Ey_Range),
       YScale, (-1.0f * UVScale * Eb_minus_Ey_Range * Kb_over_Kg),  (-1.0f * UVScale * Er_minus_Ey_Range * Kr_over_Kg),
       YScale, (UVScale * Eb_minus_Ey_Range),  0.000f,
     };

     // Matrix multiply operation
     //
     // rgb = BT709Mat * YCbCr

     // Convert input Y, Cb, Cr to normalized float values

     float Rn = (Yn * BT709Mat[0]) + (Cbn * BT709Mat[1]) + (Crn * BT709Mat[2]);
     float Gn = (Yn * BT709Mat[3]) + (Cbn * BT709Mat[4]) + (Crn * BT709Mat[5]);
     float Bn = (Yn * BT709Mat[6]) + (Cbn * BT709Mat[7]) + (Crn * BT709Mat[8]);

     // Saturate normalzied linear (R G B) to range [0.0, 1.0]

     Rn = saturatef(Rn);
     Gn = saturatef(Gn);
     Bn = saturatef(Bn);

     // Gamma adjustment for RGB components after matrix transform

     if (applyGammaMap) {
       Rn = BT709_nonLinearNormToLinear(Rn);
       Gn = BT709_nonLinearNormToLinear(Gn);
       Bn = BT709_nonLinearNormToLinear(Bn);
     }

     *RPtr = Rn;
     *GPtr = Gn;
     *BPtr = Bn;

     return 0;
    }

    I believe this logic is implemented correctly, but I am having a very difficult time validating the results. When I generate a .m4v file that contains gamma adjusted color values (osxcolor_test_image_24bit_BT709.m4v), the result come out as expected. But a test case like (bars_709_Frame01.m4v) that I found here does not seem to work as the color bar values seem to be encoded as linear (no gamma adjustment).

    For a SMPTE test pattern, the 0.75 graylevel is linear RGB (191 191 191), should this RGB be encoded with no gamma adjustment as (Y Cb Cr) (180 128 128) or should the value in the bitstream appear as the gamma adjusted (Y Cb Cr) (206 128 128) ?

    (follow up)
    After doing additional research into this gamma issue, it has become clear that what Apple is actually doing in AVFoundation is using a 1.961 gamma function. This is the case when encoding with AVAssetWriterInputPixelBufferAdaptor, when using vImage, or with CoreVideo APIs. This piecewise gamma function is defined as follows :

    #define APPLE_GAMMA_196 (1.960938f)

    static inline
    float Apple196_nonLinearNormToLinear(float normV) {
     const float xIntercept = 0.05583828f;

     if (normV &lt; xIntercept) {
       normV *= (1.0f / 16.0f);
     } else {
       const float gamma = APPLE_GAMMA_196;
       normV = pow(normV, gamma);
     }

     return normV;
    }

    static inline
    float Apple196_linearNormToNonLinear(float normV) {
     const float yIntercept = 0.00349f;

     if (normV &lt; yIntercept) {
       normV *= 16.0f;
     } else {
       const float gamma = 1.0f / APPLE_GAMMA_196;
       normV = pow(normV, gamma);
     }

     return normV;
    }