質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

3576閲覧

S3にアップロードしたmov形式の動画ファイルをmp4形式にエンコードする方法

kuriya

総合スコア35

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2017/05/15 02:46

編集2017/05/15 03:33

mp4動画ファイルのトランスコードを Python for Lambda で自動化
こちらの方法でts形式でエンコードすることは出来ました。

import boto3 from botocore.client import ClientError import json import urllib REGION_NAME = 'ap-northeast-1' TRANSCODER_ROLE_NAME = 'lambda_auto_transcoder_role' PIPELINE_NAME = 'testPipeline' OUT_BUCKET_NAME = 'ana-in' COMPLETE_TOPIC_NAME = 'test-complete' print('Loading function') s3 = boto3.resource('s3') iam = boto3.resource('iam') sns = boto3.resource('sns', REGION_NAME) transcoder = boto3.client('elastictranscoder', REGION_NAME) def lambda_handler(event, context): #print("Received event: " + json.dumps(event, indent=2)) # Get ARN complete_topic_arn = sns.create_topic(Name=COMPLETE_TOPIC_NAME).arn transcoder_role_arn = iam.Role(TRANSCODER_ROLE_NAME).arn # Get the object from the event bucket = event['Records'][0]['s3']['bucket']['name'] key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8') print("bucket={}, key={}".format(bucket, key)) try: obj = s3.Object(bucket, key) except Exception as e: print(e) print("Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.".format(key, bucket)) # Publish a message sns.Topic(complete_topic_arn).publish( Subject="Error!", Message="Failed to get object from S3. bucket={}, key={}, {}".format(bucket, key, e), ) raise e # Delete inactive pipelines pipeline_ids = [pipeline['Id'] for pipeline in transcoder.list_pipelines()['Pipelines'] if pipeline['Name'] == PIPELINE_NAME] for pipeline_id in pipeline_ids: try: response = transcoder.delete_pipeline(Id=pipeline_id) print("Delete a transcoder pipeline. pipeline_id={}".format(pipeline_id)) print("response={}".format(response)) except Exception as e: # Raise nothing print("Failed to delete a transcoder pipeline. pipeline_id={}".format(pipeline_id)) print(e) # Create a pipeline try: response = transcoder.create_pipeline( Name=PIPELINE_NAME, InputBucket=bucket, OutputBucket=OUT_BUCKET_NAME, Role=transcoder_role_arn, Notifications={ 'Progressing': '', 'Completed': complete_topic_arn, 'Warning': '', 'Error': '' }, ) pipeline_id = response['Pipeline']['Id'] print("Create a transcoder pipeline. pipeline_id={}".format(pipeline_id)) print("response={}".format(response)) except Exception as e: print("Failed to create a transcoder pipeline.") print(e) # Publish a message sns.Topic(complete_topic_arn).publish( Subject="Error!", Message="Failed to create a transcoder pipeline. bucket={}, key={}, {}".format(bucket, key, e), ) raise e # Create a job try: job = transcoder.create_job( PipelineId=pipeline_id, Input={ 'Key': key, 'FrameRate': 'auto', 'Resolution': 'auto', 'AspectRatio': 'auto', 'Interlaced': 'auto', 'Container': 'auto', }, Outputs=[ { 'Key': 'output/{}'.format('.'.join(key.split('.')[:-1])), 'PresetId': '1351620000001-200030', # System preset: HLS 1M 'SegmentDuration': '10', }, ], ) job_id = job['Job']['Id'] print("Create a transcoder job. job_id={}".format(job_id)) print("job={}".format(job)) except Exception as e: print("Failed to create a transcoder job. pipeline_id={}".format(pipeline_id)) print(e) # Publish a message sns.Topic(complete_topic_arn).publish( Subject="Error!", Message="Failed to create transcoder job. pipeline_id={}, {}".format(pipeline_id, e), ) raise e return "Success"

PresetIdを1351620000001-100070(System preset: Web)
に変更すればmp4でエンコードされると思ったのですが、変更すると何もエンコードされなくなりました。

エラー内容

Failed to create a transcoder job. pipeline_id=1494818317732-9k629f
An error occurred (ValidationException) when calling the CreateJob operation: SegmentDuration '30' is not a valid option for preset 1351620000001-100070, because the container is not ts or fmp4.: ValidationException Traceback (most recent call last): File "/var/task/lambda_function.py", line 113, in lambda_handler raise e ValidationException: An error occurred (ValidationException) when calling the CreateJob operation: SegmentDuration '30' is not a valid option for preset 1351620000001-100070, because the container is not ts or fmp4.
REPORT RequestId: 2e7fee02-391d-11e7-947b-31c8905c64e9 Duration: 2409.70 ms Billed Duration: 2500 ms Memory Size: 128 MB Max Memory Used: 51 MB

lambdaのコードをPresetId以外にも修正する必要がありそうなのですが、どこを修正すれば良いか分かりません。

どなたかご教授いただければ幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kunai

2017/05/15 03:15

「うまくエンコードされない」と言うのがどういう状況なのか説明いただいた方が良いかと思います。再生できなかった、ファイルサイズが0になった、エラーになって変換自体が行われなかった(その場合はどういうエラーが発生したかなど)
kuriya

2017/05/15 03:34

ありがとうございます。エラー詳細を追加しました。
guest

回答1

0

自己解決

'SegmentDuration': '10',の箇所を削除して
keyに.mp4を追加することで対応出来ました。

Outputs=[ { 'Key': 'output/{}'.format('.'.join(key.split('.')[:-1])) + '.mp4', 'PresetId': '1351620000001-100070' }, ],

投稿2017/05/15 03:36

kuriya

総合スコア35

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問