Recherche avancée

Médias (1)

Mot : - Tags -/remix

Autres articles (94)

  • Script d’installation automatique de MediaSPIP

    25 avril 2011, par

    Afin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
    Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
    La documentation de l’utilisation du script d’installation (...)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Possibilité de déploiement en ferme

    12 avril 2011, par

    MediaSPIP peut être installé comme une ferme, avec un seul "noyau" hébergé sur un serveur dédié et utilisé par une multitude de sites différents.
    Cela permet, par exemple : de pouvoir partager les frais de mise en œuvre entre plusieurs projets / individus ; de pouvoir déployer rapidement une multitude de sites uniques ; d’éviter d’avoir à mettre l’ensemble des créations dans un fourre-tout numérique comme c’est le cas pour les grandes plate-formes tout public disséminées sur le (...)

Sur d’autres sites (9923)

  • FFMPEG using AV_PIX_FMT_D3D11 gives "Error registering the input resource" from NVENC

    13 novembre 2024, par nbabcock

    Input frames start on the GPU as ID3D11Texture2D pointers.

    


    I encode them to H264 using FFMPEG + NVENC. NVENC works perfectly if I download the textures to CPU memory as format AV_PIX_FMT_BGR0, but I'd like to cut out the CPU texture download entirely, and pass the GPU memory pointer directly into the encoder in native format. I write frames like this :

    


    int write_gpu_video_frame(ID3D11Texture2D* gpuTex, AVFormatContext* oc, OutputStream* ost) {
    AVFrame *hw_frame = ost->hw_frame;

    printf("gpuTex address = 0x%x\n", &gpuTex);

    hw_frame->data[0] = (uint8_t *) gpuTex;
    hw_frame->data[1] = (uint8_t *) (intptr_t) 0;
    hw_frame->pts     = ost->next_pts++;

    return write_frame(oc, ost->enc, ost->st, hw_frame);
    // write_frame is identical to sample code in ffmpeg repo
}


    


    Running the code with this modification gives the following error :

    


    gpuTex address = 0x4582f6d0
[h264_nvenc @ 00000191233e1bc0] Error registering an input resource: invalid call (9):
[h264_nvenc @ 00000191233e1bc0] Could not register an input HW frame
Error sending a frame to the encoder: Unknown error occurred


    



    


    Here's some supplemental code used in setting up and configuring the hw context and encoder :

    


    /* A few config flags */
#define ENABLE_NVENC TRUE
#define USE_D3D11 TRUE // Skip downloading textures to CPU memory and send it straight to NVENC


    


    /* Init hardware frame context */
static int set_hwframe_ctx(AVCodecContext* ctx, AVBufferRef* hw_device_ctx) {
    AVBufferRef*       hw_frames_ref;
    AVHWFramesContext* frames_ctx = NULL;
    int                err        = 0;

    if (!(hw_frames_ref = av_hwframe_ctx_alloc(hw_device_ctx))) {
        fprintf(stderr, "Failed to create HW frame context.\n");
        throw;
    }
    frames_ctx                    = (AVHWFramesContext*) (hw_frames_ref->data);
    frames_ctx->format            = AV_PIX_FMT_D3D11;
    frames_ctx->sw_format         = AV_PIX_FMT_NV12;
    frames_ctx->width             = STREAM_WIDTH;
    frames_ctx->height            = STREAM_HEIGHT;
    //frames_ctx->initial_pool_size = 20;
    if ((err = av_hwframe_ctx_init(hw_frames_ref)) < 0) {
        fprintf(stderr, "Failed to initialize hw frame context. Error code: %s\n", av_err2str(err));
        av_buffer_unref(&hw_frames_ref);
        throw;
    }
    ctx->hw_frames_ctx = av_buffer_ref(hw_frames_ref);
    if (!ctx->hw_frames_ctx)
        err = AVERROR(ENOMEM);

    av_buffer_unref(&hw_frames_ref);
    return err;
}


    


    /* Add an output stream. */
static void add_video_stream(
    OutputStream* ost,
    AVFormatContext* oc,
    const AVCodec** codec,
    enum AVCodecID  codec_id,
    int width,
    int height
) {
    AVCodecContext* c;
    int             i;
    bool            nvenc = false;

    /* find the encoder */
    if (ENABLE_NVENC) {
        printf("Getting nvenc encoder\n");
        *codec = avcodec_find_encoder_by_name("h264_nvenc");
        nvenc  = true;
    }
    
    if (!ENABLE_NVENC || *codec == NULL) {
        printf("Getting standard encoder\n");
        avcodec_find_encoder(codec_id);
        nvenc = false;
    }
    if (!(*codec)) {
        fprintf(stderr, "Could not find encoder for '%s'\n",
                avcodec_get_name(codec_id));
        exit(1);
    }

    ost->st = avformat_new_stream(oc, NULL);
    if (!ost->st) {
        fprintf(stderr, "Could not allocate stream\n");
        exit(1);
    }
    ost->st->id = oc->nb_streams - 1;
    c           = avcodec_alloc_context3(*codec);
    if (!c) {
        fprintf(stderr, "Could not alloc an encoding context\n");
        exit(1);
    }
    ost->enc = c;

    printf("Using video codec %s\n", avcodec_get_name(codec_id));

    c->codec_id = codec_id;
    c->bit_rate = 4000000;
    /* Resolution must be a multiple of two. */
    c->width  = STREAM_WIDTH;
    c->height = STREAM_HEIGHT;
    /* timebase: This is the fundamental unit of time (in seconds) in terms
        * of which frame timestamps are represented. For fixed-fps content,
        * timebase should be 1/framerate and timestamp increments should be
        * identical to 1. */
    ost->st->time_base = {1, STREAM_FRAME_RATE};
    c->time_base       = ost->st->time_base;
    c->gop_size = 12; /* emit one intra frame every twelve frames at most */

    if (nvenc && USE_D3D11) {
        const std::string hw_device_name = "d3d11va";
        AVHWDeviceType    device_type    = av_hwdevice_find_type_by_name(hw_device_name.c_str());

        // set up hw device context
        AVBufferRef *hw_device_ctx;
        // const char*  device = "0"; // Default GPU (may be integrated in the case of switchable graphics!)
        const char*  device = "1";
        ret = av_hwdevice_ctx_create(&hw_device_ctx, device_type, device, nullptr, 0);

        if (ret < 0) {
            fprintf(stderr, "Could not create hwdevice context; %s", av_err2str(ret));
        }

        set_hwframe_ctx(c, hw_device_ctx);
        c->pix_fmt = AV_PIX_FMT_D3D11;
    } else if (nvenc && !USE_D3D11)
        c->pix_fmt = AV_PIX_FMT_BGR0;
    else
        c->pix_fmt = STREAM_PIX_FMT;

    if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
        /* just for testing, we also add B-frames */
        c->max_b_frames = 2;
    }

    if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
        /* Needed to avoid using macroblocks in which some coeffs overflow.
            * This does not happen with normal video, it just happens here as
            * the motion of the chroma plane does not match the luma plane. */
        c->mb_decision = 2;
    }

    /* Some formats want stream headers to be separate. */
    if (oc->oformat->flags & AVFMT_GLOBALHEADER)
        c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}


    


  • How to averagely extract frames from a video using ffmpeg by specifying "fps"

    14 juin 2021, par alanzzz

    I have a job of using ffmpeg to extract the frames averagely from a video, with different fps. I use this command for it.

    


    ffmpeg -i input.mp4 -r specified_fps -q:v 2 image %4d.png

    


    And I have 3 questions about this task.

    


      

    1. what I expect is that if I double the fps, the number of extracted frames will also get doubled. However, that's not the case. Take one of the input videos as an example.
    2. 


    


    video info

    


      

    • Duration : 1min18s
    • 


    • Total number of frames : 2340
    • 


    • Frame rate mode : constant (CFR)
    • 


    • Frame rate : 30.0 FPS
    • 


    


    Config setting & results

    


      

    • FPS=1 => number of frames=80
    • 


    • FPS=2 => number of frames=158 (2x80-2)
    • 


    • FPS=3 => number of frames=236 (3x80-4)
    • 


    • FPS=5 => number of frames=392 (5x80-8)
    • 


    


    Is it possible for me to get the exact doubled number of frames when fps get doubled ? In such case, number of frames is 160 for FPS=2, 240 for FPS=3, 400 for FPS=5.

    


      

    1. I check for the output images, the extracted frames in different fps are totally different from each other. In other words, for example, the 1st image for fps=1 is not the same as the 1st image for fps=2. Is that legitimate ? And is it possible for me the get some identical images for different fps ?

      


    2. 


    3. The last problem is that for some videos I use, the difference between the 1st and 2nd image is different from the difference between the 2nd and 3rd. While for the remaining images, the differences become average. To be specific, there is only a slight change from 1st to 2nd frame, while for 2nd to 3rd, 3rd to 4th, and so on, the changes are the same, which is normally distributed according to the specified FPS. I am wondering why such a case happens ? Does it related to the I-frame, B-frame, P-frame, GOP or IDR ?

      


    4. 


    


    I am new to this field and cannot find some useful info from other places. I've tried my best to describe my questions clearly. Feel free to leave some comments. Any help would do me a great favor. Thanks in advance !

    


  • Revert "avcodec : add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common...

    24 décembre 2020, par Andreas Rheinhardt
    Revert "avcodec : add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common_init()"
    

    This mostly reverts commit 4b2863ff01b1fe93d9a518523c9098d17a9d8c6f.
    Said commit removed the freeing code from ff_mpv_common_init(),
    ff_mpv_common_frame_size_change() and ff_mpeg_framesize_alloc() and
    instead added the FF_CODEC_CAP_INIT_CLEANUP to several codecs that use
    ff_mpv_common_init(). This introduced several bugs :

    a) Several decoders using ff_mpv_common_init() in their init function were
    forgotten : This affected FLV, Intel H.263, RealVideo 3.0 and V4.0 as well as
    VC-1/WMV3.
    b) ff_mpv_common_init() is not only called from the init function of
    codecs, it is also called from AVCodec.decode functions. If an error
    happens after an allocation has succeeded, it can lead to memleaks ;
    furthermore, it is now possible for the MpegEncContext to be marked as
    initialized even when ff_mpv_common_init() returns an error and this can
    lead to segfaults because decoders that call ff_mpv_common_init() when
    decoding a frame can mistakenly think that the MpegEncContext has been
    properly initialized. This can e.g. happen with H.261 or MPEG-4.
    c) Removing code for freeing from ff_mpeg_framesize_alloc() (which can't
    be called from any init function) can lead to segfaults because the
    check for whether it needs to allocate consists of checking whether the
    first of the buffers allocated there has been allocated. This part has
    already been fixed in 76cea1d2ce3f23e8131c8664086a1daf873ed694.
    d) ff_mpv_common_frame_size_change() can also not be reached from any
    AVCodec.init function ; yet the changes can e.g. lead to segfaults with
    decoders using ff_h263_decode_frame() upon allocation failure, because
    the MpegEncContext will upon return be flagged as both initialized and
    not in need of reinitialization (granted, the fact that
    ff_h263_decode_frame() clears context_reinit before the context has been
    reinited is a bug in itself). With the earlier version, the context
    would be cleaned upon failure and it would be attempted to initialize
    the context again in the next call to ff_h263_decode_frame().

    While a) could be fixed by adding the missing FF_CODEC_CAP_INIT_CLEANUP,
    keeping the current approach would entail adding cleanup code to several
    other places because of b). Therefore ff_mpv_common_init() is again made
    to clean up after itself ; the changes to the wmv2 decoder and the SVQ1
    encoder have not been reverted : The former fixed a memleak, the latter
    allowed to remove cleanup code.

    Fixes : double free
    Fixes : ff_free_picture_tables.mp4
    Fixes : ff_mpeg_update_thread_context.mp4
    Fixes : decode_colskip.mp4
    Fixes : memset.mp4

    Reviewed-by : Michael Niedermayer <michael@niedermayer.cc>
    Signed-off-by : Andreas Rheinhardt <andreas.rheinhardt@gmail.com>

    • [DH] libavcodec/h261dec.c
    • [DH] libavcodec/h263dec.c
    • [DH] libavcodec/mpeg12dec.c
    • [DH] libavcodec/mpeg4videodec.c
    • [DH] libavcodec/mpegvideo.c
    • [DH] libavcodec/msmpeg4dec.c
    • [DH] libavcodec/rv10.c