"""Validate metadata.""" from video.constants import job_io_fields from video.constants import mediaconvert as mediaconvert_constants from video.logic.activity_task_logger import activity_task_logger OUTPUT_FRAMERATES = { 23.976, 24, 25, 29.97, } INPUT_FRAMERATES = { *OUTPUT_FRAMERATES, 30, 50, 60, } acceptable_values = { job_io_fields.VIDEO_STREAM_FRAME_RATE_FRAMES_PER_SECOND: INPUT_FRAMERATES } min_width = 640 min_height = 404 JOB_INPUTS = { job_io_fields.NUM_AUDIO_STREAMS, job_io_fields.NUM_VIDEO_STREAMS, job_io_fields.AUDIO_STREAM_CHANNEL_COUNT, job_io_fields.AUDIO_STREAM_CHANNEL_LAYOUT, job_io_fields.AUDIO_STREAM_DURATION_SECONDS, job_io_fields.VIDEO_STREAM_FRAME_RATE_FRAMES_PER_SECOND, job_io_fields.VIDEO_STREAM_WIDTH_PIXELS, job_io_fields.VIDEO_STREAM_HEIGHT_PIXELS, job_io_fields.VIDEO_STREAM_PIXEL_ASPECT_RATIO, job_io_fields.VIDEO_STREAM_DURATION_SECONDS, job_io_fields.VIDEO_STREAM_CODEC, job_io_fields.VIDEO_STREAM_CODEC_PROFILE, } @activity_task_logger(JOB_INPUTS) def validate_metadata(inputs): """Validate metadata. Args: inputs (dict): Inputs. Returns: dict: Outputs. """ outputs = {} if inputs[job_io_fields.NUM_AUDIO_STREAMS] != 1: outputs[job_io_fields.ERROR_MUST_CONTAIN_EXACTLY_1_AUDIO_STREAM] = ( 'Must contain exactly 1 audio stream.') if inputs[job_io_fields.NUM_VIDEO_STREAMS] != 1: outputs[job_io_fields.ERROR_MUST_CONTAIN_EXACTLY_1_VIDEO_STREAM] = ( 'Must contain exactly 1 video stream.') if outputs: return outputs if max(inputs[job_io_fields.AUDIO_STREAM_DURATION_SECONDS], inputs[job_io_fields.VIDEO_STREAM_DURATION_SECONDS]) < 10: outputs[ job_io_fields.ERROR_VIDEO_DURATION_TOO_SHORT] = ( 'Video duration must be at least 10 seconds.') if outputs: return outputs if (inputs[job_io_fields.VIDEO_STREAM_CODEC] == 'vc-3' and inputs[job_io_fields.VIDEO_STREAM_CODEC_PROFILE] == 'ri@hq'): outputs[job_io_fields.ERROR_UNSUPPORTED_VIDEO_CODEC] = ( 'The DNxHR codec is not currently supported. Please use ProRes.') if inputs[job_io_fields.AUDIO_STREAM_CHANNEL_COUNT] != 2: outputs[job_io_fields.ERROR_AUDIO_MUST_BE_STEREO] = ( 'Audio must be stereo.') if ( inputs[job_io_fields.VIDEO_STREAM_FRAME_RATE_FRAMES_PER_SECOND] not in acceptable_values[ job_io_fields.VIDEO_STREAM_FRAME_RATE_FRAMES_PER_SECOND] ): outputs[job_io_fields.ERROR_UNSUPPORTED_FRAME_RATE] = ( 'Unsupported frame rate.') if (inputs[job_io_fields.VIDEO_STREAM_WIDTH_PIXELS] * inputs[job_io_fields.VIDEO_STREAM_PIXEL_ASPECT_RATIO]) < min_width: outputs[job_io_fields.ERROR_WIDTH_TOO_SMALL] = ( 'Video width must be at least {} pixels.'.format(min_width)) if inputs[job_io_fields.VIDEO_STREAM_HEIGHT_PIXELS] < min_height: outputs[job_io_fields.ERROR_HEIGHT_TOO_SMALL] = ( 'Video height must be at least {} pixels.'.format(min_height)) if (inputs[job_io_fields.VIDEO_STREAM_WIDTH_PIXELS] > mediaconvert_constants.MAX_WIDTH_SUPPORTED_BY_MEDIACONVERT): outputs[job_io_fields.ERROR_WIDTH_TOO_LARGE] = ( 'Video width must be at most {} pixels.'.format( mediaconvert_constants.MAX_WIDTH_SUPPORTED_BY_MEDIACONVERT)) if (inputs[job_io_fields.VIDEO_STREAM_HEIGHT_PIXELS] > mediaconvert_constants.MAX_HEIGHT_SUPPORTED_BY_MEDIACONVERT): outputs[job_io_fields.ERROR_HEIGHT_TOO_LARGE] = ( 'Video height must be at most {} pixels.'.format( mediaconvert_constants.MAX_HEIGHT_SUPPORTED_BY_MEDIACONVERT)) return outputs