示例#1
0
        private static void ValidateAlternateAudioToVideo(IMediaInfoFacade mediaInfoFacade, string audioPath)
        {
            var             result = new MediaInfoValidationResult();
            MediaInfoResult mi;

            try
            {
                mi = mediaInfoFacade.Read(audioPath);
            }
            catch (Exception ex)
            {
                throw new OrderException("Error while reading metadata from file. " + ex.Message);
            }
            ValidateAudioInVideo(mi);
        }
示例#2
0
        private static MediaInfoValidationResult MediaInfoValidation(IMediaInfoFacade mediaInfoFacade, string filePath, bool skipAsceptRatioValidation = false, bool skipResolutionValidation = false)
        {
            var             result = new MediaInfoValidationResult();
            MediaInfoResult mi;

            try
            {
                mi = mediaInfoFacade.Read(filePath);
            }
            catch (Exception ex)
            {
                throw new OrderException("Error while reading metadata from file. " + ex.Message);
            }

            if (mi != null)
            {
                result.Duration = mi.Duration;
            }

            if (mi?.Video != null)
            {
                var         videoStream = mi.Video;
                StateFormat temp;
                if (Enum.TryParse(videoStream.CodecId, out temp))
                {
                    result.Format = temp;
                }
                else
                {
                    // TODO: Temp work around , allows unknow formats. Should rather throw when we know all allowed formats.
                    //throw new OrderException("File is not in a valid format. Source file must be dvpp, dv5p or xd5c format.");
                    result.Format       = StateFormat.custom;
                    result.CustomFormat = videoStream.CodecId;
                }
                if (!skipAsceptRatioValidation)
                {
                    switch (videoStream.DisplayAspectRatio)
                    {
                    case DisplayAspectRatio.ratio_4x3:
                        result.AspectRatio = AspectRatio.ratio_4x3;
                        break;

                    case DisplayAspectRatio.ratio_16x9:
                        result.AspectRatio = AspectRatio.ratio_16x9;
                        break;

                    case DisplayAspectRatio.unknown:
                    default:
                        throw new OrderException("Unsupport aspect ratio. Only 16x9 and 4x3 is supported.");
                    }
                }

                if (!skipResolutionValidation)
                {
                    switch (videoStream.Resolution)
                    {
                    case MediaInfoService.Resolution.sd:
                        result.Resolution = Resolution.sd;
                        break;

                    case MediaInfoService.Resolution.hd:
                        result.Resolution = Resolution.hd;
                        break;

                    case MediaInfoService.Resolution.full_hd:
                        result.Resolution = Resolution.fullhd;
                        break;

                    case MediaInfoService.Resolution.unknown:
                    default:
                        throw new OrderException("Unsupport resultion. Only sd, hd and fullhd is supported.");
                    }
                }

                ValidateAudioInVideo(mi);
            }
            else if (mi?.Audio != null)
            {
                var         audioStream = mi.Audio;
                StateFormat temp;

                if (Enum.TryParse(audioStream.Format, out temp))
                {
                    result.Format = temp;
                }
                else
                {
                    // TODO: Temp work around , allows unknow formats. Should rather throw when we know all allowed formats.
                    result.Format       = StateFormat.custom;
                    result.CustomFormat = audioStream.Format;
                }
            }
            else
            {
                throw new OrderException("File is not a valid media file. Source file must be dv5p or xd5c for video or wma, mpeg or pcm for audio format or wav for alternate audio.");
            }

            return(result);
        }