[Ffmpeg-devel] vhook jpeg problem
Vecais_Dumais_Laacis
spam
Mon Mar 20 10:22:18 CET 2006
Hello ffmpeg-devel,
i'm trying to fix this problem for 3 days and i cant get any
further.
1) i modified framehook and ffmpeg sources to pass additional data
(AVFormatContext *is, AVInputStream *ist, - so i can know
duration/framecount in hook)
2) i modified null.c hook to save specific frames - 4 frames from
whole video.
3) i tried to save them as jpeg but as result i get pixelated image
example: http://3priedez.net/files/pljek51.jpg
image width and height is as should be
4) converting to rgb24 and saving as ppm works correctly
(ppm converted to jpeg to save traffic -
http://3priedez.net/files/frame0.jpg )
5) exporting code (mostly taken from jpeg.c and added some values to
try to fix pixelate problem). also nothing changes if i use
AVPicture pointer passed to hook.
int my_write_jpeg(AVInputStream *ist){
char *buf=0;
AVPicture picture1;
char b[1024];
FILE *fil;
AVCodecContext *c;
uint8_t *outbuf = NULL;
int outbuf_size, ret, size, i;
AVFrame *picture;
ret = -1;
c = avcodec_alloc_context();
if (!c)
return -1;
picture = avcodec_alloc_frame();
if (!picture)
goto fail2;
c->width = ist->st->codec->width;
c->height = ist->st->codec->height;
c->codec_id=CODEC_ID_MJPEG;
c->pix_fmt=PIX_FMT_YUVJ420P;
//as ffmpeg already outputs yuv420 image to hook we dont convert
//anything here
for(i=0;i<3;i++) {
picture->data[i] = ist->st->codec->coded_frame->data[i];
picture->linesize[i] = ist->st->codec->coded_frame->linesize[i];
}
picture->quality = 3;
c->flags |= CODEC_FLAG_QSCALE;
c->time_base.num=1;
c->time_base.den=1;
c->bit_rate=4000000;
c->nsse_weight=0;
if (avcodec_open(c, &mjpeg_encoder) < 0)
goto fail1;
c->bit_rate=4000000;
c->nsse_weight=0;
outbuf_size = 1000000;
outbuf = av_malloc(outbuf_size);
size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
if (size < 0)
goto fail;
snprintf(b, 1024, "pljek%ld.jpg", pr);
fil=fopen(b, "wb");
if(fil){
fwrite(outbuf, size, 1, fil);
fclose(fil);
}
ret = 0;
fail:
avcodec_close(c);
av_free(outbuf);
fail1:
av_free(picture);
fail2:
av_free(c);
return ret;
}
what am i doing wrong?
--
Best regards,
Vecais_Dumais_Laacis mailto:vdl at 3priedez.net
More information about the ffmpeg-devel
mailing list