hai.i am using libavcodec to write video file from buffer which is capture from usb camera.i am getting video output file with larger in size.i have to compress my video file size.plz suggest me needful thing..my code is here...

OS:linux IDE:Qt #

void videoctl(uint8_t *destination)
    {
    //destination  -->buffer from video  camera

        AVCodec *codec;
            AVCodecContext *c;
            int out_size, size, x, y, outbuf_size;
            FILE *f;
            AVFrame *picture;
            uint8_t *outbuf, *picture_buf;



          avcodec_init(); //BLOCK ONE
          //register all the codecs
          avcodec_register_all();

          c= NULL;


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

           c= avcodec_alloc_context();
              picture= avcodec_alloc_frame();
              /* put sample parameters */
              c->bit_rate = 400000;
              /* resolution must be a multiple of two */
              c->width = 320 ;
              c->height = 240 ;
              /* 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 = PIX_FMT_YUV420P;

              /* open it */
                 if (avcodec_open(c, codec) < 0)
              {
                     fprintf(stderr, "could not open codec\n");
                     exit(1);

              }                                               //BLOCK FOUR

                 /* alloc image and output buffer */
                 outbuf_size = buf.length;//1000000;
                 outbuf = (uint8_t *)malloc(outbuf_size);
                 size = c->width * c->height ;
                 picture_buf =(uint8_t *) malloc((size * 3) / 2); /* size for YUV 420 */

                 picture_buf=(uint8_t *)destination;

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


                 for(i=0;i<25;i++)
                 {
                       // picture->pts = i;
                        out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
                        printf("encoding frame %3d (size=%5d)\n", i, out_size);
                        fwrite(outbuf, 1, out_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);

                 }
                 free(picture_buf);
                 free(outbuf);
                 av_free(c);
                 av_free(picture);
                 fclose(f);
                 avcodec_close(c);
          }

What do you know about compression algorithms? There are RLL (run-length limited) ones that work well with streaming data, and others, such as zip and similar ones (Lemple-Ziv) for data sets that are fixed in size. What have you tried?

thank you for reply to this...sorry i am not much familier with encoding technique.i am just trying to write video file using FFMPEG...is it right choice or not

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.