Recherche avancée

Médias (1)

Mot : - Tags -/biographie

Autres articles (63)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

Sur d’autres sites (4893)

  • swscale : fix gbrap to gbrap alpha scaling

    15 janvier 2015, par Vittorio Giovara
    swscale : fix gbrap to gbrap alpha scaling
    
    • [DBH] libswscale/input.c
    • [DBH] tests/ref/fate/filter-pixfmts-scale
  • How can I use ffmpeg to create video with alpha from png in C code ?

    29 juin 2023, par reborn

    I'm trying to encode a video (mov) from png images with alpha channel in FFMPEG. Using cmd :

    


    ffmpeg -i %d.png -r 25 -vcodec png -b:v 2500K out.mov -y


    


    It works well.

    


    Now I want to use in c++ code, but it got error like this :

    


    [mov @ 0x29bf0c0] muxer does not support non seekable output


    


    I use it in code like this :

    


    oformat = av_guess_format("mov", nullptr, nullptr)
oformat->video_codec = AV_CODEC_ID_PNG;


    


    The ffmpeg shows :

    


    ffmpeg -h muxer=mov
Muxer mov [QuickTime / MOV]:
Common extensions: mov.
Default video codec: h264.
Default audio codec: aac.


    


    The default video codec is h264, but it can create mov with png encoder using ffmpeg Command Line like above

    


    ffmpeg -i out.mov

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'resa.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf59.24.100
  Duration: 00:00:03.00, start: 0.000000, bitrate: 13430 kb/s
  Stream #0:0: Video: png (png  / 0x20676E70), rgba(pc), 1280x720, 13427 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : FFMP


    


    How can I change this cmd to c code ?

    


    ffmpeg -i %d.png -r 25 -vcodec png -b:v 2500K out.mov -y


    


    The code I use :
Header file :

    


    #ifndef _RENDER_H_&#xA;#define _RENDER_H_&#xA;#include <iostream>&#xA;#include <cstdio>&#xA;#include <cstdlib>&#xA;#include <fstream>&#xA;#include <cstring>&#xA;#include &#xA;#include &#xA;#include <algorithm>&#xA;#include <string> &#xA;&#xA;extern "C"&#xA;{&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavcodec></libavcodec>avfft.h>&#xA;&#xA;#include <libavdevice></libavdevice>avdevice.h>&#xA;&#xA;#include <libavfilter></libavfilter>avfilter.h>&#xA;//#include <libavfilter></libavfilter>avfiltergraph.h>&#xA;#include <libavfilter></libavfilter>buffersink.h>&#xA;#include <libavfilter></libavfilter>buffersrc.h>&#xA;&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavformat></libavformat>avio.h>&#xA;&#xA;    &#xA;&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavutil></libavutil>common.h>&#xA;#include <libavutil></libavutil>channel_layout.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libavutil></libavutil>mathematics.h>&#xA;#include <libavutil></libavutil>samplefmt.h>&#xA;#include <libavutil></libavutil>time.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavutil></libavutil>pixdesc.h>&#xA;#include <libavutil></libavutil>file.h>&#xA;&#xA;&#xA;    &#xA;//#include "libavcodec/vdpau.h"&#xA;#include "libavutil/hwcontext.h"&#xA;//#include "libavutil/hwcontext_vdpau.h"&#xA;&#xA;    &#xA;&#xA;#include <libswscale></libswscale>swscale.h>&#xA;&#xA;    class VideoCapture {&#xA;    public:&#xA;&#xA;        VideoCapture() {&#xA;            oformat = nullptr;&#xA;            ofctx = nullptr;&#xA;            videoStream = nullptr;&#xA;            videoFrame = nullptr;&#xA;            swsCtx = nullptr;&#xA;            frameCounter = 0;&#xA;&#xA;            &#xA;            av_register_all();&#xA;            //av_log_set_callback(avlog_cb);&#xA;        }&#xA;&#xA;        ~VideoCapture() {&#xA;            //Free();&#xA;        }&#xA;&#xA;        void Init(std::string name, int width, int height, int fpsrate, int bitrate);&#xA;&#xA;        void AddFrame(uint8_t *data);&#xA;&#xA;        void Finish();&#xA;&#xA;    private:&#xA;&#xA;        AVOutputFormat *oformat;&#xA;        AVFormatContext *ofctx;&#xA;        AVIOContext *avio_out;&#xA;        AVStream *videoStream;&#xA;        AVFrame *videoFrame;&#xA;&#xA;        AVCodec *codec;&#xA;        AVCodecContext *cctx;&#xA;        struct buffer_data *bd;&#xA;        struct buffer_data* res_video;&#xA;        SwsContext *swsCtx;&#xA;        //FILE *fp_write;&#xA;        char* filename;&#xA;        //int buf_len;&#xA;        int frameCounter;&#xA;&#xA;        int fps;&#xA;&#xA;        void Free();&#xA;&#xA;        void Remux();&#xA;    };&#xA;&#xA;    struct buffer_data {&#xA;        uint8_t *ptr;&#xA;        size_t size; ///&lt; size left in the buffer&#xA;    };&#xA;&#xA;}&#xA;#endif&#xA;</string></algorithm></cstring></fstream></cstdlib></cstdio></iostream>

    &#xA;

    and the code :

    &#xA;

    #include "VideoCapture.h"&#xA;#define FINAL_FILE_NAME "record.mov"&#xA;#define VIDEO_TMP_FILE "tmp.avi"&#xA;&#xA;&#xA;using namespace std;&#xA;&#xA;FILE *fp_write;&#xA;static int write_packet(void *opaque, uint8_t *buf, size_t buf_size)&#xA;{&#xA;    struct buffer_data *bd = (struct buffer_data *)opaque;&#xA;    printf("ptr  :%p size:%zu\n", bd->ptr, bd->size);&#xA;    memcpy(bd->ptr &#x2B; bd->size, buf, buf_size);&#xA;    bd->size = buf_size &#x2B; bd->size;&#xA;    return 1;&#xA;}&#xA;&#xA;void VideoCapture::Init(string filename, int width, int height, int fpsrate, int bitrate) {&#xA;&#xA;    fps = fpsrate;&#xA;&#xA;    int err;&#xA;    uint8_t *outbuffer=nullptr;&#xA;    outbuffer=(uint8_t*)av_malloc(32768);&#xA;    bd = (struct buffer_data*)malloc(sizeof(struct buffer_data));&#xA;    bd->ptr = (uint8_t*)av_malloc(1000000000);&#xA;    bd->size = 0;&#xA;    avio_out =avio_alloc_context(outbuffer, 32768,1,bd,nullptr,write_packet,nullptr);&#xA;    if (!(oformat = av_guess_format("mov", nullptr, nullptr))) {&#xA;        cout &lt;&lt; "Failed to define output format"&lt;&lt; endl;&#xA;        return;&#xA;    }&#xA;    oformat->video_codec = AV_CODEC_ID_PNG;&#xA;    cout &lt;&lt; "oformat->video_codec " &lt;&lt; oformat->video_codec &lt;&lt; endl;&#xA;    if ((err = avformat_alloc_output_context2(&amp;ofctx, oformat, nullptr, nullptr) &lt; 0)) {&#xA;        cout  &lt;&lt;"Failed to allocate output context"&lt;&lt; endl;&#xA;        //Free();&#xA;        return;&#xA;    }&#xA;    cout &lt;&lt; "oformat->video_codec " &lt;&lt; oformat->video_codec &lt;&lt; endl;&#xA;    if (!(codec = avcodec_find_encoder(oformat->video_codec))) {&#xA;        cout &lt;&lt;"Failed to find encoder"&lt;&lt; endl;&#xA;        //Free();&#xA;        return;&#xA;    }&#xA;&#xA;    if (!(videoStream = avformat_new_stream(ofctx, codec))) {&#xA;        cout &lt;&lt;"Failed to create new stream"&lt;&lt; endl;&#xA;        //Free();&#xA;        return;&#xA;    }&#xA;&#xA;    if (!(cctx = avcodec_alloc_context3(codec))) {&#xA;        cout &lt;&lt;"Failed to allocate codec context"&lt;&lt; endl;&#xA;        //Free();&#xA;        return;&#xA;    }&#xA;&#xA;    videoStream->codecpar->codec_id = oformat->video_codec;&#xA;    videoStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    videoStream->codecpar->width = width;&#xA;    videoStream->codecpar->height = height;&#xA;    videoStream->codecpar->format = AV_PIX_FMT_RGBA;&#xA;    videoStream->codecpar->bit_rate = bitrate * 1000;&#xA;    videoStream->time_base = { 1, fps };&#xA;&#xA;    avcodec_parameters_to_context(cctx, videoStream->codecpar);&#xA;    cctx->time_base = { 1, fps };&#xA;    cctx->max_b_frames = 2;&#xA;    cctx->gop_size = 12;&#xA;    if (videoStream->codecpar->codec_id == AV_CODEC_ID_PNG) {&#xA;        //av_opt_set(cctx, "preset", "ultrafast", 0);&#xA;    }&#xA;    if (ofctx->oformat->flags &amp; AVFMT_GLOBALHEADER) {&#xA;        cctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;    avcodec_parameters_from_context(videoStream->codecpar, cctx);&#xA;&#xA;    if ((err = avcodec_open2(cctx, codec, nullptr)) &lt; 0) {&#xA;        cout &lt;&lt;"Failed to open codec"&lt;&lt; endl;&#xA;        Free();&#xA;        return;&#xA;    }&#xA;    &#xA;    ofctx->pb = avio_out;&#xA;    &#xA;    ofctx->flags=AVFMT_FLAG_CUSTOM_IO;&#xA;    if ((err = avformat_write_header(ofctx, nullptr)) &lt; 0) {&#xA;        cout &lt;&lt;"Failed to write header"&lt;&lt; endl;&#xA;        Free();&#xA;        return;&#xA;    }&#xA;&#xA;    //av_dump_format(ofctx, 0, VIDEO_TMP_FILE, 1);&#xA;    cout &lt;&lt; "init com" &lt;&lt; endl;&#xA;}&#xA;&#xA;void VideoCapture::AddFrame(uint8_t *data) {&#xA;    int err;&#xA;    if (!videoFrame) {&#xA;&#xA;        videoFrame = av_frame_alloc();&#xA;        videoFrame->format = AV_PIX_FMT_RGBA;&#xA;        videoFrame->width = cctx->width;&#xA;        videoFrame->height = cctx->height;&#xA;&#xA;        if ((err = av_frame_get_buffer(videoFrame, 32)) &lt; 0) {&#xA;            cout &lt;&lt;"Failed to allocate picture"&lt;&lt; endl;&#xA;            return;&#xA;        }&#xA;    }&#xA;    cout &lt;&lt; "finish" &lt;&lt; endl;&#xA;    if (!swsCtx) {&#xA;        swsCtx = sws_getContext(cctx->width, cctx->height, AV_PIX_FMT_RGBA, cctx->width, cctx->height, AV_PIX_FMT_RGBA, SWS_BICUBIC, 0, 0, 0);&#xA;    }&#xA;&#xA;    int inLinesize[1] = { 4 * cctx->width};&#xA;&#xA;    &#xA;    sws_scale(swsCtx, (const uint8_t * const *)&amp;data, inLinesize, 0, cctx->height, videoFrame->data, videoFrame->linesize);&#xA;&#xA;    videoFrame->pts = (1.0 / 30.0) * 90000 * (frameCounter&#x2B;&#x2B;);;&#xA;&#xA;    if ((err = avcodec_send_frame(cctx, videoFrame)) &lt; 0) {&#xA;        cout &lt;&lt;"Failed to send frame"&lt;&lt; endl;&#xA;        return;&#xA;    }&#xA;&#xA;    AVPacket pkt;&#xA;    av_init_packet(&amp;pkt);&#xA;    pkt.data = nullptr;&#xA;    pkt.size = 0;&#xA;&#xA;    if (avcodec_receive_packet(cctx, &amp;pkt) == 0) {&#xA;        pkt.flags |= AV_PKT_FLAG_KEY;&#xA;        av_interleaved_write_frame(ofctx, &amp;pkt);&#xA;        av_packet_unref(&amp;pkt);&#xA;    }&#xA;}&#xA;&#xA;void VideoCapture::Finish() {&#xA;    &#xA;    AVPacket pkt;&#xA;    av_init_packet(&amp;pkt);&#xA;    pkt.data = nullptr;&#xA;    pkt.size = 0;&#xA;&#xA;    for (;;) {&#xA;        avcodec_send_frame(cctx, nullptr);&#xA;        if (avcodec_receive_packet(cctx, &amp;pkt) == 0) {&#xA;            av_interleaved_write_frame(ofctx, &amp;pkt);&#xA;            av_packet_unref(&amp;pkt);&#xA;        }&#xA;        else {&#xA;            break;&#xA;        }&#xA;    }&#xA;    &#xA;    &#xA;    av_write_trailer(ofctx);&#xA;    /*&#xA;    if (!(oformat->flags &amp; AVFMT_NOFILE)) {&#xA;        int err = avio_close(ofctx->pb);&#xA;        if (err &lt; 0) {&#xA;            cout &lt;&lt;"Failed to close file"&lt;&lt; endl;&#xA;        }&#xA;    }&#xA;    */&#xA;    fp_write = fopen(VIDEO_TMP_FILE, "wb");&#xA;    if (!feof(fp_write)) {&#xA;        int true_size = fwrite(bd->ptr, 1, bd->size, fp_write);&#xA;        std::cout &lt;&lt; true_size &lt;&lt; std::endl;&#xA;    }&#xA;    fcloseall();&#xA;&#xA;    //Remux();&#xA;    //Free();&#xA;}&#xA;&#xA;void VideoCapture::Free() {&#xA;    if (videoFrame) {&#xA;        //std::cout &lt;&lt; "videoFrame " &lt;&lt; std::endl;&#xA;        av_frame_free(&amp;videoFrame);&#xA;    }&#xA;    if (cctx) {&#xA;        //std::cout &lt;&lt; "cctx" &lt;&lt; std::endl;&#xA;        avcodec_free_context(&amp;cctx);&#xA;    }&#xA;    if (ofctx) {&#xA;        //std::cout &lt;&lt; "ofctx" &lt;&lt; ofctx &lt;&lt; std::endl;&#xA;        avformat_free_context(ofctx);&#xA;    }&#xA;    if (swsCtx) {&#xA;        //std::cout &lt;&lt; "swsCtx" &lt;&lt; std::endl;&#xA;        sws_freeContext(swsCtx);&#xA;    }&#xA;    /*&#xA;    if (bd->ptr != (void*)0)&#xA;    {&#xA;        free(bd->ptr);&#xA;    }&#xA;    free(bd);*/&#xA;}&#xA;&#xA;static int read_packet(void *opaque, uint8_t *buf, int buf_size)&#xA;{&#xA;    struct buffer_data *bd = (struct buffer_data *)opaque;&#xA;    buf_size = FFMIN(buf_size, bd->size);&#xA;    if(buf_size == 0) return -1;&#xA;    //printf("read ptr:%p size:%zu\n", bd->ptr, bd->size);&#xA;    /* copy internal buffer data to buf */&#xA;    memcpy(buf, bd->ptr, buf_size);&#xA;    bd->ptr  &#x2B;= buf_size;&#xA;    bd->size -= buf_size;&#xA;    return buf_size;&#xA;}&#xA;&#xA;void VideoCapture::Remux() {&#xA;    AVFormatContext *ifmt_ctx = nullptr, *ofmt_ctx = nullptr;&#xA;    int err;&#xA;&#xA;    unsigned char* inbuffer=nullptr;&#xA;    inbuffer=(unsigned char*)av_malloc(32768);&#xA;    ifmt_ctx = avformat_alloc_context();&#xA;    AVIOContext *avio_in =avio_alloc_context(inbuffer, 32768 ,0,bd,read_packet,nullptr,nullptr);&#xA;    ifmt_ctx->pb=avio_in;&#xA;    &#xA;    if (!(oformat = av_guess_format(nullptr, nullptr, "h264"))) {&#xA;        cout &lt;&lt; "Failed to define output format";&#xA;        return;&#xA;    }&#xA;&#xA;    if ((err = avformat_open_input(&amp;ifmt_ctx, "nullptr", 0, 0)) &lt; 0) {&#xA;        cout &lt;&lt;"Failed to open input file for remuxing"&lt;&lt; endl;&#xA;    }&#xA;    if ((err = avformat_find_stream_info(ifmt_ctx, 0)) &lt; 0) {&#xA;        cout &lt;&lt;"Failed to retrieve input stream information"&lt;&lt; endl;&#xA;    }&#xA;    if ((err = avformat_alloc_output_context2(&amp;ofmt_ctx, oformat, nullptr, nullptr))) {&#xA;        cout &lt;&lt;"Failed to allocate output context"&lt;&lt; endl;&#xA;    }&#xA;&#xA;    AVStream *inVideoStream = ifmt_ctx->streams[0];&#xA;    AVStream *outVideoStream = avformat_new_stream(ofmt_ctx, nullptr);&#xA;    if (!outVideoStream) {&#xA;        cout &lt;&lt;"Failed to allocate output video stream" &lt;&lt; endl;&#xA;    }&#xA;    outVideoStream->time_base = { 1, fps };&#xA;    avcodec_parameters_copy(outVideoStream->codecpar, inVideoStream->codecpar);&#xA;    outVideoStream->codecpar->codec_tag = 0;&#xA;    &#xA;    uint8_t *outbuffer=nullptr;&#xA;    outbuffer=(uint8_t*)av_malloc(32768);&#xA;    res_video = (struct buffer_data*)malloc(sizeof(struct buffer_data));&#xA;    res_video->ptr = (uint8_t*)av_malloc(100000000);&#xA;    res_video->size = 0;&#xA;&#xA;    if (!(ofmt_ctx->oformat->flags &amp; AVFMT_NOFILE)) {&#xA;        avio_out =avio_alloc_context(outbuffer, 32768,1, res_video, nullptr, write_packet, nullptr);&#xA;        ofmt_ctx->pb = avio_out;&#xA;    }&#xA;    AVDictionary* opts = nullptr;&#xA;    av_dict_set(&amp;opts, "movflags", "frag_keyframe&#x2B;empty_moov", 0);&#xA;    if ((err = avformat_write_header(ofmt_ctx, &amp;opts)) &lt; 0) {&#xA;        cout &lt;&lt;"Failed to write header to output file"&lt;&lt; endl;&#xA;    }&#xA;&#xA;    AVPacket videoPkt;&#xA;    int ts = 0;&#xA;    while (true) {&#xA;        if ((err = av_read_frame(ifmt_ctx, &amp;videoPkt)) &lt; 0) {&#xA;            break;&#xA;        }&#xA;        videoPkt.stream_index = outVideoStream->index;&#xA;        videoPkt.pts = ts;&#xA;        videoPkt.dts = ts;&#xA;        videoPkt.duration = av_rescale_q(videoPkt.duration, inVideoStream->time_base, outVideoStream->time_base);&#xA;        ts &#x2B;= videoPkt.duration;&#xA;        videoPkt.pos = -1;&#xA;        if ((err = av_interleaved_write_frame(ofmt_ctx, &amp;videoPkt)) &lt; 0) {&#xA;            cout &lt;&lt;"Failed to mux packet"&lt;&lt; endl;&#xA;            av_packet_unref(&amp;videoPkt);&#xA;            break;&#xA;        }&#xA;        av_packet_unref(&amp;videoPkt);&#xA;    }&#xA;&#xA;    av_write_trailer(ofmt_ctx);&#xA;    cout &lt;&lt; "res_video->size " &lt;&lt; res_video->size &lt;&lt; endl;&#xA;    fp_write=fopen(FINAL_FILE_NAME,"wb");&#xA;    if(!feof(fp_write)){&#xA;        int true_size=fwrite(res_video->ptr,1, res_video->size,fp_write);&#xA;        std::cout &lt;&lt; true_size &lt;&lt; std::endl;&#xA;    }&#xA;    fcloseall();&#xA;}&#xA;

    &#xA;

  • How to use callback function in ffmpeg

    9 septembre 2014, par chesschi
    static int interrupt_cb(void *ctx)

    I understand that many of the functions provided by the ffmpeg libraries are blocking. In order to control the blocking function to timeout, we can assign a callback function to interrupt_callback.

    For example, the avformat_open_input may take 1 second to complete. If I set a timer for 500 milliseconds, will it never be able to connect to the RTSP server and return non-zero value ?

    What is the optimal value for setting this timeout ? What will these blocking functions behave when the timeout value is too small ?

    What is the best approach to use this callback function ?