Okay.....
http://ffmpeg.arrozcru.org/forum/viewtopic.php?f=8&t=454&p=1236&hilit=transcoding#p1236
this link is working it will help you transcoding code....
This is part of my work as i am not able to share all my modified code
...i will share my procedure and few lines to explain the encode
first we capture the image using loadbitmap in vc++ ...so my input in
BRG25 image sayi got the image(Frame) in pSrcImage in below code..
i do the initialisation all the step required for the first time... from
second time every frame....
i call the below code
void WriteVideoFrame(AVFormatContext *oc, AVStream *st,LPBYTE
pSrcImage,intcount) //count does make for you just to calculate fhr
frame count...
{
int out_size=0, ret;
AVCodecContext *c;
static struct SwsContext *img_convert_ctx;
int size ;
int bytesperline;
c = st->codec;
LPBYTE DstImage = new BYTE [ (800/2) * (600/2) * 3 ];
bytesperline=(c->width*c->height*3)/c->height;
convert_rgb24_to_yuv420((unsigned char *)pSrcImage,(unsigned char *)
DstImage,
c->width,c->height,bytesperline,1,0);/// here 1(flag) set its to BGR24toyuv
conversion ...
tmp_picture=avcodec_alloc_frame();
size=avpicture_get_size((PixelFormat)PIX_FMT_YUV420P, c->width,c->height);
avpicture_fill((AVPicture *)tmp_picture, DstImage,
PIX_FMT_YUV420P,c->width,c->height);
/* encode the image */
#if 1
out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size,
tmp_picture
#endif
//i/p buffer is failed in ffmpeg its avoided using this macro */
/* if zero size, it means the image was buffered */
if (out_size > 0) {
AVPacket pkt;
av_init_packet(&pkt);
if (c->coded_frame->pts != AV_NOPTS_VALUE)
pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
if(c->coded_frame->key_frame)
pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index= st->index;
pkt.data= video_outbuf;
pkt.size= out_size;
/* write the compressed frame in the media file */
ret = av_interleaved_write_frame(oc, &pkt);
} else {
ret = 0;
}
count++;
delete DstImage;
av_free(tmp_picture);
/// free memory to avoid heap overflow -vijay
}
mail me... further if you are really struck....
Mukilan S
On 5/20/09, Ajay <[email protected]> wrote:
>
> Hi Vijay,
>
> it seems the following link is broken
>
>
> http://thefoundry.anywebcam.com/index.php/image-processing/transcoding-with-libavformatlibavcodec/
>
> Could you send me code that you used for encoding mpeg ,so that i can
> compare with my piece of code.
>
> Regards
> Ajay
>
>
> ----- Original Message ----- From: "Vijay Mukilan" <[email protected]
> >
> To: "Libav* user questions and discussions" <[email protected]>
> Sent: Wednesday, May 20, 2009 12:12 PM
> Subject: Re: [libav-user] Encode raw video to desired codec ?
>
>
> 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
>>
>
> _______________________________________________
> 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