Recherche avancée

Médias (1)

Mot : - Tags -/bug

Autres articles (55)

  • Mise à disposition des fichiers

    14 avril 2011, par

    Par défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
    Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
    Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...)

  • La sauvegarde automatique de canaux SPIP

    1er avril 2010, par

    Dans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
    Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...)

  • Script d’installation automatique de MediaSPIP

    25 avril 2011, par

    Afin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
    Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
    La documentation de l’utilisation du script d’installation (...)

Sur d’autres sites (4396)

  • 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 << "Codec " << codec_name << " not found\n";
       exit(1);
    }

    c = avcodec_alloc_context3(codec);
    if (!c) {
       cerr << "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 < 0) {
       cerr << "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(&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

  • 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() << "Could not find suitable format for" << fileName;
       return false;
    }

    enum AVCodecID codec_id = AV_CODEC_ID_MJPEG;

    qDebug() << "Format Name:" << outputFormat->name;
    qDebug() << "Format Video Codec:" << 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() << "codec not found";
       return false;
    }

    qDebug() << "Codec name:" << 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() << "Error parameting the context:" << av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
       return false;
    }

    // open it
    if (int error = avcodec_open2(codecContext, codec, nullptr)) {
       qDebug() << "Could not open codec:" << 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 ?

  • 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>