void GetCustomProfile() { if (_UseMp4) { _Profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Wvga); } else { _Profile = MediaEncodingProfile.CreateWmv(VideoEncodingQuality.Wvga); } try { _Profile.Video.Width = UInt32.Parse(VideoW.Text); _Profile.Video.Height = UInt32.Parse(VideoH.Text); _Profile.Video.Bitrate = UInt32.Parse(VideoBR.Text); _Profile.Video.FrameRate.Numerator = UInt32.Parse(VideoFR.Text); _Profile.Video.FrameRate.Denominator = 1; _Profile.Audio.BitsPerSample = UInt32.Parse(AudioBPS.Text); _Profile.Audio.ChannelCount = UInt32.Parse(AudioCC.Text); _Profile.Audio.Bitrate = UInt32.Parse(AudioBR.Text); _Profile.Audio.SampleRate = UInt32.Parse(AudioSR.Text); } catch (Exception exception) { TranscodeError(exception.Message); _Profile = null; } }
public IAsyncOperationWithProgress<TranscodeFailureReason, double> RenderToFileAsync(StorageFile video, MediaEncodingProfile profile) { TimeSpan end = clip.OriginalDuration - FinishPosition; // Set trimming clip.TrimTimeFromStart = StartPosition; clip.TrimTimeFromEnd = end > TimeSpan.Zero ? end : TimeSpan.Zero; // Render return composition.RenderToFileAsync( video, MediaTrimmingPreference.Precise, profile ); }
void GetCustomProfile() { if (_UseMp4) { _Profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Wvga); } else { _Profile = MediaEncodingProfile.CreateWmv(VideoEncodingQuality.Wvga); } try { _Profile.Video.Width = UInt32.Parse(VideoW.Text); _Profile.Video.Height = UInt32.Parse(VideoH.Text); _Profile.Video.Bitrate = UInt32.Parse(VideoBR.Text); _Profile.Video.FrameRate.Numerator = UInt32.Parse(VideoFR.Text); _Profile.Video.FrameRate.Denominator = 1; _Profile.Audio.BitsPerSample = UInt32.Parse(AudioBPS.Text); _Profile.Audio.ChannelCount = UInt32.Parse(AudioCC.Text); _Profile.Audio.Bitrate = UInt32.Parse(AudioBR.Text); _Profile.Audio.SampleRate = UInt32.Parse(AudioSR.Text); // Video sources providing more than about 250 megapixels per second require the // H.264 encoder to be set to level 5.2. Information about H.264 encoding levels: // https://en.wikipedia.org/wiki/Advanced_Video_Coding#Levels // Windows doesn't always set the higher level automatically so it should be set // explicitly to avoid encoding failures. Constants needed to set the encoding level: // https://docs.microsoft.com/en-us/windows/win32/medfound/mf-mt-video-level // https://docs.microsoft.com/en-us/windows/win32/api/codecapi/ne-codecapi-eavench264vlevel if (_UseMp4) { const int c_PixelsPerSecondRequiringLevel52 = 250000000; if (_Profile.Video.Width * _Profile.Video.Height * _Profile.Video.FrameRate.Numerator / _Profile.Video.FrameRate.Denominator > c_PixelsPerSecondRequiringLevel52) { _Profile.Video.Properties[MediaFoundationConstants.MF_MT_VIDEO_LEVEL] = (UInt32)MediaFoundationConstants.eAVEncH264VLevel.eAVEncH264VLevel5_2; } } } catch (Exception exception) { TranscodeError(exception.Message); _Profile = null; } }
public async Task<MediaCapture> Initialize(CaptureUse primaryUse = CaptureUse.Photo) { // Create MediaCapture and init mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); mediaCapture.VideoDeviceController.PrimaryUse = primaryUse; // Create photo encoding properties as JPEG and set the size that should be used for photo capturing imgEncodingProperties = ImageEncodingProperties.CreateJpeg(); imgEncodingProperties.Width = 640; imgEncodingProperties.Height = 480; // Create video encoding profile as MP4 videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); // Lots of properties for audio and video could be set here... return mediaCapture; }
private async void Run() { try { var files = await Windows.Storage.KnownFolders.VideosLibrary.GetFilesAsync( Windows.Storage.Search.CommonFileQuery.OrderBySearchRank, 0, 10); var pics = files.Where(f =>{ return f.Name.EndsWith("wmv"); }); foreach (var pic in pics) { _OutputFile = await KnownFolders.VideosLibrary.CreateFileAsync("out.mp4", CreationCollisionOption.GenerateUniqueName); _Profile = MediaEncodingProfile.CreateAvi(VideoEncodingQuality.Vga); var preparedTranscodeResult = await _Transcoder.PrepareFileTranscodeAsync(pic, _OutputFile, _Profile); _Transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default; if (preparedTranscodeResult.CanTranscode) { var progress = new Progress<double>(TranscodeProgress); _cts = new CancellationTokenSource(); await preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, progress); TranscodeComplete(); } else { TranscodeFailure(preparedTranscodeResult.FailureReason); } } } catch (TaskCanceledException) { TranscodeError("Transcode Canceled"); } catch (Exception exception) { Console.WriteLine("error"); Console.WriteLine(exception); TranscodeError(exception.Message); } }
public static async void VideoConvert(StorageFile file,MediaEncodingProfile mediaProfile,VideoItem caller) { try { var outFolder = await Settings.GetOutputFolder(); StorageFile audioFile; if (Settings.GetBoolSettingValueForKey(Settings.PossibleSettingsBool.SETTING_AUTO_RENAME) && caller.tagTitle != "") audioFile = await outFolder.CreateFileAsync(caller.tagTitle+"."+mediaProfile.Container.Subtype.ToLower(), CreationCollisionOption.ReplaceExisting); else audioFile = await outFolder.CreateFileAsync(file.Name.Replace("mp4", mediaProfile.Container.Subtype.ToLower()), CreationCollisionOption.ReplaceExisting); MediaTranscoder transcoder = new MediaTranscoder(); if (caller.trimEnd != null) transcoder.TrimStartTime = new TimeSpan(0, 0, 0, (int)caller.trimStart, 0); if (caller.trimEnd != null) transcoder.TrimStopTime = new TimeSpan(0, 0, 0, (int)caller.trimEnd, 0); var result = await transcoder.PrepareFileTranscodeAsync(file, audioFile, mediaProfile); if(result.CanTranscode) { var transcodeOp = result.TranscodeAsync(); transcodeOp.Progress += async (IAsyncActionWithProgress<double> asyncInfo, double percent) => { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { caller.SetConvProgress((int)percent); }); }; transcodeOp.Completed += (IAsyncActionWithProgress<double> asyncInfo, AsyncStatus status) => { QueueManager.Instance.ConvCompleted(caller.id); Utils.TryToRemoveFile(5, file); TagProcessing.SetTagsSharp(new TagsPackage(caller.tagArtist, caller.tagAlbum, caller.tagTitle,caller.AlbumCoverPath), audioFile); }; } } catch (Exception exc) { Debug.WriteLine("Conversion : " + exc.Message); } }
static void GetProfile() { try { _Profile = new MediaEncodingProfile(); /* * "3GP" 3GP file. * "AC3" AC-3 audio. * "ADTS" Audio Data Transport Stream (ADTS) stream. * "MP3" MPEG Audio Layer-3 (MP3). * "MPEG2PS" MPEG-2 program stream. * "MPEG2TS" MPEG-2 transport stream. * "MPEG4" MP4 file container. */ _Profile.Container.Subtype = "MPEG4"; _Profile.Audio.BitsPerSample = UInt32.Parse("16"); _Profile.Audio.SampleRate = UInt32.Parse("44100"); _Profile.Audio.Bitrate = UInt32.Parse("256000"); _Profile.Audio.ChannelCount = UInt32.Parse("2"); _Profile.Audio.Subtype = "AAC"; /* * "AAC" Advanced Audio Coding (AAC). The stream can contain either raw * AAC data or AAC data in an Audio Data Transport Stream (ADTS) stream. * "AC3" Dolby Digital audio (AC-3). * "EAC3" Dolby Digital Plus audio (E-AC-3). * "MP3" MPEG Audio Layer-3 (MP3). * "MPEG" MPEG-1 audio payload. * "PCM" Uncompressed 16-bit PCM audio. * "Float" Uncompressed 32-bit float PCM audio. * "WMA8" Windows Media Audio 8 codec, Windows Media Audio 9 codec, or Windows Media Audio 9.1 codec. * "WMA9" Windows Media Audio 9 Professional codec or Windows Media Audio 9.1 Professional codec. * "ADTS" Audio Data Transport Stream * "AACADTS" Advanced Audio Coding (AAC) audio in Audio Data Transport Stream (ADTS) format. * "AMRNB" Adaptive Multi-Rate audio codec (AMR-NB) * "AWRWB" Adaptive Multi-Rate Wideband audio codec (AMR-WB) */ } catch (Exception exception) { Console.Error.WriteLine(exception.Message); Environment.Exit(1); } }
void GetPresetProfile(ComboBox combobox) { Profile = null; VideoEncodingQuality videoEncodingProfile = VideoEncodingQuality.Wvga; switch (combobox.SelectedIndex) { case 0: videoEncodingProfile = VideoEncodingQuality.HD1080p; break; case 1: videoEncodingProfile = VideoEncodingQuality.HD720p; break; case 2: videoEncodingProfile = VideoEncodingQuality.Wvga; break; case 3: videoEncodingProfile = VideoEncodingQuality.Ntsc; break; case 4: videoEncodingProfile = VideoEncodingQuality.Pal; break; case 5: videoEncodingProfile = VideoEncodingQuality.Vga; break; case 6: videoEncodingProfile = VideoEncodingQuality.Qvga; break; } if (_UseMp4) { Profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(videoEncodingProfile); } else { Profile = MediaEncodingProfile.CreateWmv(videoEncodingProfile); } }
private async void Run() { try { var files = await Windows.Storage.KnownFolders.VideosLibrary.GetFilesAsync( Windows.Storage.Search.CommonFileQuery.OrderBySearchRank, 0, 10); var pics = files.Where(f => { return(f.Name.EndsWith("wmv")); }); foreach (var pic in pics) { _OutputFile = await KnownFolders.VideosLibrary.CreateFileAsync("out.mp4", CreationCollisionOption.GenerateUniqueName); _Profile = MediaEncodingProfile.CreateAvi(VideoEncodingQuality.Vga); var preparedTranscodeResult = await _Transcoder.PrepareFileTranscodeAsync(pic, _OutputFile, _Profile); _Transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default; if (preparedTranscodeResult.CanTranscode) { var progress = new Progress <double>(TranscodeProgress); _cts = new CancellationTokenSource(); await preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, progress); TranscodeComplete(); } else { TranscodeFailure(preparedTranscodeResult.FailureReason); } } } catch (TaskCanceledException) { TranscodeError("Transcode Canceled"); } catch (Exception exception) { Console.WriteLine("error"); Console.WriteLine(exception); TranscodeError(exception.Message); } }
public async Task<MediaCapture> Initialize(CaptureUse primaryUse = CaptureUse.Photo) { var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); mediaCapture = new MediaCapture(); if (devices.Count() > 0) { await this.mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = devices.ElementAt(1).Id, PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview }); } mediaCapture.VideoDeviceController.PrimaryUse = primaryUse; mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees); imgEncodingProperties = ImageEncodingProperties.CreateJpeg(); imgEncodingProperties.Width = 640; imgEncodingProperties.Height = 480; videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); return mediaCapture; }
public async Task InitialAsync(CaptureElement captureElement, MediaEncodingProfile profile = null, bool BackCamera = false) { if (initialized) Dispose(true); initialized = true; this.captureElement = captureElement; this.activeProfile = profile; if (CameraDeviceList == null) await EnumerateCameras(); mediaCapture = null; mediaCapture = new MediaCapture(); IsBackCamera = BackCamera; captureInitSettings = InitCaptureSettings(IsBackCamera); await mediaCapture.InitializeAsync(captureInitSettings); mediaCapture.VideoDeviceController.DesiredOptimization = MediaCaptureOptimization.LatencyThenQuality; mediaCapture.CameraStreamStateChanged += MediaCapture_CameraStreamStateChanged; mediaCapture.Failed += MediaCapture_Failed; mediaCapture.FocusChanged += MediaCapture_FocusChanged; mediaCapture.PhotoConfirmationCaptured += MediaCapture_PhotoConfirmationCaptured; mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded; mediaCapture.ThermalStatusChanged += MediaCapture_ThermalStatusChanged; await SetResolutionAsync(); if (Manager.DeviceService.CurrentDevice() == DeviceTypes.Mobile) { if (IsBackCamera) { mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees); } else { mediaCapture.SetPreviewRotation(VideoRotation.Clockwise270Degrees); } } activeProfile = CreateProfile(); mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Video; captureElement.Source = mediaCapture; }
public void SetActiveProfile(MediaEncodingProfile profile) { this.activeProfile = profile; }
/// <summary> /// Initializes video preview and updates the <see cref="PreviewBrush"/> accordingly. /// </summary> /// <param name="previewFormatSelector"> /// Function that chooses the most suitable preview format from the provided collection. /// </param> /// <returns>Awaitable task.</returns> /// <exception cref="ArgumentNullException"><paramref name="previewFormatSelector"/> is <see langword="null"/>.</exception> /// <exception cref="InvalidOperationException">No suitable video preview formats found.</exception> public async Task StartPreviewAsync(Func<IEnumerable<VideoEncodingProperties>, VideoEncodingProperties> previewFormatSelector) { if (previewFormatSelector == null) { throw new ArgumentNullException("previewFormatSelector"); } Tracing.Trace("CameraController: Starting video preview."); if (!string.IsNullOrEmpty(this.PreviewVideoPort)) { Tracing.Trace("CameraController: Video preview is already started."); return; } try { // Set the video preview format. VideoEncodingProperties previewFormat = await this.DoSetMediaFormatAsync(MediaStreamType.VideoPreview, previewFormatSelector); MediaCapturePreviewSink previewSink = new MediaCapturePreviewSink(); VideoBrush videoBrush = new VideoBrush(); videoBrush.SetSource(previewSink); MediaEncodingProfile profile = new MediaEncodingProfile { Audio = null, Video = previewFormat }; await this.MediaCapture.StartPreviewToCustomSinkAsync(profile, previewSink); this.PreviewFormat = previewFormat; this.PreviewResolution = new Size(previewFormat.Width, previewFormat.Height); this.PreviewBrush = videoBrush; this.PreviewVideoPort = previewSink.ConnectionPort; //// //// Update camera properties. //// this.Rotation = this.MediaCapture.GetPreviewRotation(); this.FocusSupported = this.MediaCapture.VideoDeviceController.FocusControl.Supported; this.FocusAtPointSupported = this.MediaCapture.VideoDeviceController.RegionsOfInterestControl.AutoFocusSupported && this.MediaCapture.VideoDeviceController.RegionsOfInterestControl.MaxRegions > 0; this.ContinuousAutoFocusSupported = this.MediaCapture.VideoDeviceController.FocusControl.SupportedFocusModes.Contains(FocusMode.Continuous); this.FlashSupported = this.MediaCapture.VideoDeviceController.FlashControl.Supported; if (this.FocusSupported) { this.ConfigureAutoFocus(continuous: false); if (this.MediaCapture.VideoDeviceController.FocusControl.FocusChangedSupported) { this.MediaCapture.FocusChanged += this.MediaCaptureFocusChanged; } } this.NotifyPropertiesChanged(); } catch (Exception e) { Tracing.Trace("CameraController: StartPreviewAsync: 0x{0:X8}\r\n{1}", e.HResult, e); throw; } Tracing.Trace("CameraController: Video preview started."); }
void GetCustomProfile() { if(_UseMp4) { _Profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Wvga); } else { _Profile = MediaEncodingProfile.CreateWmv(VideoEncodingQuality.Wvga); } try { _Profile.Video.Width = UInt32.Parse(VideoW.Text); _Profile.Video.Height = UInt32.Parse(VideoH.Text); _Profile.Video.Bitrate = UInt32.Parse(VideoBR.Text); _Profile.Video.FrameRate.Numerator = UInt32.Parse(VideoFR.Text); _Profile.Video.FrameRate.Denominator = 1; _Profile.Audio.BitsPerSample = UInt32.Parse(AudioBPS.Text); _Profile.Audio.ChannelCount = UInt32.Parse(AudioCC.Text); _Profile.Audio.Bitrate = UInt32.Parse(AudioBR.Text); _Profile.Audio.SampleRate = UInt32.Parse(AudioSR.Text); } catch (Exception exception) { TranscodeError(exception.Message); _Profile = null; } }
private void Initialize() { _settings = new MediaCaptureInitializationSettings(); _settings.StreamingCaptureMode = StreamingCaptureMode.Audio; _capturer = new MediaCapture(); _profile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High); }
public void PrintMicrophoneSample() { MediaCapture capture; IRandomAccessStream stream; const int BufferSize = 64000; bool recording; float volume = 100; capture = new MediaCapture(); stream = new InMemoryRandomAccessStream(); var captureInitSettings2 = new MediaCaptureInitializationSettings(); captureInitSettings2.StreamingCaptureMode = StreamingCaptureMode.Audio; capture.InitializeAsync(captureInitSettings2).AsTask().Wait(); capture.AudioDeviceController.VolumePercent = volume; MediaEncodingProfile profile = new MediaEncodingProfile(); AudioEncodingProperties audioProperties = AudioEncodingProperties.CreatePcm(16000, 1, 16); profile.Audio = audioProperties; profile.Video = null; profile.Container = new ContainerEncodingProperties() { Subtype = MediaEncodingSubtypes.Wave }; capture.StartRecordToStreamAsync(profile, stream).GetResults(); recording = true; // waste time for (int i = 0; i < 5; i++) { i = i * 232323 + 89;// WriteLine(i); } capture.StopRecordAsync().GetResults(); byte[] wav = new byte[stream.Size]; stream.Seek(0); stream.ReadAsync(wav.AsBuffer(), (uint)stream.Size, InputStreamOptions.None).GetResults(); int sum = 0; for(int i = 0; i < wav.Count(); i++) { sum += (int) wav[i]; } WriteLine((double) wav.Count() / sum); }
static VideoEncodingProfile() { Instance = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Wvga); }
/// <summary> /// Initializes the MediaCapture, registers events, gets camera device information for mirroring and rotating, starts preview and unlocks the UI /// </summary> /// <returns></returns> private async Task InitializeCameraAsync() { Debug.WriteLine("InitializeCameraAsync"); if (_mediaCapture == null) { // Attempt to get the back camera if one is available, but use any camera device if not var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back); if (cameraDevice == null) { Debug.WriteLine("No camera device found!"); return; } // Create MediaCapture and its settings _mediaCapture = new MediaCapture(); // Register for a notification when video recording has reached the maximum time and when something goes wrong _mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded; _mediaCapture.Failed += MediaCapture_Failed; var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id }; // Initialize MediaCapture try { await _mediaCapture.InitializeAsync(settings); _isInitialized = true; } catch (UnauthorizedAccessException) { Debug.WriteLine("The app was denied access to the camera"); } catch (Exception ex) { Debug.WriteLine("Exception when initializing MediaCapture with {0}: {1}", cameraDevice.Id, ex.ToString()); } // Set up the encoding profile for video recording _encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); // If initialization succeeded, start the preview if (_isInitialized) { // Figure out where the camera is located if (cameraDevice.EnclosureLocation == null || cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown) { // No information on the location of the camera, assume it's an external camera, not integrated on the device _externalCamera = true; } else { // Camera is fixed on the device _externalCamera = false; // Only mirror the preview if the camera is on the front panel _mirroringPreview = (cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front); } await StartPreviewAsync(); UpdateCaptureControls(); } } }
/// <summary> /// Initializes the <see cref="MediaCapture"/> element. /// </summary> /// <param name="primaryUse"> /// The primary use for the camera. /// </param> /// <param name="videoQuality"> /// The video quality (for recording only). /// </param> /// <returns> /// The <see cref="MediaCapture"/>. /// </returns> public async Task<MediaCapture> Initialize( CaptureUse primaryUse, VideoEncodingQuality videoQuality) { if (this._mediaCapture != null) { this.Dispose(); } this.IsCameraAvailable = true; var camera = await this.GetCamera(this.ActiveCamera); this._mediaCapture = new MediaCapture(); this._mediaCapture.Failed += this.OnMediaCaptureFailed; await this._mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = camera.Id }); this._mediaCapture.VideoDeviceController.PrimaryUse = primaryUse; this._imageEncodingProperties = ImageEncodingProperties.CreateJpeg(); this._videoEncodingProfile = MediaEncodingProfile.CreateMp4(videoQuality); this.SetEncodingProperties(primaryUse); var rotation = this.GetVideoRotation(DisplayInformation.GetForCurrentView().CurrentOrientation); if (primaryUse == CaptureUse.Photo) { await this._mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync( MediaStreamType.Photo, this._mediaEncodingProperties); this.IsFlashAvailable = this.Settings.FlashControl.Supported; } else if (primaryUse == CaptureUse.Video) { await this._mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync( MediaStreamType.VideoPreview, this._mediaEncodingProperties); await this._mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync( MediaStreamType.VideoRecord, this._mediaEncodingProperties); this.SetRecordOrientation(rotation); this.IsFlashAvailable = this.Settings.TorchControl.Supported; } this._mediaCapture.SetPreviewRotation(rotation); return this._mediaCapture; }
public static async void VideoConvert(string fileName,MediaEncodingProfile mediaProfile,VideoItem caller) { var outFolder = await Settings.GetOutputFolder(); StorageFile file = await outFolder.GetFileAsync(fileName); VideoConvert(file, mediaProfile,caller); }
void GetPresetProfile(ComboBox combobox) { _Profile = null; VideoEncodingQuality videoEncodingProfile = VideoEncodingQuality.Wvga; switch (combobox.SelectedIndex) { case 0: videoEncodingProfile = VideoEncodingQuality.HD1080p; break; case 1: videoEncodingProfile = VideoEncodingQuality.HD720p; break; case 2: videoEncodingProfile = VideoEncodingQuality.Wvga; break; case 3: videoEncodingProfile = VideoEncodingQuality.Ntsc; break; case 4: videoEncodingProfile = VideoEncodingQuality.Pal; break; case 5: videoEncodingProfile = VideoEncodingQuality.Vga; break; case 6: videoEncodingProfile = VideoEncodingQuality.Qvga; break; } switch(_OutputType) { case "AVI": _Profile = MediaEncodingProfile.CreateAvi(videoEncodingProfile); break; case "WMV": _Profile = MediaEncodingProfile.CreateWmv(videoEncodingProfile); break; default: _Profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(videoEncodingProfile); break; } /* For transcoding to audio profiles, create the encoding profile using one of these APIs: MediaEncodingProfile.CreateMp3(audioEncodingProfile) MediaEncodingProfile.CreateM4a(audioEncodingProfile) MediaEncodingProfile.CreateWma(audioEncodingProfile) MediaEncodingProfile.CreateWav(audioEncodingProfile) where audioEncodingProfile is one of these presets: AudioEncodingQuality.High AudioEncodingQuality.Medium AudioEncodingQuality.Low */ }
public async void ExtractAudio(string artist, string title, StorageFile videoFile, StorageFile audioFile) { if (this.transcoder == null) { this.transcoder = new MediaTranscoder(); this.encodingProfile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High); } var preparedTranscodeResult = await this.transcoder.PrepareFileTranscodeAsync(videoFile, audioFile, this.encodingProfile); await preparedTranscodeResult.TranscodeAsync(); await TagStorageFile(artist, title, audioFile); }
/// <summary> /// Starts media recording asynchronously /// </summary> /// <param name="encodingProfile"> /// Encoding profile used for the recording session /// </param> public async Task StartRecordingAsync(MediaEncodingProfile encodingProfile) { try { // We cannot start recording twice. if (mediaSink != null && recordingStarted) { throw new InvalidOperationException("Recording already started."); } // Release sink if there is one already. CleanupSink(); // Create new sink mediaSink = new StspMediaSink(); mediaSink.IncomingConnectionEvent += mediaSink_IncomingConnectionEvent; await mediaSink.InitializeAsync(encodingProfile.Audio, encodingProfile.Video); await mediaCapture.StartRecordToCustomSinkAsync(encodingProfile, mediaSink); recordingStarted = true; } catch (Exception e) { CleanupSink(); throw e; } }
public IAsyncOperationWithProgress<TranscodeFailureReason, double> RenderToFileAsync(StorageFile video, MediaEncodingProfile profile) { // Render return composition.RenderToFileAsync( video, MediaTrimmingPreference.Precise, profile ); }
void GetPresetProfile(ComboBox combobox) { _Profile = null; VideoEncodingQuality videoEncodingProfile = VideoEncodingQuality.Wvga; switch (combobox.SelectedIndex) { case 0: videoEncodingProfile = VideoEncodingQuality.HD1080p; break; case 1: videoEncodingProfile = VideoEncodingQuality.HD720p; break; case 2: videoEncodingProfile = VideoEncodingQuality.Wvga; break; case 3: videoEncodingProfile = VideoEncodingQuality.Ntsc; break; case 4: videoEncodingProfile = VideoEncodingQuality.Pal; break; case 5: videoEncodingProfile = VideoEncodingQuality.Vga; break; case 6: videoEncodingProfile = VideoEncodingQuality.Qvga; break; } switch (_OutputType) { case "AVI": _Profile = MediaEncodingProfile.CreateAvi(videoEncodingProfile); break; case "WMV": _Profile = MediaEncodingProfile.CreateWmv(videoEncodingProfile); break; default: _Profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(videoEncodingProfile); break; } /* * For transcoding to audio profiles, create the encoding profile using one of these APIs: * MediaEncodingProfile.CreateMp3(audioEncodingProfile) * MediaEncodingProfile.CreateM4a(audioEncodingProfile) * MediaEncodingProfile.CreateWma(audioEncodingProfile) * MediaEncodingProfile.CreateWav(audioEncodingProfile) * * where audioEncodingProfile is one of these presets: * AudioEncodingQuality.High * AudioEncodingQuality.Medium * AudioEncodingQuality.Low */ }
void 音訊或視訊檔案的編碼設定() { encodingProfile = null; string xs = 選擇視訊編碼格式.SelectedItem as string; switch (xs) { case "Auto": SelectedQuality = VideoEncodingQuality.Auto; break; case "HD1080p": SelectedQuality = VideoEncodingQuality.HD1080p; break; case "HD720p": //SelectedQuality = VideoEncodingQuality.HD720p; break; case "Wvga": SelectedQuality = VideoEncodingQuality.Wvga; break; case "Ntsc": SelectedQuality = VideoEncodingQuality.Ntsc; break; case "Pal": SelectedQuality = VideoEncodingQuality.Pal; break; case "Vga": SelectedQuality = VideoEncodingQuality.Vga; break; case "Qvga": SelectedQuality = VideoEncodingQuality.Qvga; break; } encodingProfile = MediaEncodingProfile.CreateMp4(SelectedQuality); AudioStream = new InMemoryRandomAccessStream(); }