0

ユーザーがアプリ内からビデオを作成できるようにすると、.jpg サムネイル画像が自動的に生成されるはずだと言われました。ただし、Windows Phone パワー ツールを使用すると、ビデオのみが生成され、画像は生成されないことがわかります。以下にコードを示します。

編集: ここでの質問は、分離ストレージに保存されている特定のビデオからサムネイル画像を取得する方法です。

        ' Set recording state: start recording.
Private Async Sub StartVideoRecording()
    Try
        App.ViewModel.IsDataLoaded = False

        'isoStore = Await ApplicationData.Current.LocalFolder.GetFolderAsync("IsolatedStore")
        strVideoName = GenerateVideoName()
        isoFile = Await isoVideoFolder.CreateFileAsync(strVideoName, CreationCollisionOption.ReplaceExisting)
        thisAccessStream = Await isoFile.OpenAsync(FileAccessMode.ReadWrite)
        Await avDevice.StartRecordingToStreamAsync(thisAccessStream)

        'save the name of the video file into the list of video files in isolated storage settings
        Dim videoList As New List(Of InfoViewModel)

        isoSettings = IsolatedStorageSettings.ApplicationSettings
        If isoSettings.Contains("ListOfVideos") Then
            videoList = isoSettings("ListOfVideos")
        Else
            isoSettings.Add("ListOfVideos", videoList)
        End If
        videoList.Add(New InfoViewModel With {.Name = strVideoName, .DateRecorded = Date.Now})
        isoSettings("ListOfVideos") = videoList
        isoSettings.Save()
        isoSettings = Nothing


        ' Set the button states and the message.
        UpdateUI(ButtonState.Recording, "Recording...")
    Catch e As Exception
        ' If recording fails, display an error.
        Me.Dispatcher.BeginInvoke(Sub() txtDebug.Text = "ERROR: " & e.Message.ToString())
    End Try
End Sub
4

1 に答える 1

1

Windows Phone 7.0 では、 CameraCaptureTaskを使用する以外に、「公式」SDK を使用してカメラにアクセスすることはできませんでした。しかし、Microsoft.Phone.InteropServicesライブラリを使用すると、アプリケーションでカスタム カメラ ビューを作成することができました。このVideoCameraクラスを使用した場合は、 というイベントがありましたThumbnailSavedToDisk。これは、聞いたことがあるかもしれません。しかし、アプリの使用Microsoft.Phone.InteropServicesは Windows Phone マーケットプレースでは許可されていませんでした。詳細については、こちらをご覧ください


ビデオ ファイルからサムネイルを生成する 1 つの解決策は、MP4 ファイル形式がどのように機能するかを調べて、フレームの 1 つを抽出し、それをサムネイルとして使用することです。残念ながら、これを実行できるライブラリは見つかりませんでした。

最適な解決策とはほど遠いもう 1 つの方法は、MediaElement でビデオを再生し、その Control をビットマップにレンダリングすることです。これは、次のコードで実行できます (XAML/C# で記述されています。VB.net はわかりませんが、簡単に移植できるはずです)。

<MediaElement 
    x:Name="VideoPlayer" 
    Width="640" 
    Height="480"
    AutoPlay="True" 
    RenderTransformOrigin="0.5, 0.5" 
    VerticalAlignment="Center" 
    HorizontalAlignment="Center" 
    Stretch="Fill"
    Canvas.Left="80"/>

次に、サムネイルを作成します。

// Set an event handler for when video has loaded
VideoPlayer.MediaOpened += VideoPlayer_MediaOpened;
// Read video from storage
IsolatedStorageFileStream videoFile = new IsolatedStorageFileStream("MyVideo.mp4", FileMode.Open, FileAccess.Read, IsolatedStorageFile.GetUserStoreForApplication());
VideoPlayer.SetSource(videoFile);
// Start playback
VideoPlayer.Play();

次に、サムネイルを「キャプチャ」するイベント ハンドラーを作成します。

void VideoPlayer_MediaOpened(object sender, RoutedEventArgs e)
{
    Thread.Sleep(100); // Wait for a short time to avoid black frame
    WriteableBitmap wb = new WriteableBitmap(VideoPlayer, new TranslateTransform());
    thumbnailImageHolder.Source = wb; // Setting it to a Image in the XAML code to see it
    VideoPlayer.Stop();
}

Video Recorder Sampleの修正版を使用すると、次のようになります。(右上隅にある青い枠の小さな画像は、録画されたビデオのサムネイルです。その後ろはカメラ ビューアーです。)

ここに画像の説明を入力

于 2013-03-26T17:32:12.347 に答える