Skip to content

Fix negative offset #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/AvTranscoder/decoder/AudioDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/decoder/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/encoder/AudioEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/encoder/VideoEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 2 additions & 4 deletions src/AvTranscoder/file/FormatContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/file/FormatContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/AvTranscoder/file/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/file/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) )
Expand Down
8 changes: 8 additions & 0 deletions src/AvTranscoder/reader/IReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <AvTranscoder/mediaProperty/print.hpp>

#include <cassert>

namespace avtranscoder
{

Expand Down Expand Up @@ -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
Expand All @@ -65,6 +72,7 @@ Frame* IReader::readFrameAt( const size_t frame )

void IReader::printInfo()
{
assert( _streamProperties != NULL );
std::cout << *_streamProperties << std::endl;
}

Expand Down
43 changes: 43 additions & 0 deletions test/pyTest/testOffset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand All @@ -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 )