Recherche avancée

Médias (91)

Autres articles (54)

  • (Dés)Activation de fonctionnalités (plugins)

    18 février 2011, par

    Pour gérer l’ajout et la suppression de fonctionnalités supplémentaires (ou plugins), MediaSPIP utilise à partir de la version 0.2 SVP.
    SVP permet l’activation facile de plugins depuis l’espace de configuration de MediaSPIP.
    Pour y accéder, il suffit de se rendre dans l’espace de configuration puis de se rendre sur la page "Gestion des plugins".
    MediaSPIP est fourni par défaut avec l’ensemble des plugins dits "compatibles", ils ont été testés et intégrés afin de fonctionner parfaitement avec chaque (...)

  • Activation de l’inscription des visiteurs

    12 avril 2011, par

    Il est également possible d’activer l’inscription des visiteurs ce qui permettra à tout un chacun d’ouvrir soit même un compte sur le canal en question dans le cadre de projets ouverts par exemple.
    Pour ce faire, il suffit d’aller dans l’espace de configuration du site en choisissant le sous menus "Gestion des utilisateurs". Le premier formulaire visible correspond à cette fonctionnalité.
    Par défaut, MediaSPIP a créé lors de son initialisation un élément de menu dans le menu du haut de la page menant (...)

  • MediaSPIP : Modification des droits de création d’objets et de publication définitive

    11 novembre 2010, par

    Par défaut, MediaSPIP permet de créer 5 types d’objets.
    Toujours par défaut les droits de création et de publication définitive de ces objets sont réservés aux administrateurs, mais ils sont bien entendu configurables par les webmestres.
    Ces droits sont ainsi bloqués pour plusieurs raisons : parce que le fait d’autoriser à publier doit être la volonté du webmestre pas de l’ensemble de la plateforme et donc ne pas être un choix par défaut ; parce qu’avoir un compte peut servir à autre choses également, (...)

Sur d’autres sites (12367)

  • Using libavformat to mux H.264 frames into RTP

    22 novembre 2016, par DanielB6

    I have an encoder that produces a series of H.264 I-frames and P-frames. I’m trying to use libavformat to mux and transmit these frames over RTP, but I’m stuck.

    My program sends RTP data, but the RTP timestamp increments by 1 each successive frame, instead of 90000/fps. It also doesn’t look like it’s doing the proper framing for H.264 NAL, since I can’t decode the stream as H.264 in Wireshark.

    I suspect that I’m not setting up the codec information properly, but it appears in many places in the output format context, so it’s unclear what exactly needs to be setup. The examples seem to all copy codec context info from encoders, which isn’t my use case.

    This is what I’m trying :

    int main() {
       AVFormatContext context = avformat_alloc_context();

       if (!context) {
           printf("avformat_alloc_context failed\n");
           return;
       }

       AVOutputFormat *format = av_guess_format("rtp", NULL, NULL);

       if (!format) {
           printf("av_guess_format failed\n");
           return;
       }

       context->oformat = format;

       snprintf(context->filename, sizeof(context->filename), "rtp://%s:%d", "192.168.2.16", 10000);

       if (avio_open(&(context->pb), context->filename, AVIO_FLAG_READ_WRITE) < 0) {
           printf("avio_open failed\n");
           return;
       }

       stream = avformat_new_stream(context, NULL);

       if (!stream) {
           printf("avformat_new_stream failed\n");
           return;
       }

       stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
       stream->codecpar->codec_id = AV_CODEC_ID_H264;
       stream->codecpar->width = 1920;
       stream->codecpar->height = 1080;

       avformat_write_header(context, NULL);

       ...
       write packets
       ...
    }

    Example write packet :

    int write_packet(uint8_t *data, int size) {
       AVPacket p;
       av_init_packet(&p);
       p.data = buffer;
       p.size = size;
       p.stream_index = stream->index;

       av_interleaved_write_frame(context, &p);
    }

    I’ve even went so far to build in libx264, find the encoder, and copy the codec context info from there into the stream codecpar, with the same result. My goal is to build without libx264, and any other libs that aren’t required, but it isn’t clear whether libx264 is required for defaults such as time base.

    How can the libavformat RTP muxer be initialized to properly send H.264 frames over RTCP+RTP ?

  • File encoded as FFV1 with libavcodec is unplayable

    19 novembre 2016, par Ali Alidoust

    I’m using the following code to encode a series of frames into an mkv or avi file with FFV1 encoding :

    HRESULT Session::createContext(LPCSTR filepath, UINT width, UINT height, UINT fps_num, UINT fps_den) {
       LOG(filepath);

       this->codec = avcodec_find_encoder(AV_CODEC_ID_FFV1);
       RET_IF_NULL(this->codec, "Could not create codec", E_FAIL);

       this->oformat = av_guess_format(NULL, filepath, NULL);
       RET_IF_NULL(this->oformat, "Could not create format", E_FAIL);
       this->oformat->video_codec = AV_CODEC_ID_FFV1;
       this->width = width;
       this->height = height;
       this->context = avcodec_alloc_context3(this->codec);
       RET_IF_NULL(this->context, "Could not allocate context for the codec", E_FAIL);

       this->context->codec = this->codec;
       this->context->codec_id = AV_CODEC_ID_FFV1;
       this->context->codec_type = AVMEDIA_TYPE_VIDEO;

       this->context->pix_fmt = AV_PIX_FMT_YUV420P;
       this->context->width = this->width;
       this->context->height = this->height;
       this->context->time_base.num = fps_den;
       this->context->time_base.den = fps_num;

       this->context->gop_size = 1;

       av_opt_set_int(this->context->priv_data, "coder", 0, 0);
       av_opt_set_int(this->context->priv_data, "context", 1, 0);
       av_opt_set_int(this->context->priv_data, "slicecrc", 1, 0);

       avformat_alloc_output_context2(&fmtContext, NULL, NULL, filepath);

       this->fmtContext->oformat = this->oformat;
       this->fmtContext->video_codec_id = AV_CODEC_ID_FFV1;

       this->stream = avformat_new_stream(this->fmtContext, this->codec);
       RET_IF_NULL(this->fmtContext, "Could not create new stream", E_FAIL);
       avcodec_parameters_from_context(this->stream->codecpar, this->context);
       this->stream->codecpar->level = 3;

       /*if (this->fmtContext->oformat->flags & AVFMT_GLOBALHEADER)
       {*/
           this->context->flags |= CODEC_FLAG_GLOBAL_HEADER;
       /*}*/

       RET_IF_FAILED_AV(avcodec_open2(this->context, this->codec, NULL), "Could not open codec", E_FAIL);
       RET_IF_FAILED_AV(avio_open(&this->fmtContext->pb, filepath, AVIO_FLAG_READ_WRITE), "Could not open output file", E_FAIL);
       RET_IF_NULL(this->fmtContext->pb, "Could not open output file", E_FAIL);
       RET_IF_FAILED_AV(avformat_write_header(this->fmtContext, NULL), "Could not write header", E_FAIL);

       frame = av_frame_alloc();
       RET_IF_NULL(frame, "Could not allocate frame", E_FAIL);
       frame->format = this->context->pix_fmt;
       frame->width = width;
       frame->height = height;
       // RET_IF_FAILED(av_image_alloc(frame->data, frame->linesize, context->width, context->height, context->pix_fmt, 32), "Could not allocate image", E_FAIL);
       return S_OK;
    }

    HRESULT Session::writeFrame(IMFSample * pSample) {
       IMFMediaBuffer *mediaBuffer = NULL;
       BYTE *pData = NULL;
       DWORD length;

       RET_IF_FAILED(pSample->ConvertToContiguousBuffer(&mediaBuffer), "Could not convert IMFSample to contagiuous buffer", E_FAIL);
       RET_IF_FAILED(mediaBuffer->GetCurrentLength(&length), "Could not get buffer length", E_FAIL);
       RET_IF_FAILED(mediaBuffer->Lock(&pData, NULL, NULL), "Could not lock the buffer", E_FAIL);
       RET_IF_FAILED(av_image_fill_arrays(frame->data, frame->linesize, pData, AV_PIX_FMT_YUV420P, this->width, this->height, 1), "Could not fill the frame with data from the buffer", E_FAIL);
       LOG_IF_FAILED(mediaBuffer->Unlock(), "Could not unlock the buffer");

       frame->pts = this->pts++;

       AVPacket pkt;

       av_init_packet(&pkt);
       pkt.data = NULL;
       pkt.size = 0;

       RET_IF_FAILED_AV(avcodec_send_frame(this->context, frame), "Could not send the frame to the encoder", E_FAIL);
       if (SUCCEEDED(avcodec_receive_packet(this->context, &pkt))) {
           RET_IF_FAILED_AV(av_interleaved_write_frame(this->fmtContext, &pkt), "Could not write the received packet.", E_FAIL);
       }

       av_packet_unref(&pkt);

       return S_OK;
    }

    HRESULT Session::endSession() {
       LOG("Ending session...");
       LOG("Closing files...");
       av_write_trailer(this->fmtContext);
       avio_close(this->fmtContext->pb);
       avcodec_close(this->context);
       av_free(this->context);
       //fclose(this->file);
       LOG("Done.");
       return S_OK;
    }

    The problem is that the generated file is not playable in either VLC or MPC-HC. However, MPC-HC reports following info in file properties :

    General
    Unique ID                      : 202978442142665779317960161865934977227 (0x98B439D9BE859109BD5EC00A62A238CB)
    Complete name                  : T:\Test.mkv
    Format                         : Matroska
    Format version                 : Version 4 / Version 2
    File size                      : 24.6 MiB
    Duration                       : 147ms
    Overall bit rate               : 1 401 Mbps
    Writing application            : Lavf57.57.100
    Writing library                : Lavf57.57.100

    Video
    ID                             : 1
    Format                         : FFV1
    Format version                 : Version 0
    Codec ID                       : V_MS/VFW/FOURCC / FFV1
    Duration                       : 147ms
    Width                          : 1 280 pixels
    Height                         : 720 pixels
    Display aspect ratio           : 16:9
    Frame rate mode                : Constant
    Frame rate                     : 1 000.000 fps
    Color space                    : YUV
    Chroma subsampling             : 4:2:0
    Bit depth                      : 8 bits
    Compression mode               : Lossless
    Default                        : Yes
    Forced                         : No
    DURATION                       : 00:00:00.147000000
    coder_type                     : Golomb Rice

    Something to note is that it reports 1000 FPS which is weird since I’ve set AVCodecContext::time_base in the code.

    UPDATE :

    I managed to set the correct fps by setting time_base property of the stream :

    this->stream->time_base.den = fps_num;
    this->stream->time_base.num = fps_den;

    VLC plays the output file but it shows VLC logo instead of the video, as if there is no video stream in the file.

  • File encoded as FFV1 with ffmpeg is unplayable

    18 novembre 2016, par Ali Alidoust

    I’m using the following code to encode a series of frames into an mkv or avi file with FFV1 encoding :

    HRESULT Session::createContext(LPCSTR filepath, UINT width, UINT height, UINT fps_num, UINT fps_den) {
       LOG(filepath);

       this->codec = avcodec_find_encoder(AV_CODEC_ID_FFV1);
       RET_IF_NULL(this->codec, "Could not create codec", E_FAIL);

       this->oformat = av_guess_format(NULL, filepath, NULL);
       RET_IF_NULL(this->oformat, "Could not create format", E_FAIL);
       this->oformat->video_codec = AV_CODEC_ID_FFV1;
       this->width = width;
       this->height = height;
       this->context = avcodec_alloc_context3(this->codec);
       RET_IF_NULL(this->context, "Could not allocate context for the codec", E_FAIL);

       this->context->codec = this->codec;
       this->context->codec_id = AV_CODEC_ID_FFV1;
       this->context->codec_type = AVMEDIA_TYPE_VIDEO;

       this->context->pix_fmt = AV_PIX_FMT_YUV420P;
       this->context->width = this->width;
       this->context->height = this->height;
       this->context->time_base.num = fps_num;
       this->context->time_base.den = fps_den;

       this->context->gop_size = 1;

       av_opt_set_int(this->context->priv_data, "coder", 0, 0);
       av_opt_set_int(this->context->priv_data, "context", 1, 0);
       av_opt_set_int(this->context->priv_data, "slicecrc", 1, 0);

       avformat_alloc_output_context2(&fmtContext, NULL, NULL, filepath);

       this->fmtContext->oformat = this->oformat;
       this->fmtContext->video_codec_id = AV_CODEC_ID_FFV1;

       this->stream = avformat_new_stream(this->fmtContext, this->codec);
       RET_IF_NULL(this->fmtContext, "Could not create new stream", E_FAIL);
       avcodec_parameters_from_context(this->stream->codecpar, this->context);
       this->stream->codecpar->level = 3;

       /*if (this->fmtContext->oformat->flags & AVFMT_GLOBALHEADER)
       {*/
           this->context->flags |= CODEC_FLAG_GLOBAL_HEADER;
       /*}*/

       RET_IF_FAILED_AV(avcodec_open2(this->context, this->codec, NULL), "Could not open codec", E_FAIL);
       RET_IF_FAILED_AV(avio_open(&this->fmtContext->pb, filepath, AVIO_FLAG_READ_WRITE), "Could not open output file", E_FAIL);
       RET_IF_NULL(this->fmtContext->pb, "Could not open output file", E_FAIL);
       RET_IF_FAILED_AV(avformat_write_header(this->fmtContext, NULL), "Could not write header", E_FAIL);

       frame = av_frame_alloc();
       RET_IF_NULL(frame, "Could not allocate frame", E_FAIL);
       frame->format = this->context->pix_fmt;
       frame->width = width;
       frame->height = height;
       // RET_IF_FAILED(av_image_alloc(frame->data, frame->linesize, context->width, context->height, context->pix_fmt, 32), "Could not allocate image", E_FAIL);
       return S_OK;
    }

    HRESULT Session::writeFrame(IMFSample * pSample) {
       IMFMediaBuffer *mediaBuffer = NULL;
       BYTE *pData = NULL;
       DWORD length;

       RET_IF_FAILED(pSample->ConvertToContiguousBuffer(&mediaBuffer), "Could not convert IMFSample to contagiuous buffer", E_FAIL);
       RET_IF_FAILED(mediaBuffer->GetCurrentLength(&length), "Could not get buffer length", E_FAIL);
       RET_IF_FAILED(mediaBuffer->Lock(&pData, NULL, NULL), "Could not lock the buffer", E_FAIL);
       RET_IF_FAILED(av_image_fill_arrays(frame->data, frame->linesize, pData, AV_PIX_FMT_YUV420P, this->width, this->height, 1), "Could not fill the frame with data from the buffer", E_FAIL);
       LOG_IF_FAILED(mediaBuffer->Unlock(), "Could not unlock the buffer");

       frame->pts = this->pts++;

       AVPacket pkt;

       av_init_packet(&pkt);
       pkt.data = NULL;
       pkt.size = 0;

       RET_IF_FAILED_AV(avcodec_send_frame(this->context, frame), "Could not send the frame to the encoder", E_FAIL);
       if (SUCCEEDED(avcodec_receive_packet(this->context, &pkt))) {
           RET_IF_FAILED_AV(av_interleaved_write_frame(this->fmtContext, &pkt), "Could not write the received packet.", E_FAIL);
       }

       av_packet_unref(&pkt);

       return S_OK;
    }

    HRESULT Session::endSession() {
       LOG("Ending session...");
       LOG("Closing files...");
       av_write_trailer(this->fmtContext);
       avio_close(this->fmtContext->pb);
       avcodec_close(this->context);
       av_free(this->context);
       //fclose(this->file);
       LOG("Done.");
       return S_OK;
    }

    The problem is that the generated file is not playable in either VLC or MPC-HC. However, MPC-HC reports following info in file properties :

    General
    Unique ID                      : 202978442142665779317960161865934977227 (0x98B439D9BE859109BD5EC00A62A238CB)
    Complete name                  : T:\Test.mkv
    Format                         : Matroska
    Format version                 : Version 4 / Version 2
    File size                      : 24.6 MiB
    Duration                       : 147ms
    Overall bit rate               : 1 401 Mbps
    Writing application            : Lavf57.57.100
    Writing library                : Lavf57.57.100

    Video
    ID                             : 1
    Format                         : FFV1
    Format version                 : Version 0
    Codec ID                       : V_MS/VFW/FOURCC / FFV1
    Duration                       : 147ms
    Width                          : 1 280 pixels
    Height                         : 720 pixels
    Display aspect ratio           : 16:9
    Frame rate mode                : Constant
    Frame rate                     : 1 000.000 fps
    Color space                    : YUV
    Chroma subsampling             : 4:2:0
    Bit depth                      : 8 bits
    Compression mode               : Lossless
    Default                        : Yes
    Forced                         : No
    DURATION                       : 00:00:00.147000000
    coder_type                     : Golomb Rice

    Something to note is that it reports 1000 FPS which is weird since I’ve set AVCodecContext::time_base in the code.