Recherche avancée

Médias (0)

Mot : - Tags -/metadatas

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (19)

  • Taille des images et des logos définissables

    9 février 2011, par

    Dans beaucoup d’endroits du site, logos et images sont redimensionnées pour correspondre aux emplacements définis par les thèmes. L’ensemble des ces tailles pouvant changer d’un thème à un autre peuvent être définies directement dans le thème et éviter ainsi à l’utilisateur de devoir les configurer manuellement après avoir changé l’apparence de son site.
    Ces tailles d’images sont également disponibles dans la configuration spécifique de MediaSPIP Core. La taille maximale du logo du site en pixels, on permet (...)

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

  • Use, discuss, criticize

    13 avril 2011, par

    Talk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
    The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
    A discussion list is available for all exchanges between users.

Sur d’autres sites (3725)

  • Encode video with FFmpeg fps have been wrong

    7 novembre 2016, par Burak Hamuryen

    I’m trying to encod a video with FFmpeg but i have a problem about fps.
    So i build the sample code as follows

    AVCodec *codec;
    AVCodecContext *c = NULL;
    int i, ret, x, y, got_output;
    FILE *f;
    AVFrame *frame;
    AVPacket pkt;
    uint8_t endcode[] = { 0, 0, 1, 0xb7 };

    printf("Encode video file %s\n", filename);

    /* find the mpeg1 video encoder */
    codec = avcodec_find_encoder((AVCodecID)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 = 352;
    c->height = 288;
    /* frames per second */
    c->time_base.num = 1;
    c->time_base.den = 5; //changed

    /* emit one intra frame every ten frames
    * check frame pict_type before passing frame
    * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
    * then gop_size is ignored and the output of encoder
    * will always be I frame irrespective to gop_size
    */
    c->gop_size = 10;
    c->max_b_frames = 1;
    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);
    }

    f = fopen(filename, "wb");
    if (!f) {
       fprintf(stderr, "Could not open %s\n", filename);
       exit(1);
    }

    frame = av_frame_alloc();
    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);
    if (ret < 0) {
       fprintf(stderr, "Could not allocate raw picture buffer\n");
       exit(1);
    }

    /* encode 5 second of video */
    for (i = 0; i < 25; i++) {
       av_init_packet(&pkt);
       pkt.data = NULL;    // packet data will be allocated by the encoder
       pkt.size = 0;

       fflush(stdout);
       /* prepare a dummy image */
       /* Y */
       for (y = 0; y < c->height; y++) {
           for (x = 0; x < c->width; x++) {
               frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
           }
       }

       /* Cb and Cr */
       for (y = 0; y < c->height / 2; y++) {
           for (x = 0; x < c->width / 2; x++) {
               frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
               frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
           }
       }

       frame->pts = i;

       /* encode the image */
       ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
       if (ret < 0) {
           fprintf(stderr, "Error encoding frame\n");
           exit(1);
       }

       if (got_output) {
           printf("Write frame %3d (size=%5d)\n", i, pkt.size);
           fwrite(pkt.data, 1, pkt.size, f);
           av_free_packet(&pkt);
       }
    }

    /* get the delayed frames */
    for (got_output = 1; got_output; i++) {
       fflush(stdout);

       ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
       if (ret < 0) {
           fprintf(stderr, "Error encoding frame\n");
           exit(1);
       }

       if (got_output) {
           printf("Write frame %3d (size=%5d)\n", i, pkt.size);
           fwrite(pkt.data, 1, pkt.size, f);
           av_free_packet(&pkt);
       }
    }

    /* add sequence end code to have a real mpeg file */
    fwrite(endcode, 1, sizeof(endcode), f);
    fclose(f);

    avcodec_close(c);
    av_free(c);
    av_freep(&frame->data[0]);
    av_frame_free(&frame);
    printf("\n");

    and I changed the following parts from the original

    c->time_base.num = 1;
    c->time_base.den = 5;

    after these changes, i expect a video to be composed of 5 seconds and 5 fps.
    But when i play the output video file, the video ends in 1 2 seconds.
    The ffprob output of output video is as follows.

    Edit :
    ffprobe output added as a text

    ffprobe version 2.0.1 Copyright (c) 2007-2013 the FFmpeg developers
     built on Sep 26 2013 02:00:03 with gcc 4.8.1 (GCC)
     configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
     libavutil      52. 38.100 / 52. 38.100
     libavcodec     55. 18.102 / 55. 18.102
     libavformat    55. 12.100 / 55. 12.100
     libavdevice    55.  3.100 / 55.  3.100
     libavfilter     3. 79.101 /  3. 79.101
     libswscale      2.  3.100 /  2.  3.100
     libswresample   0. 17.102 /  0. 17.102
     libpostproc    52.  3.100 / 52.  3.100
    Input #0, h264, from 'C:\Users\bhamuryen\Desktop\Dev\Test\ffmpeg_test\ffmpeg_test\test.h264':
     Duration: N/A, bitrate: N/A
       Stream #0:0: Video: h264 (High), yuv420p, 352x288, 5 fps, 5 tbr, 1200k tbn, 10 tbc
    [STREAM]
    index=0
    codec_name=h264
    codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
    profile=High
    codec_type=video
    codec_time_base=1/10
    codec_tag_string=[0][0][0][0]
    codec_tag=0x0000
    width=352
    height=288
    has_b_frames=1
    sample_aspect_ratio=0:1
    display_aspect_ratio=0:1
    pix_fmt=yuv420p
    level=13
    timecode=N/A
    id=N/A
    r_frame_rate=10/2
    avg_frame_rate=5/1
    time_base=1/1200000
    start_pts=N/A
    start_time=N/A
    duration_ts=N/A
    duration=N/A
    bit_rate=N/A
    nb_frames=N/A
    nb_read_frames=N/A
    nb_read_packets=N/A
    DISPOSITION:default=0
    DISPOSITION:dub=0
    DISPOSITION:original=0
    DISPOSITION:comment=0
    DISPOSITION:lyrics=0
    DISPOSITION:karaoke=0
    DISPOSITION:forced=0
    DISPOSITION:hearing_impaired=0
    DISPOSITION:visual_impaired=0
    DISPOSITION:clean_effects=0
    DISPOSITION:attached_pic=0

    The output video file played with VLC and VLC statistic is as follows.

    vlc output

    As shown, i setted fps 5 but vlc read it like 10 fps also ffprobe say to us

    Stream #0:0 : Video : h264 (High), yuv420p, 352x288, 5 fps, 5 tbr, 1200k tbn, 10 tbc

    and

    codec_time_base=1/10

    i think the important thing is codec_time_base=1/10 and 10 tbc.
    What is wrong in this code ? i don’t know exactly the reason for the problem.
    How can i create a video(5 fps -10 fps or custom fps) and play correctly the created video ?

    Thanks for your help.

  • Access Violation at avcodec_encode_video2()

    23 mars 2016, par bot1131357

    I am trying to understand the FFmpeg API by following online examples available but it seems that the FFmpeg API has changed over time, making most of the examples obsolete ; I hope some of you can help me make more sense of the FFmpeg API examples.

    I am currently trying to understand the encoding-example from FFmpeg, but I am getting an Access Violation error at this line :

    out_size = avcodec_encode_video2(codecCtx, &avpkt, picture, &got_packet);

    where I get "Unhandled exception at 0x77c29e42 in test01_encode.exe : 0xC0000005 : Access violation reading location 0xccccccc8." from Visual Studio.

    I understand that avcodec_encode_video() is deprecated in favour of avcodec_encode_video2(), which uses AVPacket. I’ve allocated a buffer to data member of AVPacket and set its size, but still the same. What did I miss ?

    The library that I’m using is ffmpeg-20160219-git-98a0053-win32-dev. I would really really appreciate if you could help me out of this confusion.

    (Side : What does it mean by "get delayed frames" and why are we encoding by specifying AVFrame* parameter as NULL ?)

    /*
    * Video encoding example
    */
    char filename[] = "test.mpg";
    int main(int argc, char** argv)
    {
       AVCodec *codec;
       AVCodecContext *codecCtx= NULL;
       int i, out_size, size, x, y, outbuf_size;
       FILE *f;
       AVFrame *picture;
       uint8_t *outbuf, *picture_buf;

       printf("Video encoding\n");

       // Register all formats and codecs
       av_register_all();

       /* find the mpeg1 video encoder */
       codec = avcodec_find_encoder(AV_CODEC_ID_MPEG1VIDEO);
       if (!codec) {
           fprintf(stderr, "codec not found\n");
           exit(1);
       }

       codecCtx= avcodec_alloc_context3(codec);
       picture= av_frame_alloc();

       /* put sample parameters */
       codecCtx->bit_rate = 400000;
       /* resolution must be a multiple of two */
       codecCtx->width = 352;
       codecCtx->height = 288;
       /* frames per second */
       //codecCtx->time_base= (AVRational){1,25};
       codecCtx->time_base.num = 1;
       codecCtx->time_base.den = 25;

       codecCtx->gop_size = 10; /* emit one intra frame every ten frames */
       codecCtx->max_b_frames=1;
       codecCtx->pix_fmt = AV_PIX_FMT_YUV420P;

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

       fopen_s(&f,filename, "wb");
       if (!f) {
           fprintf(stderr, "could not open %s\n", filename);
           exit(1);
       }

       /* alloc image and output buffer */
       outbuf_size = 100000;
       outbuf = (uint8_t*) malloc(outbuf_size);
       size = codecCtx->width * codecCtx->height;
       picture_buf = (uint8_t*) malloc((size * 3) / 2); /* size for YUV 420 */

       picture->data[0] = picture_buf;
       picture->data[1] = picture->data[0] + size;
       picture->data[2] = picture->data[1] + size / 4;
       picture->linesize[0] = codecCtx->width;
       picture->linesize[1] = codecCtx->width / 2;
       picture->linesize[2] = codecCtx->width / 2;

       picture->width = codecCtx->width;
       picture->height = codecCtx->height;
       picture->format = codecCtx->pix_fmt;

       AVPacket avpkt;
       int got_packet;

       avpkt.size=av_image_get_buffer_size(codecCtx->pix_fmt, codecCtx->width,
                       codecCtx->height,1);    
       avpkt.data = (uint8_t *)av_malloc(avpkt.size*sizeof(uint8_t));

       /* encode 1 second of video */
       for(i=0;i<25;i++) {
           fflush(stdout);
           /* prepare a dummy image */
           /* Y */
           for(y=0;yheight;y++) {
               for(x=0;xwidth;x++) {
                   picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
               }
           }

           /* Cb and Cr */
           for(y=0;yheight/2;y++) {
               for(x=0;xwidth/2;x++) {
                   picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
                   picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
               }
           }

           /* encode the image */
           //out_size = avcodec_encode_video(codecCtx, outbuf, outbuf_size, picture);
           // <access violation="violation">
           out_size = avcodec_encode_video2(codecCtx, &amp;avpkt, picture, &amp;got_packet);
           printf("encoding frame %3d (size=%5d)\n", i, out_size);
           //fwrite(outbuf, 1, out_size, f);
           fwrite(avpkt.data, 1, avpkt.size, f);
       }

       /* get the delayed frames */
       for(; out_size; i++) {
           fflush(stdout);

           //out_size = avcodec_encode_video(codecCtx, outbuf, outbuf_size, NULL);
           out_size = avcodec_encode_video2(codecCtx, &amp;avpkt, NULL, &amp;got_packet);
           printf("write frame %3d (size=%5d)\n", i, out_size);
           //fwrite(outbuf, 1, out_size, f);
           fwrite(avpkt.data, 1, avpkt.size, f);
       }

       /* add sequence end code to have a real mpeg file */
       outbuf[0] = 0x00;
       outbuf[1] = 0x00;
       outbuf[2] = 0x01;
       outbuf[3] = 0xb7;
       fwrite(outbuf, 1, 4, f);
       fclose(f);
       free(picture_buf);
       free(outbuf);

       avcodec_close(codecCtx);
       av_free(codecCtx);
       av_free(picture);
       printf("\n");
    }
    </access>
  • H264 decoding using ffmpeg

    14 juillet 2016, par Kindermann

    I’m trying to decode a video stream with ffmpeg library, that’s how I do it basically :

    void video_decode(const char *filename)
    {
       AVCodec *codec;
       AVCodecContext *c= NULL;
       int frame_count=0;
       FILE *f;
       AVFrame *frame;
       uint8_t inbuf[INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
       AVPacket avpkt;
       av_init_packet(&amp;avpkt);
       memset(inbuf + INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);
       printf("Decoding video file...\n");
       /* find the h264 video decoder */
       codec = avcodec_find_decoder(AV_CODEC_ID_H264);
       c = avcodec_alloc_context3(codec);
       c->bit_rate = 400000;
       c->width = 1920;
       c->height = 1080;

       if (avcodec_open2(c, codec, NULL) &lt; 0) {
           fprintf(stderr, "Could not open codec\n");
           exit(1);
       }
       frame = av_frame_alloc();
       for (;;) {
           avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);        
       if (avpkt.size == 0)
               break;
           avpkt.data = inbuf;
           while(avpkt.size > 0){

           int len, got_frame;
               len = avcodec_decode_video2(c, frame, &amp;got_frame, &amp;avpkt);          
           if (len &lt; 0) {
                   fprintf(stderr, "Errr while decding frame %d\n", frame_count);
                   exit (1);
               }
               if (got_frame) {
                   //Print out frame information..
           }
               if (avpkt.data) {
                   avpkt.size -= len;
                   avpkt.data += len;
               }
       }              
       }  
    }

    But I got the following outputs :

    Decoding video file...
    [h264 @ 0x303c040] decode_slice_header error
    [h264 @ 0x303c040] decode_slice_header error
    [h264 @ 0x303c040] decode_slice_header error
    [h264 @ 0x303c040] no frame!
    Errr while decding frame 0

    Obviously the initiation of codec was incomplete. Do you have experience with h264 api ? Any help would be appreciated.