Recherche avancée

Médias (2)

Mot : - Tags -/media

Autres articles (68)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

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

Sur d’autres sites (7440)

  • libavformat/libavcodec providing invalid container header

    14 décembre 2017, par seanr8

    I’m using libavcodec to encode a stream to h264 and libavformat to store it in an mp4. The resulting container has an invalid header that can be played in VLC, but not any other player.

    I’ve found that using the mp4 container and the "mpeg4" codec produces a valid mp4 file, but using libx265 (HEVC) or the libx264 codec produces invalid mp4s.

    I can use ffmpeg -i invalid.mp4 -vcodec copy valid.mp4 and I get a file of almost the exact same size, but in a valid container.

    Examples of these files are here : Broken file and
    Repaied file [use the download links in the upper right to examine]

    I used a hex editor to see the differences in the headers of the two files and the invalid one is 1 byte smaller than the valid one.

    The code I’m using to open the container and codec and to write the header is here :

    AVOutputFormat *container_format;
    AVFormatContext *container_format_context;
    AVStream *video_stream;
    int ret;

    /* allocate the output media context */
    avformat_alloc_output_context2(&container_format_context, NULL, NULL, out_file);
    if (!container_format_context) {
       log(INFO, "Unable to determine container format from filename, exiting\n");
       exit(1);
    }
    else {
       log(INFO, "Using container %s\n", container_format_context->oformat->name);
    }

    if (!container_format_context) {
       log(ERROR, "Could not build container format context. Encoding failed.");
       exit(1);
    }

    container_format = container_format_context->oformat;

    /* Pull codec based on name */
    AVCodec* codec = avcodec_find_encoder_by_name(codec_name);
    if (codec == NULL) {
       log(ERROR, "Failed to locate codec \"%s\".",
               codec_name);
       exit(1);
    }

    /* create stream */
    video_stream = NULL;
    video_stream = avformat_new_stream(container_format_context, codec);
    if (!video_stream) {
       log(ERROR, "Could not allocate encoder stream. Cannot continue.\n");
       exit(1);
    }
    video_stream->id = container_format_context->nb_streams - 1;

    video_stream->time_base = video_stream->codec->time_base = (AVRational) { 1, 25};

    av_dump_format(container_format_context, 0, out_file, 1);



    /* Retrieve encoding context */
    AVCodecContext* avcodec_context = video_stream->codec;
    if (avcodec_context == NULL) {
       log(ERROR, "Failed to allocate context for "
               "codec \"%s\".", codec_name);
       exit(1);
    }


    /* Init context with encoding parameters */
    avcodec_context->bit_rate = bitrate;
    avcodec_context->width = width;
    avcodec_context->height = height;
    avcodec_context->gop_size = 10;
    avcodec_context->max_b_frames = 1;
    avcodec_context->qmax = 31;
    avcodec_context->qmin = 2;
    avcodec_context->pix_fmt = AV_PIX_FMT_YUV420P;

    av_dump_format(container_format_context, 0, out_file, 1);

    /* Open codec for use */
    if (avcodec_open2(avcodec_context, codec, NULL) < 0) {
       log(ERROR, "Failed to open codec \"%s\".", codec_name);
       exit(1);
    }

    /* Allocate corresponding frame */
    AVFrame* frame = av_frame_alloc();
    if (frame == NULL) {
       exit(1);
    }

    /* Copy necessary data for frame from avcodec_context */
    frame->format = avcodec_context->pix_fmt;
    frame->width = avcodec_context->width;
    frame->height = avcodec_context->height;

    /* Allocate actual backing data for frame */
    if (av_image_alloc(frame->data, frame->linesize, frame->width,
               frame->height, frame->format, 32) < 0) {
       exit(1);
    }

    /* open the output file, if the container needs it */
    if (!(container_format->flags & AVFMT_NOFILE)) {
       ret = avio_open(&container_format_context->pb, out_file, AVIO_FLAG_WRITE);
       if (ret < 0) {
           log(ERROR, "Error occurred while opening output file: %s\n",
                   av_err2str(ret));
           exit(1);
       }
    }

    /* write the stream header, if needed */
    ret = avformat_write_header(container_format_context, NULL);
    if (ret < 0) {
       log(ERROR, "Error occurred while writing output file header: %s\n",
                   av_err2str(ret));
    }

    The code to encode a frame is here :

    /* Init video packet */
    AVPacket packet;
    av_init_packet(&packet);

    /* Request that encoder allocate data for packet */
    packet.data = NULL;
    packet.size = 0;

    /* Write frame to video */
    int got_data;
    if (avcodec_encode_video2(avcontext, &packet, frame, &got_data) < 0) {
       log(WARNING, "Error encoding frame #%" PRId64,
               video_struct->next_pts);
       return -1;
    }

    /* Write corresponding data to file */
    if (got_data) {
       if (packet.pts != AV_NOPTS_VALUE) {
           packet.pts = av_rescale_q(packet.pts, video_struct->output_stream->codec->time_base, video_struct->output_stream->time_base);
       }
       if (packet.dts != AV_NOPTS_VALUE) {
           packet.dts = av_rescale_q(packet.dts, video_struct->output_stream->codec->time_base, video_struct->output_stream->time_base);
       }
       write_packet(video_struct, &packet, packet.size);
       av_packet_unref(&packet);
    }

    And the code to write the packet to the video stream :

    static int write_packet(video_struct* video, void* data, int size) {

    int ret;

    /* use AVStream is not null, otherwise write to output fd */
    AVPacket *pkt = (AVPacket*) data;
    pkt->stream_index = video->output_stream->index;
    ret = av_interleaved_write_frame(video->container_format_context, pkt);
    if (ret != 0) {
       return -1;
    }

    /* Data was written successfully */
    return ret;
    }
  • libavformat/libavcodec providing invalid container header

    14 décembre 2017, par seanr8

    I’m using libavcodec to encode a stream to h264 and libavformat to store it in an mp4. The resulting container has an invalid header that can be played in VLC, but not any other player.

    I’ve found that using the mp4 container and the "mpeg4" codec produces a valid mp4 file, but using libx265 (HEVC) or the libx264 codec produces invalid mp4s.

    I can use ffmpeg -i invalid.mp4 -vcodec copy valid.mp4 and I get a file of almost the exact same size, but in a valid container.

    Examples of these files are here : Broken file and
    Repaied file [use the download links in the upper right to examine]

    I used a hex editor to see the differences in the headers of the two files and the invalid one is 1 byte smaller than the valid one.

    The code I’m using to open the container and codec and to write the header is here :

    AVOutputFormat *container_format;
    AVFormatContext *container_format_context;
    AVStream *video_stream;
    int ret;

    /* allocate the output media context */
    avformat_alloc_output_context2(&container_format_context, NULL, NULL, out_file);
    if (!container_format_context) {
       log(INFO, "Unable to determine container format from filename, exiting\n");
       exit(1);
    }
    else {
       log(INFO, "Using container %s\n", container_format_context->oformat->name);
    }

    if (!container_format_context) {
       log(ERROR, "Could not build container format context. Encoding failed.");
       exit(1);
    }

    container_format = container_format_context->oformat;

    /* Pull codec based on name */
    AVCodec* codec = avcodec_find_encoder_by_name(codec_name);
    if (codec == NULL) {
       log(ERROR, "Failed to locate codec \"%s\".",
               codec_name);
       exit(1);
    }

    /* create stream */
    video_stream = NULL;
    video_stream = avformat_new_stream(container_format_context, codec);
    if (!video_stream) {
       log(ERROR, "Could not allocate encoder stream. Cannot continue.\n");
       exit(1);
    }
    video_stream->id = container_format_context->nb_streams - 1;

    video_stream->time_base = video_stream->codec->time_base = (AVRational) { 1, 25};

    av_dump_format(container_format_context, 0, out_file, 1);



    /* Retrieve encoding context */
    AVCodecContext* avcodec_context = video_stream->codec;
    if (avcodec_context == NULL) {
       log(ERROR, "Failed to allocate context for "
               "codec \"%s\".", codec_name);
       exit(1);
    }


    /* Init context with encoding parameters */
    avcodec_context->bit_rate = bitrate;
    avcodec_context->width = width;
    avcodec_context->height = height;
    avcodec_context->gop_size = 10;
    avcodec_context->max_b_frames = 1;
    avcodec_context->qmax = 31;
    avcodec_context->qmin = 2;
    avcodec_context->pix_fmt = AV_PIX_FMT_YUV420P;

    av_dump_format(container_format_context, 0, out_file, 1);

    /* Open codec for use */
    if (avcodec_open2(avcodec_context, codec, NULL) < 0) {
       log(ERROR, "Failed to open codec \"%s\".", codec_name);
       exit(1);
    }

    /* Allocate corresponding frame */
    AVFrame* frame = av_frame_alloc();
    if (frame == NULL) {
       exit(1);
    }

    /* Copy necessary data for frame from avcodec_context */
    frame->format = avcodec_context->pix_fmt;
    frame->width = avcodec_context->width;
    frame->height = avcodec_context->height;

    /* Allocate actual backing data for frame */
    if (av_image_alloc(frame->data, frame->linesize, frame->width,
               frame->height, frame->format, 32) < 0) {
       exit(1);
    }

    /* open the output file, if the container needs it */
    if (!(container_format->flags & AVFMT_NOFILE)) {
       ret = avio_open(&container_format_context->pb, out_file, AVIO_FLAG_WRITE);
       if (ret < 0) {
           log(ERROR, "Error occurred while opening output file: %s\n",
                   av_err2str(ret));
           exit(1);
       }
    }

    /* write the stream header, if needed */
    ret = avformat_write_header(container_format_context, NULL);
    if (ret < 0) {
       log(ERROR, "Error occurred while writing output file header: %s\n",
                   av_err2str(ret));
    }

    The code to encode a frame is here :

    /* Init video packet */
    AVPacket packet;
    av_init_packet(&packet);

    /* Request that encoder allocate data for packet */
    packet.data = NULL;
    packet.size = 0;

    /* Write frame to video */
    int got_data;
    if (avcodec_encode_video2(avcontext, &packet, frame, &got_data) < 0) {
       log(WARNING, "Error encoding frame #%" PRId64,
               video_struct->next_pts);
       return -1;
    }

    /* Write corresponding data to file */
    if (got_data) {
       if (packet.pts != AV_NOPTS_VALUE) {
           packet.pts = av_rescale_q(packet.pts, video_struct->output_stream->codec->time_base, video_struct->output_stream->time_base);
       }
       if (packet.dts != AV_NOPTS_VALUE) {
           packet.dts = av_rescale_q(packet.dts, video_struct->output_stream->codec->time_base, video_struct->output_stream->time_base);
       }
       write_packet(video_struct, &packet, packet.size);
       av_packet_unref(&packet);
    }

    And the code to write the packet to the video stream :

    static int write_packet(video_struct* video, void* data, int size) {

    int ret;

    /* use AVStream is not null, otherwise write to output fd */
    AVPacket *pkt = (AVPacket*) data;
    pkt->stream_index = video->output_stream->index;
    ret = av_interleaved_write_frame(video->container_format_context, pkt);
    if (ret != 0) {
       return -1;
    }

    /* Data was written successfully */
    return ret;
    }
  • Seeking in Libav / FFMPEG a DASH stream

    23 janvier 2018, par Glen Rhodes

    Recently, the functionality for playing DASH format files (mpd) was added to Libav. I’m trying to determine the best way to seek forward in the stream.

    When I use av_seek_frame, it does go to the correct time, but there’s a considerable delay which makes me think it’s not properly jumping to a segment / byte offset in the HTTP request, but rather just downloading with all its might until it arrives at the correct timestamp.

    int ret = av_seek_frame(is->pFormatCtx, stream_index, seek_target, is->seek_flags);

    When I use avformat_seek_file, it only seems to go forward several seconds before just continuing to play. So if I start playback, and then seek to 50 seconds, it will jump to something like 12. If I do the same seek again, it’ll jump further ahead, but still not 50.. however if it eventually gets to 50, then I do avformat_seek_file, it will successfully jump back to 50 no problem. So it’s like it tries, and gives up.

    int ret = avformat_seek_file(is->pFormatCtx, stream_index, INT64_MIN, tm, INT64_MAX, 0);

    Does anyone know how seeking is managed in the Libav dash playback ?