Recherche avancée

Médias (0)

Mot : - Tags -/xmlrpc

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

Autres articles (65)

  • 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

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

  • Supporting all media types

    13 avril 2011, par

    Unlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)

Sur d’autres sites (11037)

  • libav how to change stream codec

    9 novembre 2018, par Rodolfo Picoreti

    I am trying to reproduce with libav the same thing that the following ffmpeg command does :

    ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video 0 -f
    mpegts -codec:v mpeg1video -s 640x480 -b:v 1000k -bf 0 -muxdelay
    0.001 http://localhost:8081/supersecret

    I manage to reproduce most part of it. The problem is that when allocating the "mpegts" stream (line 23) the codec that is selected is "mpeg2video", but I need it to be "mpeg1video". I tried forcing the codec_id variable to be "mpeg1video" (line 25) and it kinda worked, although I get a lot of artifacts in the image so I am guessing this is not how you do it. How can I properly change the codec in this case (that is, the "-codec:v mpeg1video" part of the ffmpeg command) ?

    C++ code being used :

    #include <exception>
    #include <opencv2></opencv2>core.hpp>
    #include <opencv2></opencv2>highgui.hpp>
    #include <opencv2></opencv2>imgproc.hpp>

    extern "C" {
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libavutil></libavutil>error.h>
    #include <libavutil></libavutil>frame.h>
    #include <libavutil></libavutil>imgutils.h>
    }

    struct AVStreamer {
     AVFormatContext* format_context;
     AVStream* stream;
     AVCodecContext* codec_context;
     AVCodec* codec;
     AVFrame* frame;
     int64_t next_pts;

     void init_format_context(const char* url) {
       avformat_alloc_output_context2(&amp;format_context, nullptr, "mpegts", url);
       if (format_context == nullptr) throw std::runtime_error("Could not create output context");
       format_context->oformat->video_codec = AV_CODEC_ID_MPEG1VIDEO;
     }

     void init_codec() {
       auto codec_id = format_context->oformat->video_codec;
       codec = avcodec_find_encoder(codec_id);
       if (codec == nullptr) throw std::runtime_error("Could not find encoder");
     }

     void init_stream() {
       stream = avformat_new_stream(format_context, nullptr);
       if (stream == nullptr) throw std::runtime_error("Failed to alloc stream");
       stream->id = format_context->nb_streams - 1;
     }

     void init_codec_context() {
       codec_context = avcodec_alloc_context3(codec);
       if (codec_context == nullptr) throw std::runtime_error("Failed to alloc encoding context");

       auto codec_id = format_context->oformat->video_codec;
       codec_context->codec_id = codec_id;
       codec_context->bit_rate = 400000;
       codec_context->width = 640;
       codec_context->height = 480;
       stream->time_base = AVRational{1, 30};
       codec_context->time_base = stream->time_base;
       codec_context->gop_size = 30;  // one intra frame every gop_size
       // codec_context->max_b_frames = 0;  // output delayed by max_b_frames
       codec_context->pix_fmt = AV_PIX_FMT_YUV420P;
       if (codec_context->codec_id == AV_CODEC_ID_MPEG1VIDEO) { codec_context->mb_decision = 2; }
       if (format_context->oformat->flags &amp; AVFMT_GLOBALHEADER) {
         codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
       }
     }

     void init_frame() {
       frame = av_frame_alloc();
       if (frame == nullptr) throw std::runtime_error("Failed to alloc frame");
       frame->format = codec_context->pix_fmt;
       frame->width = codec_context->width;
       frame->height = codec_context->height;

       auto status = av_frame_get_buffer(frame, 32);
       if (status &lt; 0) { throw std::runtime_error("Could not allocate frame data.\n"); }
     }

     void open_stream(const char* url) {
       int status = avcodec_open2(codec_context, codec, nullptr);
       if (status != 0) throw std::runtime_error("Failed to open codec");

       // copy the stream parameters to the muxer
       status = avcodec_parameters_from_context(stream->codecpar, codec_context);
       if (status &lt; 0) throw std::runtime_error("Could not copy the stream parameters");

       av_dump_format(format_context, 0, url, 1);

       if (!(format_context->oformat->flags &amp; AVFMT_NOFILE)) {
         status = avio_open(&amp;format_context->pb, url, AVIO_FLAG_WRITE);
         if (status &lt; 0) throw std::runtime_error("Could not open output file");
       }

       // Write the stream header, if any.
       status = avformat_write_header(format_context, nullptr);
       if (status &lt; 0) throw std::runtime_error("Error occurred when opening output file");
     }

     AVStreamer(const char* url) : next_pts(0) {
       init_format_context(url);
       init_codec();
       init_stream();
       init_codec_context();
       init_frame();
       open_stream(url);
     }

     virtual ~AVStreamer() {
       avformat_free_context(format_context);
       avcodec_free_context(&amp;codec_context);
       av_frame_free(&amp;frame);
     }

     void send(cv::Mat const&amp; image) {
       cv::cvtColor(image, image, CV_BGR2YUV);
       cv::Mat planes[3];
       cv::split(image, planes);
       cv::pyrDown(planes[1], planes[1]);
       cv::pyrDown(planes[2], planes[2]);

       if (av_frame_make_writable(frame) &lt; 0) {
         throw std::runtime_error("Failed to make frame writable");
       }

       frame->data[0] = planes[0].data;
       frame->linesize[0] = planes[0].step;
       frame->data[1] = planes[1].data;
       frame->linesize[1] = planes[1].step;
       frame->data[2] = planes[2].data;
       frame->linesize[2] = planes[2].step;
       frame->pts = next_pts++;

       AVPacket packet;
       av_init_packet(&amp;packet);

       int status = avcodec_send_frame(codec_context, frame);
       if (status &lt; 0) throw std::runtime_error("Send frame failed");

       status = avcodec_receive_packet(codec_context, &amp;packet);
       if (status == AVERROR(EAGAIN)) { return; }
       if (status &lt; 0) throw std::runtime_error("Receive packet failed");

       av_packet_rescale_ts(&amp;packet, codec_context->time_base, stream->time_base);
       packet.stream_index = stream->index;
       av_interleaved_write_frame(format_context, &amp;packet);
     }
    };

    int main(int argc, char** argv) {
     av_register_all();
     avformat_network_init();

     auto url = argc == 2 ? argv[1] : "http://localhost:8081/supersecret";
     AVStreamer streamer(url);

     cv::VideoCapture video(0);
     assert(video.isOpened() &amp;&amp; "Failed to open video");

     for (;;) {
       cv::Mat image;
       video >> image;
       streamer.send(image);
     }
    }
    </exception>
  • Create movie programatically with ffmpeg

    16 janvier 2019, par Martin Delille

    I would like to create a movie programatically with ffmpeg.

    Here is my code :

    QString fileName = "test.mov";
    static char errorString[AV_ERROR_MAX_STRING_SIZE];

    printf("Video encoding\n");

    AVOutputFormat *outputFormat = av_guess_format(nullptr, fileName.toStdString().c_str(), nullptr);

    if (outputFormat == nullptr) {
       qDebug() &lt;&lt; "Could not find suitable format for" &lt;&lt; fileName;
       return false;
    }

    enum AVCodecID codec_id = AV_CODEC_ID_MJPEG;

    qDebug() &lt;&lt; "Format Name:" &lt;&lt; outputFormat->name;
    qDebug() &lt;&lt; "Format Video Codec:" &lt;&lt; outputFormat->video_codec;
    outputFormat->video_codec = codec_id;

    /// allocate the output media context, formatContext
    AVFormatContext *formatContext = avformat_alloc_context();
    formatContext->oformat = outputFormat;

    // find the mpeg1 video encoder
    AVCodec *codec = avcodec_find_encoder(codec_id);

    if (!codec) {
       qDebug() &lt;&lt; "codec not found";
       return false;
    }

    qDebug() &lt;&lt; "Codec name:" &lt;&lt; codec->name;

    AVStream *videoStream = avformat_new_stream(formatContext, codec);
    // put sample parameters
    videoStream->codecpar->bit_rate = 400000;
    videoStream->codecpar->width = width;
    videoStream->codecpar->height = height;
    videoStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
    videoStream->codecpar->format = AV_PIX_FMT_YUVJ422P;
    videoStream->time_base.num = 1;
    videoStream->time_base.den = 25;

    AVCodecContext *codecContext = avcodec_alloc_context3(nullptr);
    codecContext->codec_id = codec_id;
    codecContext->codec_type = AVMEDIA_TYPE_VIDEO;
    codecContext->width = width;
    codecContext->height = height;
    codecContext->time_base.num = 1;
    codecContext->time_base.den = 25;
    codecContext->pix_fmt = AV_PIX_FMT_YUVJ422P;

    if (int error = avcodec_parameters_to_context(codecContext, videoStream->codecpar)) {
       qDebug() &lt;&lt; "Error parameting the context:" &lt;&lt; av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
       return false;
    }

    // open it
    if (int error = avcodec_open2(codecContext, codec, nullptr)) {
       qDebug() &lt;&lt; "Could not open codec:" &lt;&lt; av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
       return false;
    }

    // alloc image and output buffer
    AVFrame *frame = av_frame_alloc();
    frame->format = codecContext->pix_fmt;
    frame->width = codecContext->width;
    frame->height = codecContext->height;

    if (int error = av_image_alloc(frame->data, frame->linesize, frame->width, frame->height, static_cast<enum avpixelformat="avpixelformat">(frame->format), 0)) {
       qDebug() &lt;&lt; "Error allocating image data:" &lt;&lt; av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
       return false;
    }

    // Open the output file, if needed
    if (!(outputFormat->flags &amp; AVFMT_NOFILE)) {
       if (avio_open(&amp;formatContext->pb, fileName.toStdString().c_str(), AVIO_FLAG_WRITE) &lt; 0) {
           qDebug() &lt;&lt; "Could not open" &lt;&lt; fileName;
           return false;
       }
    }

    // some formats want stream headers to be separate
    if (formatContext->oformat->flags &amp; AVFMT_GLOBALHEADER) {
       codecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
    }

    if (int error = avformat_write_header(formatContext, nullptr)) {
       qDebug() &lt;&lt; "error writing header:" &lt;&lt; av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
       return false;
    }
    </enum>

    Unfortunately, when I execute it I have the following output :

    Format Name: mov
    Format Video Codec: 27
    Codec name: mjpeg
    [mov @ 0x1048c7000] Could not find tag for codec none in stream #0, codec not currently supported in container
    error writing header: Invalid argument

    What am I doing wrong ?

  • Live555 truncates encoded data of FFMpeg

    22 novembre 2019, par Harshil Makwana

    I am trying to stream H264 based data using Live555 over RTSP.

    I am capturing data using V4L2, and then encodes it using FFMPEG and then passing data to Live555’s DeviceSource file, in that I using H264VideoStreamFramer class,

    Below is my codec settings to configure AVCodecContext of encoder,

    codec = avcodec_find_encoder_by_name(CODEC_NAME);
    if (!codec) {
       cerr &lt;&lt; "Codec " &lt;&lt; codec_name &lt;&lt; " not found\n";
       exit(1);
    }

    c = avcodec_alloc_context3(codec);
    if (!c) {
       cerr &lt;&lt; "Could not allocate video codec context\n";
       exit(1);
    }

    pkt = av_packet_alloc();
    if (!pkt)
       exit(1);

    /* put sample parameters */
    c->bit_rate = 400000;
    /* resolution must be a multiple of two */
    c->width = PIC_HEIGHT;
    c->height = PIC_WIDTH;
    /* frames per second */
    c->time_base = (AVRational){1, FPS};
    c->framerate = (AVRational){FPS, 1};
    c->gop_size = 10;
    c->max_b_frames = 1;
    c->pix_fmt = AV_PIX_FMT_YUV420P;
    c->rtp_payload_size = 30000;
    if (codec->id == AV_CODEC_ID_H264)
       av_opt_set(c->priv_data, "preset", "fast", 0);
    av_opt_set_int(c->priv_data, "slice-max-size", 30000, 0);
    /* open it */
    ret = avcodec_open2(c, codec, NULL);
    if (ret &lt; 0) {
       cerr &lt;&lt; "Could not open codec\n";
       exit(1);
    }

    And I am getting encoded data using avcodec_receive_packet() function. which will return AVPacket.

    And I am passing AVPacket’s data into DeviceSource file below is code snippet of my Live555 code :

    void DeviceSource::deliverFrame() {
       if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet

       u_int8_t* newFrameDataStart = (u_int8_t*) pkt->data;
       unsigned newFrameSize = pkt->size; //%%% TO BE WRITTEN %%%
       // Deliver the data here:
       if (newFrameSize > fMaxSize) { // Condition becomes true many times
           fFrameSize = fMaxSize;
           fNumTruncatedBytes = newFrameSize - fMaxSize;
       } else {
           fFrameSize = newFrameSize;
       }
       gettimeofday(&amp;fPresentationTime, NULL); // If you have a more accurate time - e.g., from an encoder - then use that instead.
       // If the device is *not* a 'live source' (e.g., it comes instead from a file or buffer), then set "fDurationInMicroseconds" here.
       memmove(fTo, newFrameDataStart, fFrameSize);
    }

    But here, sometimes my packet’s size is getting more than fMaxSize value and as per LIVE555 logic it will truncate frame data, so that sometimes I am getting bad frames on my VLC,

    From Live555 forum, I get to know that encoder should not send packet whose size is more than fMaxSize value, so my question is :

    How to restrict encoder to limit size of packet ?

    Thanks in Advance,

    Harshil