Recherche avancée

Médias (29)

Mot : - Tags -/Musique

Autres articles (21)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

  • Encoding and processing into web-friendly formats

    13 avril 2011, par

    MediaSPIP automatically converts uploaded files to internet-compatible formats.
    Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
    Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
    Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
    All uploaded files are stored online in their original format, so you can (...)

  • Ajouter notes et légendes aux images

    7 février 2011, par

    Pour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
    Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
    Modification lors de l’ajout d’un média
    Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...)

Sur d’autres sites (4776)

  • FFMPEG (C++) convert & compress a single image out of buffer

    27 mars 2018, par MrEinsa

    i try to encode (with compression) and decode (without compression) a image with ffmpeg. But if i want to get the sent image back with avcodec_receive_packet i get only the error AVERROR(EAGAIN).

    It doesnt matter what i change ... allways AVERROR(EAGAIN) is the outcome. Is it maybe a problem of sending just one single frame to the encoder ? And if yes, how to fix it ?

    Code (only relevant stuff shown) :

           avcodec_register_all();


       /* ------ init codec ------------------*/
       AVCodec *codec;
       codec = avcodec_find_decoder(AV_CODEC_ID_H264);
       if (!codec)
       {
           print("compressH264, could not find decoder:\"AV_CODEC_ID_H264\"!!!");
           return false;
       }

       AVCodec *nVidiaCodec = avcodec_find_encoder_by_name("h264_nvenc");
       if (!nVidiaCodec)
       {
           print("err");
       }
       /* ------ ------------ ------------------*/

       /* ------ init context ------------------*/
       AVCodecContext* av_codec_context_ = NULL;
       av_codec_context_ = avcodec_alloc_context3(nVidiaCodec);
       if (!av_codec_context_)
       {
           print("compressH264, avcodec_alloc_context3 failed!!!");
           return false;
       }
       int w = imgSrc.width();
       int h = imgSrc.height();
       if ((w % 2) != 0)
       {
           ++w;
       }
       if ((h % 2) != 0)
       {
           ++h;
       }
       av_codec_context_->width = w;
       av_codec_context_->height = h;
       av_codec_context_->pix_fmt = AV_PIX_FMT_YUV420P;
       av_codec_context_->gop_size = 1;
       av_codec_context_->max_b_frames = 1;
       av_codec_context_->bit_rate = 400000;
       av_codec_context_->time_base.den = 1;
       av_codec_context_->time_base.num = 1;

       av_opt_set(av_codec_context_->priv_data, "preset", "slow", 0);

       int ret = avcodec_open2(av_codec_context_, nVidiaCodec, NULL);
       if (0 > ret)
       {
           print("compressH264, could not open codec context for decoder:\"AV_CODEC_ID_H264\"!!!");
           return false;
       }


       AVFrame *picture = av_frame_alloc();
       picture->format = AV_PIX_FMT_RGB24;
       picture->width = w;
       picture->height = h;

       ret = avpicture_fill((AVPicture *)picture, imgSrc.bits(), AV_PIX_FMT_RGB24, w, h);
       if (0 > ret)
       {
           print("compressH264, avpicture_fill - failed!!!");
           return false;
       }

       AVFrame *tmp_picture = av_frame_alloc();
       tmp_picture->format = AV_PIX_FMT_YUV420P;
       tmp_picture->width = w;
       tmp_picture->height = h;

       ret = av_frame_get_buffer(tmp_picture, 32);

       SwsContext *img_convert_ctx = sws_getContext(av_codec_context_->width, av_codec_context_->height, AV_PIX_FMT_RGB24, av_codec_context_->width, av_codec_context_->height, av_codec_context_->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL);

       ret = sws_scale(img_convert_ctx, picture->data, picture->linesize, 0, av_codec_context_->height, tmp_picture->data, tmp_picture->linesize);

       int h264Size = avpicture_get_size(AV_PIX_FMT_YUV420P, w, h);

       ret = avcodec_send_frame(av_codec_context_, tmp_picture);
       if (0 > ret)
       {
           char err[AV_ERROR_MAX_STRING_SIZE];
           av_make_error_string(err, AV_ERROR_MAX_STRING_SIZE, ret);
           print("compressH264, avcodec_send_frame: %s", err);
       }


       AVPacket *pkt = av_packet_alloc();

       while (ret >= 0)
       {
           ret = avcodec_receive_packet(av_codec_context_, pkt);
           if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
           {
               break;
           }
           else if (ret < 0)
           {
               fprintf(stderr, "Error during encoding\n");
               exit(1);
           }
           av_packet_unref(pkt);
       }
       print("success");

    Everything works well until :
    - avcodec_receive_packet ... i get all time the error AVERROR(EAGAIN).

    I can start decoding just if i have the compressed image.

    Thanks for your help guys.

    Edit :
    If i do now the following code, i get a packet and ret == 0, but i have to send 46 times the same image ... for me this makes no sence.

           do
       {
           ret = avcodec_receive_packet(av_codec_context_, &pkt);
           if (ret == 0)
           {
               break;
           }
           else if ((ret < 0) && (ret != AVERROR(EAGAIN)))
           {
               coutF("error");
           }
           else if (ret == AVERROR(EAGAIN))
           {
               ret = avcodec_send_frame(av_codec_context_, tmp_picture);
               if (0 > ret)
               {
                   char err[AV_ERROR_MAX_STRING_SIZE];
                   av_make_error_string(err, AV_ERROR_MAX_STRING_SIZE, ret);
                   coutFRed("compressH264, avcodec_send_frame: %s", err);
               }
               coutF("cnt:%d", ++cnt);
           }

       } while (ret == 0);

    Edit :

    Good morning,

    after more invest, i got the issue. I have to send the same frame a lot of time, because of the keyframe stuff for h264. The question now is, if it is possible to remove the h264 standart stuff from the encoder and just let FFMPEG convert one single frame.

  • Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead

    28 février 2018, par user1496491

    I’m using C API of MMPEG and getting this message. So I added time_base to my stream

    videoStream = avformat_new_stream(formatContext, codec);
    videoStream->time_base = AVRational{1, fps};

    and got rid of it in context

    codecContext->bit_rate = 400000;
    codecContext->width = width;
    codecContext->height = height;
    codecContext->gop_size = 10;
    codecContext->max_b_frames = 1;
    //codecContext->time_base = AVRational{1, fps};
    codecContext->pix_fmt = AV_PIX_FMT_YUV420P;

    avcodec_open2(codecContext, codec, NULL) immediately breaks

    WHY ? Do I need to apply the value to both of them ? I’ve duplicated values to both, and the message gone. But isn’t it just wrong ?

  • FFmpeg live streaming RGB frame buffer

    23 février 2018, par Mher Didaryan

    When we have a local video file This code works for streaming. What we want to achieve is to change input file with RGB frame buffer that we grab from screen. The code below uses input file’s time_base for PTS and DTS calculation.

    if(pkt.stream_index==videoindex) {
       AVRational time_base=ifmt_ctx->streams[videoindex]->time_base;
       AVRational time_base_q={1,AV_TIME_BASE};
       int64_t pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);
       int64_t now_time = av_gettime() - start_time;
       if (pts_time > now_time)
           av_usleep(pts_time - now_time);
    }

    in_stream  = ifmt_ctx->streams[pkt.stream_index];
    out_stream = ofmt_ctx->streams[pkt.stream_index];
    /* copy packet */
    //Convert PTS/DTS
    pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
    pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
    pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);

    Following this answer which increments PTS value by one for every frame VideoSt.Frame->pts = VideoSt.NextPts++; saving in local file or streaming to Wowza server works (low quality) but fails on Youtube and Twitch. av_interleaved_write_frame function returns error -22. To improve quality we lowered qmin and qmax values but the bit-rate of video increased too much (30Mb/s and even more for HD video).

    VideoSt.Ctx->codec_id = VideoCodec->id;
    VideoSt.Ctx->width = ViewportSize.X;
    VideoSt.Ctx->height = ViewportSize.Y;
    VideoSt.Stream->time_base = VideoSt.Ctx->time_base = { 1, 30 };
    VideoSt.Ctx->time_base = timeBase;
    VideoSt.Ctx->gop_size = 60;
    VideoSt.Ctx->bit_rate = 400000;
    VideoSt.Ctx->pix_fmt = AV_PIX_FMT_YUV420P;
    VideoSt.Ctx->qmin = 1;
    VideoSt.Ctx->qmax = 2;
    VideoSt.Ctx->max_qdiff = 3;
    VideoSt.Ctx->qcompress = 1.0f;

    How can we stream lossless quality video with reasonable bit-rate using flv1 codec ? If streaming to Youtube or Twitch fails is it just a problem with requirements of this services or there’s an issue with encoding ?

    Regarding error code -22 there’s a detailed explanation which explains how we should increment PTS and DTS values.

    In which cases calculating PTS and DTS values are necessary ?

    And by the way what are these PTS and DTS ? After reading many posts and Understanding PTS and DTS in video frames accepted answer I still do not understand.