Recherche avancée

Médias (0)

Mot : - Tags -/gis

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (45)

  • 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

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

Sur d’autres sites (6203)

  • Memory Leak in c++/cli application

    10 décembre 2013, par Ankush

    I am passing bitmap from my c# app to c++/cli dll that add it to video.
    The problem is program slowly leaking memory. I tried _CrtDumpMemoryLeaks() shows me leak of bitmap & another 40 byte leak but i am disposing bitmap.
    Can anyone see memory leak, Here is code..

    Flow :

    1) Capture screenshot by takescreenshot()

    2) pass it to c++/cli function

    3) dispose bitmap

    lines from my c# app

    Bitmap snap = takescreeshot();
    vencoder.AddBitmap(snap);
    snap.Dispose();
    vencoder.printleak();

    private static Bitmap takescreeshot()
       {
           System.Drawing.Bitmap bitmap = null;
           System.Drawing.Graphics graphics = null;

           bitmap = new Bitmap
           (
               System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
               System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height,
               System.Drawing.Imaging.PixelFormat.Format24bppRgb
           );

           graphics = System.Drawing.Graphics.FromImage(bitmap);

           graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size);

           //Write TimeSpamp
           Rectangle rect = new Rectangle(1166, 738, 200, 20);
           String datetime= System.String.Format("{0:dd:MM:yy  hh:mm:ss}",DateTime.Now);
           System.Drawing.Font sysfont = new System.Drawing.Font("Times New Roman", 14, FontStyle.Bold);
           graphics.DrawString(datetime, sysfont, Brushes.Red,rect);
           //

           Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
           Bitmap grayImage = filter.Apply(bitmap);

           //Dispose
           bitmap.Dispose();
           graphics.Dispose();

           return grayImage;
       }

    now in c++/cli dll

    bool VideoEncoder::AddBitmap(Bitmap^ bitmap)
       {
           BitmapData^ bitmapData = bitmap->LockBits( System::Drawing::Rectangle( 0, 0,bitmap->Width, bitmap->Height ),ImageLockMode::ReadOnly,PixelFormat::Format8bppIndexed);
           uint8_t* ptr = reinterpret_cast( static_cast( bitmapData->Scan0 ) );
           uint8_t* srcData[4] = { ptr, NULL, NULL, NULL };
           int srcLinesize[4] = { bitmapData->Stride, 0, 0, 0 };

           pCurrentPicture = CreateFFmpegPicture(pVideoStream->codec->pix_fmt, pVideoStream->codec->width, pVideoStream->codec->height);

           sws_scale(pImgConvertCtx, srcData, srcLinesize, 0, bitmap->Height, pCurrentPicture->data, pCurrentPicture->linesize );

           bitmap->UnlockBits( bitmapData );

           write_video_frame();

           bitmapData=nullptr;
           ptr=NULL;

           return true;
       }

    AVFrame * VideoEncoder::CreateFFmpegPicture(int pix_fmt, int nWidth, int nHeight)
       {

         AVFrame *picture     = NULL;
         uint8_t *picture_buf = NULL;
         int size;

         picture = avcodec_alloc_frame();
         if ( !picture)
         {
           printf("Cannot create frame\n");
           return NULL;
         }

         size = avpicture_get_size((AVPixelFormat)pix_fmt, nWidth, nHeight);

         picture_buf = (uint8_t *) av_malloc(size);

         if (!picture_buf)
         {
           av_free(picture);
           printf("Cannot allocate buffer\n");
           return NULL;
         }

         avpicture_fill((AVPicture *)picture, picture_buf,
           (AVPixelFormat)pix_fmt, nWidth, nHeight);

         return picture;
       }

       void VideoEncoder::write_video_frame()
       {
           AVCodecContext* codecContext = pVideoStream->codec;

           int out_size, ret = 0;

           if ( pFormatContext->oformat->flags & AVFMT_RAWPICTURE )
           {
               printf( "raw picture must be written" );
           }
           else
           {
               out_size = avcodec_encode_video( codecContext, pVideoEncodeBuffer,nSizeVideoEncodeBuffer, pCurrentPicture );

               if ( out_size > 0 )
               {
                   AVPacket packet;
                   av_init_packet( &packet );

                   if ( codecContext->coded_frame->pts != AV_NOPTS_VALUE )
                   {
                       packet.pts = av_rescale_q( packet.pts, codecContext->time_base, pVideoStream->time_base );
                   }

                   if ( codecContext->coded_frame->pkt_dts != AV_NOPTS_VALUE )
                   {
                       packet.dts = av_rescale_q( packet.dts, codecContext->time_base, pVideoStream->time_base );
                   }

                   if ( codecContext->coded_frame->key_frame )
                   {
                       packet.flags |= AV_PKT_FLAG_KEY;
                   }

                   packet.stream_index = pVideoStream->index;
                   packet.data = pVideoEncodeBuffer;
                   packet.size = out_size;

                   ret = av_interleaved_write_frame( pFormatContext, &packet );

                   av_free_packet(&packet);
                   av_freep(pCurrentPicture);
               }
               else
               {
                   // image was buffered
               }
           }

           if ( ret != 0 )
           {
               throw gcnew Exception( "Error while writing video frame." );
           }
       }


       void VideoEncoder::printleak()
       {
           printf("No of leaks: %d",_CrtDumpMemoryLeaks());
           printf("\n");
       }
  • FFMPEG libx265 encoding leaves memory unfreed after avcodec_free_context

    28 août 2020, par ahugeat

    I am working on H265 encoding software and, in my unit tests, I have some weird memory leaks. To found them, I have modified the encode_video.c example from FFMPEG documentation. I have changed the resolution to correspond at a 4K video, I have adapted the bitrate and I have added a pause before context allocation and another one before the final return :

    


    #include &#xA;#include &#xA;#include &#xA;#include &#xA;&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;&#xA;static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,&#xA;                   FILE *outfile)&#xA;{&#xA;    int ret;&#xA;&#xA;    /* send the frame to the encoder */&#xA;    if (frame)&#xA;        printf("Send frame %3"PRId64"\n", frame->pts);&#xA;&#xA;    ret = avcodec_send_frame(enc_ctx, frame);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Error sending a frame for encoding\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    while (ret >= 0) {&#xA;        ret = avcodec_receive_packet(enc_ctx, pkt);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;            return;&#xA;        else if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error during encoding\n");&#xA;            exit(1);&#xA;        }&#xA;&#xA;        printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);&#xA;        fwrite(pkt->data, 1, pkt->size, outfile);&#xA;        av_packet_unref(pkt);&#xA;    }&#xA;}&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    const char *filename, *codec_name;&#xA;    const AVCodec *codec;&#xA;    AVCodecContext *c= NULL;&#xA;    int i, ret, x, y;&#xA;    FILE *f;&#xA;    AVFrame *frame;&#xA;    AVPacket *pkt;&#xA;    uint8_t endcode[] = { 0, 0, 1, 0xb7 };&#xA;&#xA;    if (argc &lt;= 2) {&#xA;        fprintf(stderr, "Usage: %s <output file="file"> <codec>\n", argv[0]);&#xA;        exit(0);&#xA;    }&#xA;    filename = argv[1];&#xA;    codec_name = argv[2];&#xA;&#xA;    sleep(10);&#xA;&#xA;    /* find the mpeg1video encoder */&#xA;    codec = avcodec_find_encoder_by_name(codec_name);&#xA;    if (!codec) {&#xA;        fprintf(stderr, "Codec &#x27;%s&#x27; not found\n", codec_name);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    c = avcodec_alloc_context3(codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not allocate video codec context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    pkt = av_packet_alloc();&#xA;    if (!pkt)&#xA;        exit(1);&#xA;&#xA;    /* put sample parameters */&#xA;    c->bit_rate = 1000000;&#xA;    /* resolution must be a multiple of two */&#xA;    c->width = 3840;&#xA;    c->height = 2160;&#xA;    /* frames per second */&#xA;    c->time_base = (AVRational){1, 25};&#xA;    c->framerate = (AVRational){25, 1};&#xA;&#xA;    /* emit one intra frame every ten frames&#xA;     * check frame pict_type before passing frame&#xA;     * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I&#xA;     * then gop_size is ignored and the output of encoder&#xA;     * will always be I frame irrespective to gop_size&#xA;     */&#xA;    c->gop_size = 10;&#xA;    c->max_b_frames = 1;&#xA;    c->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;&#xA;    if (codec->id == AV_CODEC_ID_H264)&#xA;        av_opt_set(c->priv_data, "preset", "slow", 0);&#xA;&#xA;    /* open it */&#xA;    ret = avcodec_open2(c, codec, NULL);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    f = fopen(filename, "wb");&#xA;    if (!f) {&#xA;        fprintf(stderr, "Could not open %s\n", filename);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame = av_frame_alloc();&#xA;    if (!frame) {&#xA;        fprintf(stderr, "Could not allocate video frame\n");&#xA;        exit(1);&#xA;    }&#xA;    frame->format = c->pix_fmt;&#xA;    frame->width  = c->width;&#xA;    frame->height = c->height;&#xA;&#xA;    ret = av_frame_get_buffer(frame, 0);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Could not allocate the video frame data\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* encode 1 second of video */&#xA;    for (i = 0; i &lt; 25; i&#x2B;&#x2B;) {&#xA;        fflush(stdout);&#xA;&#xA;        /* make sure the frame data is writable */&#xA;        ret = av_frame_make_writable(frame);&#xA;        if (ret &lt; 0)&#xA;            exit(1);&#xA;&#xA;        /* prepare a dummy image */&#xA;        /* Y */&#xA;        for (y = 0; y &lt; c->height; y&#x2B;&#x2B;) {&#xA;            for (x = 0; x &lt; c->width; x&#x2B;&#x2B;) {&#xA;                frame->data[0][y * frame->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;            }&#xA;        }&#xA;&#xA;        /* Cb and Cr */&#xA;        for (y = 0; y &lt; c->height/2; y&#x2B;&#x2B;) {&#xA;            for (x = 0; x &lt; c->width/2; x&#x2B;&#x2B;) {&#xA;                frame->data[1][y * frame->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;                frame->data[2][y * frame->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;            }&#xA;        }&#xA;&#xA;        frame->pts = i;&#xA;&#xA;        /* encode the image */&#xA;        encode(c, frame, pkt, f);&#xA;    }&#xA;&#xA;    /* flush the encoder */&#xA;    encode(c, NULL, pkt, f);&#xA;&#xA;    /* add sequence end code to have a real MPEG file */&#xA;    if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)&#xA;        fwrite(endcode, 1, sizeof(endcode), f);&#xA;    fclose(f);&#xA;&#xA;    avcodec_free_context(&amp;c);&#xA;    av_frame_free(&amp;frame);&#xA;    av_packet_free(&amp;pkt);&#xA;&#xA;    sleep(10);&#xA;&#xA;    return 0;&#xA;}&#xA;</codec></output>

    &#xA;

    I was expecting that the RAM memory usage at the first pause is the same as the second pause but there is about 55 Mo of difference. If I increase the number of encoded frames, this difference up to 390 Mo. I have tested this code under Linux Mint LMDE 4 (roughly same as Debian 10).

    &#xA;

    I guess this memory "leak" it isn't a real memory leak but that it's some internal values used by libx265 to be maybe reused for another encoding. But has there a way to free this memory through FFMPEG API ?

    &#xA;

  • FFMpeg DVB Subtitles memory leak

    13 janvier 2015, par WLGfx

    When decoding the subtitles track from an mpegts udp mutlicast stream I am getting a memory leak using avcodec_decode_subtitle2. The audio and video streams are fine. And all three streams are manually memory managed by pre-allocating all buffers.

    There’s very little information about but I do believe there’s a patch somewhere.

    I’m currently using ffmpeg 2.0.4 compiled for armv7-a for android.

    In the process I’ve found that video streams are different resolutions, ie, 720x576 or 576x576 which doesn’t matter now as I am rendering the subtitles separately as an overlay on the video. My original decoding function (which is changing to render a separate overlay) is :

    void ffProcessSubtitlePacket( AVPacket *pkt )
    {
       //LOGI("NATIVE FFMPEG SUBTITLE - Decoding subtitle packet");

       int got = 0;

       avcodec_decode_subtitle2(ffSubtitleContext, &amp;ffSubtitleFrame, &amp;got, pkt);

       if ( got )
       {
           //LOGI("NATIVE FFMPEG SUBTITLE - Got subtitle frame");
           //LOGI("NATIVE FFMPEG SUBTITLE - Format = %d, Start = %d, End = %d, Rects = %d, PTS = %llu, AudioPTS = %llu, PacketPTS = %llu",
           //      ffSubtitleFrame.format, ffSubtitleFrame.start_display_time,
           //      ffSubtitleFrame.end_display_time, ffSubtitleFrame.num_rects,
           //      ffSubtitleFrame.pts, ffAudioGetPTS(), pkt->pts);

           // now add the subtitle data to the list ready

           for ( int s = 0; s &lt; ffSubtitleFrame.num_rects; s++ )
           {
               ffSubtitle *sub = (ffSubtitle*)mmAlloc(sizeof(ffSubtitle)); //new ffSubtitle;

               if ( sub )
               {
                   AVSubtitleRect *r = ffSubtitleFrame.rects[s];
                   AVPicture *p = &amp;r->pict;

                   // set main data

                   sub->startPTS   = pkt->pts + (uint64_t)ffSubtitleFrame.start_display_time;
                   sub->endPTS     = pkt->pts + (uint64_t)ffSubtitleFrame.end_display_time * (uint64_t)500;
                   sub->nb_colors  = r->nb_colors;
                   sub->xpos       = r->x;
                   sub->ypos       = r->y;
                   sub->width      = r->w;
                   sub->height     = r->h;

                   // allocate space for CLUT and image all in one chunk

                   sub->data       = mmAlloc(r->nb_colors * 4 + r->w * r->h); //new char[r->nb_colors * 4 + r->w * r->h];

                   if ( sub->data )
                   {
                       // copy the CLUT data

                       memcpy(sub->data, p->data[1], r->nb_colors * 4);

                       // copy the bitmap onto the end

                       memcpy(sub->data + r->nb_colors * 4, p->data[0], r->w * r->h);

                       // check for duplicate subtitles and remove them as this
                       // one replaces it with a new bitmap data

                       int pos = ffSubtitles.size();

                       while ( pos-- )
                       {
                           ffSubtitle *s = ffSubtitles[pos];
                           if ( s->xpos == sub->xpos &amp;&amp;
                                s->ypos == sub->ypos &amp;&amp;
                                s->width == sub->width &amp;&amp;
                                s->height == sub->height )
                           {
                               //delete s;
                               ffSubtitles.erase( ffSubtitles.begin() + pos );

                               //LOGI("NATIVE FFMPEG SUBTITLE - Removed old duplicate subtitle, size %d", ffSubtitles.size());
                           }
                       }

                       // append to subtitles list

                       ffSubtitles.push_back( sub );

                       char *dat;  // data pointer used for the CLUT table

                       //LOGI("NATIVE FFMPEG SUBTITLE - Added %d,%d - %d,%d, Queue %d, Length = %d",
                       //  r->x, r->y, r->w, r->h, ffSubtitles.size(), ffSubtitleFrame.end_display_time);

                       // convert the CLUT (RGB) to YUV values

                       dat = sub->data;

                       for ( int c = 0; c &lt; r->nb_colors; c++ )
                       {
                           int r = dat[0];
                           int g = dat[1];
                           int b = dat[2];

                           int y = ( (  65 * r + 128 * g +  24 * b + 128) >> 8) +  16;
                           int u = ( ( -37 * r -  74 * g + 112 * b + 128) >> 8) + 128;
                           int v = ( ( 112 * r -  93 * g -  18 * b + 128) >> 8) + 128;

                           *dat++ = (char)y;
                           *dat++ = (char)u;
                           *dat++ = (char)v;
                           dat++;  // skip the alpha channel
                       }
                   }
                   else
                   {
                       //delete sub;
                       sub = 0;
                       LOGI("NATIVE FFMPEG SUBTITLE - Memory allocation error CLUT and BITMAP");
                   }
               }
               else
               {
                   LOGI("NATIVE FFMPEG SUBTITLE - Memory allocation error ffSubtitle struct");
                   mmGarbageCollect();
                   ffSubtitles.clear();
               }
           }
       }
    }

    void ffSubtitleRenderCheck(int bpos)
    {
       if ( ffSubtitleID == -1 || !usingSubtitles )
       {
           // empty the list in case of memory leaks

           ffSubtitles.clear();
           mmGarbageCollect();
           return;
       }

       uint64_t audioPTS = ffAudioGetPTS();
       int pos = 0;

       // draw the subtitle list to the YUV frames

       char *yframe = ffVideoBuffers[bpos].yFrame;
       char *uframe = ffVideoBuffers[bpos].uFrame;
       char *vframe = ffVideoBuffers[bpos].vFrame;

       int ywidth = fv.frameActualWidth;   // actual width with padding
       int uvwidth = fv.frameAWidthHalf;   // and for uv frames

       while ( pos &lt; ffSubtitles.size() )
       {
           ffSubtitle *sub = ffSubtitles[pos];

           if ( sub->startPTS >= audioPTS ) // okay to draw this one?
           {
               //LOGI("NATIVE FFMPEG SUBTITLE - Rendering subtitle bitmap %d", pos);

               char *clut = sub->data;     // colour table
               char *dat = clut + sub->nb_colors * 4; // start of bitmap data

               int w = sub->width;
               int h = sub->height;
               int x = sub->xpos;
               int y = sub->ypos;

               for ( int xpos = 0; xpos &lt; w; xpos++ )
               {
                   for ( int ypos = 0; ypos &lt; h; ypos++ )
                   {
                       // get colour for pixel
                       char bcol = dat[ypos * w + xpos];

                       if ( bcol != 0 )    // ignore 0 pixels
                       {
                           char cluty = clut[bcol * 4 + 0];    // get colours from CLUT
                           char clutu = clut[bcol * 4 + 1];
                           char clutv = clut[bcol * 4 + 2];

                           // draw to Y frame

                           int newx = x + xpos;
                           int newy = y + ypos;

                           yframe[newy * ywidth + newx] = cluty;

                           // draw to uv frames if we have a quarter pixel only

                           if ( ( newy &amp; 1 ) &amp;&amp; ( newx &amp; 1 ) )
                           {
                               uframe[(newy >> 1) * uvwidth + (newx >> 1)] = clutu;
                               vframe[(newy >> 1) * uvwidth + (newx >> 1)] = clutv;
                           }
                       }
                   }
               }
           }

           pos++;
       }

       // Last thing is to erase timed out subtitles

       pos = ffSubtitles.size();

       while ( pos-- )
       {
           ffSubtitle *sub = ffSubtitles[pos];

           if ( sub->endPTS &lt; audioPTS )
           {
               //delete sub;
               ffSubtitles.erase( ffSubtitles.begin() + pos );

               //LOGI("NATIVE FFMPEG SUBTITLE - Removed timed out subtitle");
           }
       }

       if ( ffSubtitles.size() == 0 )
       {
           // garbage collect the custom memory pool

           mmGarbageCollect();
       }

       //LOGI("NATIVE FFMPEG SUBTITLE - Size of subtitle list = %d", ffSubtitles.size());
    }

    Any information would be appreciated or would I have to upgrade to a later version of ffmpeg ?