Ajay ,

 i did the same it worked fine for me .....


http://ffmpeg.arrozcru.org/forum/viewtopic.php?f=8&t=454&p=1236&hilit=transcoding#p1236
look this link it will help ...

mpeg compression i did..


On 5/19/09, Ajay <[email protected]> wrote:
>
> Hi,
>
> Please let me know how to fix this issue.
> it can be any codec (Like MPEG2 , Dirac , h264 etc ......),  i am not stick
> to WMV2 .
>
> Regards
> Ajay
> ----- Original Message ----- From: "Ajay" <[email protected]>
> To: "Libav* user questions and discussions" <[email protected]>
> Sent: Tuesday, May 19, 2009 4:59 PM
> Subject: [libav-user] Encode raw video to desired codec ?
>
>
> Hi,
>>
>> I am facing issue while encoding live capture video data.
>> i want to encode raw video data captured from web cam into wmv2 codec.
>> i am able to  encode the video frames  & write them in a file , but @
>> decoding side it shows lot of mess.
>> pls have a look at my code below
>> actually i have some queries , pls resolve them.
>>
>> 1 what should be container format for this output file.
>> 2 As sson as i captured first frame i start writing them to file , i am
>> not writing any header info , pls let me know how to get this header.
>> when i tried to decode this file it says
>>                   picture size invalid (0x0)
>>                   [rawvideo @ 0x3edb30]Could not find codec parameters
>> (Video: rawvideo, yuv420p)
>>                   Straem info can't be retrieve
>>
>> Regards
>> Ajay
>>
>>
>>
>> ==============================================================================================
>> void  My_Video_Encode()
>> {
>>   const char      *ofilename    = "D:\\Ajay\\video\\myenc.yuv";
>>   AVOutputFormat  *fmt          = NULL;
>>   AVFormatContext *pInFormatCtx = NULL;
>>   AVCodec         *codec        = NULL;
>>   int              i = 0;
>> #if WIN_CAP
>> FILE *f;
>> AVFrame            *Rframe      = NULL;
>> AVPacket            packet      ;
>> AVCodecContext     *pCodecCtx   = NULL;
>> AVFormatParameters  formatParams;
>> AVInputFormat      *pInfmt      = NULL;
>> uint8_t            *outbuf      = NULL;
>> int                 size, out_size ,outbuf_size , ret ;
>>
>>  memset(&formatParams, 0, sizeof(AVFormatParameters));
>>   formatParams.time_base.num = 1;
>>  formatParams.time_base.den = 25;
>>  #endif
>>
>>    f = fopen(ofilename, "wb");
>>    if (!f)
>>    {
>>       fprintf(stderr, "could not open %s\n", ofilename);
>>       exit(1);
>>    }
>>
>>    av_register_all();
>>    /* allocate the output media context */
>>
>>  #if WIN_CAP
>>    avdevice_register_all();
>>    pInfmt = av_find_input_format("vfwcap");
>>    if( !pInfmt )
>>    {
>>       fprintf(stderr,"Unknown input format:mjpeg\n");
>>       return -1;
>>    }
>>
>>    if (av_open_input_file(&pInFormatCtx, "0",  pInfmt, 0, &formatParams)
>> != 0)
>>         printf( "Could not open input file for windows  \n");
>>   #endif
>>
>>   if(av_find_stream_info(pInFormatCtx) <0)
>>         printf("Stream info can't be retrieve \n"  );
>>
>>   dump_format( pInFormatCtx , 0 ,"0" ,0 ) ;
>>
>>   fmt = guess_format("rawvideo", "vfwcap", NULL);
>>
>>   pInFormatCtx->oformat = fmt;
>>
>>   /* ptr to codec ctx for video stream */
>>   pCodecCtx = pInFormatCtx->streams[0]->codec ;
>>
>>      /* put sample parameters */
>>   pCodecCtx->bit_rate = 400000;
>>   /* resolution must be a multiple of two */
>>      pCodecCtx->max_b_frames=0;
>>  pCodecCtx->codec_id = CODEC_ID_WMV2 ;
>>
>>   codec = avcodec_find_encoder(CODEC_ID_WMV2);
>>   if (!codec)
>>   {
>>       fprintf(stderr, "codec not found\n");
>>       exit(1);
>>   }
>>
>> if (avcodec_open(pCodecCtx, codec) < 0)
>> {
>>       fprintf(stderr, "could not open codec\n");
>>       exit(1);
>>   }
>>
>>   Rframe = avcodec_alloc_frame();
>>   if (!Rframe)
>>       return NULL;
>>
>>
>>   outbuf_size = 100000;
>>   outbuf = malloc(outbuf_size);
>>
>>   size = pCodecCtx->width * pCodecCtx->height;
>>   while (av_read_frame (pInFormatCtx , &packet ) >= 0)
>>     {
>>
>>       Rframe->data[0] = packet.data;
>>       Rframe->data[1] = Rframe->data[0] + size;
>>       Rframe->data[2] = Rframe->data[1] + size / 4;
>>       Rframe->linesize[0] = pCodecCtx->width;
>>       Rframe->linesize[1] = pCodecCtx->width / 2;
>>       Rframe->linesize[2] = pCodecCtx->width / 2;
>>
>>
>>     out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size,
>> Rframe);
>>           printf("encoding frame %3d (size=%5d)\n", i, out_size);
>>           fwrite(outbuf, 1, out_size, f);
>>
>>            if (i++ > 100)
>>              break;
>>
>>      }
>>
>> fclose(f);
>> }
>> _______________________________________________
>> libav-user mailing list
>> [email protected]
>> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>>
>
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to