Skip to content

Commit 05c214f

Browse files
author
Clement Champetier
committed
Merge branch 'develop' of https://github.com/mikrosimage/avTranscoder into dev_OuputFileCreateNameWithoutExtension
Conflicts: test/pyTest/testOffset.py
2 parents 4cc3848 + c391609 commit 05c214f

File tree

10 files changed

+89
-16
lines changed

10 files changed

+89
-16
lines changed

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ void AudioDecoder::setupDecoder( const ProfileLoader::Profile& profile )
6262
throw std::runtime_error( msg );
6363
}
6464

65-
LOG_INFO( "Setup audio decoder with:\n" << profile )
65+
if( ! profile.empty() )
66+
{
67+
LOG_INFO( "Setup audio decoder with:\n" << profile )
68+
}
6669

6770
AudioCodec& codec = _inputStream->getAudioCodec();
6871

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ void VideoDecoder::setupDecoder( const ProfileLoader::Profile& profile )
6060
throw std::runtime_error( msg );
6161
}
6262

63-
LOG_INFO( "Setup video decoder with:\n" << profile )
63+
if( ! profile.empty() )
64+
{
65+
LOG_INFO( "Setup video decoder with:\n" << profile )
66+
}
6467

6568
VideoCodec& codec = _inputStream->getVideoCodec();
6669

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ AudioEncoder::~AudioEncoder()
3737

3838
void AudioEncoder::setupAudioEncoder( const AudioFrameDesc& frameDesc, const ProfileLoader::Profile& profile )
3939
{
40-
LOG_INFO( "Setup audio encoder with:\n" << profile )
40+
if( ! profile.empty() )
41+
{
42+
LOG_INFO( "Setup audio encoder with:\n" << profile )
43+
}
4144

4245
// set sampleRate, number of channels, sample format
4346
_codec.setAudioParameters( frameDesc );

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ VideoEncoder::~VideoEncoder()
3838

3939
void VideoEncoder::setupVideoEncoder( const VideoFrameDesc& frameDesc, const ProfileLoader::Profile& profile )
4040
{
41-
LOG_INFO( "Setup video encoder with:\n" << profile )
41+
if( ! profile.empty() )
42+
{
43+
LOG_INFO( "Setup video encoder with:\n" << profile )
44+
}
4245

4346
// set width, height, pixel format, fps
4447
_codec.setImageParameters( frameDesc );

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,9 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec )
142142
return *stream;
143143
}
144144

145-
bool FormatContext::seek( uint64_t position, const int flag )
145+
bool FormatContext::seek( const uint64_t position, const int flag )
146146
{
147-
if( (int)getStartTime() != AV_NOPTS_VALUE )
148-
position += getStartTime();
149-
147+
LOG_INFO( "Seek in '" << _avFormatContext->filename << "' at " << position << " (in AV_TIME_BASE units)" )
150148
int err = av_seek_frame( _avFormatContext, -1, position, flag );
151149
if( err < 0 )
152150
{

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ class AvExport FormatContext
7777
* @brief Seek at a specific position
7878
* @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value
7979
* @param flag: seeking mode (AVSEEK_FLAG_xxx)
80-
* @note before seek, add offset of start time
8180
* @return seek status
81+
* @see flushDecoder
8282
*/
83-
bool seek( uint64_t position, const int flag );
83+
bool seek( const uint64_t position, const int flag );
8484

8585
size_t getNbStreams() const { return _avFormatContext->nb_streams; }
8686
/// Get duration of the program, in seconds

src/AvTranscoder/file/InputFile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ void InputFile::setupUnwrapping( const ProfileLoader::Profile& profile )
173173
throw std::runtime_error( msg );
174174
}
175175

176-
// set profile
177-
LOG_INFO( "Setup unwrapping with:\n" << profile )
176+
if( ! profile.empty() )
177+
{
178+
LOG_INFO( "Setup unwrapping with:\n" << profile )
179+
}
178180

179181
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
180182
{

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ void OutputFile::setupWrapping( const ProfileLoader::Profile& profile )
223223
throw std::runtime_error( msg );
224224
}
225225

226-
LOG_INFO( "Setup wrapping with:\n" << profile )
226+
if( ! profile.empty() )
227+
{
228+
LOG_INFO( "Setup wrapping with:\n" << profile )
229+
}
227230

228231
// check if output format indicated is valid with the filename extension
229232
if( ! matchFormat( profile.find( constants::avProfileFormat )->second, getFilename() ) )

src/AvTranscoder/reader/IReader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <AvTranscoder/mediaProperty/print.hpp>
44

5+
#include <cassert>
6+
57
namespace avtranscoder
68
{
79

@@ -49,6 +51,11 @@ Frame* IReader::readPrevFrame()
4951

5052
Frame* IReader::readFrameAt( const size_t frame )
5153
{
54+
assert( _decoder != NULL );
55+
assert( _transform != NULL );
56+
assert( _srcFrame != NULL );
57+
assert( _dstFrame != NULL );
58+
5259
if( (int)frame != _currentFrame + 1 )
5360
{
5461
// seek
@@ -65,6 +72,7 @@ Frame* IReader::readFrameAt( const size_t frame )
6572

6673
void IReader::printInfo()
6774
{
75+
assert( _streamProperties != NULL );
6876
std::cout << *_streamProperties << std::endl;
6977
}
7078

test/pyTest/testOffset.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def testRewrapAudioPositiveOffset():
102102

103103
# check output duration
104104
assert_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration() )
105+
# check output duration
106+
assert_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration() )
107+
assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() * dst_audioStream.getChannels() ), dst_audioStream.getNbSamples() )
105108

106109

107110
def testRewrapAudioNegativeOffset():
@@ -132,6 +135,9 @@ def testRewrapAudioNegativeOffset():
132135

133136
# check output duration
134137
assert_almost_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration(), delta=0.01 )
138+
# check output duration
139+
assert_almost_equals( src_audioStream.getDuration() + offset, dst_audioStream.getDuration(), delta=0.01 )
140+
assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() * dst_audioStream.getChannels() ), dst_audioStream.getNbSamples() )
135141

136142

137143
def testTranscodeVideoPositiveOffset():
@@ -160,7 +166,7 @@ def testTranscodeVideoPositiveOffset():
160166
dst_properties = dst_inputFile.getProperties()
161167
dst_videoStream = dst_properties.getVideoProperties()[0]
162168

163-
# check output duration
169+
# check output duration
164170
assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() )
165171

166172

@@ -190,7 +196,7 @@ def testTranscodeVideoNegativeOffset():
190196
dst_properties = dst_inputFile.getProperties()
191197
dst_videoStream = dst_properties.getVideoProperties()[0]
192198

193-
# check output duration
199+
# check output duration
194200
assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() )
195201

196202

@@ -222,6 +228,9 @@ def testRewrapVideoPositiveOffset():
222228

223229
# check output duration
224230
assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() )
231+
# check output duration
232+
assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() )
233+
assert_equals( src_videoStream.getNbFrames() + ( offset * dst_videoStream.getFps() ), dst_videoStream.getNbFrames() )
225234

226235

227236
def testRewrapVideoNegativeOffset():
@@ -252,6 +261,9 @@ def testRewrapVideoNegativeOffset():
252261

253262
# check output duration
254263
assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() )
264+
# check output duration
265+
assert_equals( src_videoStream.getDuration() + offset, dst_videoStream.getDuration() )
266+
assert_equals( src_videoStream.getNbFrames() + ( offset * dst_videoStream.getFps() ), dst_videoStream.getNbFrames() )
255267

256268

257269
def testMultipleOffsetFromSameInputFile():
@@ -276,12 +288,50 @@ def testMultipleOffsetFromSameInputFile():
276288
src_inputFile = av.InputFile( inputFileName )
277289
src_properties = src_inputFile.getProperties()
278290
src_videoStream = src_properties.getVideoProperties()[0]
291+
src_audioStream = src_properties.getAudioProperties()[0]
279292

280293
# get dst file
281294
dst_inputFile = av.InputFile( outputFileName )
282295
dst_properties = dst_inputFile.getProperties()
283296
dst_videoStream = dst_properties.getVideoProperties()[0]
297+
dst_audioStream = dst_properties.getAudioProperties()[0]
284298

285-
# check output duration
299+
# check output duration
286300
assert_equals( src_videoStream.getDuration() + offset_1, dst_videoStream.getDuration() )
301+
assert_equals( src_audioStream.getDuration() + offset_1, dst_audioStream.getDuration() )
302+
303+
304+
def testMultipleOffsetFromSameStream():
305+
"""
306+
Process same stream several times with different offset at the beginning of the process.
307+
"""
308+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE']
309+
outputFileName = "testMultipleOffsetFromSameStream.mov"
310+
offset_1 = 2
311+
offset_2 = -2
312+
313+
ouputFile = av.OutputFile( outputFileName )
314+
transcoder = av.Transcoder( ouputFile )
315+
316+
transcoder.add( inputFileName, 0, "", offset_1 )
317+
transcoder.add( inputFileName, 0, "", offset_2 )
287318

319+
progress = av.ConsoleProgress()
320+
transcoder.process( progress )
321+
322+
# get src file
323+
src_inputFile = av.InputFile( inputFileName )
324+
src_properties = src_inputFile.getProperties()
325+
src_videoStream = src_properties.getVideoProperties()[0]
326+
327+
# get dst file
328+
dst_inputFile = av.InputFile( outputFileName )
329+
dst_properties = dst_inputFile.getProperties()
330+
dst_videoStream_1 = dst_properties.getVideoProperties()[0]
331+
dst_videoStream_2 = dst_properties.getVideoProperties()[1]
332+
333+
# check output duration
334+
assert_equals( src_videoStream.getDuration() + offset_1, dst_videoStream_1.getDuration() )
335+
assert_equals( src_videoStream.getDuration() + offset_1, dst_videoStream_2.getDuration() )
336+
assert_almost_equals( src_videoStream.getNbFrames() + ( offset_1 * dst_videoStream_1.getFps() ), dst_videoStream_1.getNbFrames(), delta=0.01 )
337+
assert_almost_equals( src_videoStream.getNbFrames() + ( offset_1 * dst_videoStream_2.getFps() ), dst_videoStream_2.getNbFrames(), delta=0.01 )

0 commit comments

Comments
 (0)