From f9733b615614a990d3e047f251b4ad1ea48a0534 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 22 Jul 2005 15:59:39 +0000 Subject: *** empty log message *** --- ChangeLog | 3 +- TODO | 13 ++-- etc/miav.conf | 4 + man/Makefile.am | 8 ++ man/miav.conf.1 | 19 +++++ man/miav.conf.5 | 19 +++++ src/frame.cc | 4 + src/frame.h | 4 + src/libfame_wrapper.cc | 11 ++- src/liblame_wrapper.cc | 58 +++++++++++---- src/liblame_wrapper.h | 12 ++- src/mov_encoder.cc | 31 ++++++-- src/mov_encoder_writer.cc | 185 +++++----------------------------------------- 13 files changed, 172 insertions(+), 199 deletions(-) create mode 100644 man/Makefile.am diff --git a/ChangeLog b/ChangeLog index e2b549b..8d7fd82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,8 +12,9 @@ New Features: - Added 'encrypted' filenames for the image files. - Added audio encoding and mulitplexing to the output file. Audio is out of sync though! :-( + - Added mp3 control parameters to the config file. Bug Fixes: - - Timecode issue seems to be fixed. + - Config variables can now contain numbers. ======================================= Juni 19 2005 - MIaV version 0.2.6 diff --git a/TODO b/TODO index 11eb141..2d7a403 100644 --- a/TODO +++ b/TODO @@ -52,7 +52,6 @@ Mainwindow: [x] - Create snapshot thumbnails from dv stream instead of the widget. [x] - Make sure the same frame is shown in thumbnail as the one actually shot on the server. - [ ] - Test it. [x] - Show recordtime in client window. [x] - Clear / update taskbar. [ ] - Make new messagebox when asking to save movie. @@ -61,6 +60,7 @@ Mainwindow: the next enters. [ ] - Realscale all window components. [ ] - Realscale all icons (use highresolution icons and scale them down) + [ ] - Test it. CPRQueryDialog: [x] - Make it! @@ -79,7 +79,7 @@ Encoder: [x] - Crash bug, when network connection is broken, during transfer. Decoder: - [ ] - Enable sound decoding for the network stream. + [x] - Enable sound decoding for the network stream. [x] - Remove ffmpeg code. [x] - Make use of 2.6 kernel (through raw1394) [x] - Set flags on frame objects. @@ -99,19 +99,22 @@ Player: ImgEncoder: [x] - Make libjpeg calls work again. - [ ] - Save jpeg files in special cpr hierake 'encrypted'! + [x] - Save jpeg files in special cpr hierake 'encrypted'! + [ ] - Clean up code! [ ] - Make save method configurable in options file. MovEncoder: [x] - Test Mpeg4. (no good) [x] - Remove ffmpeg code. - [ ] - Enable sound. + [x] - Enable sound. [x] - Find good quality settings (Best quality less than 22mb/s realtime encoded) [x] - Multithread encoding, for multi cpu support. [ ] - libFame frames have no timecodes!!! + [ ] - Fix audio sync problem. + [ ] - Make audio quality configurable [x] - Files turning too big (>2gb) must automatically close and - conitnue in another file. + continue in another file. Main: [ ] - Save movie signal handling. diff --git a/etc/miav.conf b/etc/miav.conf index 82cf98f..bbbb9f6 100644 --- a/etc/miav.conf +++ b/etc/miav.conf @@ -44,6 +44,10 @@ frame_sequence = "IPPPP" # quality in % - 100% is best quality frame_quality = 85 +# mp3 encoding quality settings +mp3_quality = 3 +mp3_bitrate = 112 + # The number of threads started for parallel encoding on the server # (for multiprocessor systems) encoding_threads = 1 diff --git a/man/Makefile.am b/man/Makefile.am new file mode 100644 index 0000000..f617b68 --- /dev/null +++ b/man/Makefile.am @@ -0,0 +1,8 @@ +# Man pages +man_MANS = \ + miav.1 \ + miav.conf.1 + +EXTRA_DIST = \ + miav.1 \ + miav.conf.1 diff --git a/man/miav.conf.1 b/man/miav.conf.1 index a9d90fa..dc213e9 100644 --- a/man/miav.conf.1 +++ b/man/miav.conf.1 @@ -127,6 +127,21 @@ lot less diskspace than I frames .I frame_quality in % - 100% is best quality +.B MP3 encoding quality +.RE +.I mp3_quality +internal algorithm selection. True quality is determined by the bitrate +but this variable will effect quality by selecting expensive or cheap algorithms. +quality=0..9. 0=best (very slow). 9=worst. +recommended: 2 near-best quality, not too slow + 5 good quality, fast + 7 ok quality, really fast + +.B The MP3 output bitrate +.RE +.I mp3_bitrate +in kilobits pr. second. (112 is recommended) + .B Encoder threads. .RE The number of threads started for parallel encoding on the server @@ -179,6 +194,10 @@ frame_sequence = "IPPPP" frame_quality = 85 +mp3_quality = 3 + +mp3_bitrate = 112 + encoding_threads = 1 encoding_codec = "mpeg4" diff --git a/man/miav.conf.5 b/man/miav.conf.5 index a9d90fa..dc213e9 100644 --- a/man/miav.conf.5 +++ b/man/miav.conf.5 @@ -127,6 +127,21 @@ lot less diskspace than I frames .I frame_quality in % - 100% is best quality +.B MP3 encoding quality +.RE +.I mp3_quality +internal algorithm selection. True quality is determined by the bitrate +but this variable will effect quality by selecting expensive or cheap algorithms. +quality=0..9. 0=best (very slow). 9=worst. +recommended: 2 near-best quality, not too slow + 5 good quality, fast + 7 ok quality, really fast + +.B The MP3 output bitrate +.RE +.I mp3_bitrate +in kilobits pr. second. (112 is recommended) + .B Encoder threads. .RE The number of threads started for parallel encoding on the server @@ -179,6 +194,10 @@ frame_sequence = "IPPPP" frame_quality = 85 +mp3_quality = 3 + +mp3_bitrate = 112 + encoding_threads = 1 encoding_codec = "mpeg4" diff --git a/src/frame.cc b/src/frame.cc index e204a2b..d723e02 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.10 2005/07/22 15:59:39 deva + * *** empty log message *** + * * Revision 1.9 2005/06/16 21:28:57 deva * Rewrote thread object * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to @@ -65,6 +68,7 @@ Frame::Frame(unsigned char *d, int sz) if(sz && d) memcpy(data, d, sz); size = sz; number = 0; + memset(timecode, 0, sizeof(timecode)); } Frame::~Frame() diff --git a/src/frame.h b/src/frame.h index 3300fff..fe67a62 100644 --- a/src/frame.h +++ b/src/frame.h @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.9 2005/07/22 15:59:39 deva + * *** empty log message *** + * * Revision 1.8 2005/06/16 21:28:57 deva * Rewrote thread object * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to @@ -76,6 +79,7 @@ public: bool shoot; int freeze; // 1 is freeze, -1 is unfreeze bool record; + char timecode[12]; }; #include diff --git a/src/libfame_wrapper.cc b/src/libfame_wrapper.cc index 64eb9f5..a7e52e3 100644 --- a/src/libfame_wrapper.cc +++ b/src/libfame_wrapper.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.3 2005/07/22 15:59:39 deva + * *** empty log message *** + * * Revision 1.2 2005/07/05 23:15:16 deva * *** empty log message *** * @@ -239,15 +242,17 @@ Frame *LibFAMEWrapper::encode(Frame *dvframe) // Allocate a new frame for the output Frame *output = new Frame(NULL, FAME_BUFFER_SIZE); - output->size = 0; - unsigned char* pt = output->data; + + // Init frame params + dv_get_timestamp(dvdecoder, output->timecode); // Set timecode + output->size = 0; // Init size (incremented as we read) + unsigned char* pt = output->data; // Set pointer to start of data buffer // Encode YUV frame and write it to disk. fame_start_frame(fame_context, &yuv, 0); int written; while((written = fame_encode_slice(fame_context))) { - // fwrite(fame_buffer, written, 1, f); memcpy(pt, fame_buffer, written); pt += written; output->size += written; diff --git a/src/liblame_wrapper.cc b/src/liblame_wrapper.cc index d74233e..f204214 100644 --- a/src/liblame_wrapper.cc +++ b/src/liblame_wrapper.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.5 2005/07/22 15:59:39 deva + * *** empty log message *** + * * Revision 1.4 2005/07/09 16:23:15 deva * Added audio. * @@ -48,6 +51,7 @@ #include #include "liblame_wrapper.h" +#include "miav_config.h" LibLAMEWrapper::LibLAMEWrapper(Info *i) { @@ -59,17 +63,27 @@ LibLAMEWrapper::LibLAMEWrapper(Info *i) return; } - lame_set_in_samplerate(gfp, SAMPLE_RATE); - lame_set_out_samplerate(gfp, SAMPLE_RATE); - lame_set_num_channels(gfp, CHANNELS); - // lame 3.91 dies on quality != 5 - lame_set_quality(gfp, 3); - // lame 3.91 doesn't work in mono - lame_set_mode(gfp, JOINT_STEREO); - lame_set_brate(gfp, 112); - lame_set_strict_ISO(gfp, 1); + lame_set_in_samplerate(gfp, INPUT_SAMPLE_RATE); + lame_set_out_samplerate(gfp, OUTPUT_SAMPLE_RATE); + + lame_set_num_channels(gfp, CHANNELS); lame_set_num_samples(gfp, SAMPLES); + lame_set_quality(gfp, config->readInt("mp3_quality")); + lame_set_mode(gfp, STEREO); + lame_set_brate(gfp, config->readInt("mp3_bitrate")); + + lame_set_strict_ISO(gfp, 0); + + // 1 = write a Xing VBR header frame. + lame_set_bWriteVbrTag(gfp, 0); + + // Types of VBR. default = vbr_off = CBR + // lame_set_VBR(gfp, vbr_rh); + + // VBR quality level. 0=highest 9=lowest + // lame_set_VBR_q(gfp, 6); + lame_set_copyright(gfp, 0); // is there a copyright on the encoded data? lame_set_original(gfp, 1); // is the encoded data on the original media? lame_set_error_protection(gfp, 0);// add 2 byte CRC protection to each frame? @@ -79,15 +93,12 @@ LibLAMEWrapper::LibLAMEWrapper(Info *i) // 2 = adjust padding to satisfy bit rate lame_set_extension(gfp, 0); // private extension bit - info->info("Lame version %d", lame_get_version(gfp)); if (lame_init_params(gfp) < 0) { info->error("LAME parameter initialization failed."); return; } - lame_init_bitstream(gfp); - audio_buffer[0] = new int16_t[AUDIO_BUFFER_SIZE]; audio_buffer[1] = new int16_t[AUDIO_BUFFER_SIZE]; @@ -186,7 +197,28 @@ Frame *LibLAMEWrapper::encode(Frame *dvframe) } } - audio_frame->size = val; + /** + * OPTIONAL: + * lame_encode_flush_nogap will flush the internal mp3 buffers and pad + * the last frame with ancillary data so it is a complete mp3 frame. + * + * 'mp3buf' should be at least 7200 bytes long + * to hold all possible emitted data. + * + * After a call to this routine, the outputed mp3 data is complete, but + * you may continue to encode new PCM samples and write future mp3 data + * to a different file. The two mp3 files will play back with no gaps + * if they are concatenated together. + * + * This routine will NOT write id3v1 tags into the bitstream. + * + * return code = number of bytes output to mp3buf. Can be 0 + */ + int flush_sz = lame_encode_flush_nogap(gfp, // global context handle + mp3buf + val, // pointer to encoded MP3 stream + mp3buf_size - val); // number of valid octets in this stream + + audio_frame->size = val + flush_sz; return audio_frame; } diff --git a/src/liblame_wrapper.h b/src/liblame_wrapper.h index 37af54c..1044abd 100644 --- a/src/liblame_wrapper.h +++ b/src/liblame_wrapper.h @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.4 2005/07/22 15:59:39 deva + * *** empty log message *** + * * Revision 1.3 2005/07/07 12:42:19 deva * *** empty log message *** * @@ -57,11 +60,14 @@ #include "frame.h" #include "info.h" -#define CHANNELS 2 -#define SAMPLE_RATE 48000 -#define SAMPLES SAMPLE_RATE / 25 #define AUDIO_BUFFER_SIZE DV_AUDIO_MAX_SAMPLES +#define CHANNELS 2 +#define INPUT_SAMPLE_RATE 48000 +#define OUTPUT_SAMPLE_RATE 48000 +#define SAMPLES AUDIO_BUFFER_SIZE +//OUTPUT_SAMPLE_RATE / 25 + class LibLAMEWrapper { public: LibLAMEWrapper(Info *info); diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc index f21cc3a..74f9b90 100644 --- a/src/mov_encoder.cc +++ b/src/mov_encoder.cc @@ -39,6 +39,9 @@ /* * $Log$ + * Revision 1.36 2005/07/22 15:59:39 deva + * *** empty log message *** + * * Revision 1.35 2005/07/07 12:42:19 deva * *** empty log message *** * @@ -150,9 +153,6 @@ MovEncoder::MovEncoder(sem_t *r_sem, info = i; info->info("MovEncoder"); - // fame = new LibFAMEWrapper(info); - // lame = new LibLAMEWrapper(info); - running = true; inputqueue = in; @@ -170,11 +170,11 @@ MovEncoder::MovEncoder(sem_t *r_sem, MovEncoder::~MovEncoder() { info->info("~MovEncoder"); - - // delete fame; - // delete lame; } + +//#define COPY_DV 1 + // this runs in a thread void MovEncoder::thread_main() { @@ -192,11 +192,15 @@ void MovEncoder::thread_main() Frame *out_a_frame; LibFAMEWrapper fame(info); - LibLAMEWrapper lame(info); + // LibLAMEWrapper lame(info); while(running) { sem_wait(input_sem); + // Make a new instance for every frame sequence (usually 5) to ensure no + // frame dependencies are broken when running multithreaded. + LibLAMEWrapper lame(info); + // Lock inout mutex pthread_mutex_lock(input_mutex); item = inputqueue->front(); @@ -211,6 +215,18 @@ void MovEncoder::thread_main() for(unsigned int cnt = 0; cnt < item->size(); cnt++) { in_frame = item->at(cnt); +#ifdef COPY_DV + + // Encode video + out_v_frame = new Frame(in_frame->data, in_frame->size); + out_v_frame->number = in_frame->number; + + // Encode audio + out_a_frame = new Frame(in_frame->data, in_frame->size); + out_a_frame->number = in_frame->number + 1; + +#else /*COPY_DV*/ + // Encode video out_v_frame = fame.encode(in_frame); out_v_frame->number = in_frame->number; @@ -219,6 +235,7 @@ void MovEncoder::thread_main() out_a_frame = lame.encode(in_frame); out_a_frame->number = in_frame->number + 1; +#endif /*COPY_DV*/ delete in_frame; // Lock output mutex diff --git a/src/mov_encoder_writer.cc b/src/mov_encoder_writer.cc index d53d805..98e5ece 100644 --- a/src/mov_encoder_writer.cc +++ b/src/mov_encoder_writer.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.12 2005/07/22 15:59:39 deva + * *** empty log message *** + * * Revision 1.11 2005/07/09 16:23:15 deva * Added audio. * @@ -137,14 +140,20 @@ MovEncoderWriter::~MovEncoderWriter() delete file; } +//#define WRITE_DV 1 + void MovEncoderWriter::thread_main() { info->info("MovEncoderWriter::run"); Frame *frame; +#ifndef WRITE_DV + write_header(); +#endif/*WRITE_DV*/ + while(running) { sem_wait(sem); @@ -161,10 +170,19 @@ void MovEncoderWriter::thread_main() int ret = 0; +#ifndef WRITE_DV + if(frame->number%2 == 1) write_audio_header((unsigned short int)frame->size); else write_video_header((unsigned short int)frame->size); ret = file->Write(frame->data, frame->size); + +#else/*WRITE_DV*/ + + if(frame->number%2 == 0) ret = file->Write(frame->data, frame->size); + +#endif/*WRITE_DV*/ + frame_number++; wrote ++; @@ -327,170 +345,3 @@ void MovEncoderWriter::write_audio_header(unsigned short int psize) } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/* -void MovEncoderWriter::write_video_header(unsigned short int psize) -{ - // PES Header startcode - char startcode[] = { - 0x00, 0x00, 0x01 - }; - - file->Write(startcode, sizeof(startcode)); - - // Audio stream, index = 0 - char streamID[] = { - 0xE0 - }; - - file->Write(streamID, sizeof(streamID)); - - char packetsize[] = { 0x00, 0x00 }; - - psize += sizeof(startcode) + sizeof(streamID) + sizeof(packetsize); - - packetsize[0] = ((char*)&psize)[1]; - packetsize[1] = ((char*)&psize)[0]; - - file->Write(packetsize, sizeof(packetsize)); -} - -void MovEncoderWriter::write_audio_header(unsigned short int psize) -{ - // PES Header startcode - char startcode[] = { - 0x00, 0x00, 0x01 - }; - - file->Write(startcode, sizeof(startcode)); - - // Audio stream, index = 0 - char streamID[] = { - 0xC0 - }; - - file->Write(streamID, sizeof(streamID)); - - char packetsize[] = { 0x00, 0x00 }; - - psize += sizeof(startcode) + sizeof(streamID) + sizeof(packetsize); - - packetsize[0] = ((char*)&psize)[1]; - packetsize[1] = ((char*)&psize)[0]; - - file->Write(packetsize, sizeof(packetsize)); -} - -void MovEncoderWriter::write_header() -{ - // PACK - char pack_start_code[] = { - 0x00, 0x00, 0x01, 0xBA, - }; - - file->Write(pack_start_code, sizeof(pack_start_code)); - - char pack_data[] = { - 0x21, // SCR-32 thru 30, marker bit - 0x00, 0x01, // SCR-29 thru 15, marker bit - 0x1E, 0x81, // SCR-14 thru 0, marker bit - 0x80, 0x1B, 0x83 // Marker bit, mux_rate, marker_bit - }; - - file->Write(pack_data, sizeof(pack_data)); - - // SYSTEM - char system_header_start_code[] = { - 0x00, 0x00, 0x01, 0xBB, - }; - - file->Write(system_header_start_code, sizeof(system_header_start_code)); - - char system_data[] = { - 0x00, 0x0C, // Header length - 0x80, 0x1B, 0x83, // Marker bit, rate_bound,marker_bit - 0x07, // Audio bound, fixed_flag, CSPS_flag - 0xA1, // system_audio_lock_flag, system_video_lock_flag - 0xFF, // Reserved byte - 0xC0, // Stream id (audio) - // 0xC0, 0x20, // '11', STD_buffer_bound_scale, STD_buffer_size_bound - 0xFF, 0xFF, // '11', STD_buffer_bound_scale, STD_buffer_size_bound - 0xE0, // Stream id (video) - // 0xE0, 0x2E // '11', STD_buffer_bound_scale, STD_buffer_size_bound - 0xFF, 0xFF // '11', STD_buffer_bound_scale, STD_buffer_size_bound - }; - - file->Write(system_data, sizeof(system_data)); - - char padding_header_start_code[] = { - 0x00, 0x00, 0x01, 0xBE - }; - - file->Write(padding_header_start_code, sizeof(padding_header_start_code)); - - char padding_data[] = { - 0x00, 0x04, // Padding length - 0x0F, 0xFF, 0xFF, 0xFF // Padding - }; - - file->Write(padding_data, sizeof(padding_data)); -} -*/ -- cgit v1.2.3