Recherche avancée

Médias (0)

Mot : - Tags -/page unique

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

Autres articles (105)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Gestion des droits de création et d’édition des objets

    8 février 2011, par

    Par défaut, beaucoup de fonctionnalités sont limitées aux administrateurs mais restent configurables indépendamment pour modifier leur statut minimal d’utilisation notamment : la rédaction de contenus sur le site modifiables dans la gestion des templates de formulaires ; l’ajout de notes aux articles ; l’ajout de légendes et d’annotations sur les images ;

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (11017)

  • OpenCV video writing to named pipe

    21 janvier 2012, par user28667

    I'm trying to send videos created with OpenCV in real-time to user though Apache (user downloads video from a website). I don't need streaming video. I'm just trying to transfer whole video file. My OpenCV program writes video to a named pipe (created with mkfifo) and PHP scrpt reads from it and outputs to user.

    The problem is that pipe-transfered videos doesn't open in Windows. They're shorter exactly at 7072 bytes (checked with different videos). They are not just truncated. The first difference between videos appeared in 5-th byte. And there is no mistake in PHP script. I've checked it using :

    cat fifo.avi > output.avi

    The result was the same. How to make OpenCV write videos to pipes just as to normal files ? Why this happens ? Or is there another way to send videos in real-time to user ?

    P. S. Thanks and sorry for bad English
    P. P. S. I'm creating CvVideoWriter with this code if it matters :

    cvCreateVideoWriter("fifo.avi",CV_FOURCC('M','J','P','G'),25,cvSize(blah blah blah),1)
  • I'm attempting to retrieve the dimensions of in-memory video buffer objects in Node.js without writing to disk

    23 mars 2021, par undefined

    All right, so I have a Node.js server where media files can be uploaded by the user. It's important for displaying the media in the client later on that I can retrieve and store the width and height dimensions of the video in advance.

    


    For performance reasons, disk space limitations, and a few other reasons, I'm attempting to do so without saving the video buffer object (retrieved via Multer) to disk as it has terrible performance on the server I am using.

    


    I have FFmpeg and ffprobe, as well as the nom get-video-dimensions module, but I can't find a way to get media statistics without writing the file. For example, get-video-dimensions only allows you to enter a file path.

    


    Is there a way to either feed the buffer into one of these utilities using either a stream/pipe to simulate the source coming from disk, or is there an rpm module I've overlooked that could achieve this task ?

    


    if (imageBufferObject.media_type == "video") {
  // Get resolution

  // Save to disk
  let write_response = await writeFile(imageBufferObject)
  // Use utility
  let dim = await dimensions(path.join(__dirname, 'tmp', newName))
  // Delete file
  let delete_response = await deleteFile(imageBufferObject)


   async function writeFile(file){
     return new Promise((resolve, reject)=>{
       fs.writeFile(path.join(__dirname, 'tmp', file.newName), file.buffer, (err)=>{
         resolve(200)
        })
     })
   }
   async function deleteFile(file){
     return new Promise((resolve, reject)=>{
       fs.unlink(path.join(__dirname, 'tmp', file.newName), (err)=>{
         resolve(200)
       })
     })
   }


    


    I desperately want to avoid using the hard disk !

    


  • Writing opencv frames to avi container using libavformat Custom IO

    16 juillet 2017, par Aryan

    I have to write OpenCV cv::Mat frames to an AVI container. I cannot use OpenCV’s VideoWriter because I do not intend to write the AVI file to disk directly, instead I want to send it to a custom stream, so I have to use ffmpeg/libav. As I have never used ffmpeg before I have taken help from solutions provided here and here, alongwith the ffmpeg documentation.

    I am able to send AVI container packets to my custom output stream as required but the performance is very bad. Specifically, the call to avcodec_encode_video2 is taking too long.

    First, I suspect that due to my inexperience I have misconfigured or wrongly coded something. I am currently working wit 640*480 grayscale frames. On my i.MX6 platform the call to avcodec_encode_video2 is taking about 130ms on average per frame, which is unacceptably slow. Any pointers to an obvious performance killer ??? (i know sws_scale looks useless but it takes negligible time, and might be useful for me later).

    Second, I am using PNG encoder, but that is not required, I would be happy to write uncompressed data if I know how to : If the slowdown is not due to my bad programming, can we just get rid of the encoder and generate uncompressed packets for the avi container ? Or use some encoder that accepts grayscale images and is not that slow ?

    For Initialization and writing of header I am using :

    void MyWriter::WriteHeader()  
    {
       av_register_all();

       // allocate output format context
       if (avformat_alloc_output_context2(&avFmtCtx, NULL, "avi", NULL) < 0) { printf("DATAREC: avformat_alloc_output_context2 failed"); exit(1); }

       // buffer for avio context    
       bufSize = 640 * 480 * 4; // Don't know how to derive, but this should be big enough for now
       buffer = (unsigned char*)av_malloc(bufSize);
       if (!buffer) { printf("DATAREC: Buffer alloc failed"); exit(1); }

       // allocate avio context
       avIoCtx = avio_alloc_context(buffer, bufSize, 1, this, NULL, WriteCallbackWrapper, NULL);
       if (!avIoCtx) { printf("DATAREC: avio_alloc_context failed"); exit(1); }

       // connect avio context to format context
       avFmtCtx->pb = avIoCtx;

       // set custom IO flag
       avFmtCtx->flags |= AVFMT_FLAG_CUSTOM_IO;

       // get encoder
       encoder = avcodec_find_encoder(AV_CODEC_ID_PNG);
       if (!encoder) { printf("DATAREC: avcodec_find_encoder failed"); exit(1); }

       // create new stream
       avStream = avformat_new_stream(avFmtCtx, encoder);
       if (!avStream) { printf("DATAREC: avformat_new_stream failed"); exit(1); }

       // set stream codec defaults
       if (avcodec_get_context_defaults3(avStream->codec, encoder) < 0)  { printf("DATAREC: avcodec_get_context_defaults3 failed"); exit(1); }

      // hardcode settings for now
       avStream->codec->pix_fmt = AV_PIX_FMT_GRAY8;
       avStream->codec->width = 640;
       avStream->codec->height = 480;
       avStream->codec->time_base.den = 15;
       avStream->codec->time_base.num = 1;
       avStream->time_base.den = avStream->codec->time_base.den;
       avStream->time_base.num = avStream->codec->time_base.num;
       avStream->r_frame_rate.num = avStream->codec->time_base.den;
       avStream->r_frame_rate.den = avStream->codec->time_base.num;

       // open encoder    
       if (avcodec_open2(avStream->codec, encoder, NULL) < 0) {
           printf("DATAREC: Cannot open codec\n");
           exit(1);
       }

       // write header
       if(avformat_write_header(avFmtCtx, NULL) < 0) { printf("DATAREC: avformat_write_header failed\n"); exit(1);}

       // prepare for first frame
       framePts = 0;
       firstFrame = true;
    }

    After writing the header, the following function is called in a loop for each cv::Mat frame :

    void MyWriter::WriteFrame(cv::Mat& item)
    {
       if (firstFrame) // do only once, before writing the first frame
       {
           // allocate frame
           frame = av_frame_alloc();
           if (!frame) { printf("DATAREC: av_frame_alloc failed"); exit(1); }

           // get size for framebuffer
           int picsz = av_image_get_buffer_size(avStream->codec->pix_fmt, avStream->codec->width, avStream->codec->height, 1);

           // allocate frame buffer
           framebuf = (unsigned char*)av_malloc(picsz);
           if (!framebuf) { printf("DATAREC: fail to alloc framebuf"); exit(1); }

           // set frame width, height, format
           frame->width = avStream->codec->width;
           frame->height = avStream->codec->height;
           frame->format = static_cast<int>(avStream->codec->pix_fmt);

           // set up data pointers and linesizes
           if (av_image_fill_arrays(frame->data, frame->linesize, framebuf, avStream->codec->pix_fmt, avStream->codec->width, avStream->codec->height, 1) &lt; 0) { printf("DATAREC: av_image_fill_arrays failed\n"); exit(1);}

           // get sws context
           swsctx = sws_getCachedContext(nullptr, avStream->codec->width, avStream->codec->height, avStream->codec->pix_fmt, avStream->codec->width, avStream->codec->height, avStream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr);
           if (!swsctx) { printf("DATAREC: fail to sws_getCachedContext"); exit(1); }

           // done initializing
           firstFrame = false; // don't repeat this for the following frames
       }

       // call sws scale
       const int stride[] = { static_cast<int>(item.step[0]) };
       sws_scale(swsctx, &amp;item.data, stride, 0, item.rows, frame->data, frame->linesize);

       // set presentation timestamp
       frame->pts = framePts++;

       // initialize packet
       av_init_packet(&amp;pkt);
       pkt.data = NULL;
       pkt.size = 0;

       // THIS TAKES VERY LONG TO EXECUTE
       // call encoder, convert frame to packet
       if (avcodec_encode_video2(avStream->codec, &amp;pkt, frame, &amp;got_pkt) &lt; 0) { printf("DATAREC: fail to avcodec_encode_video2");  exit(1); }

       write packet if available
       if (got_pkt)
       {
           pkt.duration = 1;
           av_write_frame(avFmtCtx, &amp;pkt);
       }

       // wipe packet
       av_packet_unref(&amp;pkt);
    }
    </int></int>

    After writing required frames, trailer is written :

    void MyWriter::WriteTrailer()
    {
       // prepare packet for trailer
       av_init_packet(&amp;pkt);
       pkt.data = NULL;
       pkt.size = 0;

       // encode trailer packet
       if (avcodec_encode_video2(avStream->codec, &amp;pkt, nullptr, &amp;got_pkt) &lt; 0) { printf("DATAREC: fail to avcodec_encode_video2");    exit(1); }

       // write trailer packet
       if (got_pkt)
       {
           pkt.duration = 1;
           av_write_frame(avFmtCtx, &amp;pkt);
       }

       // free everything
       av_packet_unref(&amp;pkt);
       av_write_trailer(avFmtCtx);
       av_frame_free(&amp;frame);
       avcodec_close(avStream->codec);
       av_free(avIoCtx);
       sws_freeContext(swsctx);
       avformat_free_context(avFmtCtx);
       av_free(framebuf);
       av_free(buffer);
       firstFrame = true; // for the next file
    }

    Many many thanks to everyone who made it down to this line !