Recherche avancée

Médias (1)

Mot : - Tags -/Christian Nold

Autres articles (109)

  • L’agrémenter visuellement

    10 avril 2011

    MediaSPIP est basé sur un système de thèmes et de squelettes. Les squelettes définissent le placement des informations dans la page, définissant un usage spécifique de la plateforme, et les thèmes l’habillage graphique général.
    Chacun peut proposer un nouveau thème graphique ou un squelette et le mettre à disposition de la communauté.

  • Problèmes fréquents

    10 mars 2010, par

    PHP et safe_mode activé
    Une des principales sources de problèmes relève de la configuration de PHP et notamment de l’activation du safe_mode
    La solution consiterait à soit désactiver le safe_mode soit placer le script dans un répertoire accessible par apache pour le site

  • Ajouter des informations spécifiques aux utilisateurs et autres modifications de comportement liées aux auteurs

    12 avril 2011, par

    La manière la plus simple d’ajouter des informations aux auteurs est d’installer le plugin Inscription3. Il permet également de modifier certains comportements liés aux utilisateurs (référez-vous à sa documentation pour plus d’informations).
    Il est également possible d’ajouter des champs aux auteurs en installant les plugins champs extras 2 et Interface pour champs extras.

Sur d’autres sites (6640)

  • Capture and encode desktop with libav in real time not giving corect images

    3 septembre 2022, par thoxey

    As part of a larger project I want to be able to capture and encode the desktop frame by frame in real time. I have the following test code to reproduce the issue shown in the screenshot :

    


    #include &#xA;#include &#xA;#include <iostream>&#xA;#include <fstream>&#xA;#include <string>&#xA;#include &#xA;#include &#xA;&#xA;extern "C"&#xA;{&#xA;#include "libavdevice/avdevice.h"&#xA;#include "libavutil/channel_layout.h"&#xA;#include "libavutil/mathematics.h"&#xA;#include "libavutil/opt.h"&#xA;#include "libavformat/avformat.h"&#xA;#include "libswscale/swscale.h"&#xA;}&#xA;&#xA;&#xA;/* 5 seconds stream duration */&#xA;#define STREAM_DURATION   5.0&#xA;#define STREAM_FRAME_RATE 25 /* 25 images/s */&#xA;#define STREAM_NB_FRAMES  ((int)(STREAM_DURATION * STREAM_FRAME_RATE))&#xA;#define STREAM_PIX_FMT    AV_PIX_FMT_YUV420P /* default pix_fmt */&#xA;&#xA;int videoStreamIndx;&#xA;int framerate = 30;&#xA;&#xA;int width = 1920;&#xA;int height = 1080;&#xA;&#xA;int encPacketCounter;&#xA;&#xA;AVFormatContext* ifmtCtx;&#xA;AVCodecContext* avcodecContx;&#xA;AVFormatContext* ofmtCtx;&#xA;AVStream* videoStream;&#xA;AVCodecContext* avCntxOut;&#xA;AVPacket* avPkt;&#xA;AVFrame* avFrame;&#xA;AVFrame* outFrame;&#xA;SwsContext* swsCtx;&#xA;&#xA;std::ofstream fs;&#xA;&#xA;&#xA;AVDictionary* ConfigureScreenCapture()&#xA;{&#xA;&#xA;    AVDictionary* options = NULL;&#xA;    //Try adding "-rtbufsize 100M" as in https://stackoverflow.com/questions/6766333/capture-windows-screen-with-ffmpeg&#xA;    av_dict_set(&amp;options, "rtbufsize", "100M", 0);&#xA;    av_dict_set(&amp;options, "framerate", std::to_string(framerate).c_str(), 0);&#xA;    char buffer[16];&#xA;    sprintf(buffer, "%dx%d", width, height);&#xA;    av_dict_set(&amp;options, "video_size", buffer, 0);&#xA;    return options;&#xA;}&#xA;&#xA;AVCodecParameters* ConfigureAvCodec()&#xA;{&#xA;    AVCodecParameters* av_codec_par_out = avcodec_parameters_alloc();&#xA;    av_codec_par_out->width = width;&#xA;    av_codec_par_out->height = height;&#xA;    av_codec_par_out->bit_rate = 40000;&#xA;    av_codec_par_out->codec_id = AV_CODEC_ID_H264; //AV_CODEC_ID_MPEG4; //Try H.264 instead of MPEG4&#xA;    av_codec_par_out->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    av_codec_par_out->format = 0;&#xA;    return av_codec_par_out;&#xA;}&#xA;&#xA;int GetVideoStreamIndex()&#xA;{&#xA;    int VideoStreamIndx = -1;&#xA;    avformat_find_stream_info(ifmtCtx, NULL);&#xA;    /* find the first video stream index . Also there is an API available to do the below operations */&#xA;    for (int i = 0; i &lt; (int)ifmtCtx->nb_streams; i&#x2B;&#x2B;) // find video stream position/index.&#xA;    {&#xA;        if (ifmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;        {&#xA;            VideoStreamIndx = i;&#xA;            break;&#xA;        }&#xA;    }&#xA;&#xA;    if (VideoStreamIndx == -1)&#xA;    {&#xA;    }&#xA;&#xA;    return VideoStreamIndx;&#xA;}&#xA;&#xA;void CreateFrames(AVCodecParameters* av_codec_par_in, AVCodecParameters* av_codec_par_out)&#xA;{&#xA;&#xA;    avFrame = av_frame_alloc();&#xA;    avFrame->width = avcodecContx->width;&#xA;    avFrame->height = avcodecContx->height;&#xA;    avFrame->format = av_codec_par_in->format;&#xA;    av_frame_get_buffer(avFrame, 0);&#xA;&#xA;    outFrame = av_frame_alloc();&#xA;    outFrame->width = avCntxOut->width;&#xA;    outFrame->height = avCntxOut->height;&#xA;    outFrame->format = av_codec_par_out->format;&#xA;    av_frame_get_buffer(outFrame, 0);&#xA;}&#xA;&#xA;bool Init()&#xA;{&#xA;    AVCodecParameters* avCodecParOut = ConfigureAvCodec();&#xA;&#xA;    AVDictionary* options = ConfigureScreenCapture();&#xA;&#xA;    AVInputFormat* ifmt = av_find_input_format("gdigrab");&#xA;    auto ifmtCtxLocal = avformat_alloc_context();&#xA;    if (avformat_open_input(&amp;ifmtCtxLocal, "desktop", ifmt, &amp;options) &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;    ifmtCtx = ifmtCtxLocal;&#xA;&#xA;    videoStreamIndx = GetVideoStreamIndex();&#xA;&#xA;    AVCodecParameters* avCodecParIn = avcodec_parameters_alloc();&#xA;    avCodecParIn = ifmtCtx->streams[videoStreamIndx]->codecpar;&#xA;&#xA;    AVCodec* avCodec = avcodec_find_decoder(avCodecParIn->codec_id);&#xA;    if (avCodec == NULL)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    avcodecContx = avcodec_alloc_context3(avCodec);&#xA;    if (avcodec_parameters_to_context(avcodecContx, avCodecParIn) &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    //av_dict_set&#xA;    int value = avcodec_open2(avcodecContx, avCodec, NULL); //Initialize the AVCodecContext to use the given AVCodec.&#xA;    if (value &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    AVOutputFormat* ofmt = av_guess_format("h264", NULL, NULL);&#xA;&#xA;    if (ofmt == NULL)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    auto ofmtCtxLocal = avformat_alloc_context();&#xA;    avformat_alloc_output_context2(&amp;ofmtCtxLocal, ofmt, NULL, NULL);&#xA;    if (ofmtCtxLocal == NULL)&#xA;    {&#xA;        return false;&#xA;    }&#xA;    ofmtCtx = ofmtCtxLocal;&#xA;&#xA;    AVCodec* avCodecOut = avcodec_find_encoder(avCodecParOut->codec_id);&#xA;    if (avCodecOut == NULL)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    videoStream = avformat_new_stream(ofmtCtx, avCodecOut);&#xA;    if (videoStream == NULL)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    avCntxOut = avcodec_alloc_context3(avCodecOut);&#xA;    if (avCntxOut == NULL)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avcodec_parameters_copy(videoStream->codecpar, avCodecParOut) &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avcodec_parameters_to_context(avCntxOut, avCodecParOut) &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    avCntxOut->gop_size = 30; //3; //Use I-Frame frame every 30 frames.&#xA;    avCntxOut->max_b_frames = 0;&#xA;    avCntxOut->time_base.num = 1;&#xA;    avCntxOut->time_base.den = framerate;&#xA;&#xA;    //avio_open(&amp;ofmtCtx->pb, "", AVIO_FLAG_READ_WRITE);&#xA;&#xA;    if (avformat_write_header(ofmtCtx, NULL) &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    value = avcodec_open2(avCntxOut, avCodecOut, NULL); //Initialize the AVCodecContext to use the given AVCodec.&#xA;    if (value &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avcodecContx->codec_id == AV_CODEC_ID_H264)&#xA;    {&#xA;        av_opt_set(avCntxOut->priv_data, "preset", "ultrafast", 0);&#xA;        av_opt_set(avCntxOut->priv_data, "zerolatency", "1", 0);&#xA;        av_opt_set(avCntxOut->priv_data, "tune", "ull", 0);&#xA;    }&#xA;&#xA;    if ((ofmtCtx->oformat->flags &amp; AVFMT_GLOBALHEADER) != 0)&#xA;    {&#xA;        avCntxOut->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;&#xA;    CreateFrames(avCodecParIn, avCodecParOut);&#xA;&#xA;    swsCtx = sws_alloc_context();&#xA;    if (sws_init_context(swsCtx, NULL, NULL) &lt; 0)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    swsCtx = sws_getContext(avcodecContx->width, avcodecContx->height, avcodecContx->pix_fmt,&#xA;        avCntxOut->width, avCntxOut->height, avCntxOut->pix_fmt, SWS_FAST_BILINEAR,&#xA;        NULL, NULL, NULL);&#xA;    if (swsCtx == NULL)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;void Encode(AVCodecContext* enc_ctx, AVFrame* frame, AVPacket* pkt)&#xA;{&#xA;    int ret;&#xA;&#xA;    /* send the frame to the encoder */&#xA;    ret = avcodec_send_frame(enc_ctx, frame);&#xA;    if (ret &lt; 0)&#xA;    {&#xA;        return;&#xA;    }&#xA;&#xA;    while (ret >= 0)&#xA;    {&#xA;        ret = avcodec_receive_packet(enc_ctx, pkt);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;            return;&#xA;        if (ret &lt; 0)&#xA;        {&#xA;            return;&#xA;        }&#xA;&#xA;        fs.write((char*)pkt->data, pkt->size);&#xA;        av_packet_unref(pkt);&#xA;    }&#xA;}&#xA;&#xA;void EncodeFrames(int noFrames)&#xA;{&#xA;    int frameCount = 0;&#xA;    avPkt = av_packet_alloc();&#xA;    AVPacket* outPacket = av_packet_alloc();&#xA;    encPacketCounter = 0;&#xA;&#xA;    while (av_read_frame(ifmtCtx, avPkt) >= 0)&#xA;    {&#xA;        if (frameCount&#x2B;&#x2B; == noFrames)&#xA;            break;&#xA;        if (avPkt->stream_index != videoStreamIndx) continue;&#xA;&#xA;        avcodec_send_packet(avcodecContx, avPkt);&#xA;&#xA;        if (avcodec_receive_frame(avcodecContx, avFrame) >= 0) // Frame successfully decoded :)&#xA;        {&#xA;            outPacket->data = NULL; // packet data will be allocated by the encoder&#xA;            outPacket->size = 0;&#xA;&#xA;            outPacket->pts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);&#xA;            if (outPacket->dts != AV_NOPTS_VALUE)&#xA;                outPacket->dts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);&#xA;&#xA;            outPacket->dts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);&#xA;            outPacket->duration = av_rescale_q(1, avCntxOut->time_base, videoStream->time_base);&#xA;&#xA;            outFrame->pts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);&#xA;            outFrame->pkt_duration = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);&#xA;            encPacketCounter&#x2B;&#x2B;;&#xA;&#xA;            int sts = sws_scale(swsCtx,&#xA;                avFrame->data, avFrame->linesize, 0, avFrame->height,&#xA;                outFrame->data, outFrame->linesize);&#xA;&#xA;            /* make sure the frame data is writable */&#xA;            auto ret = av_frame_make_writable(outFrame);&#xA;            if (ret &lt; 0)&#xA;                break;&#xA;            Encode(avCntxOut, outFrame, outPacket);&#xA;        }&#xA;        av_frame_unref(avFrame);&#xA;        av_packet_unref(avPkt);&#xA;    }&#xA;}&#xA;&#xA;void Dispose()&#xA;{&#xA;    fs.close();&#xA;&#xA;    auto ifmtCtxLocal = ifmtCtx;&#xA;    avformat_close_input(&amp;ifmtCtx);&#xA;    avformat_free_context(ifmtCtx);&#xA;    avcodec_free_context(&amp;avcodecContx);&#xA;&#xA;}&#xA;&#xA;int main(int argc, char** argv)&#xA;{&#xA;    avdevice_register_all();&#xA;&#xA;    fs.open("out.h264");&#xA;&#xA;    if (Init())&#xA;    {&#xA;        EncodeFrames(300);&#xA;    }&#xA;    else&#xA;    {&#xA;        std::cout &lt;&lt; "Failed to Init \n";&#xA;    }    &#xA;&#xA;    Dispose();&#xA;&#xA;    return 0;&#xA;}&#xA;</string></fstream></iostream>

    &#xA;

    As far as I can tell the setup of the encoding process is correct as it is largely unchanged from how the example given in the official documentation is working : https://libav.org/documentation/doxygen/master/encode__video_8c_source.html

    &#xA;

    However there is limited documentation around the desktop capture online so I am not sure if I have set that up correctly.

    &#xA;

    Bad image

    &#xA;

  • Revision 3213 : des items de langue et un logo par défaut

    9 avril 2010, par kent1 — Log

    des items de langue et un logo par défaut

  • Adding text to movie using ffmpeg

    23 août 2014, par microspace

    I use git to track *.ass subtitle files.
    Here is example of *.ass file :

    [Script Info]
    ; Script generated by Aegisub 3.1.2
    ; http://www.aegisub.org/
    Title: Default Aegisub file
    ScriptType: v4.00+

    [V4+ Styles]
    Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour,    BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
    Style: Default,Arial,20,&amp;H00FFFFFF,&amp;H000000FF,&amp;H00000000,&amp;H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
    Style: titr,DejaVu    

    Sans,20,&amp;H007DDBFA,&amp;H000000FF,&amp;H00000000,&amp;HFF000000,0,0,0,0,100,100,0,0,1,2,2,1,10,10,10,1

    [Events]
    Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
    Dialogue: 0,0:00:00.46,0:00:11.22,Default,,0,0,0,,Если это можно было бы
    Dialogue: 0,0:00:03.44,0:00:08.96,titr,,0,0,0,,{\pos(20,240)\fad(600,600)}бывший министр

    After commit I burn subtitles into video :

    ffmpeg -i video.avi -vf "ass=subtitle.ass" out.avi

    My goal is to show commit date for 10 second at the start of movie. This should be done automatically.

    1) It can be easily done with by modifying subtitle.ass itself, but I can’t do it after commit and there are other reasons.

    2) It can be done by ffmpeg from command line : How to use ffmpeg to add a text to avi video ?

    Problem is that in this case text will be shown for the whole lenght of movie.

    3) I can copy *.ass file to temporary directory, insert date, render and delete *.ass file.

    Is there a simpler way ?