Recherche avancée

Médias (0)

Mot : - Tags -/utilisateurs

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

Autres articles (58)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

Sur d’autres sites (10298)

  • How to release resources from ffmpeg

    11 février 2020, par Summit

    I have built a class that reads avi file and displays it.

    This is the defination for the class.

    typedef struct {

       AVFormatContext *fmt_ctx;
       int stream_idx;
       AVStream *video_stream;
       AVCodecContext *codec_ctx;
       AVCodec *decoder;
       AVPacket *packet;
       AVFrame *av_frame;
       AVFrame *gl_frame;
       struct SwsContext *conv_ctx;
       unsigned int  frame_tex;    
    }AppData;


    class ClipPlayer{

    private:    
       AppData data;  
       std::vector< AVFrame* > cache;
    public:

       ClipPlayer();
       ClipPlayer(const  ClipPlayer& player);
       ClipPlayer& operator=(const  ClipPlayer& player);
            ~ClipPlayer();
       void initializeAppData();
       void clearAppData();
       bool readFrame();
       bool initReadFrame();
       void playCache();  
       void init();
       void draw();
       void reset();
       }

    In the init function the AVI file is read and the frames are saved in memory.

    void init()
    {

    initializeAppData();

       // open video
       if (avformat_open_input(&data.fmt_ctx, stdstrPathOfVideo.c_str(), NULL, NULL) < 0) {
           clearAppData();
           return;
       }    
       // find stream info
       if (avformat_find_stream_info(data.fmt_ctx, NULL) < 0) {
           clearAppData();
           return;
       }
       // find the video stream
       for (unsigned int i = 0; i < data.fmt_ctx->nb_streams; ++i)
       {
           if (data.fmt_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
           {
               data.stream_idx = i;
               break;
           }
       }

       if (data.stream_idx == -1)
       {
           clearAppData();
           return;
       }

       data.video_stream = data.fmt_ctx->streams[data.stream_idx];
       data.codec_ctx = data.video_stream->codec;

       // find the decoder
       data.decoder = avcodec_find_decoder(data.codec_ctx->codec_id);
       if (data.decoder == NULL)
       {
           clearAppData();
           return;
       }

       // open the decoder
       if (avcodec_open2(data.codec_ctx, data.decoder, NULL) < 0)
       {
           clearAppData();
           return;
       }

       // allocate the video frames
       data.av_frame = av_frame_alloc();
       data.gl_frame = av_frame_alloc();
       int size = avpicture_get_size(AV_PIX_FMT_RGBA, data.codec_ctx->width,
           data.codec_ctx->height);
       uint8_t *internal_buffer = (uint8_t *)av_malloc(size * sizeof(uint8_t));
       avpicture_fill((AVPicture *)data.gl_frame, internal_buffer, AV_PIX_FMT_RGBA,
           data.codec_ctx->width, data.codec_ctx->height);
       data.packet = (AVPacket *)av_malloc(sizeof(AVPacket));
    }

    /////////////////////////////////////////////////////////////

    bool ClipPlayer::initReadFrame()
    {
       do {
           glBindTexture(GL_TEXTURE_2D, data.frame_tex);
           int error = av_read_frame(data.fmt_ctx, data.packet);      
           if (error)
           {          
               av_free_packet(data.packet);
               return false;
           }

           if (data.packet->stream_index == data.stream_idx)
           {
               int frame_finished = 0;
               if (avcodec_decode_video2(data.codec_ctx, data.av_frame, &frame_finished,
                   data.packet) < 0) {
                   av_free_packet(data.packet);
                   return false;
               }
               if (frame_finished)
               {              
                   if (!data.conv_ctx)
                   {
                       data.conv_ctx = sws_getContext(data.codec_ctx->width,
                           data.codec_ctx->height, data.codec_ctx->pix_fmt,
                           data.codec_ctx->width, data.codec_ctx->height, AV_PIX_FMT_RGBA,
                           SWS_BICUBIC, NULL, NULL, NULL);
                   }
                   sws_scale(data.conv_ctx, data.av_frame->data, data.av_frame->linesize, 0,
                       data.codec_ctx->height, data.gl_frame->data, data.gl_frame->linesize);

                   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, data.codec_ctx->width,
                       data.codec_ctx->height, GL_RGBA, GL_UNSIGNED_BYTE,
                       data.gl_frame->data[0]);    

                   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                   AVFrame *cachedValue = av_frame_alloc();
                   cachedValue->format = data.av_frame->format;
                   cachedValue->width = data.av_frame->width;
                   cachedValue->height = data.av_frame->height;
                   cachedValue->channels = data.av_frame->channels;
                   cachedValue->channel_layout = data.av_frame->channel_layout;
                   cachedValue->nb_samples = data.av_frame->nb_samples;
                   av_frame_get_buffer(cachedValue, 32);
                   av_frame_copy(cachedValue, data.av_frame);
                   av_frame_copy_props(cachedValue, data.av_frame);
                   cache.push_back((cachedValue));
               }
           }      
       } while (data.packet->stream_index != data.stream_idx);

    ////////////////////////////////////////////////////////////////////

    In the play cache function the frames are displayed

    void ClipPlayer::playCache()
    {
          glActiveTexture(GL_TEXTURE0);
          sws_scale(data.conv_ctx, cache[loop]->data, cache[loop]->linesize, 0,
          data.codec_ctx->height, data.gl_frame->data, data.gl_frame->linesize);
          glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, data.codec_ctx->width,
           data.codec_ctx->height, GL_RGBA, GL_UNSIGNED_BYTE,data.gl_frame->data[0]);
          glBindTexture(GL_TEXTURE_2D, data.frame_tex);    
    }

    In the destructor i try to free the memory

    ~ClipPlayer()
    {
        for (auto &frame : cache)
           {
            av_freep(frame);
           }
    }

    I am not very proficient in using FFmpeg , my question is that have i freed the memory properly.

  • C++ Invalid read of size 16, Address is 744 bytes inside a block of size 752 alloc'd

    17 août 2022, par Turgut

    I know there are similar questions to this one but I can't seem to find the solution in my own circumstances.

    


    I've made a program using opengl and ffmpeg that uses a buffer to complete it's operations. Normally, the program runs just fine with no errors whatsoever. However when I run my application using valgrind I get this error :

    


    ==31277== Invalid read of size 16
==31277==    at 0xD27852: memcpy (string_fortified.h:29)
==31277==    by 0xD27852: scale_internal (swscale.c:947)
==31277==    by 0xD29EE8: sws_scale (swscale.c:1213)
==31277==    by 0x268BBC: Videooio::video_encoder::set_frame_yuv_from_rgb(AVFrame*, SwsContext*) (video_encoder.cpp:441)
==31277==    by 0x268D18: Videooio::video_encoder::get_video_frame(Videooio::OutputStream*) (video_encoder.cpp:486)
==31277==    by 0x269032: write_video_frame (video_encoder.cpp:499)
==31277==    by 0x269032: Videooio::video_encoder::encode_one_frame() (video_encoder.cpp:553)
==31277==    by 0x22BD89: Videooio::Application::main_loop() (Application.cpp:212)
==31277==    by 0x21B007: Videooio::Application::Run() (Application.cpp:70)
==31277==    by 0x219C94: main (main.cpp:22)
==31277==  Address 0x50df9c8 is 744 bytes inside a block of size 752 alloc'd
==31277==    at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==31277==    by 0x21A970: Videooio::Application::Run() (Application.cpp:40)
==31277==    by 0x219C94: main (main.cpp:22)


    


    I've diagnosed the problem down to the following lines but I'm not quite sure how to fix it :

    


    Application.cpp

    


    void Run()
{
  ...
40   encoder = new video_encoder(width, height, fps, duration);
  ...
      while (second < duration)
     {
      auto* fbo = opengl_engine.glBuffer;

      encoder->set_encode_framebuffer(fbo);
212   encoder->encode_one_Frame();
     }
}


    


    video_encoder.h :

    


    namespace Videooio{
class video_encoder{
    public:
        video_encoder(int w, int h, unsigned int fps, unsigned int duration);
        
        void set_encode_framebuffer(uint8_t* data, bool audio_only = false);

        void encode_one_frame();
        ~video_encoder();  
    private:
        int write_frame(AVFormatContext *fmt_ctx, AVCodecContext *c,
                       AVStream *st, AVFrame *frame, AVPacket *pkt);

        AVFrame *get_video_frame(OutputStream *ost);

        int write_video_frame(AVFormatContext *oc, OutputStream *ost);

        uint8_t *rgb_data;

        int width;
        int height;
        
        void set_frame_yuv_from_rgb(AVFrame *frame, struct SwsContext *sws_context);
       
    };
}  


    


    Here is opengl_engine, where fbo is allocated :

    


    ...
if (posix_memalign((void**)&glBuffer, 128, (gl_width * gl_height * 4) ) != 0) 
{
   ERROR("Couldn't allocate frame buffer ");
   return false;
}
...


    


    Here is where I set the rgb_data that is inside the encoder (Probably the culprit too) is set to the allocated fbo :

    


    void video_encoder::set_audio_frame(AVFrame* audio, AVSampleFormat* format)
{
    audio_data = *audio;
    input_sample_fmt = *format;
}


    


    rgb_data is set uninitialized up until this point before it's usage (I've tried mallocing it inside the constructor, which was a horrible practice, but doing so changed nothing.).
And here is where it's used and where valgrind mentions :

    


       void video_encoder::set_frame_yuv_from_rgb(AVFrame *frame, struct SwsContext 
   *sws_context) {
       const int in_linesize[1] = { 4 * width };
       //uint8_t* dest[4] = { rgb_data, NULL, NULL, NULL };
       sws_context = sws_getContext(
               width, height, AV_PIX_FMT_RGBA,
               width, height, AV_PIX_FMT_YUV420P,
               SWS_BICUBIC, 0, 0, 0);
440    std::cout << "Address: " << rgb_data << std::endl;
441    sws_scale(sws_context, (const uint8_t * const *)&rgb_data, in_linesize, 0,
442            height, frame->data, frame->linesize);
}


    


    I'm not %100 sure whether rgb_data is causing this error or not but digging into sws_scale and finding where memcpy is used shows that rgb_data is used inside it.

    


    I've tried changing the buffer size of glBuffer to no avail since valgrind allways says 744 bytes inside a block of size 752 the size of which the error mentions is not changing when I change glBuffers size, this led me to believe that rgb_data might not be the culprit. But it's still my best bet.

    


    I've looked into these questions but I just can't seem to apply them to my own circumstance.

    


    Question 1
Question 2

    


    I'm using ubuntu.

    


  • How to contribute to open source, for companies

    18 octobre 2010, par Dark Shikari — development, open source, x264

    I have seen many nigh-incomprehensible attempts by companies to contribute to open source projects, including x264. Developers are often simply boggled, wondering why the companies seem incapable of proper communication. The companies assume the developers are being unreceptive, while the developers assume the companies are being incompetent, idiotic, or malicious. Most of this seems to boil down to a basic lack of understanding of how open source works, resulting in a wide variety of misunderstandings. Accordingly, this post will cover the dos and don’ts of corporate contribution to open source.

    Do : contact the project using their preferred medium of communication.

    Most open source projects use public methods of communication, such as mailing lists and IRC. It’s not the end of the world if you mistakenly make contact with the wrong people or via the wrong medium, but be prepared to switch to the correct one once informed ! You may not be experienced using whatever form of communication the project uses, but if you refuse to communicate through proper channels, they will likely not be as inclined to assist you. Larger open source projects are often much like companies in that they have different parts to their organization with different roles. Don’t assume that everyone is a major developer !

    If you don’t know what to do, a good bet is often to just ask someone.

    Don’t : contact only one person.

    Open source projects are a communal effort. Major contributions are looked over by multiple developers and are often discussed by the community as a whole. Yet many companies tend to contact only a single person in lieu of dealing with the project proper. This has many flaws : to begin with, it forces a single developer (who isn’t paid by you) to act as your liaison, adding yet another layer between what you want and the people you want to talk to. Contribution to open source projects should not be a game of telephone.

    Of course, there are exceptions to this : sometimes a single developer is in charge of the entirety of some particular aspect of a project that you intend to contribute to, in which case this might not be so bad.

    Do : make clear exactly what it is you are contributing.

    Are you contributing code ? Development resources ? Money ? API documentation ? Make it as clear as possible, from the start ! How developers react, which developers get involved, and their expectations will depend heavily on what they think you are providing. Make sure their expectations match reality. Great confusion can result when they do not.

    This also applies in the reverse — if there’s something you need from the project, such as support or assistance with development of your patch, make that explicitly clear.

    Don’t : code dump.

    Code does not have intrinsic value : it is only useful as part of a working, living project. Most projects react very negatively to large “dumps” of code without associated human resources. That is, they expect you to work with them to finalize the code until it is ready to be committed. Of course, it’s better to work with the project from the start : this avoids the situation of writing 50,000 lines of code independently and then finding that half of it needs to be rewritten. Or, worse, writing an enormous amount of code only to find it completely unnecessary.

    Of course, the reverse option — keeping such code to yourself — is often even more costly, as it forces you to maintain the code instead of the official developers.

    Do : ignore trolls.

    As mentioned above, many projects use public communication methods — which, of course, allow anyone to communicate, by nature of being public. Not everyone on a project’s IRC or mailing list is necessarily qualified to officially represent the project. It is not too uncommon for a prospective corporate contributor to be turned off by the uninviting words of someone who isn’t even involved in the project due to assuming that they were. Make sure you’re dealing with the right people before making conclusions.

    Don’t : disappear.

    If you are going to try to be involved in a project, you need to stay in contact. We’ve had all too many companies who simply disappear after the initial introduction. Some tell us that we’ll need an NDA, then never provide it or send status updates. You may know why you’re not in contact — political issues at the company, product launch crunches, a nice vacation to the Bahamas — but we don’t ! If you disappear, we will assume that you gave up.

    Above all, don’t assume that being at a large successful company makes you immune to these problems. If anything, these problems seem to be the most common at the largest companies. I didn’t name any names in this post, but practically every single one of these rules has been violated at some point by companies looking to contribute to x264. In the larger scale of open source, these problems happen constantly. Don’t fall into the same traps that many other companies have.

    If you’re an open source developer reading this post, remember it next time you see a company acting seemingly nonsensically in an attempt to contribute : it’s quite possible they just don’t know what to do. And just because they’re doing it wrong doesn’t mean that it isn’t your responsibility to try to help them do it right.