none
How to set VideoProperties.Orientation

    Question

  • Hi all

    I am developing a camera app, and I want to set the orientation properties of video file recorded from different view(Ex: Portrait view)

    I have tried MediaCapture.SetRecordRotation, but the result is not what I want.

    From my observation, the built-in camera doesn't set the record orientation for different view, instead, it changes the orientation property of video files, so player will know how to display.

    So far, I have found that MediaCapture.SetEncoderProperty(MediaStreamType.VideoRecord, Guid("MF_MT_VIDEO_ROTATION "),PropertyValue)

    might be the answer, but i can't make it work.

    (information about MF_MT_VIDEO_ROTATION attribute :http://msdn.microsoft.com/en-us/library/windows/desktop/hh162880(v=vs.85).aspx)

    Here is the code I've got

    enum MFVideoRotationFormat : uint
    {
                MFVideoRotationFormat_0 = 0,
                MFVideoRotationFormat_90 = 90,
                MFVideoRotationFormat_180 = 180,
                MFVideoRotationFormat_270 = 270,
     };
    
    
    private async startRecord()
    {
    	StorageFile RecordStorageFile= await ApplicationData.Current.LocalFolder.CreateFileAsync(VideoFileName, CreationCollisionOption.GenerateUniqueName);
    
    	MFVideoRotationFormat mfVidoeRotation=MFVideoRotationFormat.MFVideoRotationFormat_0;
    
    	mMediaCaptureMgr.SetEncoderProperty(MediaStreamType.VideoRecord, new Guid("{C380465D-2271-428C-9B83-ECEA3B4A85C1}"), mfVidoeRotation);
    
    	Windows.Media.MediaProperties.MediaEncodingProfile recordProfile = null;
    
            recordProfile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto);
    
    	await mMediaCaptureMgr.StartRecordToStorageFileAsync(recordProfile, RecordStorageFile);
    }

    So, how to make it work, or is there any other ways to set the orientation properties.

    Any suggestion would be appreciated!

    Thanks

    Wednesday, January 09, 2013 10:04 AM

Answers

  • Hi,

    It looks like you need to set the orientation property on recordProfile.Video directly.

    Can you try this and see if this helps? -

    var MF_MT_VIDEO_ROTATION = new Guid("{C380465D-2271-428C-9B83-ECEA3B4A85C1}");

           recordProfile.Video.Properties[MF_MT_VIDEO_ROTATION] = (UInt32)180;

    - Ashish [MSFT]


    Ashish Sahu [MSFT]

    Monday, January 14, 2013 4:56 PM

All replies

  • Hi all

    I have meet the same  problem.  I have tried  BitmapEncoder but have no idea to decode and encode stream.

    I meet System.Exception while I am trying to set System.Video.Orientation property. The error shows that the property is ReadOnly.

    the code bellow is what I tried. Is there any thing  I can do?

                    inputStream = await tempStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
    
                    var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(inputStream);
    
                    photoStorage = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
    
                    outputStream = await photoStorage.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
    
                    outputStream.Size = 0;
    
                    var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);
    
                    var properties = new Windows.Graphics.Imaging.BitmapPropertySet();
                    properties.Add("System.Photo.Orientation",
                        new Windows.Graphics.Imaging.BitmapTypedValue(photoRotation, Windows.Foundation.PropertyType.UInt16));
    
                    await encoder.BitmapProperties.SetPropertiesAsync(properties);
    
                    await encoder.FlushAsync();


    Thursday, January 10, 2013 9:10 AM
  • Hi,

    It looks like you need to set the orientation property on recordProfile.Video directly.

    Can you try this and see if this helps? -

    var MF_MT_VIDEO_ROTATION = new Guid("{C380465D-2271-428C-9B83-ECEA3B4A85C1}");

           recordProfile.Video.Properties[MF_MT_VIDEO_ROTATION] = (UInt32)180;

    - Ashish [MSFT]


    Ashish Sahu [MSFT]

    Monday, January 14, 2013 4:56 PM