Skip to content

Commit 03e0ea3

Browse files
author
Clement Champetier
committed
Merge branch 'develop' of https://github.com/avTranscoder/avTranscoder into dev_mediaPropertiesAsJson
Conflicts: src/AvTranscoder/properties/StreamProperties.cpp
2 parents 21d16c4 + f477447 commit 03e0ea3

20 files changed

+264
-121
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ after_success:
8383
- if [ ${ENABLE_COVERAGE} ]; then ./tools/travis.gcc.generate.coverage.sh; fi
8484

8585
before_deploy:
86+
# copy libbz2, external dependency of libavformat
87+
- if [ ${TRAVIS_OS_NAME} = "linux" ]; then cp /lib/x86_64-linux-gnu/{libbz2.so.1,libbz2.so.1.0,libbz2.so.1.0.4} ${DEPENDENCY_INSTALL_PATH}/lib; fi
8688
# create archive
8789
- cd ${TRAVIS_BUILD_DIR}
8890
- tar -cvzf avtranscoder-${TRAVIS_OS_NAME}-${CC}-${DEPENDENCY_MODE}.tgz ${DEPENDENCY_INSTALL} ${AVTRANSCODER_INSTALL}

app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ add_subdirectory(avProcessor)
88
add_subdirectory(pyProcessor)
99
add_subdirectory(pyThumbnail)
1010
add_subdirectory(pyRewrap)
11+
add_subdirectory(pyConcat)

app/pyConcat/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### python/pyConcat
2+
3+
# Install app
4+
install(
5+
FILES "pyconcat.py"
6+
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE
7+
DESTINATION "bin/python"
8+
)
9+
10+
if(UNIX)
11+
install( CODE "EXECUTE_PROCESS(COMMAND ln -sf python/pyconcat.py ${CMAKE_INSTALL_PREFIX}/bin/pyconcat)" )
12+
endif(UNIX)

app/pyConcat/pyconcat.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python
2+
3+
from pyAvTranscoder import avtranscoder as av
4+
5+
from sets import Set
6+
7+
8+
# Get command line arguments
9+
args = []
10+
try:
11+
# python2.7+
12+
import argparse
13+
14+
# Create command-line interface
15+
parser = argparse.ArgumentParser(
16+
prog='pyconcat',
17+
description='''Concatenate first stream of each given file to create an output file.''',
18+
)
19+
20+
# requirements
21+
parser.add_argument('inputs', nargs='+', action='store', help='list of files to concatenate')
22+
# options
23+
parser.add_argument("-o", "--outputFile", dest="outputFileName", type=str, default="output.mov", help="Set the output filename (output.mov by default).")
24+
# Parse command-line
25+
args = parser.parse_args()
26+
27+
except ImportError:
28+
print("pyconcat currently expects python2.7+")
29+
exit(1)
30+
31+
# setup avtranscoder
32+
logger = av.Logger().setLogLevel(av.AV_LOG_QUIET)
33+
av.preloadCodecsAndFormats()
34+
35+
streamTypeToConcat = Set()
36+
codecToConcat = Set()
37+
# get all input files
38+
inputFiles = []
39+
for input in args.inputs:
40+
inputFile = av.InputFile(input)
41+
streamTypeToConcat.add( inputFile.getStream(0).getProperties().getStreamType() )
42+
codecToConcat.add( inputFile.getStream(0).getProperties().getCodecName() )
43+
inputFiles.append(inputFile)
44+
45+
# Check type of streams to rewrap
46+
if len(streamTypeToConcat) > 1:
47+
raise RuntimeError("Cannot concatenate streams of different type.")
48+
if len(codecToConcat) > 1:
49+
raise RuntimeError("Cannot concatenate streams of different codec: ", [codec for codec in codecToConcat])
50+
51+
# Create the output
52+
outputFile = av.OutputFile( args.outputFileName );
53+
if av.AVMEDIA_TYPE_VIDEO in streamTypeToConcat:
54+
outputFile.addVideoStream( inputFiles[-1].getStream(0).getVideoCodec() )
55+
elif av.AVMEDIA_TYPE_AUDIO in streamTypeToConcat:
56+
outputFile.addVideoStream( inputFiles[-1].getStream(0).getAudioCodec() )
57+
58+
### process
59+
outputFile.beginWrap()
60+
61+
data = av.Frame()
62+
# for each input
63+
for inputFile in inputFiles:
64+
packetRead = True
65+
# read all packets of first stream
66+
while packetRead:
67+
# read
68+
packetRead = inputFile.readNextPacket( data, 0 )
69+
# wrap
70+
outputFile.wrap( data, 0 )
71+
72+
outputFile.endWrap()

app/pyRewrap/pyrewrap.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# requirements
1919
parser.add_argument('inputFileName', type=str, help='It could be any video file. Support file without extension.')
2020
# options
21-
parser.add_argument("-o", "--outputFile", dest="outputFileName", type=str, default="output.mov", help="Set the output filename (thumbnail.jpg by default). Must be with jpg extension!")
21+
parser.add_argument("-o", "--outputFile", dest="outputFileName", type=str, default="output.mov", help="Set the output filename (output.mov by default).")
2222
parser.add_argument("-c", "--format", dest="format", type=str, default="mov", help="Specify the output format.")
2323
parser.add_argument("-f", "--faststart", dest="faststart", action="store_true", default=False, help="Specify if the faststart option must be apply during rewrapping process (warning: 'mov' specific option).")
2424
# Parse command-line
@@ -37,7 +37,7 @@
3737
# requirements
3838
parser.add_option("-i", "--inputFile", dest='inputFileName', type="string", help='It could be any video file. Support file without extension.')
3939
# options
40-
parser.add_option("-o", "--outputFile", dest="outputFileName", type="string", default="output.mov", help="Set the output filename (thumbnail.jpg by default). Must be with jpg extension!")
40+
parser.add_option("-o", "--outputFile", dest="outputFileName", type="string", default="output.mov", help="Set the output filename (output.mov by default).")
4141
parser.add_option("-c", "--format", dest="format", type="string", default="mov", help="Specify the output format.")
4242
parser.add_option("-f", "--faststart", dest="faststart", action="store_true", default=False, help="Specify if the faststart option must be apply during rewrapping process (warning: 'mov' specific option).")
4343
# Parse command-line
@@ -70,16 +70,9 @@
7070

7171
# create transcoder
7272
transcoder = av.Transcoder( outputFile )
73-
74-
def addStreamsToTranscoder(transcoder, streams):
75-
for st in streams:
76-
stIndex = st.getStreamIndex()
77-
transcoder.add( args.inputFileName, stIndex )
78-
79-
addStreamsToTranscoder(transcoder, inputFile.getProperties().getVideoProperties())
80-
addStreamsToTranscoder(transcoder, inputFile.getProperties().getAudioProperties())
81-
# addStreamsToTranscoder(transcoder, inputFile.getProperties().getDataProperties())
73+
transcoder.add( args.inputFileName )
8274

8375
# launch process
8476
progress = av.ConsoleProgress()
8577
transcoder.process(progress)
78+

src/AvTranscoder/Option.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ class AvExport Option
118118
typedef std::vector<Option> OptionArray;
119119
typedef std::map<std::string, Option> OptionMap; ///< Key: option name / value: option
120120

121+
#ifndef SWIG
121122
/**
122123
* @param outOptions: map or array of options
123124
* @param av_class: a libav context (could be an AVFormatContext or an AVCodecContext).
124125
* @param req_flags: libav flag (AV_OPT_FLAG_XXX), which is a filter for AVOption loaded by the Context (default = 0: no flag restriction).
125126
*/
126127
void AvExport loadOptions( OptionMap& outOptions, void* av_class, int req_flags = 0 );
127128
void AvExport loadOptions( OptionArray& outOptions, void* av_class, int req_flags = 0 );
129+
#endif
128130

129131
}
130132

src/AvTranscoder/codec/ICodec.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class AvExport ICodec
4444
int getLatency() const;
4545

4646
OptionArray getOptions(); ///< Get options as array
47+
#ifndef SWIG
4748
OptionMap& getOptionsMap() { return _options; } ///< Get options as map
48-
49+
#endif
4950
Option& getOption( const std::string& optionName ) { return _options.at(optionName); }
5051

5152
#ifndef SWIG

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ class AvExport FormatContext
8888
size_t getStartTime() const { return _avFormatContext->start_time; }
8989

9090
OptionArray getOptions(); ///< Get options as array
91+
#ifndef SWIG
9192
OptionMap& getOptionsMap() { return _options; } ///< Get options as map
92-
93+
#endif
9394
Option& getOption( const std::string& optionName ) { return _options.at(optionName); }
9495

9596
/**

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ IOutputStream& OutputFile::addVideoStream( const VideoCodec& videoDesc )
4040
stream.codec->pix_fmt = videoDesc.getAVCodecContext().pix_fmt;
4141
stream.codec->profile = videoDesc.getAVCodecContext().profile;
4242
stream.codec->level = videoDesc.getAVCodecContext().level;
43+
stream.codec->field_order = videoDesc.getAVCodecContext().field_order;
4344

4445
// some codecs need/can use extradata to decode
4546
uint8_t* srcExtradata = videoDesc.getAVCodecContext().extradata;

src/AvTranscoder/properties/AudioProperties.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,6 @@ namespace avtranscoder
1616
AudioProperties::AudioProperties( const FormatContext& formatContext, const size_t index )
1717
: StreamProperties( formatContext, index )
1818
{
19-
if( _formatContext )
20-
_codecContext = _formatContext->streams[index]->codec;
21-
22-
if( _formatContext && _codecContext )
23-
_codec = avcodec_find_decoder( _codecContext->codec_id );
24-
}
25-
26-
std::string AudioProperties::getCodecName() const
27-
{
28-
if( ! _codec || ! _codec->name )
29-
throw std::runtime_error( "unknown codec name" );
30-
return std::string( _codec->name );
31-
}
32-
33-
std::string AudioProperties::getCodecLongName() const
34-
{
35-
if( ! _codec || ! _codec->long_name )
36-
throw std::runtime_error( "unknown codec long name" );
37-
return std::string( _codec->long_name );
3819
}
3920

4021
std::string AudioProperties::getSampleFormatName() const
@@ -121,13 +102,6 @@ std::string AudioProperties::getChannelDescription() const
121102
#endif
122103
}
123104

124-
size_t AudioProperties::getCodecId() const
125-
{
126-
if( ! _codecContext )
127-
throw std::runtime_error( "unknown codec context" );
128-
return _codecContext->codec_id;
129-
}
130-
131105
size_t AudioProperties::getSampleRate() const
132106
{
133107
if( ! _codecContext )
@@ -181,9 +155,6 @@ PropertyVector AudioProperties::asVector() const
181155
PropertyVector basedProperty = StreamProperties::asVector();
182156
data.insert( data.begin(), basedProperty.begin(), basedProperty.end() );
183157

184-
addProperty( data, "codecId", &AudioProperties::getCodecId );
185-
addProperty( data, "codecName", &AudioProperties::getCodecName );
186-
addProperty( data, "codecLongName", &AudioProperties::getCodecLongName );
187158
addProperty( data, "sampleFormatName", &AudioProperties::getSampleFormatName );
188159
addProperty( data, "sampleFormatLongName", &AudioProperties::getSampleFormatLongName );
189160
addProperty( data, "sampleRate", &AudioProperties::getSampleRate );

src/AvTranscoder/properties/AudioProperties.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ class AvExport AudioProperties : public StreamProperties
1313
public:
1414
AudioProperties( const FormatContext& formatContext, const size_t index );
1515

16-
std::string getCodecName() const;
17-
std::string getCodecLongName() const;
1816
std::string getSampleFormatName() const;
1917
std::string getSampleFormatLongName() const;
2018
std::string getChannelLayout() const;
2119
std::string getChannelName() const;
2220
std::string getChannelDescription() const;
2321

24-
size_t getCodecId() const;
2522
size_t getSampleRate() const;
2623
size_t getChannels() const;
2724
size_t getBitRate() const; ///< 0 if unknown
@@ -50,10 +47,6 @@ class AvExport AudioProperties : public StreamProperties
5047
}
5148
}
5249
#endif
53-
54-
private:
55-
AVCodecContext* _codecContext; ///< Has link (no ownership)
56-
AVCodec* _codec; ///< Has link (no ownership)
5750
};
5851

5952
}

src/AvTranscoder/properties/StreamProperties.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,26 @@ namespace avtranscoder
99

1010
StreamProperties::StreamProperties( const FormatContext& formatContext, const size_t index )
1111
: _formatContext( &formatContext.getAVFormatContext() )
12+
, _codecContext( NULL )
13+
, _codec( NULL )
1214
, _streamIndex( index )
1315
{
1416
if( _formatContext )
1517
detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas );
18+
19+
if( _formatContext )
20+
{
21+
if( _streamIndex > _formatContext->nb_streams )
22+
{
23+
std::stringstream ss;
24+
ss << "Stream at index " << _streamIndex << " does not exist.";
25+
throw std::runtime_error( ss.str() );
26+
}
27+
_codecContext = _formatContext->streams[_streamIndex]->codec;
28+
}
29+
30+
if( _formatContext && _codecContext )
31+
_codec = avcodec_find_decoder( _codecContext->codec_id );
1632
}
1733

1834
StreamProperties::~StreamProperties()
@@ -47,6 +63,41 @@ AVMediaType StreamProperties::getStreamType() const
4763
return _formatContext->streams[_streamIndex]->codec->codec_type;
4864
}
4965

66+
size_t StreamProperties::getCodecId() const
67+
{
68+
if( ! _codecContext )
69+
throw std::runtime_error( "unknown codec context" );
70+
return _codecContext->codec_id;
71+
}
72+
73+
std::string StreamProperties::getCodecName() const
74+
{
75+
if( ! _codecContext || ! _codec )
76+
throw std::runtime_error( "unknown codec" );
77+
78+
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
79+
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
80+
81+
if( ! _codec->name )
82+
throw std::runtime_error( "unknown codec name" );
83+
84+
return std::string( _codec->name );
85+
}
86+
87+
std::string StreamProperties::getCodecLongName() const
88+
{
89+
if( ! _codecContext || ! _codec )
90+
throw std::runtime_error( "unknown codec" );
91+
92+
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
93+
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
94+
95+
if( ! _codec->long_name )
96+
throw std::runtime_error( "unknown codec long name" );
97+
98+
return std::string( _codec->long_name );
99+
}
100+
50101
PropertyVector StreamProperties::asVector() const
51102
{
52103
PropertyVector data;
@@ -55,6 +106,9 @@ PropertyVector StreamProperties::asVector() const
55106
addProperty( data, "streamIndex", &StreamProperties::getStreamIndex );
56107
addProperty( data, "timeBase", &StreamProperties::getTimeBase );
57108
addProperty( data, "duration", &StreamProperties::getDuration );
109+
addProperty( data, "codecId", &StreamProperties::getCodecId );
110+
addProperty( data, "codecName", &StreamProperties::getCodecName );
111+
addProperty( data, "codecLongName", &StreamProperties::getCodecLongName );
58112

59113
for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex )
60114
{

src/AvTranscoder/properties/StreamProperties.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class AvExport StreamProperties
2020
Rational getTimeBase() const;
2121
float getDuration() const; ///< in seconds
2222
AVMediaType getStreamType() const;
23+
24+
size_t getCodecId() const;
25+
std::string getCodecName() const;
26+
std::string getCodecLongName() const;
27+
2328
const PropertyVector& getMetadatas() const { return _metadatas; }
2429

2530
#ifndef SWIG
@@ -48,6 +53,8 @@ class AvExport StreamProperties
4853

4954
protected:
5055
const AVFormatContext* _formatContext; ///< Has link (no ownership)
56+
AVCodecContext* _codecContext; ///< Has link (no ownership)
57+
AVCodec* _codec; ///< Has link (no ownership)
5158

5259
size_t _streamIndex;
5360
PropertyVector _metadatas;

0 commit comments

Comments
 (0)