Recherche avancée

Médias (0)

Mot : - Tags -/content

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

Autres articles (56)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

  • Configurer la prise en compte des langues

    15 novembre 2010, par

    Accéder à la configuration et ajouter des langues prises en compte
    Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
    De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
    Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)

  • XMP PHP

    13 mai 2011, par

    Dixit Wikipedia, XMP signifie :
    Extensible Metadata Platform ou XMP est un format de métadonnées basé sur XML utilisé dans les applications PDF, de photographie et de graphisme. Il a été lancé par Adobe Systems en avril 2001 en étant intégré à la version 5.0 d’Adobe Acrobat.
    Étant basé sur XML, il gère un ensemble de tags dynamiques pour l’utilisation dans le cadre du Web sémantique.
    XMP permet d’enregistrer sous forme d’un document XML des informations relatives à un fichier : titre, auteur, historique (...)

Sur d’autres sites (5028)

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

  • Neutral net or neutered

    4 juin 2013, par Mans — Law and liberty

    In recent weeks, a number of high-profile events, in the UK and elsewhere, have been quickly seized upon to promote a variety of schemes for monitoring or filtering Internet access. These proposals, despite their good intentions of protecting children or fighting terrorism, pose a serious threat to fundamental liberties. Although at a glance the ideas may seem like a reasonable price to pay for the prevention of some truly hideous crimes, there is more than first meets the eye. Internet regulation in any form whatsoever is the thin end of a wedge at whose other end we find severely restricted freedom of expression of the kind usually associated with oppressive dictatorships. Where the Internet was once a novelty, it now forms an integrated part of modern society ; regulating the Internet means regulating our lives.

    Terrorism

    Following the brutal murder of British soldier Lee Rigby in Woolwich, attempts were made in the UK to revive the controversial Communications Data Bill, also dubbed the snooper’s charter. The bill would give police and security services unfettered access to details (excluding content) of all digital communication in the UK without needing so much as a warrant.

    The powers afforded by the snooper’s charter would, the argument goes, enable police to prevent crimes such as the one witnessed in Woolwich. True or not, the proposal would, if implemented, also bring about infrastructure for snooping on anyone at any time for any purpose. Once available, the temptation may become strong to extend, little by little, the legal use of these abilities to cover ever more everyday activities, all in the name of crime prevention, of course.

    In the emotional aftermath of a gruesome act, anything with the promise of preventing it happening again may seem like a good idea. At times like these it is important, more than ever, to remain rational and carefully consider all the potential consequences of legislation, not only the intended ones.

    Hate speech

    Hand in hand with terrorism goes hate speech, preachings designed to inspire violence against people of some singled-out nation, race, or other group. Naturally, hate speech is often to be found on the Internet, where it can reach large audiences while the author remains relatively protected. Naturally, we would prefer for it not to exist.

    To fulfil the utopian desire of a clean Internet, some advocate mandatory filtering by Internet service providers and search engines to remove this unwanted content. Exactly how such censoring might be implemented is however rarely dwelt upon, much less the consequences inadvertent blocking of innocent material might have.

    Pornography

    Another common target of calls for filtering is pornography. While few object to the blocking of child pornography, at least in principle, the debate runs hotter when it comes to the legal variety. Pornography, it is claimed, promotes violence towards women and is immoral or generally offensive. As such it ought to be blocked in the name of the greater good.

    The conviction last week of paedophile Mark Bridger for the abduction and murder of five-year-old April Jones renewed the debate about filtering of pornography in the UK ; his laptop was found to contain child pornography. John Carr of the UK government’s Council on Child Internet Safety went so far as suggesting a default blocking of all pornography, access being granted to an Internet user only once he or she had registered with some unspecified entity. Registering people wishing only to access perfectly legal material is not something we do in a democracy.

    The reality is that Google and other major search engines already remove illegal images from search results and report them to the appropriate authorities. In the UK, the Internet Watch Foundation, a non-government organisation, maintains a blacklist of what it deems ‘potentially criminal’ content, and many Internet service providers block access based on this list.

    While well-intentioned, the IWF and its blacklist should raise some concerns. Firstly, a vigilante organisation operating in secret and with no government oversight acting as the nation’s morality police has serious implications for freedom of speech. Secondly, the blocks imposed are sometimes more far-reaching than intended. In one incident, an attempt to block the cover image of the Scorpions album Virgin Killer hosted by Wikipedia (in itself a dubious decision) rendered the entire related article inaccessible as well as interfered with editing.

    Net neutrality

    Content filtering, or more precisely the lack thereof, is central to the concept of net neutrality. Usually discussed in the context of Internet service providers, this is the principle that the user should have equal, unfiltered access to all content. As a consequence, ISPs should not be held responsible for the content they deliver. Compare this to how the postal system works.

    The current debate shows that the principle of net neutrality is important not only at the ISP level, but should also include providers of essential services on the Internet. This means search engines should not be responsible for or be required to filter results, email hosts should not be required to scan users’ messages, and so on. No mandatory censoring can be effective without infringing the essential liberties of freedom of speech and press.

    Social networks operate in a less well-defined space. They are clearly not part of the essential Internet infrastructure, and they require that users sign up and agree to their terms and conditions. Because of this, they can include restrictions that would be unacceptable for the Internet as a whole. At the same time, social networks are growing in importance as means of communication between people, and as such they have a moral obligation to act fairly and apply their rules in a transparent manner.

    Facebook was recently under fire, accused of not taking sufficient measures to curb ‘hate speech,’ particularly against women. Eventually they pledged to review their policies and methods, and reducing the proliferation of such content will surely make the web a better place. Nevertheless, one must ask how Facebook (or another social network) might react to similar pressure from, say, a religious group demanding removal of ‘blasphemous’ content. What about demands from a foreign government ? Only yesterday, the Turkish prime minister Erdogan branded Twitter ‘a plague’ in a TV interview.

    Rather than impose upon Internet companies the burden of law enforcement, we should provide them the latitude to set their own policies as well as the legal confidence to stand firm in the face of unreasonable demands. The usual market forces will promote those acting responsibly.

    Further reading