Recherche avancée

Médias (1)

Mot : - Tags -/Christian Nold

Autres articles (56)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

Sur d’autres sites (9304)

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

  • Output black when I decode h264 720p with ffmpeg

    6 décembre 2017, par José Marqueses Saxo

    First, sorry for my english. When I decode h264 720p in ardrone2.0 my output is black and I cant see anything.

    I have try to change the value of pCodecCtx->pix_fmt = AV_PIX_FMT_BGR24; to pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P; and the value of pCodecCtxH264->pix_fmt = AV_PIX_FMT_BGR24; to pCodecCtxH264->pix_fmt = AV_PIX_FMT_YUV420P; but my program crash. What am I doing wrong ?. Thank you, see part of my code :

    av_register_all();
    avcodec_register_all();
    avformat_network_init();

    // 1.2. Open video file
    if(avformat_open_input(&pFormatCtx, drone_addr, NULL, NULL) != 0) {
     mexPrintf("No conecct with Drone");
     EndVideo();
     return;
    }

    pCodec    = avcodec_find_decoder(AV_CODEC_ID_H264);

    pCodecCtx = avcodec_alloc_context3(pCodec);
    pCodecCtx->pix_fmt = AV_PIX_FMT_BGR24;
    pCodecCtx->skip_frame = AVDISCARD_DEFAULT;
    pCodecCtx->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
    pCodecCtx->err_recognition = AV_EF_CAREFUL;
    pCodecCtx->skip_loop_filter = AVDISCARD_DEFAULT;
    pCodecCtx->workaround_bugs = FF_BUG_AUTODETECT;
    pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
    pCodecCtx->codec_id = AV_CODEC_ID_H264;
    pCodecCtx->skip_idct = AVDISCARD_DEFAULT;
    pCodecCtx->width = 1280;
    pCodecCtx->height = 720;

    pCodecH264 = avcodec_find_decoder(AV_CODEC_ID_H264);
    pCodecCtxH264 = avcodec_alloc_context3(pCodecH264);


    pCodecCtxH264->pix_fmt = AV_PIX_FMT_BGR24;
    pCodecCtxH264->skip_frame = AVDISCARD_DEFAULT;
    pCodecCtxH264->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
    pCodecCtxH264->err_recognition = AV_EF_CAREFUL;
    pCodecCtxH264->skip_loop_filter = AVDISCARD_DEFAULT;
    pCodecCtxH264->workaround_bugs = FF_BUG_AUTODETECT;
    pCodecCtxH264->codec_type = AVMEDIA_TYPE_VIDEO;
    pCodecCtxH264->codec_id = AV_CODEC_ID_H264;
    pCodecCtxH264->skip_idct = AVDISCARD_DEFAULT;

    if(avcodec_open2(pCodecCtxH264, pCodecH264, &optionsDict) < 0)
    {
      mexPrintf("Error opening H264 codec");
      return ;
    }

    pFrame_BGR24 = av_frame_alloc();


    if(pFrame_BGR24 == NULL) {
      mexPrintf("Could not allocate pFrame_BGR24\n");
      return ;
    }

    // Determine required buffer size and allocate buffer

    buffer_BGR24 =
    (uint8_t *)av_mallocz(av_image_get_buffer_size(AV_PIX_FMT_BGR24,
    pCodecCtx->width, ((pCodecCtx->height == 720) ? 720 : pCodecCtx->height) *
    sizeof(uint8_t)*3,1));

    // Assign buffer to image planes

    av_image_fill_arrays(pFrame_BGR24->data, pFrame_BGR24->linesize,
    buffer_BGR24,AV_PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height,1);

    // format conversion context
    pConvertCtx_BGR24 = sws_getContext(pCodecCtx->width, pCodecCtx->height,
    pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,  AV_PIX_FMT_BGR24,
                                    SWS_BILINEAR | SWS_ACCURATE_RND, 0, 0, 0);

    // 1.6. get video frames
    pFrame = av_frame_alloc();

    av_init_packet(&packet);
    packet.data = NULL;
    packet.size = 0;
    }

    //Captura un frame
    void video::capture(mxArray *plhs[]) {

     if(av_read_frame(pFormatCtx, &packet) < 0){
         mexPrintf("Error al leer frame");
         return;
     }
      do {
          do {
             rest = avcodec_send_packet(pCodecCtxH264, &packet);
          } while(rest == AVERROR(EAGAIN));

          if(rest == AVERROR_EOF || rest == AVERROR(EINVAL)) {
                   printf("AVERROR(EAGAIN): %d, AVERROR_EOF: %d,
                   AVERROR(EINVAL): %d\n", AVERROR(EAGAIN), AVERROR_EOF,
                   AVERROR(EINVAL));
               printf("fe_read_frame: Frame getting error (%d)!\n", rest);
               return;
          }

          rest = avcodec_receive_frame(pCodecCtxH264, pFrame);
      } while(rest == AVERROR(EAGAIN));

      if(rest == AVERROR_EOF || rest == AVERROR(EINVAL)) {

       // An error or EOF occured,index break out and return what
       // we have so far.
         printf("AVERROR(EAGAIN): %d, AVERROR_EOF: %d, AVERROR(EINVAL): %d\n",
         AVERROR(EAGAIN), AVERROR_EOF, AVERROR(EINVAL));
           printf("fe_read_frame: EOF or some othere decoding error (%d)!\n",
           rest);
           return;
      }


      // 2.1.1. convert frame to GRAYSCALE [or BGR] for OpenCV
      sws_scale(pConvertCtx_BGR24,   (const uint8_t* const*)pFrame->data,
          pFrame->linesize, 0,pCodecCtx->height,   pFrame_BGR24->data,  
                pFrame_BGR24->linesize);
    //}
      av_packet_unref(&packet);
      av_init_packet(&packet);
      mwSize dims[] = {(pCodecCtx->width)*((pCodecCtx->height == 720) ? 720 :
      pCodecCtx->height)*sizeof(uint8_t)*3};
      plhs[0] = mxCreateNumericArray(1,dims,mxUINT8_CLASS, mxREAL);
       //plhs[0]=mxCreateDoubleMatrix(pCodecCtx->height,pCodecCtx-
       >width,mxREAL);
      point=mxGetPr(plhs[0]);
      memcpy(point, pFrame_BGR24->data[0],(pCodecCtx->width)*(pCodecCtx-
       >height)*sizeof(uint8_t)*3);
    }