Recherche avancée

Médias (1)

Mot : - Tags -/MediaSPIP 0.2

Autres articles (81)

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

  • Organiser par catégorie

    17 mai 2013, par

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

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

    26 novembre 2010, par

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

Sur d’autres sites (5302)

  • ffmpeg way to encode h265 video that allows fast-forward play without jumps

    27 octobre 2022, par SysHex

    Let me start of by saying that this issue presents itself on a Android headset, while running a Unity app with unity video player component that plays a video on it at 2 times the speed. Hence, the issue might be related to these components and not the video file itself.

    


    I have a library of video files with properties as I will describe further down this post.

    


    When I play these files at 2x the speed , the become extremelly jumpy to the point they can't be watched.

    


    I've played with configurations such as : min-keyint=30:keyint=30:scenecut=0:open-gop=0:lossless=1 but I have to be honest and state that I have almost no clue as to what they do. I've read the documentation and understand gop, I-Frames , and the need to exist reference frames for fast seek, and almost for sure Fast playing of the file (?! maybe not ?) , but don't know how to fine tune this.

    


    Maybe I'm missing out something completely and/or someone as any advice as to what I could try ?

    


    The goal is to play these files at 2x its speed, or possibly faster.

    


    Now for the details on the mpeg4 files :

    


    Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main@L5@Main
Codec ID                                 : hev1
Codec ID/Info                            : High Efficiency Video Coding
Duration                                 : 15 min 0 s
Bit rate                                 : 6 578 kb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0 (Type 0)
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.026
Stream size                              : 706 MiB (98%)
Writing library                          : x265 3.5+37-07b011400:[Windows][GCC 11.2.0][64 bit] 8bit+10bit+12bit
Encoding settings                        : cpuid=1111039 / frame-threads=3 / numa-pools=8 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=1 / input-res=3840x2160 / interlace=0 / total-frames=0 / level-idc=0 / high-tier=1 / uhd-bd=0 / ref=4 / no-allow-non-conformance / no-repeat-headers / annexb / no-aud / no-eob / no-eos / no-hrd / info / hash=0 / no-temporal-layers / open-gop / min-keyint=25 / keyint=250 / gop-lookahead=0 / bframes=4 / b-adapt=2 / b-pyramid / bframe-bias=0 / rc-lookahead=25 / lookahead-slices=4 / scenecut=40 / no-hist-scenecut / radl=0 / no-splice / no-intra-refresh / ctu=64 / min-cu-size=8 / rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=2 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=3 / limit-refs=3 / limit-modes / me=3 / subme=3 / merange=57 / temporal-mvp / no-frame-dup / no-hme / weightp / no-weightb / no-analyze-src-pics / deblock=0:0 / sao / no-sao-non-deblock / rd=4 / selective-sao=4 / no-early-skip / rskip / no-fast-intra / no-tskip-fast / no-cu-lossless / no-b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=2.00 / psy-rdoq=1.00 / no-rd-refine / no-lossless / cbqpoffs=0 / crqpoffs=0 / rc=crf / crf=20.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / ipratio=1.40 / pbratio=1.30 / aq-mode=2 / aq-strength=1.00 / cutree / zone-count=0 / no-strict-cbr / qg-size=32 / no-rc-grain / qpmax=69 / qpmin=0 / no-const-vbv / sar=0 / overscan=0 / videoformat=5 / range=0 / colorprim=1 / transfer=1 / colormatrix=1 / chromaloc=1 / chromaloc-top=0 / chromaloc-bottom=0 / display-window=0 / cll=0,0 / min-luma=0 / max-luma=255 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / hist-threshold=0.03 / no-opt-cu-delta-qp / no-aq-motion / no-hdr10 / no-hdr10-opt / no-dhdr10-opt / no-idr-recovery-sei / analysis-reuse-level=0 / analysis-save-reuse-level=0 / analysis-load-reuse-level=0 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=1 / refine-ctu-distortion=0 / no-limit-sao / ctu-info=0 / no-lowpass-dct / refine-analysis-type=0 / copy-pic=1 / max-ausize-factor=1.0 / no-dynamic-refine / no-single-sei / no-hevc-aq / no-svt / no-field / qp-adaptation-range=1.00 / scenecut-aware-qp=0conformance-window-offsets / right=0 / bottom=0 / decoder-max-rate=0 / no-vbv-live-multi-pass
Language                                 : English
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Codec configuration box                  : hvcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 15 min 0 s
Source duration                          : 15 min 0 s
Source_Duration_LastFrame                : -12 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 13.8 MiB (2%)
Source stream size                       : 13.8 MiB (2%)
Default                                  : Yes
Alternate group                          : 1
mdhd_Duration                            : 900233



    


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