Repository navigation
Expand file tree
/
Copy pathtranscode.py
More file actions
128 lines (119 loc) · 4.84 KB
/
Copy pathtranscode.py
File metadata and controls
128 lines (119 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import boto3
import hashlib
import pickle
'''
Uses AWS media convert to transcode all .flv files in an S3 bucket into .mp4 files
'''
# You set these. To get endpoint, run
# mediaconvert=boto3.client('mediaconvert')
# mediaconvert.describe_endpoints()
bucket="infantrekognition"
endpoint_url='https://fdeup1ey.mediaconvert.eu-west-1.amazonaws.com'
# List all objects in the bucket
s3=boto3.client('s3')
allfiles=s3.list_objects(Bucket=bucket)
# Create mediaconvert object
mediaconvert=boto3.client('mediaconvert',endpoint_url=endpoint_url)
# For each file create transcode job
for myobj in allfiles['Contents']:
# Only process objects with .flv suffix
ext=myobj['Key'][-4:]
if ext=='.flv':
print "File %s"%myobj['Key']
filename="s3://" + bucket +"/"+myobj['Key']
settings={
"OutputGroups": [
{
"Name": "File Group",
"Outputs": [
{
"ContainerSettings": {
"Container": "MP4",
"Mp4Settings": {
"CslgAtom": "INCLUDE",
"FreeSpaceBox": "EXCLUDE",
"MoovPlacement": "PROGRESSIVE_DOWNLOAD"
}
},
"VideoDescription": {
"ScalingBehavior": "DEFAULT",
"TimecodeInsertion": "DISABLED",
"AntiAlias": "ENABLED",
"Sharpness": 50,
"CodecSettings": {
"Codec": "H_264",
"H264Settings": {
"InterlaceMode": "PROGRESSIVE",
"NumberReferenceFrames": 3,
"Syntax": "DEFAULT",
"Softness": 0,
"GopClosedCadence": 1,
"GopSize": 90,
"Slices": 1,
"GopBReference": "DISABLED",
"SlowPal": "DISABLED",
"SpatialAdaptiveQuantization": "ENABLED",
"TemporalAdaptiveQuantization": "ENABLED",
"FlickerAdaptiveQuantization": "DISABLED",
"EntropyEncoding": "CABAC",
"Bitrate": 5000000,
"FramerateControl": "INITIALIZE_FROM_SOURCE",
"RateControlMode": "CBR",
"CodecProfile": "MAIN",
"Telecine": "NONE",
"MinIInterval": 0,
"AdaptiveQuantization": "HIGH",
"CodecLevel": "AUTO",
"FieldEncoding": "PAFF",
"SceneChangeDetect": "ENABLED",
"QualityTuningLevel": "SINGLE_PASS",
"FramerateConversionAlgorithm": "DUPLICATE_DROP",
"UnregisteredSeiTimecode": "DISABLED",
"GopSizeUnits": "FRAMES",
"ParControl": "INITIALIZE_FROM_SOURCE",
"NumberBFramesBetweenReferenceFrames": 2,
"RepeatPps": "DISABLED"
}
},
"AfdSignaling": "NONE",
"DropFrameTimecode": "ENABLED",
"RespondToAfd": "NONE",
"ColorMetadata": "INSERT"
},
"Extension": ".mp4"
}
],
"OutputGroupSettings": {
"Type": "FILE_GROUP_SETTINGS",
"FileGroupSettings": {
"Destination": "s3://infantrekognition/"
}
}
}
],
"AdAvailOffset": 0,
"Inputs": [
{
"VideoSelector": {
"ColorSpace": "FOLLOW"
},
"FilterEnable": "AUTO",
"PsiControl": "USE_PSI",
"FilterStrength": 0,
"DeblockFilter": "DISABLED",
"DenoiseFilter": "DISABLED",
"TimecodeSource": "EMBEDDED",
"FileInput": filename
}
]
}
response = mediaconvert.create_job(
ClientRequestToken=hashlib.md5(pickle.dumps(settings)).hexdigest(),
Queue= "arn:aws:mediaconvert:eu-west-1:807820536621:queues/Default",
UserMetadata= {},
Role="arn:aws:iam::807820536621:role/Cusack_MediaConvert",
Settings= settings
)
print response
else:
print "Ignoring %s"%myobj['Key']