summaryrefslogtreecommitdiff
path: root/src/mov_encoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mov_encoder.cc')
-rw-r--r--src/mov_encoder.cc77
1 files changed, 63 insertions, 14 deletions
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc
index 4eae91b..bce80f7 100644
--- a/src/mov_encoder.cc
+++ b/src/mov_encoder.cc
@@ -39,6 +39,10 @@
/*
* $Log$
+ * Revision 1.13 2005/05/07 10:25:34 deva
+ *
+ * Removed ffmpeg code from img_encoder and corrected decoding errors in mov_encoder
+ *
* Revision 1.12 2005/05/05 20:41:38 deva
*
* Removed the last pieces of ffmpeg... replaced it with libfame...
@@ -134,12 +138,12 @@ MovEncoder::MovEncoder(const char *filename)
// frames_per_sequence is the maximum number of frames contained in a video
// sequence.
- fame_par.frames_per_sequence = 25 * 60 * 60 * 2; // 25 fps in two hours.
+ fame_par.frames_per_sequence = 1024;//25 * 60 * 60 * 2; // 25 fps in two hours.
// frame_rate_num/frame_rate_den specify the number of frames per second for
// playback.
- fame_par.frame_rate_num = 25; // 25 / 1 fps = 25 fps
- fame_par.frame_rate_den = 1;
+ fame_par.frame_rate_num = 10;//25; // 25 / 1 fps = 25 fps
+ fame_par.frame_rate_den = 30000;//1;
// shape_quality is percentage determing the average binary shape accuracy in
// video with arbitrary shape.
@@ -148,7 +152,7 @@ MovEncoder::MovEncoder(const char *filename)
// search_range specifies the motion estimation search range in pixel unit.
// Small search ranges work best with slow motion videos, whereas larger search
// ranges are rather for fast motion videos.
- fame_par.search_range = 42; // FIXME: No idea what this should be!?
+ fame_par.search_range = 10; // FIXME: No idea what this should be!?
// verbose when set to 1 outputs information on copyright, modules used and
// current frame on standard error.
@@ -175,18 +179,33 @@ void MovEncoder::encode(Frame *dvframe)
encode_audio(dvframe);
}
+
+#define _CLAMP(x) (unsigned char) ((x)<0?0:(((x)>255)?255:(x)))
+
+inline void rgb_to_yuv(unsigned char *rgb, unsigned char &y, unsigned char &u, unsigned char &v)
+{
+ y = _CLAMP( 0.257 * rgb[0] + 0.504 * rgb[1] + 0.098 * rgb[2] + 16);
+ v = _CLAMP( 0.439 * rgb[0] - 0.368 * rgb[1] - 0.071 * rgb[2] + 128);
+ u = _CLAMP(-0.148 * rgb[0] - 0.291 * rgb[1] + 0.439 * rgb[2] + 128);
+}
+
void MovEncoder::encode_video(Frame *dvframe)
{
// Decode DV Frame to YUV
+ int w = 720;
+ int h = 576;
+ unsigned char rgb[720*576*4];
+
unsigned char *pixels[3];
int pitches[3];
- pitches[0] = yuv.w;
- pitches[1] = yuv.h;
- pitches[2] = yuv.p;
- pixels[0] = yuv.y;
- pixels[1] = yuv.u;
- pixels[2] = yuv.v;
+ pixels[ 0 ] = rgb;
+ pixels[ 1 ] = NULL;
+ pixels[ 2 ] = NULL;
+
+ pitches[ 0 ] = 720 * 3;
+ pitches[ 1 ] = 0;
+ pitches[ 2 ] = 0;
if(!dvdecoder) {
dvdecoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE);
@@ -203,14 +222,44 @@ void MovEncoder::encode_video(Frame *dvframe)
dv_decode_full_frame(dvdecoder,
dvframe->data,
- e_dv_color_yuv,
+ e_dv_color_rgb,
pixels,
pitches);
-
+
+ /*
+ e_dv_color_yuv,
+ (uint8_t**) &yuv.y, //pixels,
+ (int*) &yuv.w);//pitches);
+ */
+ // cvt rgb to yuv
+ for (int y=0; y<h; y+=2)
+ {
+ for (int x=0; x<w; x+=2)
+ {
+ unsigned char vy[4],vu[4],vv[4];
+
+ rgb_to_yuv(rgb + 3*((y+0)*w + (x+0)), vy[0],vu[0],vv[0]);
+ rgb_to_yuv(rgb + 3*((y+0)*w + (x+1)), vy[1],vu[1],vv[1]);
+ rgb_to_yuv(rgb + 3*((y+1)*w + (x+0)), vy[2],vu[2],vv[2]);
+ rgb_to_yuv(rgb + 3*((y+1)*w + (x+1)), vy[3],vu[3],vv[3]);
+ // Y
+ yuv.y[(y+0)*w+(x+0)] = vy[0];
+ yuv.y[(y+0)*w+(x+1)] = vy[1];
+ yuv.y[(y+1)*w+(x+0)] = vy[2];
+ yuv.y[(y+1)*w+(x+1)] = vy[3];
+ // Cb
+ yuv.u[y*w/4+x/2] = (vu[0]+vu[1]+vu[2]+vu[3])/4;
+ // Cr
+ yuv.v[y*w/4+x/2] = (vv[0]+vv[1]+vv[2]+vv[3])/4;
+ }
+ }
+
// Encode YUV frame and write it to disk.
fame_start_frame(fame_context, &yuv, 0);
- int written = fame_encode_slice(fame_context);
- fwrite(fame_buffer, written, 1, f);
+ int written;
+ while((written = fame_encode_slice(fame_context))) {
+ fwrite(fame_buffer, written, 1, f);
+ }
fame_end_frame(fame_context,0);
}