Recherche avancée

Médias (0)

Mot : - Tags -/optimisation

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

Autres articles (51)

  • 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

  • List of compatible distributions

    26 avril 2011, par

    The table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
    If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

Sur d’autres sites (6983)

  • conversion from cv::mat to avframe

    14 novembre 2014, par danics

    i create a method for converting between cv::mat to avframe with PIX_FMT_YUV420P format (oframe format) but _convCtx always return null, whats wrong ? thanks in advance !

    void processToFrame(cv::Mat* _mat, AVFrame* oframe)
     {
         // Create and allocate the conversion frame.
         if (_oframe == nullptr) {
             _oframe = avcodec_alloc_frame();  
             if (_oframe == nullptr)
                 throw std::runtime_error("Matrix Converter: Could not allocate the output frame.");

             avpicture_alloc(reinterpret_cast(_oframe),
                 PIX_FMT_BGR24, _mat->cols, _mat->rows);            
         }

         avpicture_fill(reinterpret_cast(_oframe),
             (uint8_t *)_mat->data,
             AV_PIX_FMT_BGR24,
             _mat->cols,
             _mat->rows);

         // Convert the image from its native format to BGR.
         if (_convCtx == nullptr) {
             _convCtx = sws_getContext(
                 oframe->width, oframe->height, (enum AVPixelFormat) oframe->format,
                 _oframe->width, _oframe->height, PIX_FMT_BGR24,
                 SWS_BICUBIC, nullptr, nullptr, nullptr);
         }
         if (_convCtx == nullptr)
             throw std::runtime_error("Matrix Converter: Unable to initialize the conversion context.");  

         // Scales the source data according to our SwsContext settings.
         if (sws_scale(_convCtx,
             _oframe->data, _oframe->linesize, 0, _oframe->height,
             oframe->data, oframe->linesize) < 0)
             throw std::runtime_error("Matrix Converter: Pixel format conversion not supported.");
     }

    edit : create oframe

    void createVideoFile(const char* filename, int w, int h, int codec_id, int fps)
     {
         /* find the mpeg1 video encoder */
         if(codec == nullptr)
         {
             /* find the mpeg1 video encoder */
             codec = avcodec_find_encoder((AVCodecID)codec_id);
             if (!codec) {
                 throw std::runtime_error("codec not found\n");
             }
         }

         if(c == nullptr)
         {
             c = avcodec_alloc_context3(codec);
             if(!c)
             {
                 throw std::runtime_error("Could not allocate video codec context\n");
             }
             /* put sample parameters */
             c->bit_rate = 400000;
             /* resolution must be a multiple of two */
             c->width = 2 * (w / 2);
             c->height = 2 * (h / 2);
             /* frames per second */
             AVRational ar;
             ar.den = 1;
             ar.num = fps;

             c->time_base= ar; //(AVRational){1,25};
             c->gop_size = 10; /* emit one intra frame every ten frames */
             c->max_b_frames=1;
             c->pix_fmt = PIX_FMT_YUV420P;

             if(codec_id == AV_CODEC_ID_H264)
                 av_opt_set(c->priv_data, "preset", "slow", 0);

             /* open it */
             if (avcodec_open2(c, codec, NULL) < 0) {
                 throw std::runtime_error("Could not open codec\n");
             }

             f = fopen(filename, "wb");
             if (!f) {
                 throw std::runtime_error("could not open file\n");
             }

             frame = avcodec_alloc_frame();
             if (!frame) {
                 throw std::runtime_error("Could not allocate video frame\n");
             }
             frame->format = c->pix_fmt;
             frame->width  = c->width;
             frame->height = c->height;

             /* the image can be allocated by any means and av_image_alloc() is
              * just the most convenient way if av_malloc() is to be used */

             int ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);

             if (ret < 0) {
                 throw std::runtime_error("Could not allocate raw picture buffer\n");
             }
         }
    }

    read mat images

    void video_encode_example(const cv::Mat& fin)
    {
       AVPacket pkt;
       /* encode 1 second of video */
       av_init_packet(&pkt);
       pkt.data = NULL;    // packet data will be allocated by the encoder
       pkt.size = 0;

       fflush(stdout);

       cv::Mat res;
       cv::resize(fin, res, cv::Size(c->width, c->height));

       processToFrame(&res, frame);
       frame->pts = i;

       /* encode the image */
       int ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
       if (ret < 0) {
       throw std::runtime_error("Error encoding frame\n");
       }

       if (got_output) {
           printf("Write frame %3d (size=%5d)\n", i, pkt.size);
           fwrite(pkt.data, 1, pkt.size, f);
           av_free_packet(&pkt);
       }
       i++;
       /* get the delayed frames */
       /*for (got_output = 1; got_output; i++) {
           fflush(stdout);

           ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
           if (ret < 0) {
               throw std::runtime_error("Error encoding frame\n");
           }

           if (got_output) {
               printf("Write frame %3d (size=%5d)\n", i, pkt.size);
               fwrite(pkt.data, 1, pkt.size, f);
               av_free_packet(&pkt);
           }
       }*/
    }
  • conversion from cv::mat to avframe, encode in h264 dont writing correctly [on hold]

    15 novembre 2014, par danics

    i create a method for converting between cv::mat to avframe with PIX_FMT_YUV420P format (oframe format) but _convCtx always return null, whats wrong ? thanks in advance ! ((i solve this)) but i have another probelm in end of this question please

    void processToFrame(cv::Mat* _mat, AVFrame* oframe)
     {
         // Create and allocate the conversion frame.
         if (_oframe == nullptr) {
             _oframe = avcodec_alloc_frame();  
             if (_oframe == nullptr)
                 throw std::runtime_error("Matrix Converter: Could not allocate the output frame.");

             avpicture_alloc(reinterpret_cast(_oframe),
                 PIX_FMT_BGR24, _mat->cols, _mat->rows);            
         }

         avpicture_fill(reinterpret_cast(_oframe),
             (uint8_t *)_mat->data,
             AV_PIX_FMT_BGR24,
             _mat->cols,
             _mat->rows);

         // Convert the image from its native format to BGR.
         if (_convCtx == nullptr) {
             _convCtx = sws_getContext(
                 oframe->width, oframe->height, (enum AVPixelFormat) oframe->format,
                 _oframe->width, _oframe->height, PIX_FMT_BGR24,
                 SWS_BICUBIC, nullptr, nullptr, nullptr);
         }
         if (_convCtx == nullptr)
             throw std::runtime_error("Matrix Converter: Unable to initialize the conversion context.");  

         // Scales the source data according to our SwsContext settings.
         if (sws_scale(_convCtx,
             _oframe->data, _oframe->linesize, 0, _oframe->height,
             oframe->data, oframe->linesize) < 0)
             throw std::runtime_error("Matrix Converter: Pixel format conversion not supported.");
     }

    create oframe

    void createVideoFile(const char* filename, int w, int h, int codec_id, int fps)
     {
         /* find the mpeg1 video encoder */
         if(codec == nullptr)
         {
             /* find the mpeg1 video encoder */
             codec = avcodec_find_encoder((AVCodecID)codec_id);
             if (!codec) {
                 throw std::runtime_error("codec not found\n");
             }
         }

         if(c == nullptr)
         {
             c = avcodec_alloc_context3(codec);
             if(!c)
             {
                 throw std::runtime_error("Could not allocate video codec context\n");
             }
             /* put sample parameters */
             c->bit_rate = 400000;
             /* resolution must be a multiple of two */
             c->width = 2 * (w / 2);
             c->height = 2 * (h / 2);
             /* frames per second */
             AVRational ar;
             ar.den = 1;
             ar.num = fps;

             c->time_base= ar; //(AVRational){1,25};
             c->gop_size = 10; /* emit one intra frame every ten frames */
             c->max_b_frames=1;
             c->pix_fmt = PIX_FMT_YUV420P;

             if(codec_id == AV_CODEC_ID_H264)
                 av_opt_set(c->priv_data, "preset", "slow", 0);

             /* open it */
             if (avcodec_open2(c, codec, NULL) < 0) {
                 throw std::runtime_error("Could not open codec\n");
             }

             f = fopen(filename, "wb");
             if (!f) {
                 throw std::runtime_error("could not open file\n");
             }

             frame = avcodec_alloc_frame();
             if (!frame) {
                 throw std::runtime_error("Could not allocate video frame\n");
             }
             frame->format = c->pix_fmt;
             frame->width  = c->width;
             frame->height = c->height;

             /* the image can be allocated by any means and av_image_alloc() is
              * just the most convenient way if av_malloc() is to be used */

             int ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);

             if (ret < 0) {
                 throw std::runtime_error("Could not allocate raw picture buffer\n");
             }
         }
    }

    read mat images

    void video_encode_example(const cv::Mat& fin)
    {
       AVPacket pkt;
       /* encode 1 second of video */
       av_init_packet(&pkt);
       pkt.data = NULL;    // packet data will be allocated by the encoder
       pkt.size = 0;

       fflush(stdout);

       cv::Mat res;
       cv::resize(fin, res, cv::Size(c->width, c->height));

       processToFrame(&res, frame);
       frame->pts = i;

       /* encode the image */
       int ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
       if (ret < 0) {
       throw std::runtime_error("Error encoding frame\n");
       }

       if (got_output) {
           printf("Write frame %3d (size=%5d)\n", i, pkt.size);
           fwrite(pkt.data, 1, pkt.size, f);
           av_free_packet(&pkt);
       }
       i++;
    }

    update :

    i can solve the conversion problem by setting of _oframe.width = _mat.cols and _oframe.height = _mat.rows, avpicture_alloc dont set this value itself.

    now i have the other problem my videowriting class seems write ok because windows slideshow show one of frames, but i cant view video in my players, this is my release function, i dont know whats wrong endcoding or endcoder structure parameter like pts and else.

    void video_release()
       {
           /* get the delayed frames */
           for (got_output = 1; got_output; i++) {
               fflush(stdout);

               int ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
               if (ret < 0) {
                   throw std::runtime_error("Error encoding frame\n");
               }

               if (got_output) {
                   printf("Write frame %3d (size=%5d)\n", i, pkt.size);
                   fwrite(pkt.data, 1, pkt.size, f);
                   av_free_packet(&pkt);
               }
           }

           uint8_t endcode[] = { 0, 0, 1, 0xb7 };

           /* add sequence end code to have a real mpeg file */
           fwrite(endcode, 1, sizeof(endcode), f);
           fclose(f);

           avcodec_close(c);
           av_free(c);
           av_freep(&frame->data[0]);
           avcodec_free_frame(&frame);

           c = nullptr;
           codec = nullptr;
           frame = nullptr;

           if (_convCtx)
               sws_freeContext(_convCtx);

           if (_oframe) {
               //if (_oframe->data)
                   //av_free(_oframe->data[0]);
               av_free(_oframe);
           }

           _oframe = nullptr;
           _convCtx = nullptr;
       }
  • How to verify user permissions – Introducing the Piwik Platform

    9 novembre 2014, par Thomas Steur — Development

    This is the next post of our blog series where we introduce the capabilities of the Piwik platform (our previous post was How to make your plugin multilingual). This time you’ll learn how to verify user permissions. For this tutorial you will need to have basic knowledge of PHP and the Piwik platform.

    When should a plugin verify permissions ?

    Usually you want to do this before executing any action – such as deleting or fetching data – and before rendering any sensitive information that should not be accessible by everyone. For instance in an API method or Controller action. You sometimes also need to verify permissions before registering menu items or widgets.

    How does Piwik’s user management work ?

    It is quite simple as it only differentiates between a few roles : View permission, Admin permission and Super User permission. If you manage multiple websites with Piwik a user can be assigned to different roles as a user might have no permission for some websites but view or admin permission for another set of websites.

    Worth mentioning is that roles inherit from each other. This means the role admin automatically includes the role view and a super user automatically covers the view and admin role.

    Getting started

    In this post, we assume that you have already set up your development environment and created a plugin. If not, visit the Piwik Developer Zone where you’ll find the tutorial Setting up Piwik and other Guides that help you to develop a plugin.

    Verifying user permissions

    To protect your data the platform offers many convenient methods in the \Piwik\Piwik class. There you will find methods that either start with check, is or has. While methods that start with check throw an exception in case a condition is not met, the other methods return a boolean true or false.

    Use methods that throw an exception if you want to stop any further execution in case a user does not have an appropriate role. The platform will catch the exception and display an error message or ask the user to log in.

    1. public function deleteAllMessages()
    2. {
    3.     // delete messages only if user has super user access, otherwise show an error message
    4.     Piwik::checkUserSuperUserAccess();
    5.  
    6.     $this->getModel()->deleteAllMessages();
    7. }

    Télécharger

    Use methods that return a boolean for instance when registering menu items or widgets.

    1. public function configureAdminMenu(MenuAdmin $menu)
    2. {
    3.     if (Piwik::hasUserSuperUserAccess()) {
    4.         $menu->addPlatformItem('Plugins', $this->urlForDefaultAction());
    5.     }
    6. }

    Télécharger

    It is important to be aware that just because the menu item won’t be displayed in the UI a user can still open the registered URL manually. Therefore you have to check for permissions in the actual controller action as well.

    View permission

    A user having a view permission should be only able to view reports but not make any changes apart from his personal settings. The methods that end with UserHasSomeViewAccess make sure a user has at least view permission for one website whereas the methods *UserHasViewAccess($idSites = array(1,2,3)) check whether a user has view access for all of the given websites.

    1. Piwik::checkUserHasSomeViewAccess();
    2.  
    3. Piwik::checkUserHasViewAccess($idSites = array(1,2,3));

    Télécharger

    As a plugin developer you would usually use the latter example to verify the permissions for specific websites. Use the first example in case you develop something like an “All Websites Dashboard” where you only want to make sure the user has a view permission for at least one website.

    Admin permission

    A user having an admin permission cannot only view reports but also change website related settings. The methods to check for this role are similar to the ones before, just swap the term View with Admin.

    1. Piwik::checkUserHasSomeAdminAccess();
    2.  
    3. Piwik::checkUserHasAdminAccess($idSites = array(1,2,3));

    Télécharger

    Super user permission

    A user having the super user permission is allowed to access all of the data stored in Piwik and change any settings. To check if a user has this role use one of the methods that end with UserSuperUserAccess.

    Piwik::checkUserHasSuperUserAccess();

    As a plugin developer you would check for this permission for instance in places where your plugin shows an activity log over all users or where it offers the possibility to change any system wide settings.

    Getting information about the currently logged in user

    Sometimes you might want to know which user is currently logged in. This can be useful if you want to persist user related information in the database or if you want to send an email to the currently logged in user. You can easily get this information by calling the following methods :

    1. $login = Piwik::getCurrentUserLogin()
    2. $email = Piwik::getCurrentUserEmail()

    Télécharger

    Advanced features

    Of course there is more that you can do. For instance you can verify whether a user is an anonymous user or whether a user has a specific role. You can also perform any operation in the context of a super user even if the current user does not have this role. Would you like to know more about those features ? Check out the Piwik class reference, the Security guide and the Manage Users user guide.

    If you have any feedback regarding our APIs or our guides in the Developer Zone feel free to send it to us.