Recherche avancée

Médias (1)

Mot : - Tags -/copyleft

Autres articles (80)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Librairies et logiciels spécifiques aux médias

    10 décembre 2010, par

    Pour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
    Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...)

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

Sur d’autres sites (6007)

  • OCPA, FDBR and TDPSA – What you need to know about the US’s new privacy laws

    22 juillet 2024, par Daniel Crough

    On July 1, 2024, new privacy laws took effect in Florida, Oregon, and Texas. People in these states now have more control over their personal data, signaling a shift in privacy policy in the United States. Here’s what you need to know about these laws and how privacy-focused analytics can help your business stay compliant.

    Consumer rights are front and centre across all three laws

    The Florida Digital Bill of Rights (FDBR), Oregon Consumer Privacy Act (OCPA), and Texas Data Privacy and Security Act (TDPSA) grant consumers similar rights.

    Access : Consumers can access their personal data held by businesses.

    Correction : Consumers can correct inaccurate data.

    Deletion : Consumers may request data deletion.

    Opt-Out : Consumers can opt-out of the sale of their personal data and targeted advertising.

    Oregon Consumer Privacy Act (OCPA)

    The Oregon Consumer Privacy Act (OCPA), signed into law on June 23, 2023, and effective as of July 1, 2024, grants Oregonians new rights regarding their personal data and imposes obligations on businesses. Starting July 1, 2025, authorities will enforce provisions that require data protection assessments, and businesses must recognize universal opt-out mechanisms by January 1, 2026. In Oregon, the OCPA applies to business that :

    • Either conduct business in Oregon or offer products and services to Oregon residents

    • Control or process the personal data of 100,000 consumers or more, or

    • Control or process the data of 25,000 or more consumers while receiving over 25% of their gross revenues from selling personal data.

    Exemptions include public bodies like state and local governments, financial institutions, and insurers that operate under specific financial regulations. The law also excludes protected health information covered by HIPAA and other specific federal regulations.

    Business obligations

    Data Protection Assessments : Businesses must conduct data protection assessments for high-risk processing activities, such as those involving sensitive data or targeting children.

    Consent for Sensitive Data : Businesses must secure explicit consent before collecting, processing, or selling sensitive personal data, such as racial or ethnic origin, religious beliefs, health information, biometric data, and geolocation.

    Universal Opt-out : Starting January 1, 2025, businesses must acknowledge universal opt-out mechanisms, like the Global Privacy Control, that allow consumers to opt out of data collection and processing activities.

    Enforcement

    The Oregon Attorney General can issue fines up to $7,500 per violation. There is no private right of action.

    Unique characteristics of the OCPA

    The OCPA differs from other state privacy laws by requiring affirmative opt-in consent for processing sensitive and children’s data, and by including nonprofit organisations under its scope. It also requires global browser opt-out mechanisms starting in 2026.

    Florida Digital Bill of Rights (FDBR)

    The Florida Digital Bill of Rights (FDBR) became law on June 6, 2023, and it came into effect on July 1, 2024. This law targets businesses with substantial operations or revenues tied to digital activities and seeks to protect the personal data of Florida residents by granting them greater control over their information and imposing stricter obligations on businesses. It applies to entities that :

    • Conduct business in Florida or provide products or services targeting Florida residents,

    • Have annual global gross revenues exceeding $1 billion,

    • Receive 50% or more of their revenues from digital advertising or operate significant digital platforms such as app stores or smart speakers with virtual assistants.

    Exemptions include governmental entities, nonprofits, financial institutions covered by the Gramm-Leach-Bliley Act, and entities covered by HIPAA.

    Business obligations

    Data Security Measures : Companies are required to implement reasonable data security measures to protect personal data from unauthorised access and breaches.

    Handling Sensitive Data : Explicit consent is required for processing sensitive data, which includes information like racial or ethnic origin, religious beliefs, and biometric data.

    Non-Discrimination : Entities must ensure they do not discriminate against consumers who exercise their privacy rights.

    Data Minimisation : Businesses must collect only necessary data.

    Vendor Management : Businesses must ensure that their processors and vendors also comply with the FDBR, regarding the secure handling and processing of personal data.

    Enforcement

    The Florida Attorney General can impose fines of up to $50,000 per violation, with higher penalties for intentional breaches.

    Unique characteristics of the FDBR

    Unlike broader privacy laws such as the California Consumer Privacy Act (CCPA), which apply to a wider range of businesses based on lower revenue thresholds and the volume of data processed, the FDBR distinguishes itself by targeting large-scale businesses with substantial revenues from digital advertising. The FDBR also emphasises specific consumer rights related to modern digital interactions, reflecting the evolving landscape of online privacy concerns.

    Texas Data Privacy and Security Act (TDPSA)

    The Texas Data Privacy and Security Act (TDPSA), signed into law on June 16, 2023, and effective as of July 1, 2024, enhances data protection for Texas residents. The TDPSA applies to entities that :

    • Conduct business in Texas or offer products or services to Texas residents.

    • Engage in processing or selling personal data.

    • Do not fall under the classification of small businesses according to the U.S. Small Business Administration’s criteria, which usually involve employee numbers or average annual receipts. 

    The law excludes state agencies, political subdivisions, financial institutions compliant with the Gramm-Leach-Bliley Act, and entities compliant with HIPAA.

    Business obligations

    Data Protection Assessments : Businesses must conduct data protection assessments for processing activities that pose a heightened risk of harm to consumers, such as processing for targeted advertising, selling personal data, or profiling.

    Consent for Sensitive Data : Businesses must get explicit consent before collecting, processing, or selling sensitive personal data, such as racial or ethnic origin, religious beliefs, health information, biometric data, and geolocation.

    Companies must have adequate data security practices based on the personal information they handle.

    Data Subject Access Requests (DSARs) : Businesses must respond to consumer requests regarding their personal data (e.g., access, correction, deletion) without undue delay, but no later than 45 days after receipt of the request.

    Sale of Data : If businesses sell personal data, they must disclose these practices to consumers and provide them with an option to opt out.

    Universal Opt-Out Compliance : Starting January 1, 2025, businesses must recognise universal opt-out mechanisms like the Global Privacy Control, enabling consumers to opt out of data collection and processing activities.

    Enforcement

    The Texas Attorney General can impose fines up to $25,000 per violation. There is no private right of action.

    Unique characteristics of the TDPSA

    The TDPSA stands out for its small business carve-out, lack of specific thresholds based on revenue or data volume, and requirements for recognising universal opt-out mechanisms starting in 2025. It also mandates consent for processing sensitive data and includes specific measures for data protection assessments and privacy notices.

    Try Matomo for Free

    Get the web insights you need, without compromising data accuracy.

    No credit card required

    Privacy notices across Florida, Oregon, and Texas

    All three laws include a mandate for privacy notices, though there are subtle variations in their specific requirements. Here’s a breakdown of these differences :

    FDBR privacy notice requirements

    Clarity : Privacy notices must clearly explain the collection and use of personal data.

    Disclosure : Notices must inform consumers about their rights, including the right to access, correct, delete their data, and opt-out of data sales and targeted advertising.

    Specificity : Businesses must disclose if they sell personal data or use it for targeted advertising.

    Security Practices : The notice should describe the data security measures in place.

    OCPA privacy notice requirements

    Comprehensive Information : Notices must provide information about the personal data collected, the purposes for processing, and any third parties that can access it.

    Consumer Rights : Must plainly outline consumers’ rights to access, correct, delete their data, and opt-out of data sales, targeted advertising, and profiling.

    Sensitive Data : To process sensitive data, businesses or entities must get explicit consent and communicate it.

    Universal Opt-Out : Starting January 1, 2026, businesses must recognise and honour universal opt-out mechanisms.

    TDPSA privacy notice requirements

    Detailed Notices : Must provide clear and detailed information about data collection practices, including the data collected and the purposes for its use.

    Consumer Rights : Must inform consumers of their rights to access, correct, delete their data, and opt-out of data sales and targeted advertising.

    High-Risk Processing : Notices should include information about any high-risk processing activities and the safeguards in place.

    Sensitive Data : To process sensitive data, entities and businesses must get explicit consent.

    What these laws mean for your businesses

    Businesses operating in Florida, Oregon, and Texas must now comply with these new data privacy laws. Here’s what you can do to avoid fines :

    1. Understand the Laws : Familiarise yourself with the specific requirements of the FDBR, OCPA, and TDPSA, including consumer rights and business obligations.

    1. Implement Data Protection Measures : Ensure you have robust data security measures in place. This includes conducting regular data protection assessments, especially for high-risk processing activities.

    1. Update Privacy Policies : Provide clear and comprehensive privacy notices that inform consumers about their rights and how their data is processed.

    1. Obtain Explicit Consent : For sensitive data, make sure you get explicit consent from consumers. This includes information like health, race, sexual orientation, and more.

    1. Manage Requests Efficiently : Be prepared to handle requests from consumers to access, correct, delete their data, and opt-out of data sales and targeted advertising within the stipulated timeframes.

    1. Recognise Opt-Out Mechanisms : For Oregon, businesses must be ready to implement and recognise universal opt-out mechanisms by January 1, 2026. In Texas, opt-out enforcement begins in 2026. In Florida, the specific opt-out provisions began on July 1, 2024.

    1. Stay Updated : Keep abreast of any changes or updates to these laws to ensure ongoing compliance. Keep an eye on the Matomo blog or sign up for our newsletter to stay in the know.

    Are we headed towards a more privacy-focused future in the United States ?

    Florida, Oregon, and Texas are joining states like California, Virginia, Colorado, Connecticut, Utah, Iowa, Indiana, Tennessee, and Montana in strengthening consumer privacy protections. This trend could signify a shift in US policy towards a more privacy-focused internet, underlining the importance of consumer data rights and transparent business practices. Even if these laws do not apply to your business, considering updates to your data and privacy policies is wise. Fortunately, there are tools and solutions designed for privacy and compliance to help you navigate these changes.

    Avoid fines and get better data with Matomo

    Most analytics tools don’t prioritize safeguarding user data. At Matomo, we believe everyone has the right to data sovereignty, privacy and amazing analytics. Matomo offers a solution that meets privacy regulations while delivering incredible insights. With Matomo, you get :

    100% Data Ownership : Keep full control over your data, ensuring it is used according to your privacy policies.

    Privacy Protection : Built with privacy in mind, Matomo helps businesses comply with privacy laws.

    Powerful Features : Gain insights with tools like heatmaps, session recordings, and A/B testing.

    Open Source : Matomo’s is open-source and committed to transparency and customisation.

    Flexibility : Choose to host Matomo on your servers or in the cloud for added security.

    No Data Sampling : Ensure accurate and complete insights without data sampling.

    Privacy Compliance : Easily meet GDPR and other requirements, with data stored securely and never sold or shared.

    Disclaimer : This content is provided for informational purposes only and is not intended as legal advice. While we strive to ensure the accuracy and timeliness of the information provided, the laws and regulations surrounding privacy are complex and subject to change. We recommend consulting with a qualified legal professional to address specific legal issues related to your circumstances. 

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

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

    14 septembre 2022, par Martin Castin

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

    Edit : example videos and complete code example

    &#xA;

    I also tried with the following ffmpeg build

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;