summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2005-05-16 13:25:52 +0000
committerdeva <deva>2005-05-16 13:25:52 +0000
commit3b5893ffa6d4a761eff0d97c7223eecd4fc123c9 (patch)
treeacb7217f941c4a066e756d70eb41af1cb700f601
parent3f9ab7f6476ecfb9feef5380e3be6d280f1de76d (diff)
Moved video setting to configuration file.
Fine tuned setting for 2.4ghz server
-rw-r--r--etc/miav.conf8
-rw-r--r--src/mov_encoder.cc86
-rw-r--r--src/server_status.cc17
3 files changed, 43 insertions, 68 deletions
diff --git a/etc/miav.conf b/etc/miav.conf
index 240d2a0..2ab5b48 100644
--- a/etc/miav.conf
+++ b/etc/miav.conf
@@ -23,3 +23,11 @@ server_port = 30000
# Where top store the files recieved by the server
server_root = "/tmp/miav_files"
+# Video output controls. A sequence of I and P, where I is keyframes
+# which is fast to create, but uses a lot of discspace.
+# B uses changes since last frame, is more cpu intensive, but uses a
+# lot less diskspace than I frames
+frame_sequence = "IPPPPPPPPPP"
+
+# quality in % - 100% is best quality
+frame_quality = 80
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc
index 9e4e6f5..143fa2b 100644
--- a/src/mov_encoder.cc
+++ b/src/mov_encoder.cc
@@ -39,6 +39,11 @@
/*
* $Log$
+ * Revision 1.19 2005/05/16 13:25:52 deva
+ *
+ * Moved video setting to configuration file.
+ * Fine tuned setting for 2.4ghz server
+ *
* Revision 1.18 2005/05/16 11:13:24 deva
*
* Optimized some encoding parameters.
@@ -79,6 +84,8 @@
#include <errno.h>
+#include "miav_config.h"
+
#include "debug.h"
//av_alloc_format_context
//av_destruct_packet_nofree
@@ -147,14 +154,13 @@ MovEncoder::MovEncoder(const char *filename)
// to JPEG), whereas P and B frames are motion compressed, respectively
// predicted from past reference (I or P) frame, or bidirectionally predicted
// from past and future reference frame.
- static const char coding[] = "IPPPPPPPPPPPPPPPPPPPPPPP\0";
- fame_par.coding = coding;
+ fame_par.coding = config->readString("frame_sequence")->c_str();
// quality is a percentage, which controls compression versus quality.
- fame_par.quality = 80; // FIXME: This should be in config file!
+ fame_par.quality = config->readInt("frame_quality");
- /////////////////////////////
- fame_par.bitrate = 0; /* video bitrate (0=VBR)*/
+ // Bitrate
+ fame_par.bitrate = 0; // video bitrate (0=VBR)
// slices_per_frame is the number of frame slices per frame. More slices provide
// better error recovery. There must be at least one slice per frame, and at most
@@ -163,7 +169,7 @@ MovEncoder::MovEncoder(const char *filename)
// frames_per_sequence is the maximum number of frames contained in a video
// sequence.
- fame_par.frames_per_sequence = 1024;//25 * 60 * 60 * 2; // 25 fps in two hours.
+ fame_par.frames_per_sequence = 0xffffffff; // Unlimited length
// frame_rate_num/frame_rate_den specify the number of frames per second for
// playback.
@@ -172,20 +178,21 @@ MovEncoder::MovEncoder(const char *filename)
// shape_quality is percentage determing the average binary shape accuracy in
// video with arbitrary shape.
- fame_par.shape_quality = 1;
+ fame_par.shape_quality = 100; // Original shape
// 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 = 10; // FIXME: No idea what this should be!?
+ fame_par.search_range = 0; // Adaptive search range
// verbose when set to 1 outputs information on copyright, modules used and
// current frame on standard error.
- fame_par.verbose = 0;
+ fame_par.verbose = 1;
- static const char profilename[] = "My Profile\0";
- fame_par.profile = profilename; /* profile name */
- fame_par.total_frames = 0; /* total number of frames */
+ static const char profilename[] = "MIaV\0";
+ fame_par.profile = profilename; // profile name
+ fame_par.total_frames = 0; // total number of frames
+ // fame_par.stats = NULL; // No need for statistics at the moment
fame_init(fame_context, &fame_par, fame_buffer, FAME_BUFFER_SIZE);
@@ -210,40 +217,17 @@ void MovEncoder::encode(Frame *dvframe)
encode_audio(dvframe);
}
-//#define RGB
-
-#ifdef RGB
-#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);
-}
-#endif
-
void MovEncoder::encode_video(Frame *dvframe)
{
if(!f) return; // The file was not opened.
- // Decode DV Frame to YUV
+ // Decode DV Frame to YUV422
int w = 720;
int h = 576;
unsigned char *pixels[3];
int pitches[3];
-#ifdef RGB
- pixels[ 0 ] = rgb;
- pixels[ 1 ] = NULL;
- pixels[ 2 ] = NULL;
-
- pitches[ 0 ] = 720 * 3;
- pitches[ 1 ] = 0;
- pitches[ 2 ] = 0;
-#endif
-
if(!dvdecoder) {
dvdecoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE);
dvdecoder->quality = DV_QUALITY_BEST;
@@ -257,34 +241,6 @@ void MovEncoder::encode_video(Frame *dvframe)
dvdecoder->num_dif_seqs = 12;
}
-#ifdef RGB
- dv_decode_full_frame(dvdecoder,
- dvframe->data,
- e_dv_color_rgb,
- pixels,
- 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;
- }
- }
-#else
pixels[ 0 ] = rgb; // We use this as the output buffer
pitches[ 0 ] = w * 2;
@@ -294,6 +250,7 @@ void MovEncoder::encode_video(Frame *dvframe)
pixels,
pitches);
+ // Convert YUV422 to YUV420p
int w2 = w / 2;
uint8_t *y = yuv.y;
uint8_t *cb = yuv.u;
@@ -319,7 +276,6 @@ void MovEncoder::encode_video(Frame *dvframe)
p++;
}
}
-#endif
// Encode YUV frame and write it to disk.
fame_start_frame(fame_context, &yuv, 0);
diff --git a/src/server_status.cc b/src/server_status.cc
index 1e58ee7..7583cc9 100644
--- a/src/server_status.cc
+++ b/src/server_status.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.5 2005/05/16 13:25:52 deva
+ *
+ * Moved video setting to configuration file.
+ * Fine tuned setting for 2.4ghz server
+ *
* Revision 1.4 2005/05/09 16:40:20 deva
*
* Added optimize yuv conversion code
@@ -47,12 +52,15 @@
#include <stdio.h>
+#define UPD 25
ServerStatus::ServerStatus()
{
+ gettimeofday(&oldtime, NULL);
+
for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
- frametime[cnt] = 0;
+ frametime[cnt] = 41660 * UPD;
}
- gettimeofday(&oldtime, NULL);
+
gettimeofday(&time, NULL);
}
@@ -62,6 +70,9 @@ ServerStatus::~ServerStatus()
void ServerStatus::checkPoint()
{
+ static int frame = 0;
+ frame++;
+ if(frame % UPD != 0) return;
for(int cnt = BUFFERSIZE - 1; cnt > 0; cnt--) {
frametime[cnt] = frametime[cnt-1];
}
@@ -76,7 +87,7 @@ void ServerStatus::checkPoint()
for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
total += (double)frametime[cnt];
}
- fprintf(stderr, "[ms: %d, fps: %f]\n", frametime[0], 1000000.0 / (total / (double)BUFFERSIZE) );
+ fprintf(stderr, "[ms: %d, fps: %f]\n", frametime[0] / UPD, (1000000.0 / (total / (double)BUFFERSIZE)) * UPD );
}