Recherche avancée

Médias (91)

Autres articles (111)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

Sur d’autres sites (10061)

  • Encoding video using FFmpeg and FreeImage

    14 mai 2014, par mike

    I have to make a video encoder to encode video using mjpeg codec from many jpgs saved on the disk. I use FreeImage to load images and ffmpeg to encode. Unfortunately, the output video isn’t that what I expect. I can’t play it in MPC. VLC can play it but there is only a single quick flash of the last picture I loaded. I want to have 1 fps video and for example I loaded 4 frames so my video should last 4 seconds.

    Input pictures are in BGR24 pixel format.

    What is more, when I run my code I got swscaler warning that picture format YUVJ420P is deprecated but I cant find another pixel format which is suitable for MJPEG codec.

    Here is my source code :

    AVPixelFormat in_pix_fmt = AV_PIX_FMT_BGR24;
    AVPixelFormat out_pix_fmt = AV_PIX_FMT_YUVJ420P;

    AVCodec *pCodec;
    AVCodecContext *pCodecCtx = NULL;
    int out_size = 0;
    int size, outbuf_size, i, outpic_size, w, h;
    FILE *file;
    const char *videofile_name = "test_video_cpp.avi";
    AVFrame *picture, *outpic;
    uint8_t *outbuf, *picture_buf, *outpic_buf;

    av_register_all();

    pCodec = avcodec_find_encoder(CODEC_ID_MJPEG);
    if (!pCodec)
    {
       cout << "Codec not found\n\n";
       return 1;
    }

    pCodecCtx = avcodec_alloc_context3(pCodec);
    picture = avcodec_alloc_frame();
    outpic = avcodec_alloc_frame();

    pCodecCtx->codec_id = CODEC_ID_MJPEG;
    pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
    pCodecCtx->pix_fmt = out_pix_fmt;
    pCodecCtx->bit_rate = 400000;
    pCodecCtx->width = 1688;            
    pCodecCtx->height = 728;
    pCodecCtx->time_base.num = 1;          
    pCodecCtx->time_base.den = 1;       //fps
    pCodecCtx->max_b_frames = 0;

    outbuf_size = 500000;
    outbuf = new uint8_t[outbuf_size];

    if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)     //open codec
    {
       cout << "Could not open codec\n";
       exit(1);
    }

    file = fopen(videofile_name, "wb");                 //open file
    if (!file)
    {
       cout << "Could not open " << videofile_name << endl;
       exit(1);
    }

    outpic_size = avpicture_get_size(out_pix_fmt, pCodecCtx->width, pCodecCtx->height);
    outpic_buf = new uint8_t[outpic_size];
    cout << "Outpic size was setted to: " << outpic_size << endl;

    size = pCodecCtx->width * pCodecCtx->height;
    picture_buf = new uint8_t[size * 3];


    for (i = 1; i < 5; i++)
    {  
       fflush(stdout);

       stringstream ss;
       ss << i;
       filename = name + ss.str() + ext;
       path = dir + filename;

       dib = FreeImage_Load(FIF_JPEG, path.c_str(), 0);

       picture_buf = FreeImage_GetBits(dib);

               h = FreeImage_GetHeight(dib);
       w = FreeImage_GetWidth(dib);

       avpicture_fill((AVPicture*)picture, picture_buf, in_pix_fmt, w, h);
       avpicture_fill((AVPicture*)outpic, outpic_buf, out_pix_fmt, pCodecCtx->width, pCodecCtx->height);

       struct SwsContext* fooContext = sws_getContext(w, h, in_pix_fmt, pCodecCtx->width, pCodecCtx->height, out_pix_fmt, SWS_BICUBIC, NULL, NULL, NULL);

       sws_scale(fooContext, picture->data, picture->linesize, 0, pCodecCtx->height, outpic->data, outpic->linesize);

       //encode single frame
       out_size = avcodec_encode_video(pCodecCtx, outpic_buf, outpic_size, outpic);
       cout << "encoding frame " << i << "(size=" << out_size << ")\n";
       fwrite(outbuf, 1, out_size, file);

    }

    //encode delayed frames
    for ( ; out_size; i++)
    {
       fflush(stdout);
       out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, NULL);
       cout << "write frame " << i << "(size=" << out_size << ")\n";
       fwrite(outbuf, 1, out_size, file);
    }

    outbuf[0] = 0x00;
    outbuf[1] = 0x00;
    outbuf[2] = 0x01;
    outbuf[3] = 0xb7;
    fwrite(outbuf, 1, 4, file);

    fclose(file);
    delete outbuf;
    avcodec_close(pCodecCtx);
    av_free(pCodecCtx);
    avpicture_free((AVPicture*)picture);
    avpicture_free((AVPicture*)outpic);
    delete picture_buf;
    delete outpic_buf;
  • Encoding with ffmpeg : video quality drops

    21 mai 2014, par Adi Ulici

    I’m trying to encode a set of pictures into a video with ffmpeg. I’m new to this stuff, but I managed to get it work. I have only one problem : the first second or two of video look good but as the time goes the video quality keeps dropping and dropping. At the end (it’s a video of about 16 seconds) the quality is really bad and I can’t understand why.

    I’m using AV_CODEC_ID_MPEG1VIDEO as video codec (frankly, it’s the only one I could make work) and here is a sample of my code :

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

    c->bit_rate = 400000;
    c->width = width;
    c->height = height;
    struct AVRational time_base = {1, 25};
    c->time_base = time_base;
    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 the codec
    if (avcodec_open2(c, 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);
    }

    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;

    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);
    }

    struct SwsContext *frameConvertContext = sws_getContext(width, height,
         PIX_FMT_RGB24,
         c->width, c->height,
         c->pix_fmt,
         SWS_LANCZOS | SWS_ACCURATE_RND, NULL, NULL, NULL);

    for (i = 0; i < framesNr; i++) {
       // Read an image
       std::stringstream filename;
       filename << "input/image-" << (i+1) << ".jpg";
       Image* img;
       img = Image::fromJpeg((char*) filename.str().c_str());
       int srcSliceY[1] = { img->getWidth() * 3 };
       const uint8_t* imgbuf[1] = { (uint8_t*) img->getData(sizeof(uint8_t)) };

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

       fflush(stdout);
       frameConvertContext = sws_getCachedContext(frameConvertContext, width, height,
         PIX_FMT_RGB24,
         c->width, c->height,
         c->pix_fmt,
         SWS_LANCZOS | SWS_ACCURATE_RND, NULL, NULL, NULL);

       sws_scale(frameConvertContext, imgbuf, srcSliceY, 0, img->getHeight(), frame->data, frame->linesize);

       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(".");
           fwrite(pkt.data, 1, pkt.size, f);
           av_free_packet(&pkt);
       }

       // Free the memory
       delete img;
    }

    Any tips ? Thanks a lot !

  • Ffmpeg video encoding and decoding

    17 décembre 2014, par iJose

    I am a newbie to FFMPEG.
    I am trying to encode a video that is captured from the camera.
    I am using the following code to encode the video. i am capturing the frames using
    AvcaptureSession, i have also tried other library files
    Kickflip and iFrameExtractor from github.com but ended up with no solution.

    Please Help me Thanking you in advance

    static void video_encode_example(const char *filename, int codec_id)
    {
       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(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= (AVRational){1,25};
       c->gop_size = 10; /* emit one intra frame every ten frames */
       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 = 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);
       if (ret < 0) {
           fprintf(stderr, "Could not allocate raw picture buffer\n");
           exit(1);
       }

       /* encode 1 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;yheight;y++) {
               for(x=0;xwidth;x++) {
                   frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
               }
           }

           /* Cb and Cr */
           for(y=0;yheight/2;y++) {
               for(x=0;xwidth/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]);
       avcodec_free_frame(&frame);
       printf("\n");
    }