summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2005-07-09 16:23:15 +0000
committerdeva <deva>2005-07-09 16:23:15 +0000
commit8b25d0d6bcf33cc8123ef9ea78eff43b1d491178 (patch)
treededc8dbde530a4623c735f1cbbfce72d9d31158f
parent88a21aa4560d0a1bfef3e706e3b460d6745b3977 (diff)
Added audio.
-rw-r--r--ChangeLog3
-rw-r--r--TODO3
-rw-r--r--src/liblame_wrapper.cc11
-rw-r--r--src/mov_encoder_writer.cc289
-rw-r--r--src/mov_encoder_writer.h5
5 files changed, 292 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 6e8cb94..e2b549b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,7 +10,10 @@ New Features:
- Man pages have been written.
- Added server_image_root and server_movie_root to the config file.
- Added 'encrypted' filenames for the image files.
+ - Added audio encoding and mulitplexing to the output file.
+ Audio is out of sync though! :-(
Bug Fixes:
+ - Timecode issue seems to be fixed.
=======================================
Juni 19 2005 - MIaV version 0.2.6
diff --git a/TODO b/TODO
index 365e5d2..11eb141 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,6 @@
+// liblame description
+http://ca.geocities.com/dennis_L76/LAME_v3r70/LAME_v3r70.html
+
// libFAME code
http://lists.debian.org/debian-user-spanish/2005/01/msg00380.html
diff --git a/src/liblame_wrapper.cc b/src/liblame_wrapper.cc
index 90b8824..d74233e 100644
--- a/src/liblame_wrapper.cc
+++ b/src/liblame_wrapper.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.4 2005/07/09 16:23:15 deva
+ * Added audio.
+ *
* Revision 1.3 2005/07/07 12:42:19 deva
* *** empty log message ***
*
@@ -60,10 +63,10 @@ LibLAMEWrapper::LibLAMEWrapper(Info *i)
lame_set_out_samplerate(gfp, SAMPLE_RATE);
lame_set_num_channels(gfp, CHANNELS);
// lame 3.91 dies on quality != 5
- lame_set_quality(gfp, 5);
+ lame_set_quality(gfp, 3);
// lame 3.91 doesn't work in mono
- lame_set_mode(gfp, STEREO);
- lame_set_brate(gfp, 192);
+ lame_set_mode(gfp, JOINT_STEREO);
+ lame_set_brate(gfp, 112);
lame_set_strict_ISO(gfp, 1);
lame_set_num_samples(gfp, SAMPLES);
@@ -161,7 +164,7 @@ Frame *LibLAMEWrapper::encode(Frame *dvframe)
val = lame_encode_buffer(gfp, buffer_l, buffer_r, nsamples, mp3buf, mp3buf_size);
// val = lame_encode_mp3_frame(gfp, buffer_l, buffer_r, mp3buf, mp3buf_size);
- info->info("Framenr: %d", lame_get_frameNum(gfp));
+ // info->info("Framenr: %d", lame_get_frameNum(gfp));
if(val < 0) {
switch(val) {
diff --git a/src/mov_encoder_writer.cc b/src/mov_encoder_writer.cc
index 6e251f8..d53d805 100644
--- a/src/mov_encoder_writer.cc
+++ b/src/mov_encoder_writer.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.11 2005/07/09 16:23:15 deva
+ * Added audio.
+ *
* Revision 1.10 2005/07/07 12:42:19 deva
* *** empty log message ***
*
@@ -140,7 +143,7 @@ void MovEncoderWriter::thread_main()
Frame *frame;
- write_multiplex_header();
+ write_header();
while(running) {
sem_wait(sem);
@@ -158,13 +161,10 @@ void MovEncoderWriter::thread_main()
int ret = 0;
- /*
- if(frame->number%2 == 1) write_video_header((unsigned short int)frame->size);
- else write_audio_header((unsigned short int)frame->size);
- */
- // if(frame->number%2 == 1) write_audio_header((unsigned short int)frame->size);
+ if(frame->number%2 == 1) write_audio_header((unsigned short int)frame->size);
+ else write_video_header((unsigned short int)frame->size);
- if(frame->number%2 == 1) ret = file->Write(frame->data, frame->size);
+ ret = file->Write(frame->data, frame->size);
frame_number++;
wrote ++;
@@ -188,6 +188,62 @@ void MovEncoderWriter::thread_main()
info->info("MovEncoderWriter::stop");
}
+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
+ 0x80, 0xF5, // 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));
+ */
+}
+
void MovEncoderWriter::write_video_header(unsigned short int psize)
{
// PES Header startcode
@@ -195,18 +251,30 @@ void MovEncoderWriter::write_video_header(unsigned short int psize)
0x00, 0x00, 0x01
};
- // Audio stream, index = 1
+ // Video stream, index = 0
char streamID[] = {
0xE0
};
char packetsize[] = { 0x00, 0x00 };
- packetsize[0] = ((char*)&psize)[0];
- packetsize[1] = ((char*)&psize)[1];
+
+ char stuffing_bytes[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0x0F
+ };
file->Write(startcode, sizeof(startcode));
+
file->Write(streamID, sizeof(streamID));
+
+ psize +=
+ sizeof(stuffing_bytes);
+ packetsize[0] = ((char*)&psize)[1];
+ packetsize[1] = ((char*)&psize)[0];
file->Write(packetsize, sizeof(packetsize));
+
+ file->Write(stuffing_bytes, sizeof(stuffing_bytes));
}
void MovEncoderWriter::write_audio_header(unsigned short int psize)
@@ -216,20 +284,213 @@ void MovEncoderWriter::write_audio_header(unsigned short int psize)
0x00, 0x00, 0x01
};
- // Audio stream, index = 1
+ // Audio stream, index = 0
char streamID[] = {
0xC0
};
char packetsize[] = { 0x00, 0x00 };
- // packetsize[0] = ((char*)&psize)[1];
- // packetsize[1] = ((char*)&psize)[0];
+
+ char stuffing_bytes[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF
+ };
+
+ char std_buffer[] = {
+ 0x40, // STD_buffer_scale
+ 0x20 // STD_buffer_size
+ };
+
+ char PTS[] = {
+ 0x21, // SCR-32 thru 30, marker bit
+ 0x00, 0x01, // SCR-29 thru 15, marker bit
+ 0xCE, 0x37 // SCR-14 thru 0, marker bit
+ };
+
+ file->Write(startcode, sizeof(startcode));
+
+ file->Write(streamID, sizeof(streamID));
+
+ psize +=
+ sizeof(stuffing_bytes) +
+ sizeof(std_buffer) +
+ sizeof(PTS);
+ packetsize[0] = ((char*)&psize)[1];
+ packetsize[1] = ((char*)&psize)[0];
+ file->Write(packetsize, sizeof(packetsize));
+
+ file->Write(stuffing_bytes, sizeof(stuffing_bytes));
+
+ file->Write(std_buffer, sizeof(std_buffer));
+
+ file->Write(PTS, sizeof(PTS));
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*
+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_multiplex_header()
+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));
}
+*/
diff --git a/src/mov_encoder_writer.h b/src/mov_encoder_writer.h
index 7f9a893..d197f2e 100644
--- a/src/mov_encoder_writer.h
+++ b/src/mov_encoder_writer.h
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.7 2005/07/09 16:23:15 deva
+ * Added audio.
+ *
* Revision 1.6 2005/07/07 12:42:19 deva
* *** empty log message ***
*
@@ -92,7 +95,7 @@ private:
void write_audio_header(unsigned short int packetsize);
void write_video_header(unsigned short int packetsize);
- void write_multiplex_header();
+ void write_header();
};