Skip to content

Commit 5915bb8

Browse files
author
Clement Champetier
committed
Add pyconcat app
v1 of the app. Next TODO: * manage when first add is audio stream. * manage input file with several streams.
1 parent f757baf commit 5915bb8

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

app/pyConcat/pyconcat.py

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

0 commit comments

Comments
 (0)