diff options
Diffstat (limited to 'src/mov_encoder_writer.cc')
-rw-r--r-- | src/mov_encoder_writer.cc | 289 |
1 files changed, 275 insertions, 14 deletions
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)); } +*/ |