Recherche avancée

Médias (1)

Mot : - Tags -/école

Autres articles (66)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • 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 (...)

Sur d’autres sites (8256)

  • Problem to write video using FFMPEG from a vector of cv::Mat

    30 décembre 2022, par Alex

    I'm trying create two functions, one to read a video and store the frmes in a vector of cv::Mat, and other to get a vector of cv::Mat and write this vector in a video. The code compile and run without exception, but the video writed doesn't run, there are data inside, but VLC is not able to run the video. What am I doing wrong in function to write video ?

    


    #include <iostream>&#xA;#include <string>&#xA;#include <vector>&#xA;&#xA;#include <opencv2></opencv2>core/mat.hpp>&#xA;#include <opencv2></opencv2>imgcodecs.hpp>&#xA;&#xA;&#xA;extern "C" {&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;    #include <libavutil></libavutil>pixdesc.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;}&#xA;&#xA;// helper function to check for FFmpeg errors&#xA;inline void checkError(int error, const std::string &amp;message) {&#xA;    if (error &lt; 0) {&#xA;        std::cerr &lt;&lt; message &lt;&lt; ": " &lt;&lt; av_err2str(error) &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;}&#xA;  &#xA;&#xA;int writeVideo(const std::string&amp; video_path, std::vector&amp; frames, int width, int height, int fps) {&#xA;    // initialize FFmpeg&#xA;    av_log_set_level(AV_LOG_ERROR);&#xA;    avformat_network_init();&#xA;&#xA;    // create the output video context&#xA;    AVFormatContext *formatContext = nullptr;&#xA;    int error = avformat_alloc_output_context2(&amp;formatContext, nullptr, nullptr, video_path.c_str());&#xA;    checkError(error, "Error creating output context");&#xA;&#xA;    // create the video stream&#xA;    AVStream *videoStream = avformat_new_stream(formatContext, nullptr);&#xA;    if (!videoStream) {&#xA;        std::cerr &lt;&lt; "Error creating video stream" &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;&#xA;    // create the video codec context&#xA;    const AVCodec *videoCodec = avcodec_find_encoder(AV_CODEC_ID_MPEG4);&#xA;    AVCodecContext *videoCodecContext = avcodec_alloc_context3(videoCodec);&#xA;    if (!videoCodecContext) {&#xA;        std::cerr &lt;&lt; "Error allocating video codec context" &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;    videoCodecContext->bit_rate = 200000;&#xA;    videoCodecContext->width = width;&#xA;    videoCodecContext->height = height;&#xA;    videoCodecContext->time_base = (AVRational){ 1, fps };&#xA;    videoCodecContext->framerate = (AVRational){ fps, 1 };&#xA;    videoCodecContext->gop_size = 12;&#xA;    videoCodecContext->max_b_frames = 0;&#xA;    videoCodecContext->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;    if (formatContext->oformat->flags &amp; AVFMT_GLOBALHEADER) {&#xA;        videoCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;    error = avcodec_open2(videoCodecContext, videoCodec, nullptr);&#xA;    checkError(error, "Error opening");&#xA;        error = avcodec_parameters_from_context(videoStream->codecpar, videoCodecContext);&#xA;    checkError(error, "Error setting video codec parameters");&#xA;&#xA;    // open the output file&#xA;    error = avio_open(&amp;formatContext->pb, video_path.c_str(), AVIO_FLAG_WRITE);&#xA;    checkError(error, "Error opening output file");&#xA;&#xA;    // write the video file header&#xA;    error = avformat_write_header(formatContext, nullptr);&#xA;    checkError(error, "Error writing video file header");&#xA;&#xA;&#xA;    AVPacket *packet = av_packet_alloc();&#xA;    if (!packet) {&#xA;        std::cerr &lt;&lt; "Error allocating packet" &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;    for (const cv::Mat &amp;frame : frames) {&#xA;        // convert the cv::Mat to an AVFrame&#xA;        AVFrame *avFrame = av_frame_alloc();&#xA;        avFrame->format = videoCodecContext->pix_fmt;&#xA;        avFrame->width = width;&#xA;        avFrame->height = height;&#xA;        error = av_frame_get_buffer(avFrame, 0);&#xA;        checkError(error, "Error allocating frame buffer");&#xA;        struct SwsContext *frameConverter = sws_getContext(width, height, AV_PIX_FMT_BGR24, width, height, videoCodecContext->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr);&#xA;        uint8_t *srcData[AV_NUM_DATA_POINTERS] = { frame.data };&#xA;        int srcLinesize[AV_NUM_DATA_POINTERS] = { static_cast<int>(frame.step) };&#xA;        sws_scale(frameConverter, srcData, srcLinesize, 0, height, avFrame->data, avFrame->linesize);&#xA;        sws_freeContext(frameConverter);&#xA;&#xA;        // encode the AVFrame&#xA;        avFrame->pts = packet->pts;&#xA;        error = avcodec_send_frame(videoCodecContext, avFrame);&#xA;        checkError(error, "Error sending frame to video codec");&#xA;        while (error >= 0) {&#xA;            error = avcodec_receive_packet(videoCodecContext, packet);&#xA;            if (error == AVERROR(EAGAIN) || error == AVERROR_EOF) {&#xA;                break;&#xA;            }&#xA;            checkError(error, "Error encoding video frame");&#xA;&#xA;            // write the encoded packet to the output file&#xA;            packet->stream_index = videoStream->index;&#xA;            error = av_interleaved_write_frame(formatContext, packet);&#xA;            checkError(error, "Error writing video packet");&#xA;            av_packet_unref(packet);&#xA;        }&#xA;        av_frame_free(&amp;avFrame);&#xA;    }&#xA;&#xA;    // clean up&#xA;    av_packet_free(&amp;packet);&#xA;    avcodec_free_context(&amp;videoCodecContext);&#xA;    avformat_free_context(formatContext);&#xA;    avformat_network_deinit();&#xA;&#xA;    return EXIT_SUCCESS;&#xA;}&#xA;&#xA;std::vector readVideo(const std::string video_path) {&#xA;    // initialize FFmpeg&#xA;    av_log_set_level(AV_LOG_ERROR);&#xA;    avformat_network_init();&#xA;&#xA;    AVFormatContext* formatContext = nullptr;&#xA;    int error = avformat_open_input(&amp;formatContext, video_path.c_str(), nullptr, nullptr);&#xA;    checkError(error, "Error opening input file");&#xA;&#xA;    //Read packets of a media file to get stream information.&#xA;    &#xA;    error = avformat_find_stream_info(formatContext, nullptr);&#xA;    checkError(error, "Error avformat find stream info");&#xA;    &#xA;    // find the video stream&#xA;    AVStream* videoStream = nullptr;&#xA;    for (unsigned int i = 0; i &lt; formatContext->nb_streams; i&#x2B;&#x2B;) {&#xA;        if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &amp;&amp; !videoStream) {&#xA;            videoStream = formatContext->streams[i];&#xA;        }&#xA;    }&#xA;    if (!videoStream) {&#xA;        std::cerr &lt;&lt; "Error: input file does not contain a video stream" &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;&#xA;    // create the video codec context&#xA;    const AVCodec* videoCodec = avcodec_find_decoder(videoStream->codecpar->codec_id);&#xA;    AVCodecContext* videoCodecContext = avcodec_alloc_context3(videoCodec);&#xA;    if (!videoCodecContext) {&#xA;        std::cerr &lt;&lt; "Error allocating video codec context" &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;    &#xA;    std::cout &lt;&lt; "::informations::\n";&#xA;    std::cout &lt;&lt; "  bit_rate:" &lt;&lt; videoCodecContext->bit_rate &lt;&lt; "\n";&#xA;    std::cout &lt;&lt; "  width:" &lt;&lt; videoCodecContext->width &lt;&lt; "\n";&#xA;    std::cout &lt;&lt; "  height:" &lt;&lt; videoCodecContext->height &lt;&lt; "\n";&#xA;    std::cout &lt;&lt; "  gop_size:" &lt;&lt; videoCodecContext->gop_size &lt;&lt; "\n";&#xA;    std::cout &lt;&lt; "  max_b_frames:" &lt;&lt; videoCodecContext->max_b_frames &lt;&lt; "\n";&#xA;    std::cout &lt;&lt; "  pix_fmt:" &lt;&lt; videoCodecContext->pix_fmt &lt;&lt; "\n";&#xA;    &#xA;    error = avcodec_parameters_to_context(videoCodecContext, videoStream->codecpar);&#xA;    checkError(error, "Error setting video codec context parameters");&#xA;    error = avcodec_open2(videoCodecContext, videoCodec, nullptr);&#xA;    checkError(error, "Error opening video codec");&#xA;&#xA;    // create the frame scaler&#xA;    int width = videoCodecContext->width;&#xA;    int height = videoCodecContext->height;&#xA;    struct SwsContext* frameScaler = sws_getContext(width, height, videoCodecContext->pix_fmt, width, height, AV_PIX_FMT_BGR24, SWS_BICUBIC, nullptr, nullptr, nullptr);&#xA;&#xA;    // read the packets and decode the video frames&#xA;    std::vector videoFrames;&#xA;    AVPacket packet;&#xA;    while (av_read_frame(formatContext, &amp;packet) == 0) {&#xA;        if (packet.stream_index == videoStream->index) {&#xA;            // decode the video frame&#xA;            AVFrame* frame = av_frame_alloc();&#xA;            int gotFrame = 0;&#xA;            error = avcodec_send_packet(videoCodecContext, &amp;packet);&#xA;            checkError(error, "Error sending packet to video codec");&#xA;            error = avcodec_receive_frame(videoCodecContext, frame);&#xA;&#xA;            //There is not enough data for decoding the frame, have to free and get more data&#xA;            &#xA;            if (error == AVERROR(EAGAIN))&#xA;            {&#xA;                av_frame_unref(frame);&#xA;                av_freep(frame);&#xA;                continue;&#xA;            }&#xA;&#xA;            if (error == AVERROR_EOF)&#xA;            {&#xA;                std::cerr &lt;&lt; "AVERROR_EOF" &lt;&lt; std::endl;&#xA;                break;&#xA;            }&#xA;&#xA;            checkError(error, "Error receiving frame from video codec");&#xA;&#xA;&#xA;            if (error == 0) {&#xA;                gotFrame = 1;&#xA;            }&#xA;            if (gotFrame) {&#xA;                // scale the frame to the desired format&#xA;                AVFrame* scaledFrame = av_frame_alloc();&#xA;                av_image_alloc(scaledFrame->data, scaledFrame->linesize, width, height, AV_PIX_FMT_BGR24, 32);&#xA;                sws_scale(frameScaler, frame->data, frame->linesize, 0, height, scaledFrame->data, scaledFrame->linesize);&#xA;&#xA;                // copy the frame data to a cv::Mat object&#xA;                cv::Mat mat(height, width, CV_8UC3, scaledFrame->data[0], scaledFrame->linesize[0]);&#xA;&#xA;                videoFrames.push_back(mat.clone());&#xA;&#xA;                // clean up&#xA;                av_freep(&amp;scaledFrame->data[0]);&#xA;                av_frame_free(&amp;scaledFrame);&#xA;            }&#xA;            av_frame_free(&amp;frame);&#xA;        }&#xA;        av_packet_unref(&amp;packet);&#xA;    }&#xA;&#xA;&#xA;    // clean up&#xA;    sws_freeContext(frameScaler);&#xA;    avcodec_free_context(&amp;videoCodecContext);&#xA;    avformat_close_input(&amp;formatContext);&#xA;    return videoFrames;&#xA;}&#xA;&#xA;int main() {&#xA;    auto videoFrames = readVideo("input.mp4");&#xA;    cv::imwrite("test.png", videoFrames[10]);&#xA;    writeVideo("outnow.mp4", videoFrames, 512, 608, 30);&#xA;    //writeVideo("outnow.mp4", videoFrames);&#xA;    return 0;&#xA;}&#xA;</int></vector></string></iostream>

    &#xA;

  • Problem with FFMPEG and PHP

    10 septembre 2014, par ziritrion

    I know this isn’t exactly a programming question per se, but rather a settings question, but still :

    I’m trying to convert video with FFMPEG with a PHP script, following this tutorial :

    http://vexxhost.com/blog/2007/05/20/how-to-convertencode-files-to-flv-using-ffmpeg-php/

    FFMPEG works perfectly and I’ve used it from the command line a number of times. PHP also seems to work fine. I’ve also installed ffmpeg-php and it seems to be loading file.

    The problem lies when I try to do the following in PHP :

    $srcFile = "p1.avi" ;

    $ffmpegObj = new ffmpeg_movie($srcFile) ;

    No matter what, PHP will return this :

    Warning : can’t open movie file p1.avi in /var/www/converter.php on line xx

    Obviously, whatever call I do afterwards with $ffmpegObj will throw a fatal error. I’m absolutely stuck and extensive googling hasn’t helped much.

    If you must know, I’m using Ubuntu 9.04 with the default LAMP server packages as well as php5-ffmpeg, and I’ve compiled ffmpeg following a tutorial I found on Ubuntuforums (I’d link to it but stackoverflow won’t let me)

    Thanks !

  • Easily track Events within Matomo Analytics thanks to Matomo Tag Manager

    7 juin 2019, par Matomo Core Team — Analytics Tips

    Easily track Events within Matomo Analytics thanks to Matomo Tag Manager

    Introduction

    In this article we’ll cover what events in Matomo Analytics are ; and how you can easily set them up thanks to Matomo Tag Manager.

    Key concepts within this article

    • Events
    • Quick definition of the Tag Management System
    • Matomo config
    • Creating triggers
    • Variables

    What are events in Matomo Analytics and why are they useful ?

    Events allow you to measure interactions on your website which are not defined by default. With them you can measure clicks on some elements of a page, such as, how visitors are interacting with dropdown menus, media players, scrolling behaviours etc. You can also use them to define goals which make them a key feature in Matomo Analytics. Learn more about tracking events in Matomo.

    You can easily access the Events report in Matomo Analytics by clicking on the Behaviour category :

    Matomo tag manager event tracking

    And you may read the following message and feel a bit frustrated :

    Matomo tag manager event tracking

    “There is no data for this report” is a nice way to say, “Hey, you are tracking just a tiny part of what Matomo Analytics can do for you.”

    Matomo is a great software, but it can’t guess what you want to track.

    In order for Matomo to register those event tracking interactions, you’ll need to explain it by adding a line of code similar to this one when the interaction happens :

     

    _paq.push(['trackEvent', 'Here you enter whatever you want', 'Here too', 'and here also']);

     

    Let’s imagine you want to track a click on an HTML button, your code will look something similar to this at the moment of the interaction :

    As you can imagine, two main challenges will arise for non developers :

    1. How to access the source code ?
    2. How to define the interaction ?

    Luckily, Matomo Tag Manager makes those steps easy for you. Let’s see how the same tracking is implemented with Matomo Tag Manager.

    A quick definition of what Matomo Tag Manager is

    Matomo Tag Manager lets you manage all your tracking and marketing tags in one easy-to-access place. Please visit this page to learn more about Matomo Tag Manager. In order to start using it, you’ll need to copy/paste a tracking code, named a “container”, within the section of your pages.

    Once the container is on your website, all you need to do is to follow these simple steps :

    1. Add a Matomo Tag.
    2. Assign the condition to fire the tag (what we call the trigger).
    3. Publish your work.
    4. And enjoy

    1 – Add a Matomo Event tracking code

    All you have to do here is click on “CREATE NEW TAG”

    Matomo tag manager event tracking

    Once selected, just mention how you’d like this tag to be named (it is for your internal purpose here so always use an explicit tag name) and the Matomo configuration (the default configuration setting will be fine in most of the cases) :

    Matomo tag manager event tracking

    Then Matomo Tag Manager will ask you the type of tracking you’d like to deploy, in this case, this is an event so select “Event” :

    Matomo tag manager event tracking

    Then all you need is to indicate the values you’d like to push through your event :

    Matomo tag manager event tracking

    To put it in perspective, all we did here through Matomo Tag Manager was implement the equivalent of the following line of code :

    _paq.push(['trackEvent', 'Element interactions', 'Click button', 'Click Me']);

    Let’s now see how can we do this on click code part which we call a trigger.

    2 – Assign the condition to fire the tag

    In order to execute the event we’ll need to define when it will happen. You do this by clicking on Create a new trigger now :

    Matomo tag manager event tracking

    As the interaction we’d like to track is happening when a click occurs, it will be a click trigger, and as our button is not a link, we’ll select All Elements Click :

    Matomo tag manager event tracking

    Once selected you’ll need to be precise on the condition in which the event will be triggered. In this case we do not want to have events pushed every time someone is clicking on something on our website. We only want to track when they click on this specific button. That’s the reason why our trigger is set to fire only when the click occurs on an element which has an id and has the value “cta” :

    Once you click on the green button named CREATE NEW TRIGGER, you validate the tag by clicking on CREATE NEW TAG :

    Matomo tag manager event tracking
    Matomo tag manager event tracking

    Then you can move to the last part.

    3 – Publish your work

    Tag Managers are very powerful as they allow you to easily execute any JavaScript code, CSS or even text content on your websites.

    That’s why when you create your tag it doesn’t go live straight away on your website. In order to do this you need to publish your tag and this is what the “Publish” category is designed for :

    Matomo tag manager event tracking

    After that, click on the second button if you’re confident your tag and trigger are both ready to go live :

    Matomo event tracking tag manager

    4 – Enjoy

    Well done. As your tag is now live, every click made on this button will now be pushed to your Matomo Analytics account within :

    1. The visitor log report :

    Matomo event tracking tag manager

    2. The events report :

    Matomo event tracking tag manager

    You may now be asking, “That’s great, but can I collect something more exciting than clicks ?” 

    Of course you can ! This is what the Matomo Tag Manager is all about.

    As long as you can express it through a trigger you can really push whatever you want to Matomo Analytics. You can track scrolling patterns, an element visible on the page like an image, an ad or the time spent on the page. The options are now open to you with Tag Manager.

    Give them a try ! Change the triggers, start playing around with variables and discover that the possibilities are endless.

    Happy analytics,
    Matomo team