Recherche avancée

Médias (1)

Mot : - Tags -/belgique

Autres articles (71)

  • Installation en mode ferme

    4 février 2011, par

    Le mode ferme permet d’héberger plusieurs sites de type MediaSPIP en n’installant qu’une seule fois son noyau fonctionnel.
    C’est la méthode que nous utilisons sur cette même plateforme.
    L’utilisation en mode ferme nécessite de connaïtre un peu le mécanisme de SPIP contrairement à la version standalone qui ne nécessite pas réellement de connaissances spécifique puisque l’espace privé habituel de SPIP n’est plus utilisé.
    Dans un premier temps, vous devez avoir installé les mêmes fichiers que l’installation (...)

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

    26 novembre 2010, par

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

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 is the first MediaSPIP stable release.
    Its official release date is June 21, 2013 and is announced here.
    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 (4811)

  • GDPR Compliance and Personal Data : The Ultimate Guide

    22 septembre 2023, par Erin — GDPR

    According to the International Data Corporation (IDC), the world generated 109 zettabytes of data in 2022 alone, and that number is on track to nearly triple to 291 zettabytes in 2027. For scale, that’s one trillion gigs or one followed by 21 zeros in bytes.

    A major portion of that data is generated online, and the conditions for securing that digital data can have major real-world consequences. For example, online identifiers that fall into the wrong hands can be used nefariously for cybercrime, identity theft or unwanted targeting. Users also want control over how their actions are tracked online and transparency into how their information is used.

    Therefore, regional and international regulations are necessary to set the terms for respecting users’ privacy and control over personal information. Perhaps the most widely known of these laws is the European Union’s General Data Protection Regulation (GDPR).

    What is personal data under GDPR ?

    Under the General Data Protection Regulation (GDPR), “personal data” refers to information linked to an identifiable natural person. An “identifiable natural person” is someone directly or indirectly recognisable via individually specific descriptors such as physical, genetic, economic, cultural, employment and social details.

    It’s important to note that under GDPR, the definition of personal data is very broad, and it encompasses both information that is commonly considered personal (e.g., names and addresses) and more technical or specialised data (e.g., IP addresses or device IDs) that can be used to identify individuals indirectly.

    Organisations that handle personal data must adhere to strict rules and principles regarding the processing and protection of this data to ensure individuals’ privacy rights are respected and upheld.

    Personal data can include, but is not limited to, the following :

    1. Basic Identity Information : This includes a person’s name, government-issued ID number, social address, phone number, email address or other similar identifiers.
    2. Biographical Information : Details such as date of birth, place of birth, nationality and gender.
    3. Contact Information : Information that allows communication with the individual, such as phone numbers, email addresses or mailing addresses.
    4. Financial Information : Data related to a person’s finances, including credit card numbers, bank account numbers, income records or financial transactions.
    5. Health and Medical Information : Information about a person’s health, medical history or healthcare treatments.
    6. Location Data : Data that can pinpoint a person’s geographical location, such as GPS coordinates or information derived from mobile devices.
    7. Online Identifiers : Information like IP addresses, cookies or other online tracking mechanisms that can be used to identify or track individuals online.
    8. Biometric Data : Unique physical or behavioural characteristics used for identification, such as fingerprints, facial recognition data or voiceprints.

    Sensitive Data

    Sensitive data is a special category of personal data prohibited from processing unless specific conditions are met, including users giving explicit consent. The data must also be necessary to fulfil one or more of a limited set of allowed purposes, such as reasons related to employment, social protections or legal claims.

    Sensitive information includes details about a person’s racial or ethnic origin, sexual orientation, political opinions, religion, trade union membership, biometric data or genetic data.

    What are the 7 main principles of GDPR ?

    The 7 principles of GDPR guide companies in how to properly handle personal data gathered from their users.

    A list of the main principles to follow for GDPR personal data handling

    The seven principles of GDPR are :

    1. Lawfulness, fairness and transparency

    Lawfulness means having legal grounds for data processing, such as consent, legitimate interests, contract and legal obligation. If you can achieve your objective without processing personal data, the basis is no longer lawful.

    Fairness means you’re processing data reasonably and in line with users’ best interests, and they wouldn’t be shocked if they find out what you’re using it for.

    Transparency means being open regarding when you’re processing user data, what you’re using it for and who you’re collecting it from.

    To get started with this, use our guide on creating a GDPR-compliant privacy policy.

    2. Purpose limitation

    You should only process user data for the original purposes you communicated to users when requesting their explicit consent. If you aim to undertake a new purpose, it must be compatible with the original stated purpose. Otherwise, you’ll need to ask for consent again.

    3. Data minimisation

    You should only collect as much data as you need to accomplish compliant objectives and nothing more, especially not other personally identifiable information (PII).

    Matomo provides several features for extensive data minimisation, including the ability to anonymize IP addresses.

    Data minimisation is well-liked by users. Around 70% of people have taken active steps towards protecting their identity online, so they’ll likely appreciate any principles that help them in this effort.

    4. Accuracy

    The user data you process should be accurate and up-to-date where necessary. You should have reasonable systems to catch inaccurate data and correct or delete it. If there are mistakes that you need to store, then you need to label them clearly as mistakes to keep them from being processed as accurate.

    5. Storage limitation

    This principle requires you to eliminate data you’re no longer using for the original purposes. You must implement time limits, after which you’ll delete or anonymize any user data on record. Matomo allows you to configure your system such that logs are automatically deleted after some time.

    6. Integrity and confidentiality

    This requires that data processors have security measures in place to protect data from threats such as hackers, loss and damage. As an open-source web analytics solution, Matomo enables you to verify its security first-hand.

    7. Accountability

    Accountability means you’re responsible for what you do with the data you collect. It’s your duty to maintain compliance and document everything for audits. Matomo tracks a lot of the data you’d need for this, including activity, task and application logs.

    Who does GDPR apply to ?

    The GDPR applies to any company that processes the personal data of EU citizens and residents (regardless of the location of the company). 

    If this is the first time you’ve heard about this, don’t worry ! Matomo provides tools that allow you to determine exactly what kinds of data you’re collecting and how they must be handled for full compliance. 

    Best practices for processing personal data under GDPR

    Companies subject to the GDPR need to be aware of several key principles and best practices to ensure they process personal data in a lawful and responsible manner.

    Here are some essential practices to implement :

    1. Lawful basis for processing : Organisations must have a lawful basis for processing personal data. Common lawful bases include the necessity of processing for compliance with a legal obligation, the performance of a contract, the protection of vital interests and tasks carried out in the public interest. Your organisation’s legitimate interests for processing must not override the individual’s legal rights. 
    2. Data minimisation : Collect and process only the personal data that is necessary for the specific purpose for which it was collected. Matomo’s anonymisation capabilities help you avoid collecting excessive or irrelevant data.
    3. Transparency : Provide clear and concise information to individuals about how their data will be processed. Privacy statements should be clear and accessible to users to allow them to easily understand how their data is used.
    4. Consent : If you are relying on consent as a lawful basis, make sure you design your privacy statements and consent forms to be usable. This lets you ensure that consent is freely given, specific, informed and unambiguous. Also, individuals must be able to withdraw their consent at any time.
    5. Data subject rights : You must have mechanisms in place to uphold the data subject’s individual rights, such as the rights to access, erase, rectify errors and restrict processing. Establish internal processes for handling such requests.
    6. Data protection impact assessments (DPIAs) : Conduct DPIAs for high-risk processing activities, especially when introducing new technologies or processing sensitive data.
    7. Security measures : You must implement appropriate technical security measures to maintain the safety of personal data. This can include ‌security tools such as encryption, firewalls and limited access controls, as well as organisational practices like regular security assessments. 
    8. Data breach response : Develop and maintain a data breach response plan. Notify relevant authorities and affected individuals of data breaches within the required timeframe.
    9. International data transfers : If transferring personal data outside the EU, ensure that appropriate safeguards are in place and consider GDPR provisions. These provisions allow data transfers from the EU to non-EU countries in three main ways :
      1. When the destination country has been deemed by the European Commission to have adequate data protection, making it similar to transferring data within the EU.
      2. Through the use of safeguards like binding corporate rules, approved contractual clauses or adherence to codes of conduct.
      3. In specific situations when none of the above apply, such as when an individual explicitly consents to the transfer after being informed of the associated risks.
    10. Data protection officers (DPOs) : Appoint a data protection officer if required by GDPR. DPOs are responsible for overseeing data protection compliance within the organisation.
    11. Privacy by design and default : Integrate data protection into the design of systems and processes. Default settings should prioritise user privacy, as is the case with something like Matomo’s first-party cookies.
    12. Documentation : Maintain records of data processing activities, including data protection policies, procedures and agreements. Matomo logs and backs up web server access, activity and more, providing a solid audit trail.
    13. Employee training : Employees who handle personal data must be properly trained to uphold data protection principles and GDPR compliance best practices. 
    14. Third-party contracts : If sharing data with third parties, have data processing agreements in place that outline the responsibilities and obligations of each party regarding data protection.
    15. Regular audits and assessments : Conduct periodic audits and assessments of data processing activities to ensure ongoing compliance. As mentioned previously, Matomo tracks and saves several key statistics and metrics that you’d need for a successful audit.
    16. Accountability : Demonstrate accountability by documenting and regularly reviewing compliance efforts. Be prepared to provide evidence of compliance to data protection authorities.
    17. Data protection impact on data analytics and marketing : Understand how GDPR impacts data analytics and marketing activities, including obtaining valid consent for marketing communications.

    Organisations should be on the lookout for GDPR updates, as the regulations may evolve over time. When in doubt, consult legal and privacy professionals to ensure compliance, as non-compliance could potentially result in significant fines, damage to reputation and legal consequences.

    What constitutes a GDPR breach ?

    Security incidents that compromise the confidentiality, integrity and/or availability of personal data are considered a breach under GDPR. This means a breach is not limited to leaks ; if you accidentally lose or delete personal data, its availability is compromised, which is technically considered a breach.

    What are the penalty fines for GDPR non-compliance ?

    The penalty fines for GDPR non-compliance are up to €20 million or up to 4% of the company’s revenue from the previous fiscal year, whichever is higher. This makes it so that small companies can also get fined, no matter how low-profile the breach is.

    In 2022, for instance, a company found to have mishandled user data was fined €2,000, and the webmaster responsible was personally fined €150.

    Is Matomo GDPR compliant ?

    Matomo is fully GDPR compliant and can ensure you achieve compliance, too. Here’s how :

    • Data anonymization and IP anonymization
    • GDPR Manager that helps you identify gaps in your compliance and address them effectively
    • Users can opt-out of all tracking
    • First-party cookies by default
    • Users can view the data collected
    • Capabilities to delete visitor data when requested
    • You own your data and it is not used for any other purposes (like advertising)
    • Visitor logs and profiles can be disabled
    • Data is stored in the EU (Matomo Cloud) or in any country of your choice (Matomo On-Premise)

    Is there a GDPR in the US ?

    There is no GDPR-equivalent law that covers the US as a whole. That said, US-based companies processing data from persons in the EU still need to adhere to GDPR principles.

    While there isn’t a federal data protection law, several states have enacted their own. One notable example is the California Consumer Privacy Act (CCPA), which Matomo is fully compliant with.

    Ready for GDPR-compliant analytics ?

    The GDPR lays out a set of regulations and penalties that govern the collection and processing of personal data from EU citizens and residents. A breach under GDPR attracts a fine of either up to €20 million or 4% of the company’s revenue, and the penalty applies to companies of all sizes.

    Matomo is fully GDPR compliant and provides several features and advanced privacy settings to ensure you ‌are as well, without sacrificing the resources you need for effective analytics. If you’re ready to get started, sign up for a 21-day free trial of Matomo — no credit card required.

    Disclaimer
    We are not lawyers and don’t claim to be. The information provided here is to help give an introduction to GDPR. We encourage every business and website to take data privacy seriously and discuss these issues with your lawyer if you have any concerns.

  • FFmpeg C++ API : Using HW acceleration (VAAPI) to transcode video coming from a webcam [closed]

    16 avril 2024, par nicoh

    I'm actually trying to use HW acceleration with the FFmpeg C++ API in order to transcode the video coming from a webcam (which may vary from one config to another) into a given output format (i.e : converting the video stream coming from the webcam in MJPEG to H264 so that it can be written into a MP4 file).

    


    I already succeeded to achieve this by transferring the AVFrame output by the HW decoder from GPU to CPU, then transfer this to the HW encoder input (so from CPU to GPU).
This is not so optimized and on top of that, for the given above config (MJPEG => H264), I cannot provide the output of the decoder as an input for the encoder as the MJPEG HW decoder wants to output in RGBA pixel format, and the H264 encoder wants NV12. So I have to perform pixel format conversion on CPU side.

    


    That's why I would like to connect the output of the HW video decoder directly to the input of the HW encoder (inside the GPU).
To do this, I followed this example given by FFmpeg : https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_transcode.c.

    


    This works fine when transcoding an AVI file with MJPEG inside to H264 but it fails when using a MJPEG stream coming from a webcam as input.
In this case, the encoder says :

    


    [h264_vaapi @ 0x5555555e5140] No usable encoding profile found.


    


    Below the code of the FFmpeg example I modified to connect on webcam instead of opening input file :

    


    /*&#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 Intel VAAPI-accelerated transcoding API usage example&#xA; * @example vaapi_transcode.c&#xA; *&#xA; * Perform VAAPI-accelerated transcoding.&#xA; * Usage: vaapi_transcode input_stream codec output_stream&#xA; * e.g: - vaapi_transcode input.mp4 h264_vaapi output_h264.mp4&#xA; *      - vaapi_transcode input.mp4 vp9_vaapi output_vp9.ivf&#xA; */&#xA;&#xA;#include &#xA;#include &#xA;#include <iostream>&#xA;&#xA;//#define USE_INPUT_FILE&#xA;&#xA;extern "C"{&#xA;#include <libavutil></libavutil>hwcontext.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavdevice></libavdevice>avdevice.h>&#xA;}&#xA;&#xA;static AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;&#xA;static AVBufferRef *hw_device_ctx = NULL;&#xA;static AVCodecContext *decoder_ctx = NULL, *encoder_ctx = NULL;&#xA;static int video_stream = -1;&#xA;static AVStream *ost;&#xA;static int initialized = 0;&#xA;&#xA;static enum AVPixelFormat get_vaapi_format(AVCodecContext *ctx,&#xA;                                           const enum AVPixelFormat *pix_fmts)&#xA;{&#xA;    const enum AVPixelFormat *p;&#xA;&#xA;    for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p&#x2B;&#x2B;) {&#xA;        if (*p == AV_PIX_FMT_VAAPI)&#xA;            return *p;&#xA;    }&#xA;&#xA;    std::cout &lt;&lt; "Unable to decode this file using VA-API." &lt;&lt; std::endl;&#xA;    return AV_PIX_FMT_NONE;&#xA;}&#xA;&#xA;static int open_input_file(const char *filename)&#xA;{&#xA;    int ret;&#xA;    AVCodec *decoder = NULL;&#xA;    AVStream *video = NULL;&#xA;    AVDictionary    *pInputOptions = nullptr;&#xA;&#xA;#ifdef USE_INPUT_FILE&#xA;    if ((ret = avformat_open_input(&amp;ifmt_ctx, filename, NULL, NULL)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot open input file &#x27;" &lt;&lt; filename &lt;&lt; "&#x27;, Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;#else&#xA;    avdevice_register_all();&#xA;    av_dict_set(&amp;pInputOptions, "input_format", "mjpeg", 0);&#xA;    av_dict_set(&amp;pInputOptions, "framerate", "30", 0);&#xA;    av_dict_set(&amp;pInputOptions, "video_size", "640x480", 0);&#xA;&#xA;    if ((ret = avformat_open_input(&amp;ifmt_ctx, "/dev/video0", NULL, &amp;pInputOptions)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot open input file &#x27;" &lt;&lt; filename &lt;&lt; "&#x27;, Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;#endif&#xA;&#xA;    ifmt_ctx->flags |= AVFMT_FLAG_NONBLOCK;&#xA;&#xA;    if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot find input stream information. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;&#xA;    ret = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &amp;decoder, 0);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot find a video stream in the input file. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;    video_stream = ret;&#xA;&#xA;    if (!(decoder_ctx = avcodec_alloc_context3(decoder)))&#xA;        return AVERROR(ENOMEM);&#xA;&#xA;    video = ifmt_ctx->streams[video_stream];&#xA;    if ((ret = avcodec_parameters_to_context(decoder_ctx, video->codecpar)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "avcodec_parameters_to_context error. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;&#xA;    decoder_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);&#xA;    if (!decoder_ctx->hw_device_ctx) {&#xA;        std::cout &lt;&lt; "A hardware device reference create failed." &lt;&lt; std::endl;&#xA;        return AVERROR(ENOMEM);&#xA;    }&#xA;    decoder_ctx->get_format    = get_vaapi_format;&#xA;&#xA;    if ((ret = avcodec_open2(decoder_ctx, decoder, NULL)) &lt; 0)&#xA;    {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Failed to open codec for decoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;    }&#xA;&#xA;    return ret;&#xA;}&#xA;&#xA;static int encode_write(AVPacket *enc_pkt, AVFrame *frame)&#xA;{&#xA;    int ret = 0;&#xA;&#xA;    av_packet_unref(enc_pkt);&#xA;&#xA;    AVHWDeviceContext *pHwDevCtx = reinterpret_cast(encoder_ctx->hw_device_ctx);&#xA;    AVHWFramesContext *pHwFrameCtx = reinterpret_cast(encoder_ctx->hw_frames_ctx);&#xA;&#xA;    if ((ret = avcodec_send_frame(encoder_ctx, frame)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Error during encoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;    while (1) {&#xA;        ret = avcodec_receive_packet(encoder_ctx, enc_pkt);&#xA;        if (ret)&#xA;            break;&#xA;&#xA;        enc_pkt->stream_index = 0;&#xA;        av_packet_rescale_ts(enc_pkt, ifmt_ctx->streams[video_stream]->time_base,&#xA;                             ofmt_ctx->streams[0]->time_base);&#xA;        ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);&#xA;        if (ret &lt; 0) {&#xA;            char errMsg[1024] = {0};&#xA;            std::cout &lt;&lt; "Error during writing data to output file. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;end:&#xA;    if (ret == AVERROR_EOF)&#xA;        return 0;&#xA;    ret = ((ret == AVERROR(EAGAIN)) ? 0:-1);&#xA;    return ret;&#xA;}&#xA;&#xA;static int dec_enc(AVPacket *pkt, const AVCodec *enc_codec, AVCodecContext *pDecCtx)&#xA;{&#xA;    AVFrame *frame;&#xA;    int ret = 0;&#xA;&#xA;    ret = avcodec_send_packet(decoder_ctx, pkt);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Error during decoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;&#xA;    while (ret >= 0) {&#xA;        if (!(frame = av_frame_alloc()))&#xA;            return AVERROR(ENOMEM);&#xA;&#xA;        ret = avcodec_receive_frame(decoder_ctx, frame);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;            av_frame_free(&amp;frame);&#xA;            return 0;&#xA;        } else if (ret &lt; 0) {&#xA;            char errMsg[1024] = {0};&#xA;            std::cout &lt;&lt; "Error while decoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;            goto fail;&#xA;        }&#xA;&#xA;        if (!initialized) {&#xA;            AVHWFramesContext *pHwFrameCtx = reinterpret_cast(decoder_ctx->hw_frames_ctx);&#xA;            &#xA;            /* we need to ref hw_frames_ctx of decoder to initialize encoder&#x27;s codec.&#xA;               Only after we get a decoded frame, can we obtain its hw_frames_ctx */&#xA;            encoder_ctx->hw_frames_ctx = av_buffer_ref(pDecCtx->hw_frames_ctx);&#xA;            if (!encoder_ctx->hw_frames_ctx) {&#xA;                ret = AVERROR(ENOMEM);&#xA;                goto fail;&#xA;            }&#xA;            /* set AVCodecContext Parameters for encoder, here we keep them stay&#xA;             * the same as decoder.&#xA;             * xxx: now the sample can&#x27;t handle resolution change case.&#xA;             */&#xA;            if(encoder_ctx->time_base.den == 1 &amp;&amp; encoder_ctx->time_base.num == 0)&#xA;            {&#xA;                encoder_ctx->time_base = av_inv_q(ifmt_ctx->streams[video_stream]->avg_frame_rate);&#xA;            }&#xA;            else&#xA;            {&#xA;                encoder_ctx->time_base = av_inv_q(decoder_ctx->framerate);&#xA;            }&#xA;            encoder_ctx->pix_fmt   = AV_PIX_FMT_VAAPI;&#xA;            encoder_ctx->width     = decoder_ctx->width;&#xA;            encoder_ctx->height    = decoder_ctx->height;&#xA;&#xA;            if ((ret = avcodec_open2(encoder_ctx, enc_codec, NULL)) &lt; 0) {&#xA;                char errMsg[1024] = {0};&#xA;                std::cout &lt;&lt; "Failed to open encode codec. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;                goto fail;&#xA;            }&#xA;&#xA;            if (!(ost = avformat_new_stream(ofmt_ctx, enc_codec))) {&#xA;                std::cout &lt;&lt; "Failed to allocate stream for output format." &lt;&lt; std::endl;&#xA;                ret = AVERROR(ENOMEM);&#xA;                goto fail;&#xA;            }&#xA;&#xA;            ost->time_base = encoder_ctx->time_base;&#xA;            ret = avcodec_parameters_from_context(ost->codecpar, encoder_ctx);&#xA;            if (ret &lt; 0) {&#xA;                char errMsg[1024] = {0};&#xA;                std::cout &lt;&lt; "Failed to copy the stream parameters. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;                goto fail;&#xA;            }&#xA;&#xA;            /* write the stream header */&#xA;            if ((ret = avformat_write_header(ofmt_ctx, NULL)) &lt; 0) {&#xA;                char errMsg[1024] = {0};&#xA;                std::cout &lt;&lt; "Error while writing stream header. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;                goto fail;&#xA;            }&#xA;&#xA;            initialized = 1;&#xA;        }&#xA;&#xA;        if ((ret = encode_write(pkt, frame)) &lt; 0)&#xA;            std::cout &lt;&lt; "Error during encoding and writing." &lt;&lt; std::endl;&#xA;&#xA;fail:&#xA;        av_frame_free(&amp;frame);&#xA;        if (ret &lt; 0)&#xA;            return ret;&#xA;    }&#xA;    return 0;&#xA;}&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    const AVCodec *enc_codec;&#xA;    int ret = 0;&#xA;    AVPacket *dec_pkt;&#xA;&#xA;    if (argc != 4) {&#xA;        fprintf(stderr, "Usage: %s <input file="file" /> <encode codec="codec"> <output file="file">\n"&#xA;                "The output format is guessed according to the file extension.\n"&#xA;                "\n", argv[0]);&#xA;        return -1;&#xA;    }&#xA;&#xA;    ret = av_hwdevice_ctx_create(&amp;hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI, NULL, NULL, 0);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Failed to create a VAAPI device. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    dec_pkt = av_packet_alloc();&#xA;    if (!dec_pkt) {&#xA;        std::cout &lt;&lt; "Failed to allocate decode packet" &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;&#xA;    if ((ret = open_input_file(argv[1])) &lt; 0)&#xA;        goto end;&#xA;&#xA;    if (!(enc_codec = avcodec_find_encoder_by_name(argv[2]))) {&#xA;        std::cout &lt;&lt; "Could not find encoder &#x27;" &lt;&lt; argv[2] &lt;&lt; "&#x27;" &lt;&lt; std::endl;&#xA;        ret = -1;&#xA;        goto end;&#xA;    }&#xA;&#xA;    if ((ret = (avformat_alloc_output_context2(&amp;ofmt_ctx, NULL, NULL, argv[3]))) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Failed to deduce output format from file extension. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;&#xA;    if (!(encoder_ctx = avcodec_alloc_context3(enc_codec))) {&#xA;        ret = AVERROR(ENOMEM);&#xA;        goto end;&#xA;    }&#xA;&#xA;    ret = avio_open(&amp;ofmt_ctx->pb, argv[3], AVIO_FLAG_WRITE);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot open output file. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;&#xA;    /* read all packets and only transcoding video */&#xA;    while (ret >= 0) {&#xA;        if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) &lt; 0)&#xA;            break;&#xA;&#xA;        if (video_stream == dec_pkt->stream_index)&#xA;            ret = dec_enc(dec_pkt, enc_codec, decoder_ctx);&#xA;&#xA;        av_packet_unref(dec_pkt);&#xA;    }&#xA;&#xA;    /* flush decoder */&#xA;    av_packet_unref(dec_pkt);&#xA;    ret = dec_enc(dec_pkt, enc_codec, decoder_ctx);&#xA;&#xA;    /* flush encoder */&#xA;    ret = encode_write(dec_pkt, NULL);&#xA;&#xA;    /* write the trailer for output stream */&#xA;    av_write_trailer(ofmt_ctx);&#xA;&#xA;end:&#xA;    avformat_close_input(&amp;ifmt_ctx);&#xA;    avformat_close_input(&amp;ofmt_ctx);&#xA;    avcodec_free_context(&amp;decoder_ctx);&#xA;    avcodec_free_context(&amp;encoder_ctx);&#xA;    av_buffer_unref(&amp;hw_device_ctx);&#xA;    av_packet_free(&amp;dec_pkt);&#xA;    return ret;&#xA;}&#xA;</output></encode></iostream>

    &#xA;

    And the content of the associated CMakeLists.txt file to build it using gcc :

    &#xA;

    cmake_minimum_required(VERSION 3.5)&#xA;&#xA;include(FetchContent)&#xA;&#xA;set(CMAKE_CXX_STANDARD 17)&#xA;set(CMAKE_CXX_STANDARD_REQUIRED ON)&#xA;&#xA;set(CMAKE_VERBOSE_MAKEFILE ON)&#xA;&#xA;SET (FFMPEG_HW_TRANSCODE_INCS&#xA;    ${CMAKE_CURRENT_LIST_DIR})&#xA;&#xA;include_directories(&#xA;    ${CMAKE_INCLUDE_PATH}&#xA;    ${CMAKE_CURRENT_LIST_DIR}&#xA;)&#xA;&#xA;project(FFmpeg_HW_transcode LANGUAGES CXX)&#xA;&#xA;set(CMAKE_CXX_FLAGS "-Wall -Werror=return-type -pedantic -fPIC -gdwarf-4")&#xA;set(CMAKE_CPP_FLAGS "-Wall -Werror=return-type -pedantic -fPIC -gdwarf-4")&#xA;&#xA;set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_LIST_DIR}/build/${CMAKE_BUILD_TYPE}/FFmpeg_HW_transcode")&#xA;set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_LIST_DIR}/build/${CMAKE_BUILD_TYPE}/FFmpeg_HW_transcode")&#xA;&#xA;add_executable(${PROJECT_NAME})&#xA;&#xA;target_sources(${PROJECT_NAME} PRIVATE&#xA;                vaapi_transcode.cpp)&#xA;&#xA;target_link_libraries(${PROJECT_NAME}&#xA;                -L${CMAKE_CURRENT_LIST_DIR}/../build/${CMAKE_BUILD_TYPE}/FFmpeg_HW_transcode&#xA;                -lavdevice&#xA;                -lavformat&#xA;                -lavutil&#xA;                -lavcodec)&#xA;

    &#xA;

    Has anyone tried to do this kind of stuff ?

    &#xA;

    Thanks for your help.

    &#xA;

  • FFmpeg C++ API : Using HW acceleration (VAAPI) to transcode video coming from a webcam

    17 avril 2024, par nicoh

    I'm actually trying to use HW acceleration with the FFmpeg C++ API in order to transcode the video coming from a webcam (which may vary from one config to another) into a given output format (i.e : converting the video stream coming from the webcam in MJPEG to H264 so that it can be written into a MP4 file).

    &#xA;

    I already succeeded to achieve this by transferring the AVFrame output by the HW decoder from GPU to CPU, then transfer this to the HW encoder input (so from CPU to GPU).&#xA;This is not so optimized and on top of that, for the given above config (MJPEG => H264), I cannot provide the output of the decoder as an input for the encoder as the MJPEG HW decoder wants to output in RGBA pixel format, and the H264 encoder wants NV12. So I have to perform pixel format conversion on CPU side.

    &#xA;

    That's why I would like to connect the output of the HW video decoder directly to the input of the HW encoder (inside the GPU).&#xA;To do this, I followed this example given by FFmpeg : https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_transcode.c.

    &#xA;

    This works fine when transcoding an AVI file with MJPEG inside to H264 but it fails when using a MJPEG stream coming from a webcam as input.&#xA;In this case, the encoder says :

    &#xA;

    [h264_vaapi @ 0x5555555e5140] No usable encoding profile found.&#xA;

    &#xA;

    Below the code of the FFmpeg example I modified to connect on webcam instead of opening input file :

    &#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 Intel VAAPI-accelerated transcoding API usage example&#xA; * @example vaapi_transcode.c&#xA; *&#xA; * Perform VAAPI-accelerated transcoding.&#xA; * Usage: vaapi_transcode input_stream codec output_stream&#xA; * e.g: - vaapi_transcode input.mp4 h264_vaapi output_h264.mp4&#xA; *      - vaapi_transcode input.mp4 vp9_vaapi output_vp9.ivf&#xA; */&#xA;&#xA;#include &#xA;#include &#xA;#include <iostream>&#xA;&#xA;//#define USE_INPUT_FILE&#xA;&#xA;extern "C"{&#xA;#include <libavutil></libavutil>hwcontext.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavdevice></libavdevice>avdevice.h>&#xA;}&#xA;&#xA;static AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;&#xA;static AVBufferRef *hw_device_ctx = NULL;&#xA;static AVCodecContext *decoder_ctx = NULL, *encoder_ctx = NULL;&#xA;static int video_stream = -1;&#xA;static AVStream *ost;&#xA;static int initialized = 0;&#xA;&#xA;static enum AVPixelFormat get_vaapi_format(AVCodecContext *ctx,&#xA;                                           const enum AVPixelFormat *pix_fmts)&#xA;{&#xA;    const enum AVPixelFormat *p;&#xA;&#xA;    for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p&#x2B;&#x2B;) {&#xA;        if (*p == AV_PIX_FMT_VAAPI)&#xA;            return *p;&#xA;    }&#xA;&#xA;    std::cout &lt;&lt; "Unable to decode this file using VA-API." &lt;&lt; std::endl;&#xA;    return AV_PIX_FMT_NONE;&#xA;}&#xA;&#xA;static int open_input_file(const char *filename)&#xA;{&#xA;    int ret;&#xA;    AVCodec *decoder = NULL;&#xA;    AVStream *video = NULL;&#xA;    AVDictionary    *pInputOptions = nullptr;&#xA;&#xA;#ifdef USE_INPUT_FILE&#xA;    if ((ret = avformat_open_input(&amp;ifmt_ctx, filename, NULL, NULL)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot open input file &#x27;" &lt;&lt; filename &lt;&lt; "&#x27;, Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;#else&#xA;    avdevice_register_all();&#xA;    av_dict_set(&amp;pInputOptions, "input_format", "mjpeg", 0);&#xA;    av_dict_set(&amp;pInputOptions, "framerate", "30", 0);&#xA;    av_dict_set(&amp;pInputOptions, "video_size", "640x480", 0);&#xA;&#xA;    if ((ret = avformat_open_input(&amp;ifmt_ctx, "/dev/video0", NULL, &amp;pInputOptions)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot open input file &#x27;" &lt;&lt; filename &lt;&lt; "&#x27;, Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;#endif&#xA;&#xA;    ifmt_ctx->flags |= AVFMT_FLAG_NONBLOCK;&#xA;&#xA;    if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot find input stream information. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;&#xA;    ret = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &amp;decoder, 0);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot find a video stream in the input file. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;    video_stream = ret;&#xA;&#xA;    if (!(decoder_ctx = avcodec_alloc_context3(decoder)))&#xA;        return AVERROR(ENOMEM);&#xA;&#xA;    video = ifmt_ctx->streams[video_stream];&#xA;    if ((ret = avcodec_parameters_to_context(decoder_ctx, video->codecpar)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "avcodec_parameters_to_context error. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;&#xA;    decoder_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);&#xA;    if (!decoder_ctx->hw_device_ctx) {&#xA;        std::cout &lt;&lt; "A hardware device reference create failed." &lt;&lt; std::endl;&#xA;        return AVERROR(ENOMEM);&#xA;    }&#xA;    decoder_ctx->get_format    = get_vaapi_format;&#xA;&#xA;    if ((ret = avcodec_open2(decoder_ctx, decoder, NULL)) &lt; 0)&#xA;    {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Failed to open codec for decoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;    }&#xA;&#xA;    return ret;&#xA;}&#xA;&#xA;static int encode_write(AVPacket *enc_pkt, AVFrame *frame)&#xA;{&#xA;    int ret = 0;&#xA;&#xA;    av_packet_unref(enc_pkt);&#xA;&#xA;    AVHWDeviceContext *pHwDevCtx = reinterpret_cast(encoder_ctx->hw_device_ctx);&#xA;    AVHWFramesContext *pHwFrameCtx = reinterpret_cast(encoder_ctx->hw_frames_ctx);&#xA;&#xA;    if ((ret = avcodec_send_frame(encoder_ctx, frame)) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Error during encoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;    while (1) {&#xA;        ret = avcodec_receive_packet(encoder_ctx, enc_pkt);&#xA;        if (ret)&#xA;            break;&#xA;&#xA;        enc_pkt->stream_index = 0;&#xA;        av_packet_rescale_ts(enc_pkt, ifmt_ctx->streams[video_stream]->time_base,&#xA;                             ofmt_ctx->streams[0]->time_base);&#xA;        ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);&#xA;        if (ret &lt; 0) {&#xA;            char errMsg[1024] = {0};&#xA;            std::cout &lt;&lt; "Error during writing data to output file. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;end:&#xA;    if (ret == AVERROR_EOF)&#xA;        return 0;&#xA;    ret = ((ret == AVERROR(EAGAIN)) ? 0:-1);&#xA;    return ret;&#xA;}&#xA;&#xA;static int dec_enc(AVPacket *pkt, const AVCodec *enc_codec, AVCodecContext *pDecCtx)&#xA;{&#xA;    AVFrame *frame;&#xA;    int ret = 0;&#xA;&#xA;    ret = avcodec_send_packet(decoder_ctx, pkt);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Error during decoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return ret;&#xA;    }&#xA;&#xA;    while (ret >= 0) {&#xA;        if (!(frame = av_frame_alloc()))&#xA;            return AVERROR(ENOMEM);&#xA;&#xA;        ret = avcodec_receive_frame(decoder_ctx, frame);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;            av_frame_free(&amp;frame);&#xA;            return 0;&#xA;        } else if (ret &lt; 0) {&#xA;            char errMsg[1024] = {0};&#xA;            std::cout &lt;&lt; "Error while decoding. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;            goto fail;&#xA;        }&#xA;&#xA;        if (!initialized) {&#xA;            AVHWFramesContext *pHwFrameCtx = reinterpret_cast(decoder_ctx->hw_frames_ctx);&#xA;            &#xA;            /* we need to ref hw_frames_ctx of decoder to initialize encoder&#x27;s codec.&#xA;               Only after we get a decoded frame, can we obtain its hw_frames_ctx */&#xA;            encoder_ctx->hw_frames_ctx = av_buffer_ref(pDecCtx->hw_frames_ctx);&#xA;            if (!encoder_ctx->hw_frames_ctx) {&#xA;                ret = AVERROR(ENOMEM);&#xA;                goto fail;&#xA;            }&#xA;            /* set AVCodecContext Parameters for encoder, here we keep them stay&#xA;             * the same as decoder.&#xA;             * xxx: now the sample can&#x27;t handle resolution change case.&#xA;             */&#xA;            if(encoder_ctx->time_base.den == 1 &amp;&amp; encoder_ctx->time_base.num == 0)&#xA;            {&#xA;                encoder_ctx->time_base = av_inv_q(ifmt_ctx->streams[video_stream]->avg_frame_rate);&#xA;            }&#xA;            else&#xA;            {&#xA;                encoder_ctx->time_base = av_inv_q(decoder_ctx->framerate);&#xA;            }&#xA;            encoder_ctx->pix_fmt   = AV_PIX_FMT_VAAPI;&#xA;            encoder_ctx->width     = decoder_ctx->width;&#xA;            encoder_ctx->height    = decoder_ctx->height;&#xA;&#xA;            if ((ret = avcodec_open2(encoder_ctx, enc_codec, NULL)) &lt; 0) {&#xA;                char errMsg[1024] = {0};&#xA;                std::cout &lt;&lt; "Failed to open encode codec. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;                goto fail;&#xA;            }&#xA;&#xA;            if (!(ost = avformat_new_stream(ofmt_ctx, enc_codec))) {&#xA;                std::cout &lt;&lt; "Failed to allocate stream for output format." &lt;&lt; std::endl;&#xA;                ret = AVERROR(ENOMEM);&#xA;                goto fail;&#xA;            }&#xA;&#xA;            ost->time_base = encoder_ctx->time_base;&#xA;            ret = avcodec_parameters_from_context(ost->codecpar, encoder_ctx);&#xA;            if (ret &lt; 0) {&#xA;                char errMsg[1024] = {0};&#xA;                std::cout &lt;&lt; "Failed to copy the stream parameters. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;                goto fail;&#xA;            }&#xA;&#xA;            /* write the stream header */&#xA;            if ((ret = avformat_write_header(ofmt_ctx, NULL)) &lt; 0) {&#xA;                char errMsg[1024] = {0};&#xA;                std::cout &lt;&lt; "Error while writing stream header. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;                goto fail;&#xA;            }&#xA;&#xA;            initialized = 1;&#xA;        }&#xA;&#xA;        if ((ret = encode_write(pkt, frame)) &lt; 0)&#xA;            std::cout &lt;&lt; "Error during encoding and writing." &lt;&lt; std::endl;&#xA;&#xA;fail:&#xA;        av_frame_free(&amp;frame);&#xA;        if (ret &lt; 0)&#xA;            return ret;&#xA;    }&#xA;    return 0;&#xA;}&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    const AVCodec *enc_codec;&#xA;    int ret = 0;&#xA;    AVPacket *dec_pkt;&#xA;&#xA;    if (argc != 4) {&#xA;        fprintf(stderr, "Usage: %s <input file="file" /> <encode codec="codec"> <output file="file">\n"&#xA;                "The output format is guessed according to the file extension.\n"&#xA;                "\n", argv[0]);&#xA;        return -1;&#xA;    }&#xA;&#xA;    ret = av_hwdevice_ctx_create(&amp;hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI, NULL, NULL, 0);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Failed to create a VAAPI device. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    dec_pkt = av_packet_alloc();&#xA;    if (!dec_pkt) {&#xA;        std::cout &lt;&lt; "Failed to allocate decode packet" &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;&#xA;    if ((ret = open_input_file(argv[1])) &lt; 0)&#xA;        goto end;&#xA;&#xA;    if (!(enc_codec = avcodec_find_encoder_by_name(argv[2]))) {&#xA;        std::cout &lt;&lt; "Could not find encoder &#x27;" &lt;&lt; argv[2] &lt;&lt; "&#x27;" &lt;&lt; std::endl;&#xA;        ret = -1;&#xA;        goto end;&#xA;    }&#xA;&#xA;    if ((ret = (avformat_alloc_output_context2(&amp;ofmt_ctx, NULL, NULL, argv[3]))) &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Failed to deduce output format from file extension. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;&#xA;    if (!(encoder_ctx = avcodec_alloc_context3(enc_codec))) {&#xA;        ret = AVERROR(ENOMEM);&#xA;        goto end;&#xA;    }&#xA;&#xA;    ret = avio_open(&amp;ofmt_ctx->pb, argv[3], AVIO_FLAG_WRITE);&#xA;    if (ret &lt; 0) {&#xA;        char errMsg[1024] = {0};&#xA;        std::cout &lt;&lt; "Cannot open output file. Error code: " &lt;&lt; av_make_error_string(errMsg, 1024, ret) &lt;&lt; std::endl;&#xA;        goto end;&#xA;    }&#xA;&#xA;    /* read all packets and only transcoding video */&#xA;    while (ret >= 0) {&#xA;        if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) &lt; 0)&#xA;            break;&#xA;&#xA;        if (video_stream == dec_pkt->stream_index)&#xA;            ret = dec_enc(dec_pkt, enc_codec, decoder_ctx);&#xA;&#xA;        av_packet_unref(dec_pkt);&#xA;    }&#xA;&#xA;    /* flush decoder */&#xA;    av_packet_unref(dec_pkt);&#xA;    ret = dec_enc(dec_pkt, enc_codec, decoder_ctx);&#xA;&#xA;    /* flush encoder */&#xA;    ret = encode_write(dec_pkt, NULL);&#xA;&#xA;    /* write the trailer for output stream */&#xA;    av_write_trailer(ofmt_ctx);&#xA;&#xA;end:&#xA;    avformat_close_input(&amp;ifmt_ctx);&#xA;    avformat_close_input(&amp;ofmt_ctx);&#xA;    avcodec_free_context(&amp;decoder_ctx);&#xA;    avcodec_free_context(&amp;encoder_ctx);&#xA;    av_buffer_unref(&amp;hw_device_ctx);&#xA;    av_packet_free(&amp;dec_pkt);&#xA;    return ret;&#xA;}&#xA;</output></encode></iostream>

    &#xA;

    And the content of the associated CMakeLists.txt file to build it using gcc :

    &#xA;

    cmake_minimum_required(VERSION 3.5)&#xA;&#xA;include(FetchContent)&#xA;&#xA;set(CMAKE_CXX_STANDARD 17)&#xA;set(CMAKE_CXX_STANDARD_REQUIRED ON)&#xA;&#xA;set(CMAKE_VERBOSE_MAKEFILE ON)&#xA;&#xA;SET (FFMPEG_HW_TRANSCODE_INCS&#xA;    ${CMAKE_CURRENT_LIST_DIR})&#xA;&#xA;include_directories(&#xA;    ${CMAKE_INCLUDE_PATH}&#xA;    ${CMAKE_CURRENT_LIST_DIR}&#xA;)&#xA;&#xA;project(FFmpeg_HW_transcode LANGUAGES CXX)&#xA;&#xA;set(CMAKE_CXX_FLAGS "-Wall -Werror=return-type -pedantic -fPIC -gdwarf-4")&#xA;set(CMAKE_CPP_FLAGS "-Wall -Werror=return-type -pedantic -fPIC -gdwarf-4")&#xA;&#xA;set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_LIST_DIR}/build/${CMAKE_BUILD_TYPE}/FFmpeg_HW_transcode")&#xA;set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_LIST_DIR}/build/${CMAKE_BUILD_TYPE}/FFmpeg_HW_transcode")&#xA;&#xA;add_executable(${PROJECT_NAME})&#xA;&#xA;target_sources(${PROJECT_NAME} PRIVATE&#xA;                vaapi_transcode.cpp)&#xA;&#xA;target_link_libraries(${PROJECT_NAME}&#xA;                -L${CMAKE_CURRENT_LIST_DIR}/../build/${CMAKE_BUILD_TYPE}/FFmpeg_HW_transcode&#xA;                -lavdevice&#xA;                -lavformat&#xA;                -lavutil&#xA;                -lavcodec)&#xA;

    &#xA;

    Has anyone tried to do this kind of stuff ?

    &#xA;

    Thanks for your help.

    &#xA;