Recherche avancée

Médias (91)

Autres articles (111)

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

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

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

  • avformat_write_header() function call crashed when I try to save several RGB data to a output.mp4 file

    1er mai 2023, par ollydbg23

    I try to save several image data(in memory, with BGR format) to a output.mp4 file, here is the C++ code to call the ffmpeg library, the code builds correctly, but will crash when I call the ret = avformat_write_header(outFormatCtx, nullptr);, do you know how to solve this crash issue ?

    


    Thanks.

    


    #include <iostream>&#xA;#include <vector>&#xA;#include <cstring>&#xA;#include <fstream>&#xA;#include <sstream>&#xA;#include <stdexcept>&#xA;#include <opencv2></opencv2>opencv.hpp>&#xA;extern "C" {&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;}&#xA;&#xA;using namespace std;&#xA;using namespace cv;&#xA;&#xA;int main()&#xA;{&#xA;    // Set up input frames as BGR byte arrays&#xA;    vector<mat> frames;&#xA;&#xA;    int width = 640;&#xA;    int height = 480;&#xA;    int num_frames = 100;&#xA;    Scalar black(0, 0, 0);&#xA;    Scalar white(255, 255, 255);&#xA;    int font = FONT_HERSHEY_SIMPLEX;&#xA;    double font_scale = 1.0;&#xA;    int thickness = 2;&#xA;&#xA;    for (int i = 0; i &lt; num_frames; i&#x2B;&#x2B;) {&#xA;        Mat frame = Mat::zeros(height, width, CV_8UC3);&#xA;        putText(frame, std::to_string(i), Point(width / 2 - 50, height / 2), font, font_scale, white, thickness);&#xA;        frames.push_back(frame);&#xA;    }&#xA;&#xA;&#xA;    // Populate frames with BGR byte arrays&#xA;&#xA;    // Initialize FFmpeg&#xA;    //av_register_all();&#xA;&#xA;    // Set up output file&#xA;    AVFormatContext* outFormatCtx = nullptr;&#xA;    //AVCodec* outCodec = nullptr;&#xA;    AVCodecContext* outCodecCtx = nullptr;&#xA;    //AVStream* outStream = nullptr;&#xA;    AVPacket outPacket;&#xA;&#xA;    const char* outFile = "output.mp4";&#xA;    int outWidth = frames[0].cols;&#xA;    int outHeight = frames[0].rows;&#xA;    int fps = 30;&#xA;&#xA;    // Open output file&#xA;    avformat_alloc_output_context2(&amp;outFormatCtx, nullptr, nullptr, outFile);&#xA;    if (!outFormatCtx) {&#xA;        cerr &lt;&lt; "Error: Could not allocate output format context" &lt;&lt; endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    // Set up output codec&#xA;    const AVCodec* outCodec = avcodec_find_encoder(AV_CODEC_ID_H264);&#xA;    if (!outCodec) {&#xA;        cerr &lt;&lt; "Error: Could not find H.264 codec" &lt;&lt; endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    outCodecCtx = avcodec_alloc_context3(outCodec);&#xA;    if (!outCodecCtx) {&#xA;        cerr &lt;&lt; "Error: Could not allocate output codec context" &lt;&lt; endl;&#xA;        return -1;&#xA;    }&#xA;    outCodecCtx->codec_id = AV_CODEC_ID_H264;&#xA;    outCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    outCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;    outCodecCtx->width = outWidth;&#xA;    outCodecCtx->height = outHeight;&#xA;    outCodecCtx->time_base = { 1, fps };&#xA;&#xA;    // Open output codec&#xA;    if (avcodec_open2(outCodecCtx, outCodec, nullptr) &lt; 0) {&#xA;        cerr &lt;&lt; "Error: Could not open output codec" &lt;&lt; endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    // Create output stream&#xA;    AVStream* outStream = avformat_new_stream(outFormatCtx, outCodec);&#xA;    if (!outStream) {&#xA;        cerr &lt;&lt; "Error: Could not allocate output stream" &lt;&lt; endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    // Configure output stream parameters (e.g., time base, codec parameters, etc.)&#xA;    // ...&#xA;&#xA;    // Connect output stream to format context&#xA;    outStream->codecpar->codec_id = outCodecCtx->codec_id;&#xA;    outStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    outStream->codecpar->width = outCodecCtx->width;&#xA;    outStream->codecpar->height = outCodecCtx->height;&#xA;    outStream->codecpar->format = outCodecCtx->pix_fmt;&#xA;    outStream->time_base = outCodecCtx->time_base;&#xA;&#xA;    int ret = avcodec_parameters_from_context(outStream->codecpar, outCodecCtx);&#xA;    if (ret &lt; 0) {&#xA;        cerr &lt;&lt; "Error: Could not copy codec parameters to output stream" &lt;&lt; endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    outStream->avg_frame_rate = outCodecCtx->framerate;&#xA;    outStream->id = outFormatCtx->nb_streams&#x2B;&#x2B;;&#xA;&#xA;&#xA;    ret = avformat_write_header(outFormatCtx, nullptr);&#xA;    if (ret &lt; 0) {&#xA;        cerr &lt;&lt; "Error: Could not write output header" &lt;&lt; endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    // Convert frames to YUV format and write to output file&#xA;    for (const auto&amp; frame : frames) {&#xA;        AVFrame* yuvFrame = av_frame_alloc();&#xA;        if (!yuvFrame) {&#xA;            cerr &lt;&lt; "Error: Could not allocate YUV frame" &lt;&lt; endl;&#xA;            return -1;&#xA;        }&#xA;        av_image_alloc(yuvFrame->data, yuvFrame->linesize, outWidth, outHeight, AV_PIX_FMT_YUV420P, 32);&#xA;&#xA;        // Convert BGR frame to YUV format&#xA;        Mat yuvMat;&#xA;        cvtColor(frame, yuvMat, COLOR_BGR2YUV_I420);&#xA;        memcpy(yuvFrame->data[0], yuvMat.data, outWidth * outHeight);&#xA;        memcpy(yuvFrame->data[1], yuvMat.data &#x2B; outWidth * outHeight, outWidth * outHeight / 4);&#xA;        memcpy(yuvFrame->data[2], yuvMat.data &#x2B; outWidth * outHeight * 5 / 4, outWidth * outHeight / 4);&#xA;&#xA;        // Set up output packet&#xA;        av_init_packet(&amp;outPacket);&#xA;        outPacket.data = nullptr;&#xA;        outPacket.size = 0;&#xA;&#xA;        // Encode frame and write to output file&#xA;        int ret = avcodec_send_frame(outCodecCtx, yuvFrame);&#xA;        if (ret &lt; 0) {&#xA;            cerr &lt;&lt; "Error: Could not send frame to output codec" &lt;&lt; endl;&#xA;            return -1;&#xA;        }&#xA;        while (ret >= 0) {&#xA;            ret = avcodec_receive_packet(outCodecCtx, &amp;outPacket);&#xA;            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;                break;&#xA;            } else if (ret &lt; 0) {&#xA;                cerr &lt;&lt; "Error: Could not receive packet from output codec" &lt;&lt; endl;&#xA;                return -1;&#xA;            }&#xA;&#xA;            av_packet_rescale_ts(&amp;outPacket, outCodecCtx->time_base, outStream->time_base);&#xA;            outPacket.stream_index = outStream->index;&#xA;&#xA;            ret = av_interleaved_write_frame(outFormatCtx, &amp;outPacket);&#xA;            if (ret &lt; 0) {&#xA;                cerr &lt;&lt; "Error: Could not write packet to output file" &lt;&lt; endl;&#xA;                return -1;&#xA;            }&#xA;        }&#xA;&#xA;        av_frame_free(&amp;yuvFrame);&#xA;    }&#xA;&#xA;    // Write output trailer&#xA;    av_write_trailer(outFormatCtx);&#xA;&#xA;    // Clean up&#xA;    avcodec_close(outCodecCtx);&#xA;    avcodec_free_context(&amp;outCodecCtx);&#xA;    avformat_free_context(outFormatCtx);&#xA;&#xA;    return 0;&#xA;}&#xA;</mat></stdexcept></sstream></fstream></cstring></vector></iostream>

    &#xA;

    In-fact, I try to solve my original question here : What is the best way to save an image sequence with different time intervals in a simgle file in C++, but in that discussion, it is difficult to write a c++ code for ffmpeg library.

    &#xA;

  • ffmpeg wont "gracefully" terminate using q or kill -2

    24 mai 2023, par Jeff Thompson

    I am trying to run a bash command on Ubuntu to pull video from a stream and make an .mp4 with it. Here is the command I am using.

    &#xA;

    ffmpeg -rtsp_transport tcp -i &#x27;rtsp://username:password!@ipaddress/?inst=1&#x27; -c copy -f segment -segment_time 180 -reset_timestamps 1 ipaddress_day_3_2_%d.mp4

    &#xA;

    It connects and begins copying the stream fine, the issue comes with trying to stop the process. It states press [q] to stop, which does not work. I have also tried kill -2 pid and kill -15 pid. Where pid is the process id. However kill -9 pid works and ctrl+c works. The issue with killing it this way is it corrupts the .mp4 rendering it useless. This is the error I get when using ctrl+c or kill -9.

    &#xA;

    av_interleaved_write_frame(): Immediate exit requested   [segment @ 0x56337ec42980] Failure occurred when ending segment &#x27;ipaddress_day_3_2_0.mp4&#x27; Error writing trailer of ipaddress_day_3_2_0%d.mp4: Immediate exit requested

    &#xA;

    One thing to note is pressing [q] did work once, when I first started working on this but has not since.

    &#xA;

    Thank You.

    &#xA;

    I have tried kill -2 pid, kill -15 pid and [q], which I expected to "gracefully" terminate it.&#xA;kill -9 pid and ctrl+c will forcefully terminate it but corrupt the file.

    &#xA;

  • How to modify the bit_rate of AVFormatContext ?

    27 mars 2023, par Zion Liu

    Hello,I would like to know how to modify the bit_rate of AVFormatContext.

    &#xA;

    Here is the minimal reproducible example.This is a simple process for pushing rtmp video streams.Now I want to control the bitrate of the video it pushes.

    &#xA;

    I tried modifying the bitrate like this, but it didn't work.

    &#xA;

    AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;&#xA;int64_t bit_rate = 400*1000;&#xA;....&#xA;ofmt_ctx->bit_rate = bit_rate;&#xA;

    &#xA;

    Can be compiled by g&#x2B;&#x2B; -Wall -o -g -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -L/usr/local/lib  simplt_push_streaming.cpp -o test.out -lavformat -lavcodec -lavutil -lgobject-2.0 -lglib-2.0 -lpthread

    &#xA;

    And my ffmpeg version : ffmpeg version 4.4.2-0ubuntu0.22.04.1

    &#xA;

    #include &#xA;extern "C"&#xA;{&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavutil></libavutil>mathematics.h>&#xA;#include <libavutil></libavutil>time.h>&#xA;};&#xA;&#xA;int main(int argc, char* argv[])&#xA;{&#xA;    AVOutputFormat *ofmt = NULL;&#xA;    //Input AVFormatContext and Output AVFormatContext&#xA;    AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;&#xA;    AVPacket pkt;&#xA;    const char *in_filename, *out_filename;&#xA;    int ret, i;&#xA;    int videoindex=-1;&#xA;    int frame_index=0;&#xA;    int64_t start_time=0;&#xA;    int64_t bit_rate = 400*1000;&#xA;    in_filename  = "/home/zion/video/mecha.flv";// Input file URL&#xA;    out_filename = "rtmp://localhost:1935/live/test";//Output URL [RTMP]&#xA;    av_register_all();&#xA;    avformat_network_init();&#xA;    avformat_open_input(&amp;ifmt_ctx, in_filename, 0, 0);&#xA;    avformat_find_stream_info(ifmt_ctx, 0);&#xA;    for(i=0; inb_streams; i&#x2B;&#x2B;) &#xA;        if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){&#xA;            videoindex=i;&#xA;            break;&#xA;        }&#xA;    //Output&#xA;    avformat_alloc_output_context2(&amp;ofmt_ctx, NULL, "flv", out_filename); //RTMP&#xA;    ofmt = ofmt_ctx->oformat;&#xA;    for (i = 0; i &lt; ifmt_ctx->nb_streams; i&#x2B;&#x2B;) {&#xA;        //Create output AVStream according to input AVStream&#xA;        AVStream *in_stream = ifmt_ctx->streams[i];&#xA;        AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);&#xA;        //Copy the settings of AVCodecContext&#xA;        ret = avcodec_copy_context(out_stream->codec, in_stream->codec);&#xA;        out_stream->codec->codec_tag = 0;&#xA;        if (ofmt_ctx->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;            out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;    //Open output URL&#xA;    if (!(ofmt->flags &amp; AVFMT_NOFILE)) {&#xA;        ret = avio_open(&amp;ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);&#xA;    }&#xA;    //Write file header&#xA;    avformat_write_header(ofmt_ctx, NULL);&#xA;    start_time=av_gettime();&#xA;    while (1) {&#xA;        AVStream *in_stream, *out_stream;&#xA;        //Get an AVPacket&#xA;        ret = av_read_frame(ifmt_ctx, &amp;pkt);&#xA;        if (ret &lt; 0)&#xA;            break;&#xA;        //Important:Delay&#xA;        if(pkt.stream_index==videoindex){&#xA;            AVRational time_base=ifmt_ctx->streams[videoindex]->time_base;&#xA;            AVRational time_base_q={1,AV_TIME_BASE};&#xA;            int64_t pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);&#xA;            int64_t now_time = av_gettime() - start_time;&#xA;            if (pts_time > now_time)&#xA;                av_usleep(pts_time - now_time);&#xA;        }&#xA;        in_stream  = ifmt_ctx->streams[pkt.stream_index];&#xA;        out_stream = ofmt_ctx->streams[pkt.stream_index];&#xA;        if(pkt.stream_index==videoindex){&#xA;            printf("Send %8d video frames to output URL\n",frame_index);&#xA;            frame_index&#x2B;&#x2B;;&#xA;        }&#xA;/*I tried modifying the bitrate here and I&#x27;m not sure if this is the correct usage.*/&#xA;        ofmt_ctx->bit_rate = bit_rate;&#xA;        av_interleaved_write_frame(ofmt_ctx, &amp;pkt);&#xA;        av_free_packet(&amp;pkt);&#xA;    }&#xA;    //Write file trailer&#xA;    av_write_trailer(ofmt_ctx);&#xA;end:&#xA;    avformat_close_input(&amp;ifmt_ctx);&#xA;    /* close output */&#xA;    if (ofmt_ctx &amp;&amp; !(ofmt->flags &amp; AVFMT_NOFILE))&#xA;        avio_close(ofmt_ctx->pb);&#xA;    avformat_free_context(ofmt_ctx);&#xA;    return 0;&#xA;}&#xA;

    &#xA;