X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fkino%2Ffilehandler.cc;h=92d793b2f426af1be2e2a37b6d4d73fa68bba4e9;hb=4e490640a573e5a9b4abd739bd0828fa8eb2b484;hp=740ee560c6ac0f8846d0ec5d9851d7e82ba7e672;hpb=815c458e95c73c39433fa7913afb4a830d7fd376;p=melted diff --git a/src/modules/kino/filehandler.cc b/src/modules/kino/filehandler.cc index 740ee56..92d793b 100644 --- a/src/modules/kino/filehandler.cc +++ b/src/modules/kino/filehandler.cc @@ -19,6 +19,10 @@ #include "config.h" +extern "C" { +#include +} + #include #include #include @@ -38,6 +42,11 @@ using std::setfill; #include #include +// libdv header files +#ifdef HAVE_LIBDV +#include +#endif + #include "filehandler.h" #include "error.h" #include "riff.h" @@ -688,6 +697,19 @@ bool AVIHandler::GetOpenDML() const #define DV_AUDIO_MAX_SAMPLES 1944 #endif +// Missing fourcc's in libquicktime (allows compilation) +#ifndef QUICKTIME_DV_AVID +#define QUICKTIME_DV_AVID "AVdv" +#endif + +#ifndef QUICKTIME_DV_AVID_A +#define QUICKTIME_DV_AVID_A "dvcp" +#endif + +#ifndef QUICKTIME_DVCPRO +#define QUICKTIME_DVCPRO "dvpp" +#endif + QtHandler::QtHandler() : fd( NULL ) { extension = ".mov"; @@ -834,7 +856,7 @@ int QtHandler::Close() off_t QtHandler::GetFileSize() { struct stat file_status; - fstat( fileno( fd->stream ), &file_status ); + stat( filename.c_str(), &file_status ); return file_status.st_size; } @@ -863,9 +885,12 @@ bool QtHandler::Open( const char *s ) Close(); return false; } - if ( strncmp( quicktime_video_compressor( fd, 0 ), QUICKTIME_DV, 4 ) != 0 ) + char * fcc = quicktime_video_compressor( fd, 0 ); + if ( strncmp( fcc, QUICKTIME_DV, 4 ) != 0 && + strncmp( fcc, QUICKTIME_DV_AVID, 4 ) != 0 && + strncmp( fcc, QUICKTIME_DV_AVID_A, 4 ) != 0 && + strncmp( fcc, QUICKTIME_DVCPRO, 4 ) != 0 ) { - fprintf( stderr, "Video in input file (%s) must be in DV format.\n", s ); Close(); return false; } @@ -882,30 +907,31 @@ int QtHandler::GetFrame( uint8_t *data, int frameNum ) quicktime_set_video_position( fd, frameNum, 0 ); quicktime_read_frame( fd, data, 0 ); -#if 0 +#ifdef HAVE_LIBDV if ( quicktime_has_audio( fd ) ) { - AudioInfo info; - double samples; - if ( ! isFullyInitialized ) - { - cerr << ">>> using audio from separarate Quicktime audio track" << endl; AllocateAudioBuffers(); - } - info.channels = channels; - info.frequency = quicktime_sample_rate( fd, 0 ); - samples = info.frequency / quicktime_frame_rate( fd, 0 ); - info.samples = (int) samples; - for ( int i = 0; i < channels; i++ ) - { - quicktime_set_audio_position( fd, ( int64_t )( frameNum * samples ), 0 ); - quicktime_decode_audio( fd, audioChannelBuffer[ i ], NULL, (long) samples, i ); - } - frame.EncodeAudio( info, audioChannelBuffer ); + // Fetch the frequency of the audio track and calc number of samples needed + int frequency = quicktime_sample_rate( fd, 0 ); + float fps = ( data[ 3 ] & 0x80 ) ? 25.0f : 29.97f; + int samples = mlt_sample_calculator( fps, frequency, frameNum ); + int64_t seek = mlt_sample_calculator_to_now( fps, frequency, frameNum ); + + // Obtain a dv encoder and initialise it with minimal info + dv_encoder_t *encoder = dv_encoder_new( 0, 0, 0 ); + encoder->isPAL = ( data[ 3 ] & 0x80 ); + encoder->samples_this_frame = samples; + + // Seek to the calculated position and decode + quicktime_set_audio_position( fd, seek, 0 ); + lqt_decode_audio( fd, audioChannelBuffer, NULL, (long) samples ); + + // Encode the audio on the frame and done + dv_encode_full_audio( encoder, audioChannelBuffer, channels, frequency, data ); + dv_encoder_free( encoder ); } - frame.ExtractHeader(); #endif return 0;