Recherche avancée

Médias (1)

Mot : - Tags -/école

Autres articles (73)

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

  • 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

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

Sur d’autres sites (12143)

  • ffmpeg video encoder skips first frames [duplicate]

    19 octobre 2022, par Eduard Barnoviciu

    I am new to ffmpeg. I am trying to run this simple video encoding example :

    


    &#xA;#include <iostream>&#xA;#include <vector>&#xA;// FFmpeg&#xA;extern "C" {&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;}&#xA;// OpenCV&#xA;#include <opencv2></opencv2>opencv.hpp>&#xA;#include <opencv2></opencv2>highgui.hpp>&#xA;&#xA;&#xA;int main(int argc, char* argv[])&#xA;{&#xA;    if (argc &lt; 2) {&#xA;        std::cout &lt;&lt; "Usage: cv2ff <outfile>" &lt;&lt; std::endl;&#xA;        return 1;&#xA;    }&#xA;    const char* outfile = argv[1];&#xA;&#xA; // av_log_set_level(AV_LOG_DEBUG);&#xA;    int ret;&#xA;&#xA;    const int dst_width = 640;&#xA;    const int dst_height = 480;&#xA;    const AVRational dst_fps = {30, 1};&#xA;&#xA;    // initialize OpenCV capture as input frame generator&#xA;    cv::VideoCapture cvcap(0);&#xA;    if (!cvcap.isOpened()) {&#xA;        std::cerr &lt;&lt; "fail to open cv::VideoCapture";&#xA;        return 2;&#xA;    }&#xA;    cvcap.set(cv::CAP_PROP_FRAME_WIDTH, dst_width);&#xA;    cvcap.set(cv::CAP_PROP_FRAME_HEIGHT, dst_height);&#xA;    cvcap.set(cv::CAP_PROP_FPS, dst_fps.num);&#xA;    // some device ignore above parameters for capturing image,&#xA;    // so we query actual parameters for image rescaler.&#xA;    const int cv_width = cvcap.get(cv::CAP_PROP_FRAME_WIDTH);&#xA;    const int cv_height = cvcap.get(cv::CAP_PROP_FRAME_HEIGHT);&#xA;    const int cv_fps = cvcap.get(cv::CAP_PROP_FPS);&#xA;&#xA;    // open output format context&#xA;    AVFormatContext* outctx = nullptr;&#xA;    ret = avformat_alloc_output_context2(&amp;outctx, nullptr, nullptr, outfile);&#xA;    if (ret &lt; 0) {&#xA;        std::cerr &lt;&lt; "fail to avformat_alloc_output_context2(" &lt;&lt; outfile &lt;&lt; "): ret=" &lt;&lt; ret;&#xA;        return 2;&#xA;    }&#xA;&#xA;    // create new video stream&#xA;    AVCodec* vcodec = avcodec_find_encoder(outctx->oformat->video_codec);&#xA;    AVStream* vstrm = avformat_new_stream(outctx, vcodec);&#xA;    if (!vstrm) {&#xA;        std::cerr &lt;&lt; "fail to avformat_new_stream";&#xA;        return 2;&#xA;    }&#xA;&#xA;    // open video encoder&#xA;    AVCodecContext* cctx = avcodec_alloc_context3(vcodec);&#xA;    if (!vstrm) {&#xA;        std::cerr &lt;&lt; "fail to avcodec_alloc_context3";&#xA;        return 2;&#xA;    }&#xA;    cctx->width = dst_width;&#xA;    cctx->height = dst_height;&#xA;    cctx->pix_fmt = vcodec->pix_fmts[0];&#xA;    cctx->time_base = av_inv_q(dst_fps);&#xA;    cctx->framerate = dst_fps;&#xA;    if (outctx->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;        cctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    ret = avcodec_open2(cctx, vcodec, nullptr);&#xA;    if (ret &lt; 0) {&#xA;        std::cerr &lt;&lt; "fail to avcodec_open2: ret=" &lt;&lt; ret;&#xA;        return 2;&#xA;    }&#xA;    avcodec_parameters_from_context(vstrm->codecpar, cctx);&#xA;&#xA;    // initialize sample scaler&#xA;    SwsContext* swsctx = sws_getContext(&#xA;        cv_width, cv_height, AV_PIX_FMT_BGR24,&#xA;        dst_width, dst_height, cctx->pix_fmt,&#xA;        SWS_BILINEAR, nullptr, nullptr, nullptr);&#xA;    if (!swsctx) {&#xA;        std::cerr &lt;&lt; "fail to sws_getContext";&#xA;        return 2;&#xA;    }&#xA;&#xA;    // allocate frame buffer for encoding&#xA;    AVFrame* frame = av_frame_alloc();&#xA;    frame->width = dst_width;&#xA;    frame->height = dst_height;&#xA;    frame->format = static_cast<int>(cctx->pix_fmt);&#xA;    ret = av_frame_get_buffer(frame, 32);&#xA;    if (ret &lt; 0) {&#xA;        std::cerr &lt;&lt; "fail to av_frame_get_buffer: ret=" &lt;&lt; ret;&#xA;        return 2;&#xA;    }&#xA;&#xA;    // allocate packet to retrive encoded frame&#xA;    AVPacket* pkt = av_packet_alloc();&#xA;&#xA;    // open output IO context&#xA;    ret = avio_open2(&amp;outctx->pb, outfile, AVIO_FLAG_WRITE, nullptr, nullptr);&#xA;    if (ret &lt; 0) {&#xA;        std::cerr &lt;&lt; "fail to avio_open2: ret=" &lt;&lt; ret;&#xA;        return 2;&#xA;    }&#xA;&#xA;    std::cout&#xA;        &lt;&lt; "camera:  " &lt;&lt; cv_width &lt;&lt; &#x27;x&#x27; &lt;&lt; cv_height &lt;&lt; &#x27;@&#x27; &lt;&lt; cv_fps &lt;&lt; "\n"&#xA;        &lt;&lt; "outfile: " &lt;&lt; outfile &lt;&lt; "\n"&#xA;        &lt;&lt; "format:  " &lt;&lt; outctx->oformat->name &lt;&lt; "\n"&#xA;        &lt;&lt; "vcodec:  " &lt;&lt; vcodec->name &lt;&lt; "\n"&#xA;        &lt;&lt; "size:    " &lt;&lt; dst_width &lt;&lt; &#x27;x&#x27; &lt;&lt; dst_height &lt;&lt; "\n"&#xA;        &lt;&lt; "fps:     " &lt;&lt; av_q2d(cctx->framerate) &lt;&lt; "\n"&#xA;        &lt;&lt; "pixfmt:  " &lt;&lt; av_get_pix_fmt_name(cctx->pix_fmt) &lt;&lt; "\n"&#xA;        &lt;&lt; std::flush;&#xA;&#xA;    // write media container header (if any)&#xA;    ret = avformat_write_header(outctx, nullptr);&#xA;    if (ret &lt; 0) {&#xA;        std::cerr &lt;&lt; "fail to avformat_write_header: ret=" &lt;&lt; ret;&#xA;        return 2;&#xA;    }&#xA;&#xA;    cv::Mat image;&#xA;&#xA;    // encoding loop&#xA;    int64_t frame_pts = 0;&#xA;    unsigned nb_frames = 0;&#xA;    bool end_of_stream = false;&#xA;    for (;;) {&#xA;        if (!end_of_stream) {&#xA;            // retrieve source image&#xA;            cvcap >> image;&#xA;            cv::imshow("press ESC to exit", image);&#xA;            if (cv::waitKey(33) == 0x1b) {&#xA;                // flush encoder&#xA;                avcodec_send_frame(cctx, nullptr);&#xA;                end_of_stream = true;&#xA;            }&#xA;        }&#xA;        if (!end_of_stream) {&#xA;            // convert cv::Mat(OpenCV) to AVFrame(FFmpeg)&#xA;            const int stride[4] = { static_cast<int>(image.step[0]) };&#xA;            sws_scale(swsctx, &amp;image.data, stride, 0, image.rows, frame->data, frame->linesize);&#xA;            frame->pts = frame_pts&#x2B;&#x2B;;&#xA;            // encode video frame&#xA;            ret = avcodec_send_frame(cctx, frame);&#xA;            if (ret &lt; 0) {&#xA;                std::cerr &lt;&lt; "fail to avcodec_send_frame: ret=" &lt;&lt; ret &lt;&lt; "\n";&#xA;                break;&#xA;            }&#xA;        }&#xA;        while ((ret = avcodec_receive_packet(cctx, pkt)) >= 0) {&#xA;            // rescale packet timestamp&#xA;            pkt->duration = 1;&#xA;            av_packet_rescale_ts(pkt, cctx->time_base, vstrm->time_base);&#xA;            // write encoded packet&#xA;            av_write_frame(outctx, pkt);&#xA;            av_packet_unref(pkt);&#xA;            std::cout &lt;&lt; nb_frames &lt;&lt; &#x27;\r&#x27; &lt;&lt; std::flush;  // dump progress&#xA;            &#x2B;&#x2B;nb_frames;&#xA;        }&#xA;        if (ret == AVERROR_EOF)&#xA;            break;&#xA;    };&#xA;    std::cout &lt;&lt; nb_frames &lt;&lt; " frames encoded" &lt;&lt; std::endl;&#xA;&#xA;    // write trailer and close file&#xA;    av_write_trailer(outctx);&#xA;    avio_close(outctx->pb);&#xA;&#xA;    av_packet_free(&amp;pkt);&#xA;    av_frame_free(&amp;frame);&#xA;    sws_freeContext(swsctx);&#xA;    avcodec_free_context(&amp;cctx);&#xA;    avformat_free_context(outctx);&#xA;    return 0;&#xA;}&#xA;</int></int></outfile></vector></iostream>

    &#xA;

    The problem is, while using codecs such as HEVC, H265 or VP9, the encoder always drops first 27 frames.

    &#xA;

    More exactly, at line 163 :

    &#xA;

      while ((ret = avcodec_receive_packet(cctx, pkt)) >= 0) {&#xA;

    &#xA;

    ret is equal to -11 and it doesn't go inside the while loop. From that point onward it's always equal to 0 and no issues are found.

    &#xA;

    If I use MPEG4 for example, ret is 0 from the start and no frames are dropped.

    &#xA;

  • Encode amr with ffmpeg (libavcodec)

    22 août 2022, par Mohammadreza Rostam

    I would like to encode a simple pcm to amr using libavcodec.

    &#xA;

    To begin with, I compiled ffmpeg and run the encode_audio example and it worked fine for the default Mp2 codec.

    &#xA;

    Then modified the encode_audio example and replace AV_CODEC_ID_MP2 with AV_CODEC_ID_AMR_NB and changed bit_rate, sample_rate, and channel_layout to 12200, 8000, and AV_CH_LAYOUT_MONO respectively. Now, I am getting invalid fastbin entry (free) error.

    &#xA;

    The compiled ffmpeg cli binary worked as expected and encode audio files to amr successfully, so the issue is not in compilation or the linking step.

    &#xA;

    Any help would be much appreciated

    &#xA;

    Update :

    &#xA;

    As mentioned in the comments, the issue is not specifically for amr and the encode_audio example would fail for all codecs if AV_CH_LAYOUT_MONO is selected for the channel layout. To get the demo to work, you need to also change the signal generator code block, in which having two channels of audio if assumed and hard-corded. Thanks @ronald-s-bultje for helping me here.

    &#xA;

  • Cant Record Stream Using MediaRecorder In Server ?

    13 avril 2022, par Riyad Zaigirdar

    First I am trying to make a Webrtc peer connection from the browser to the server using SFU model.

    &#xA;

    Here is the post request which makes the webrtc peer connection from the browser to the server(SFU)

    &#xA;

    app.post("/broadcast", async ({ body }, res) => {&#xA;  const peer = new webrtc.RTCPeerConnection({&#xA;    iceServers: [&#xA;      {&#xA;        urls: "stun:stun.stunprotocol.org",&#xA;      },&#xA;    ],&#xA;  });&#xA;  peer.ontrack = (e) => handleTrackEvent(e, peer); &lt;-- Important&#xA;  const desc = new webrtc.RTCSessionDescription(body.sdp);&#xA;  await peer.setRemoteDescription(desc);&#xA;  const answer = await peer.createAnswer();&#xA;  await peer.setLocalDescription(answer);&#xA;  const payload = {&#xA;    sdp: peer.localDescription,&#xA;  };&#xA;&#xA;  res.json(payload);&#xA;});&#xA;

    &#xA;

    In the handleTrackEvent function, I am getting the stream which I want to start record and save in the server's local storage.

    &#xA;

    function handleTrackEvent(e, peer) {&#xA;  console.log(e.streams);&#xA;  senderStream = e.streams[0];&#xA;  var recorder = new MediaStreamRecorder(e.streams);&#xA;  recorder.recorderType = MediaRecorderWrapper;&#xA;  recorder.mimeType = "video/webm";&#xA;  recorder.ondataavailable = (blob) => {&#xA;    console.log(blob);&#xA;  };&#xA;  recorder.start(5 * 1000); &lt;-- Error generator&#xA;}&#xA;

    &#xA;

    But when try to start the recording and get the blob in 5 sec intervals, it gives me "MediaRecorder Not Found" ...

    &#xA;

    Passing following params over MediaRecorder API. { mimeType: &#x27;video/webm&#x27; }&#xA;/Users/tecbackup/webrtc-peer/node_modules/msr/MediaStreamRecorder.js:672&#xA;            mediaRecorder = new MediaRecorder(mediaStream);&#xA;            ^&#xA;&#xA;ReferenceError: MediaRecorder is not defined&#xA;

    &#xA;

    I am very new to webrtc, I need some suggestion to save the live stream from the browser to the server....In future, if find the blob, then I will save the blobs sequentially in a mp4 file in the server. Then, on runtime i start pressing ffmpeg in that mp4 file to get 240p, 360p, 720p ts files for hls streaming

    &#xA;