Recherche avancée

Médias (2)

Mot : - Tags -/plugins

Autres articles (36)

  • Contribute to a better visual interface

    13 avril 2011

    MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
    Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community.

  • Librairies et logiciels spécifiques aux médias

    10 décembre 2010, par

    Pour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
    Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...)

  • Dépôt de média et thèmes par FTP

    31 mai 2013, par

    L’outil MédiaSPIP traite aussi les média transférés par la voie FTP. Si vous préférez déposer par cette voie, récupérez les identifiants d’accès vers votre site MédiaSPIP et utilisez votre client FTP favori.
    Vous trouverez dès le départ les dossiers suivants dans votre espace FTP : config/ : dossier de configuration du site IMG/ : dossier des média déjà traités et en ligne sur le site local/ : répertoire cache du site web themes/ : les thèmes ou les feuilles de style personnalisées tmp/ : dossier de travail (...)

Sur d’autres sites (3920)

  • How to explain the given ffplay C code snippet ?

    20 juillet 2015, par Jerikc XIONG

    The following code snippet is from ffplay :

    static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
       int got_frame = 0;

       do {
           int ret = -1;

           if (d->queue->abort_request)
               return -1;

           if (!d->packet_pending || d->queue->serial != d->pkt_serial) {
               AVPacket pkt;
               do {
                   if (d->queue->nb_packets == 0)
                       SDL_CondSignal(d->empty_queue_cond);
                   if (packet_queue_get(d->queue, &pkt, 1, &d->pkt_serial) < 0)
                       return -1;
                   if (pkt.data == flush_pkt.data) {
                       avcodec_flush_buffers(d->avctx);
                       d->finished = 0;
                       d->next_pts = d->start_pts;
                       d->next_pts_tb = d->start_pts_tb;
                   }
               } while (pkt.data == flush_pkt.data || d->queue->serial != d->pkt_serial);
               av_free_packet(&d->pkt);
               d->pkt_temp = d->pkt = pkt;
               d->packet_pending = 1;
           }

           switch (d->avctx->codec_type) {
               case AVMEDIA_TYPE_VIDEO:
                   ret = avcodec_decode_video2(d->avctx, frame, &got_frame, &d->pkt_temp);
                   if (got_frame) {
                       if (decoder_reorder_pts == -1) {
                           frame->pts = av_frame_get_best_effort_timestamp(frame);
                       } else if (decoder_reorder_pts) {
                           frame->pts = frame->pkt_pts;
                       } else {
                           frame->pts = frame->pkt_dts;
                       }
                   }
                   break;
               case AVMEDIA_TYPE_AUDIO:
                   ret = avcodec_decode_audio4(d->avctx, frame, &got_frame, &d->pkt_temp);
                   if (got_frame) {
                       AVRational tb = (AVRational){1, frame->sample_rate};
                       if (frame->pts != AV_NOPTS_VALUE)
                           frame->pts = av_rescale_q(frame->pts, d->avctx->time_base, tb);
                       else if (frame->pkt_pts != AV_NOPTS_VALUE)
                           frame->pts = av_rescale_q(frame->pkt_pts, av_codec_get_pkt_timebase(d->avctx), tb);
                       else if (d->next_pts != AV_NOPTS_VALUE)
                           frame->pts = av_rescale_q(d->next_pts, d->next_pts_tb, tb);
                       if (frame->pts != AV_NOPTS_VALUE) {
                           d->next_pts = frame->pts + frame->nb_samples;
                           d->next_pts_tb = tb;
                       }
                   }
                   break;
               case AVMEDIA_TYPE_SUBTITLE:
                   ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, &d->pkt_temp);
                   break;
           }

           if (ret < 0) {
               d->packet_pending = 0;
           } else {
               d->pkt_temp.dts =
               d->pkt_temp.pts = AV_NOPTS_VALUE;
               if (d->pkt_temp.data) {
                   if (d->avctx->codec_type != AVMEDIA_TYPE_AUDIO)
                       ret = d->pkt_temp.size;
                   d->pkt_temp.data += ret;
                   d->pkt_temp.size -= ret;
                   if (d->pkt_temp.size <= 0)
                       d->packet_pending = 0;
               } else {
                   if (!got_frame) {
                       d->packet_pending = 0;
                       d->finished = d->pkt_serial; // FLAG
                   }
               }
           }
       } while (!got_frame && !d->finished);

       return got_frame;
    }

    It’s difficult for me to understand the following code :

    d->finished = d->pkt_serial; // FLAG

    Can anyone help me ?

    Thanks.

  • C++, FFmpeg, save AVPacket infomation into videostate structure in ffplay.c

    28 mai 2015, par Yoohoo

    I am currently working on a project that tests video streaming. In the project, video stream is encoded with H.264 before send and decoded after receive, using FFmpeg codec and functions.

    I can encode video stream by

    init_video_encode(AV_CODEC_ID_H264);

    where

    static void init_video_encode(AVCodecID codec_id){
    codec = avcodec_find_encoder(codec_id);
    if (!codec) {
       fprintf(stderr, "Codec not found\n");
       exit(1);
    }

    c = avcodec_alloc_context3(codec);
    if (!c) {
       fprintf(stderr, "Could not allocate video codec context\n");
       exit(1);
    }

    /* put sample parameters */
    c->bit_rate = 400000;
    /* resolution must be a multiple of two */
    c->width = 640;
    c->height = 480;
    /* frames per second */
    c->time_base= (AVRational){1,25};
    c->gop_size = 10; /* emit one intra frame every ten frames */
    c->max_b_frames=max_f;
    c->pix_fmt = AV_PIX_FMT_YUV420P;

    if(codec_id == AV_CODEC_ID_H264)
       av_opt_set(c->priv_data, "preset", "slow", 0);

    /* open it */
    if (avcodec_open2(c, codec, NULL) < 0) {
       fprintf(stderr, "Could not open codec\n");
       exit(1);
    }

    frame = avcodec_alloc_frame();
    if (!frame) {
       fprintf(stderr, "Could not allocate video frame\n");
       exit(1);
    }
    frame->format = c->pix_fmt;
    frame->width  = c->width;
    frame->height = c->height;

    /* the image can be allocated by any means and av_image_alloc() is
    * just the most convenient way if av_malloc() is to be used */
    ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height,
                        c->pix_fmt, 32);

    /* get the delayed frames */
    if (ret < 0) {
       fprintf(stderr, "Could not allocate raw picture buffer\n");
       exit(1);
    }
       av_init_packet(&pkt);

    //}

       pkt.data = NULL;    // packet data will be allocated by the encoder
       pkt.size = 0;
       //cout<<"\nBefore YUV\n";
       if(count == 0)
       read_yuv420(frame->data[0]);
       count ++;
      // cout<<"\nAfter YUV\n";
       if(count == SUBSITY) {
       count = 0;
       }

       frame->pts = i++;

       /* encode the image */
       ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
       if (ret < 0) {
            fprintf(stderr, "Error encoding frame\n");
            return -1;
       }
       //cout<<"\nRecord the Video\n";
       if (got_output) {
            //printf("Write frame %3d (size=%5d)\n", i, pkt.size);
            //cout<<"\nBefore Memcpy\n\n\n";

            memcpy(inbufout+totalSize,pkt.data,pkt.size);
            //cout<<"\nAfter Memcpy\n\n\n";
            totalSize+=pkt.size;

    The video encoder works very well, if I write the encoded packet into a .h264 file, it can be played. But at the decoder side, I cannot decode the received packet with :

       codec = avcodec_find_decoder(AV_CODEC_ID_H264);
       if (!codec) {
           fprintf(stderr, "Codec not found\n");
           exit(1);
       }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate video codec context\n");
           exit(1);
       }

       if(codec->capabilities&CODEC_CAP_TRUNCATED)
           c->flags|= CODEC_FLAG_TRUNCATED;

       /* open it */
       if (avcodec_open2(c, codec, NULL) < 0) {
           fprintf(stderr, "Could not open codec\n");
           exit(1);
       }

       frame = avcodec_alloc_frame();
       if (!frame) {
           fprintf(stderr, "Could not allocate video frame\n");
           exit(1);
       }
    len = avcodec_decode_video2(avctx, frame, &got_frame, pkt);
       if (len < 0) {
           fprintf(stderr, "Error while decoding frame %d\n", *frame_count);
           return len;
       }

    The reason of failure is lacking parser, I have tried to build a parser but failed......

    Therefore I am wondering using ffplay.c as a header file in my receiver program so that I can use it as the decoder and player.

    I have took a look at ffplay.c, it actually fetch file into a videostate structure and processing it. The fetching part is from line 3188 of ffplay.c :

    VideoState *is;

       is = av_mallocz(sizeof(VideoState));
       if (!is)
           return NULL;
       av_strlcpy(is->filename, filename, sizeof(is->filename));
       is->iformat = iformat;
       is->ytop    = 0;
       is->xleft   = 0;

       /* start video display */
       if (frame_queue_init(&is->pictq, &is->videoq, VIDEO_PICTURE_QUEUE_SIZE, 1) < 0)
           goto fail;
       if (frame_queue_init(&is->subpq, &is->subtitleq, SUBPICTURE_QUEUE_SIZE, 0) < 0)
           goto fail;
       if (frame_queue_init(&is->sampq, &is->audioq, SAMPLE_QUEUE_SIZE, 1) < 0)
           goto fail;

       packet_queue_init(&is->videoq);
       packet_queue_init(&is->audioq);
       packet_queue_init(&is->subtitleq);

       is->continue_read_thread = SDL_CreateCond();

       init_clock(&is->vidclk, &is->videoq.serial);
       init_clock(&is->audclk, &is->audioq.serial);
       init_clock(&is->extclk, &is->extclk.serial);
       is->audio_clock_serial = -1;
       is->av_sync_type = av_sync_type;
       is->read_tid     = SDL_CreateThread(read_thread, is);
       if (!is->read_tid) {
    fail:
           stream_close(is);
           return NULL;
       }

    Now instead of fetching file, I want to modify ffplay.c code so that let it fetch the received packet, I can save received packet to AVPacket by

    static AVPacket avpkt;
    avpkt.data = inbuf;

    My question is : how to put AVPacket information into videostate structure ?

  • ffmpeg C API - creating queue of frames

    25 mai 2016, par lupod

    I have created using the C API of ffmpeg a C++ application that reads frames from a file and writes them to a new file. Everything works fine, as long as I write immediately the frames to the output. In other words, the following structure of the program outputs the correct result (I put only the pseudocode for now, if needed I can also post some real snippets but the classes that I have created for handling the ffmpeg functionalities are quite large) :

    AVFrame* frame = av_frame_alloc();
    int got_frame;

    // readFrame returns 0 if file is ended, got frame = 1 if
    // a complete frame has been extracted
    while(readFrame(inputfile,frame, &got_frame)) {
     if (got_frame) {
       // I actually do some processing here
       writeFrame(outputfile,frame);
     }
    }
    av_frame_free(&frame);

    The next step has been to parallelize the application and, as a consequence, frames are not written immediately after they are read (I do not want to go into the details of the parallelization). In this case problems arise : there is some flickering in the output, as if some frames get repeated randomly. However, the number of frames and the duration of the output video remains correct.

    What I am trying to do now is to separate completely the reading from writing in the serial implementation in order to understand what is going on. I am creating a queue of pointers to frames :

    std::queue queue;
    int ret = 1, got_frame;
    while (ret) {
     AVFrame* frame = av_frame_alloc();
     ret = readFrame(inputfile,frame,&got_frame);
     if (got_frame)
       queue.push(frame);
    }

    To write frames to the output file I do :

    while (!queue.empty()) {
     frame = queue.front();
     queue.pop();
     writeFrame(outputFile,frame);
     av_frame_free(&frame);
    }

    The result in this case is an output video with the correct duration and number of frames that is only a repetition of the last 3 (I think) frames of the video.

    My guess is that something might go wrong because of the fact that in the first case I use always the same memory location for reading frames, while in the second case I allocate many different frames.

    Any suggestions on what could be the problem ?