Recherche avancée

Médias (1)

Mot : - Tags -/graphisme

Autres articles (47)

  • Librairies et logiciels spécifiques aux médias

    10 décembre 2010, par

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

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

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

  • Saving multiple public domain livestreams to disk using ffmpeg/vlc some other resource ?

    20 mars 2021, par Santino

    I am trying to save a few days' worths of video from open webcams to disk, so I can run some analytics on them. (for example this video of an airport. I have a few hundred of these, plus bandwidth & storage aren't an issue, how would I go about saving the streams for say 2-3 days ?

    


      

    1. I have tried to write a small bit of python code using pyav (wrapper around ffmpeg) to open the stream and save keyframes. But it seems the connection gets dropped after an hour or so...
    2. 


    3. I have looked into ffmpeg -i <some video="video" url="url"> output.mp4</some> but it exits abruptly without any error message.
    4. &#xA;

    5. I am able to play the videos in vlc, but not sure how I can proceed with saving the videos.
    6. &#xA;

    &#xA;

    Any ideas ?

    &#xA;

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

    &#xA;

    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 :

    &#xA;

    int write_gpu_video_frame(ID3D11Texture2D* gpuTex, AVFormatContext* oc, OutputStream* ost) {&#xA;    AVFrame *hw_frame = ost->hw_frame;&#xA;&#xA;    printf("gpuTex address = 0x%x\n", &amp;gpuTex);&#xA;&#xA;    hw_frame->data[0] = (uint8_t *) gpuTex;&#xA;    hw_frame->data[1] = (uint8_t *) (intptr_t) 0;&#xA;    hw_frame->pts     = ost->next_pts&#x2B;&#x2B;;&#xA;&#xA;    return write_frame(oc, ost->enc, ost->st, hw_frame);&#xA;    // write_frame is identical to sample code in ffmpeg repo&#xA;}&#xA;

    &#xA;

    Running the code with this modification gives the following error :

    &#xA;

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

    &#xA;


    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

    /* Add an output stream. */&#xA;static void add_video_stream(&#xA;    OutputStream* ost,&#xA;    AVFormatContext* oc,&#xA;    const AVCodec** codec,&#xA;    enum AVCodecID  codec_id,&#xA;    int width,&#xA;    int height&#xA;) {&#xA;    AVCodecContext* c;&#xA;    int             i;&#xA;    bool            nvenc = false;&#xA;&#xA;    /* find the encoder */&#xA;    if (ENABLE_NVENC) {&#xA;        printf("Getting nvenc encoder\n");&#xA;        *codec = avcodec_find_encoder_by_name("h264_nvenc");&#xA;        nvenc  = true;&#xA;    }&#xA;    &#xA;    if (!ENABLE_NVENC || *codec == NULL) {&#xA;        printf("Getting standard encoder\n");&#xA;        avcodec_find_encoder(codec_id);&#xA;        nvenc = false;&#xA;    }&#xA;    if (!(*codec)) {&#xA;        fprintf(stderr, "Could not find encoder for &#x27;%s&#x27;\n",&#xA;                avcodec_get_name(codec_id));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    ost->st = avformat_new_stream(oc, NULL);&#xA;    if (!ost->st) {&#xA;        fprintf(stderr, "Could not allocate stream\n");&#xA;        exit(1);&#xA;    }&#xA;    ost->st->id = oc->nb_streams - 1;&#xA;    c           = avcodec_alloc_context3(*codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not alloc an encoding context\n");&#xA;        exit(1);&#xA;    }&#xA;    ost->enc = c;&#xA;&#xA;    printf("Using video codec %s\n", avcodec_get_name(codec_id));&#xA;&#xA;    c->codec_id = codec_id;&#xA;    c->bit_rate = 4000000;&#xA;    /* Resolution must be a multiple of two. */&#xA;    c->width  = STREAM_WIDTH;&#xA;    c->height = STREAM_HEIGHT;&#xA;    /* timebase: This is the fundamental unit of time (in seconds) in terms&#xA;        * of which frame timestamps are represented. For fixed-fps content,&#xA;        * timebase should be 1/framerate and timestamp increments should be&#xA;        * identical to 1. */&#xA;    ost->st->time_base = {1, STREAM_FRAME_RATE};&#xA;    c->time_base       = ost->st->time_base;&#xA;    c->gop_size = 12; /* emit one intra frame every twelve frames at most */&#xA;&#xA;    if (nvenc &amp;&amp; USE_D3D11) {&#xA;        const std::string hw_device_name = "d3d11va";&#xA;        AVHWDeviceType    device_type    = av_hwdevice_find_type_by_name(hw_device_name.c_str());&#xA;&#xA;        // set up hw device context&#xA;        AVBufferRef *hw_device_ctx;&#xA;        // const char*  device = "0"; // Default GPU (may be integrated in the case of switchable graphics!)&#xA;        const char*  device = "1";&#xA;        ret = av_hwdevice_ctx_create(&amp;hw_device_ctx, device_type, device, nullptr, 0);&#xA;&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not create hwdevice context; %s", av_err2str(ret));&#xA;        }&#xA;&#xA;        set_hwframe_ctx(c, hw_device_ctx);&#xA;        c->pix_fmt = AV_PIX_FMT_D3D11;&#xA;    } else if (nvenc &amp;&amp; !USE_D3D11)&#xA;        c->pix_fmt = AV_PIX_FMT_BGR0;&#xA;    else&#xA;        c->pix_fmt = STREAM_PIX_FMT;&#xA;&#xA;    if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {&#xA;        /* just for testing, we also add B-frames */&#xA;        c->max_b_frames = 2;&#xA;    }&#xA;&#xA;    if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {&#xA;        /* Needed to avoid using macroblocks in which some coeffs overflow.&#xA;            * This does not happen with normal video, it just happens here as&#xA;            * the motion of the chroma plane does not match the luma plane. */&#xA;        c->mb_decision = 2;&#xA;    }&#xA;&#xA;    /* Some formats want stream headers to be separate. */&#xA;    if (oc->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;        c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;}&#xA;

    &#xA;

  • cuda invalid resource handle when using h264_cuvid decoder in my C program [closed]

    29 juillet 2021, par ChrisFisher

    I try to use GPU acceleration in my ffmpeg decode program, and I check the codecs of ffmpeg by command :ffmpeg -codecs | grep nv, and it shows that I can use h264_cuvid decoder(In fact, I have already used ffmpeg command line to encode and decode a test video with hardware acceleration and it turned out everything was all fine), but when I use the decoder in my program

    &#xA;

    AVCodec *pCodec = avcodec_find_decoder_by_name("h264_cuvid");

    &#xA;

    here is part of my program

    &#xA;

    void FFMPEGCodec::initDecoder()&#xA;{&#xA;    AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);&#xA;    if (!pCodec) {&#xA;        LOG("Codec decoder not found\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    pCodecCtx = avcodec_alloc_context3(pCodec);&#xA;    if (!pCodecCtx) {&#xA;        LOG("Could not allocate video codec context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    pCodecCtx->width = gConfig->totalWidth;&#xA;    pCodecCtx->height = gConfig->totalHeight;&#xA;    pCodecCtx->has_b_frames = 0;&#xA;&#xA;    if (avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0) {&#xA;        LOG("Could not open codec\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    if(_x264rgb){&#xA;        //used to convert GBRP frame to RGB image.&#xA;        convertCtx = sws_getContext(gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_GBRP, &#xA;        gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL); &#xA;    } else {&#xA;        //used to convert YUV frame to RGB image.&#xA;        convertCtx = sws_getContext(gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_YUV420P, &#xA;        gConfig->totalWidth, gConfig->totalHeight, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL); &#xA;    }&#xA;&#xA;    if(convertCtx == NULL){&#xA;        LOG("Failed to get SwsContext\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    //when using x264rgb, it&#x27;s actually GBRP frame, &#xA;    //just don&#x27;t want to define another variable&#xA;    yuvFrame = av_frame_alloc();&#xA;    if (!yuvFrame) {&#xA;        LOG("Failed to allocate yuv frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    rgbFrame = av_frame_alloc();&#xA;    if (!rgbFrame) {&#xA;        LOG("Failed to allocate rgb frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    rgbFrame->format = AV_PIX_FMT_RGB24;&#xA;    rgbFrame->width  = pCodecCtx->width;&#xA;    rgbFrame->height = pCodecCtx->height;&#xA; &#xA;    int ret = av_image_alloc(rgbFrame->data, rgbFrame->linesize, rgbFrame->width, rgbFrame->height,&#xA;                         AV_PIX_FMT_RGB24, 32);&#xA;    if (ret &lt; 0) {&#xA;        LOG("Failed to allocate raw picture buffer\n");&#xA;        exit(1);&#xA;    }&#xA;}   &#xA;

    &#xA;

    and

    &#xA;

    int FFMPEGCodec::decode(byte* pktData, int pktSize, byte* imgData)&#xA;{&#xA;    int ret = 0, got_packet = 0;&#xA;    AVPacket pkt;&#xA;    av_init_packet(&amp;pkt);&#xA;    pkt.data = pktData;&#xA;    pkt.size = pktSize;&#xA;&#xA;    // decode video frame&#xA;    ret = avcodec_decode_video2(pCodecCtx, yuvFrame, &amp;got_packet, &amp;pkt);&#xA;    if (ret &lt; 0) {&#xA;        LOG("Error decoding frame\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;    sws_scale(convertCtx, yuvFrame->data, yuvFrame->linesize, 0, pCodecCtx->height, rgbFrame->data, rgbFrame->linesize);&#xA;    &#xA;    if (got_packet) {&#xA;        int width = pCodecCtx->width, height = pCodecCtx->height;&#xA;        int fsize = rgbFrame->linesize[0] * rgbFrame->height;&#xA;        int size = 54 &#x2B; fsize;&#xA;&#xA;        byte bmp_file_header[14] = { &#x27;B&#x27;, &#x27;M&#x27;, 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, };&#xA;        byte bmp_info_header[40] = { 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0, };&#xA;        byte bmp_pad[3] = { 0, 0, 0 };&#xA;&#xA;        bmp_file_header[2] = (unsigned char)size;&#xA;        bmp_file_header[3] = (unsigned char)(size >> 8);&#xA;        bmp_file_header[4] = (unsigned char)(size >> 16);&#xA;        bmp_file_header[5] = (unsigned char)(size >> 24);&#xA;&#xA;        bmp_info_header[4] = (unsigned char)(width);&#xA;        bmp_info_header[5] = (unsigned char)(width >> 8);&#xA;        bmp_info_header[6] = (unsigned char)(width >> 16);&#xA;        bmp_info_header[7] = (unsigned char)(width >> 24);&#xA;        bmp_info_header[8] = (unsigned char)(height);&#xA;        bmp_info_header[9] = (unsigned char)(height >> 8);&#xA;        bmp_info_header[10] = (unsigned char)(height >> 16);&#xA;        bmp_info_header[11] = (unsigned char)(height >> 24);&#xA;&#xA;        memcpy(imgData, bmp_file_header, 14);&#xA;        memcpy(imgData &#x2B; 14, bmp_info_header, 40);&#xA;        memcpy(imgData &#x2B; 54, rgbFrame->data[0], fsize);&#xA;        ret = size;&#xA;    }&#xA;    av_free_packet(&amp;pkt);&#xA;&#xA;    return ret;&#xA;}&#xA;&#xA;

    &#xA;

    after compiling, I ran the program, and the decoder throw me a error :

    &#xA;

    ctx->cvdl->cuvidDecodePicture(ctx->cudecoder, picparams) failed -> CUDA_ERROR_INVALID_HANDLE: invalid resource handle&#xA;when calling the function avcodec_decode_video2

    &#xA;

    I don't know why this error occurred, by the way, I use a GTX1060 6G(Sorry I'm not a native English speaker)

    &#xA;