summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frame.cc4
-rw-r--r--src/frame.h4
-rw-r--r--src/libfame_wrapper.cc11
-rw-r--r--src/liblame_wrapper.cc58
-rw-r--r--src/liblame_wrapper.h12
-rw-r--r--src/mov_encoder.cc31
-rw-r--r--src/mov_encoder_writer.cc185
7 files changed, 112 insertions, 193 deletions
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 <functional>
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 <config.h>
#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));
-}
-*/