diff --git a/src/AvTranscoder/decoder/AudioDecoder.cpp b/src/AvTranscoder/decoder/AudioDecoder.cpp index eb9432fe..346ce765 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.cpp +++ b/src/AvTranscoder/decoder/AudioDecoder.cpp @@ -62,7 +62,10 @@ void AudioDecoder::setupDecoder( const ProfileLoader::Profile& profile ) throw std::runtime_error( msg ); } - LOG_INFO( "Setup audio decoder with:\n" << profile ) + if( ! profile.empty() ) + { + LOG_INFO( "Setup audio decoder with:\n" << profile ) + } AudioCodec& codec = _inputStream->getAudioCodec(); diff --git a/src/AvTranscoder/decoder/VideoDecoder.cpp b/src/AvTranscoder/decoder/VideoDecoder.cpp index 08f87271..ae54d737 100644 --- a/src/AvTranscoder/decoder/VideoDecoder.cpp +++ b/src/AvTranscoder/decoder/VideoDecoder.cpp @@ -60,7 +60,10 @@ void VideoDecoder::setupDecoder( const ProfileLoader::Profile& profile ) throw std::runtime_error( msg ); } - LOG_INFO( "Setup video decoder with:\n" << profile ) + if( ! profile.empty() ) + { + LOG_INFO( "Setup video decoder with:\n" << profile ) + } VideoCodec& codec = _inputStream->getVideoCodec(); diff --git a/src/AvTranscoder/encoder/AudioEncoder.cpp b/src/AvTranscoder/encoder/AudioEncoder.cpp index 93e68342..85941c92 100644 --- a/src/AvTranscoder/encoder/AudioEncoder.cpp +++ b/src/AvTranscoder/encoder/AudioEncoder.cpp @@ -37,7 +37,10 @@ AudioEncoder::~AudioEncoder() void AudioEncoder::setupAudioEncoder( const AudioFrameDesc& frameDesc, const ProfileLoader::Profile& profile ) { - LOG_INFO( "Setup audio encoder with:\n" << profile ) + if( ! profile.empty() ) + { + LOG_INFO( "Setup audio encoder with:\n" << profile ) + } // set sampleRate, number of channels, sample format _codec.setAudioParameters( frameDesc ); diff --git a/src/AvTranscoder/encoder/VideoEncoder.cpp b/src/AvTranscoder/encoder/VideoEncoder.cpp index cca0820e..cce274ff 100644 --- a/src/AvTranscoder/encoder/VideoEncoder.cpp +++ b/src/AvTranscoder/encoder/VideoEncoder.cpp @@ -38,7 +38,10 @@ VideoEncoder::~VideoEncoder() void VideoEncoder::setupVideoEncoder( const VideoFrameDesc& frameDesc, const ProfileLoader::Profile& profile ) { - LOG_INFO( "Setup video encoder with:\n" << profile ) + if( ! profile.empty() ) + { + LOG_INFO( "Setup video encoder with:\n" << profile ) + } // set width, height, pixel format, fps _codec.setImageParameters( frameDesc ); diff --git a/src/AvTranscoder/file/FormatContext.cpp b/src/AvTranscoder/file/FormatContext.cpp index 7dd22cbc..1306347e 100644 --- a/src/AvTranscoder/file/FormatContext.cpp +++ b/src/AvTranscoder/file/FormatContext.cpp @@ -142,11 +142,9 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec ) return *stream; } -bool FormatContext::seek( uint64_t position, const int flag ) +bool FormatContext::seek( const uint64_t position, const int flag ) { - if( (int)getStartTime() != AV_NOPTS_VALUE ) - position += getStartTime(); - + LOG_INFO( "Seek in '" << _avFormatContext->filename << "' at " << position << " (in AV_TIME_BASE units)" ) int err = av_seek_frame( _avFormatContext, -1, position, flag ); if( err < 0 ) { diff --git a/src/AvTranscoder/file/FormatContext.hpp b/src/AvTranscoder/file/FormatContext.hpp index b446d8a9..7c080531 100644 --- a/src/AvTranscoder/file/FormatContext.hpp +++ b/src/AvTranscoder/file/FormatContext.hpp @@ -77,10 +77,10 @@ class AvExport FormatContext * @brief Seek at a specific position * @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value * @param flag: seeking mode (AVSEEK_FLAG_xxx) - * @note before seek, add offset of start time * @return seek status + * @see flushDecoder */ - bool seek( uint64_t position, const int flag ); + bool seek( const uint64_t position, const int flag ); size_t getNbStreams() const { return _avFormatContext->nb_streams; } /// Get duration of the program, in seconds diff --git a/src/AvTranscoder/file/InputFile.cpp b/src/AvTranscoder/file/InputFile.cpp index f780a090..6c945616 100644 --- a/src/AvTranscoder/file/InputFile.cpp +++ b/src/AvTranscoder/file/InputFile.cpp @@ -173,8 +173,10 @@ void InputFile::setupUnwrapping( const ProfileLoader::Profile& profile ) throw std::runtime_error( msg ); } - // set profile - LOG_INFO( "Setup unwrapping with:\n" << profile ) + if( ! profile.empty() ) + { + LOG_INFO( "Setup unwrapping with:\n" << profile ) + } for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it ) { diff --git a/src/AvTranscoder/file/OutputFile.cpp b/src/AvTranscoder/file/OutputFile.cpp index 156507b3..057a33f2 100644 --- a/src/AvTranscoder/file/OutputFile.cpp +++ b/src/AvTranscoder/file/OutputFile.cpp @@ -223,7 +223,10 @@ void OutputFile::setupWrapping( const ProfileLoader::Profile& profile ) throw std::runtime_error( msg ); } - LOG_INFO( "Setup wrapping with:\n" << profile ) + if( ! profile.empty() ) + { + LOG_INFO( "Setup wrapping with:\n" << profile ) + } // check if output format indicated is valid with the filename extension if( ! matchFormat( profile.find( constants::avProfileFormat )->second, getFilename() ) ) diff --git a/src/AvTranscoder/reader/IReader.cpp b/src/AvTranscoder/reader/IReader.cpp index 8f938805..a83608b2 100644 --- a/src/AvTranscoder/reader/IReader.cpp +++ b/src/AvTranscoder/reader/IReader.cpp @@ -2,6 +2,8 @@ #include +#include + namespace avtranscoder { @@ -49,6 +51,11 @@ Frame* IReader::readPrevFrame() Frame* IReader::readFrameAt( const size_t frame ) { + assert( _decoder != NULL ); + assert( _transform != NULL ); + assert( _srcFrame != NULL ); + assert( _dstFrame != NULL ); + if( (int)frame != _currentFrame + 1 ) { // seek @@ -65,6 +72,7 @@ Frame* IReader::readFrameAt( const size_t frame ) void IReader::printInfo() { + assert( _streamProperties != NULL ); std::cout << *_streamProperties << std::endl; } diff --git a/test/pyTest/testOffset.py b/test/pyTest/testOffset.py index 3b611a60..fec33dc7 100644 --- a/test/pyTest/testOffset.py +++ b/test/pyTest/testOffset.py @@ -102,6 +102,7 @@ def testRewrapAudioPositiveOffset(): # check output duration assert_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration() ) + assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() * dst_audioStream.getChannels() ), dst_audioStream.getNbSamples() ) def testRewrapAudioNegativeOffset(): @@ -132,6 +133,7 @@ def testRewrapAudioNegativeOffset(): # check output duration assert_almost_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration(), delta=0.01 ) + assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() * dst_audioStream.getChannels() ), dst_audioStream.getNbSamples() ) def testTranscodeVideoPositiveOffset(): @@ -222,6 +224,7 @@ def testRewrapVideoPositiveOffset(): # check output duration assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() ) + assert_equals( src_videoStream.getNbFrames() + ( offset * dst_videoStream.getFps() ), dst_videoStream.getNbFrames() ) def testRewrapVideoNegativeOffset(): @@ -252,6 +255,7 @@ def testRewrapVideoNegativeOffset(): # check output duration assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() ) + assert_equals( src_videoStream.getNbFrames() + ( offset * dst_videoStream.getFps() ), dst_videoStream.getNbFrames() ) def testMultipleOffsetFromSameInputFile(): @@ -276,12 +280,51 @@ def testMultipleOffsetFromSameInputFile(): src_inputFile = av.InputFile( inputFileName ) src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] + src_audioStream = src_properties.getAudioProperties()[0] # get dst file dst_inputFile = av.InputFile( outputFileName ) dst_properties = dst_inputFile.getProperties() dst_videoStream = dst_properties.getVideoProperties()[0] + dst_audioStream = dst_properties.getAudioProperties()[0] # check output duration assert_equals( src_videoStream.getDuration() + offset_1, dst_videoStream.getDuration() ) + assert_equals( src_audioStream.getDuration() + offset_1, dst_audioStream.getDuration() ) + + +def testMultipleOffsetFromSameStream(): + """ + Process same stream several times with different offset at the beginning of the process. + """ + inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] + outputFileName = "testMultipleOffsetFromSameStream.mov" + offset_1 = 2 + offset_2 = -2 + + ouputFile = av.OutputFile( outputFileName ) + transcoder = av.Transcoder( ouputFile ) + + transcoder.add( inputFileName, 0, "", offset_1 ) + transcoder.add( inputFileName, 0, "", offset_2 ) + + progress = av.ConsoleProgress() + transcoder.process( progress ) + + # get src file + src_inputFile = av.InputFile( inputFileName ) + src_properties = src_inputFile.getProperties() + src_videoStream = src_properties.getVideoProperties()[0] + + # get dst file + dst_inputFile = av.InputFile( outputFileName ) + dst_properties = dst_inputFile.getProperties() + dst_videoStream_1 = dst_properties.getVideoProperties()[0] + dst_videoStream_2 = dst_properties.getVideoProperties()[1] + + # check output duration + assert_equals( src_videoStream.getDuration() + offset_1, dst_videoStream_1.getDuration() ) + assert_equals( src_videoStream.getDuration() + offset_1, dst_videoStream_2.getDuration() ) + assert_almost_equals( src_videoStream.getNbFrames() + ( offset_1 * dst_videoStream_1.getFps() ), dst_videoStream_1.getNbFrames(), delta=0.01 ) + assert_almost_equals( src_videoStream.getNbFrames() + ( offset_1 * dst_videoStream_2.getFps() ), dst_videoStream_2.getNbFrames(), delta=0.01 )