diff options
Diffstat (limited to 'src/img_encoder.cc')
-rw-r--r-- | src/img_encoder.cc | 96 |
1 files changed, 43 insertions, 53 deletions
diff --git a/src/img_encoder.cc b/src/img_encoder.cc index eeddec3..7aca367 100644 --- a/src/img_encoder.cc +++ b/src/img_encoder.cc @@ -39,6 +39,10 @@ /* * $Log$ + * Revision 1.8 2005/05/07 10:25:34 deva + * + * Removed ffmpeg code from img_encoder and corrected decoding errors in mov_encoder + * * Revision 1.7 2005/05/03 08:31:59 deva * Removed the error object, and replaced it with a more generic info object. * @@ -48,76 +52,29 @@ #include "img_encoder.h" #include <stdio.h> -//#include <setjmp.h> #include "debug.h" -//av_alloc_format_context -//av_destruct_packet_nofree +// Use libdv +#include <libdv/dv.h> +#include <libdv/dv_types.h> ImgEncoder::ImgEncoder() { - //////////////////// GLOBAL INIT - av_register_all(); - - //////////////////// DECODE INIT - AVCodec *deccodec; - - // find the dvvideo decoder - deccodec = avcodec_find_decoder(CODEC_ID_DVVIDEO); - if (!deccodec) { - fprintf(stderr, "codec not found\n"); - exit(1); - } - - dcc= avcodec_alloc_context(); ALLOC(dcc, "img_encoder, dcc"); - - // open it - if (avcodec_open(dcc, deccodec) < 0) { - fprintf(stderr, "could not open codec\n"); - exit(1); - } } ImgEncoder::~ImgEncoder() { - // FIXME: free: deccodec and dcc } void ImgEncoder::encode(Frame *dvframe, char *filename, int quality) { - int ret; - AVFrame *rawframe = avcodec_alloc_frame(); ALLOC(dcc, "img_encoder, rawframe"); - - ///////////////////////// DECODE - uint8_t *ptr; - int got_picture = 1; - int len; - - ptr = (uint8_t *)dvframe->data; - len = dvframe->size; + unsigned char rgb[720*576*4]; - ret = avcodec_decode_video(dcc, rawframe, &got_picture, ptr, len); - - if(!ret) { - printf("Decoder fuckup!\n"); - return; - } - - // TODO: Do image convertion here! - AVPicture pict; - avpicture_alloc(&pict,PIX_FMT_RGB24, 720, 576); ALLOC(dcc, "img_encoder, pict"); - - img_convert(&pict, PIX_FMT_RGB24, (AVPicture *)rawframe, - PIX_FMT_YUV420P, 720, 576); - printf("converted\n"); - writeJPEGFile(filename, quality, (JSAMPLE*)(pict.data[0]), 720, 576); - printf("written\n"); - - avpicture_free(&pict); FREE(&pict); - av_free(rawframe); FREE(rawframe); + getRGB(dvframe, rgb); + writeJPEGFile(filename, quality, (JSAMPLE*)rgb, 720, 576); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -184,3 +141,36 @@ void ImgEncoder::writeJPEGFile(char *filename, // Step 7: release JPEG compression object jpeg_destroy_compress(&cinfo); } + +void ImgEncoder::getRGB(Frame *frame, unsigned char *rgb) +{ + unsigned char *pixels[3]; + int pitches[3]; + + pixels[ 0 ] = rgb; + pixels[ 1 ] = NULL; + pixels[ 2 ] = NULL; + + pitches[ 0 ] = 720 * 3; + pitches[ 1 ] = 0; + pitches[ 2 ] = 0; + + dv_decoder_t *decoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE); + decoder->quality = DV_QUALITY_BEST; + + dv_parse_header(decoder, frame->data); + + decoder->system = e_dv_system_625_50; // PAL lines, PAL framerate + decoder->sampling = e_dv_sample_422; // 4 bytes y, 2 bytes u, 2 bytes v + decoder->std = e_dv_std_iec_61834; + decoder->num_dif_seqs = 12; + + // libdv img decode to rgb + dv_decode_full_frame(decoder, + frame->data, + e_dv_color_rgb, + pixels, + pitches); + + dv_decoder_free(decoder); +} |