2017-06-23 1 views
0

In einem UWP C++/CX-Projekt versuche ich, Screenshots von jedem Frame eines MediaCapture Camera Stream zu erstellen und den Stream als Video am Ende zu speichern. Mein Ansatz:Wie extrahieren Sie Frames aus einem Stream-Datensatz in einem UWP C++ - Projekt?

/// <summary> 
/// Records an MP4 video to a StorageFile and adds rotation metadata to it 
/// </summary> 
/// <returns></returns> 
task<void> CameraControl::StartRecordingAsyncStream() 
{ 
//InMemoryRandomAccessStream^ video_stream; 
// Calculate rotation angle, taking mirroring into account if necessary 
auto rotationAngle = CameraRotationHelper::ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper->GetCameraCaptureOrientation()); 
auto encodingProfile = MediaProperties::MediaEncodingProfile::CreateMp4(MediaProperties::VideoEncodingQuality::Auto); 

encodingProfile->Video->Properties->Insert(RotationKey, rotationAngle); 


return create_task(_mediaCapture->StartRecordToStreamAsync(encodingProfile, this->video_stream)) 
    .then([this]() 
{ 
    _isRecording = true; 
    WriteLine("Started recording"); 


}).then([this](task<void> previousTask) 
{ 
    try 
    { 
     previousTask.get(); 
    } 
    catch (Exception^ ex) 
    { 
     // File I/O errors are reported as exceptions 
     WriteLine(ex->Message); 
    } 
}); 
} 

/// <summary> 
/// Stops recording a video 
/// </summary> 
/// <returns></returns> 
task<void> CameraControl::StopRecordingAsyncStream() 
{ 
_isRecording = false; 

WriteLine("Stopping recording..."); 
return create_task(_mediaCapture->StopRecordAsync()) 
    .then([this]() 
{ 
    WriteLine("Stopped recording!"); 

    }); 
} 


//Loads all frames as images from the stream 
void CameraControl::LoadVideoStream(void) { 

//TODO: Read all Frames as Thumbnails from "this->video_stream" and store them as Bitmaps, for example in a vector 

} 

/// <summary> 
/// Stores the recorded stream as a MP4 video 
/// </summary> 
/// <returns></returns> 
task<void> CameraControl::StoreRecordingAsync() 
{ 

// Create storage file for the capture 
return create_task(_captureFolder->CreateFileAsync("SimpleVideo.mp4", CreationCollisionOption::GenerateUniqueName)) 
    .then([this](StorageFile^ file) 
{ 

//TODO: Write the "this->video_stream" as a MP4 video to the file 

}); 
} 

Für die erste Frage, ich brauche so etwas wie ein MP4Decoder, die den Strom (ähnlich dem BitmapDecoder für CapturePhotoToStreamAsync)

auf die zweite Frage umwandeln kann: Ich weiß, dass es eine Funktion ist "StartRecordToStorageFileAsync". Aber das ist keine Lösung, denn das Video zu speichern ist optional am Ende. Ich möchte nicht jedes Video speichern.

Danke!

Corono

EDIT:

Ich habe versucht, einen Medienrahmen Reader zu implementieren, die eine FrameArrived Ereignis hat.

public : IAsyncOperation<MediaFrameReader> CreateFrameReaderAsync(MediaFrameSource inputSource) 

Funktioniert gut auf dem PC, aber es gibt keine MediaFrameSource auf den mobilen Win10-Geräten. Keine Ahnung warum.

+0

Warum möchten Sie Screenshots von jedem Frame eines MediaCapture Camera Stream erstellen? Es scheint, wir können das Video direkt speichern. –

+0

Weil ich kein Video will, brauche ich einen Strom von Bildern, um eine Bewegung Schritt für Schritt zu analysieren. Das Speichern des Videos sollte nur eine Option nach der Analyse sein. – Corono

Antwort

Verwandte Themen