原創|使用教程|編輯:張瑩心|2021-10-28 11:29:26.060|閱讀 259 次
概述:Microsoft PowerPoint 使您能夠將視頻幀添加到 PowerPoint 演示文稿中。視頻可用于提高演示的質量,并有助于更好地向觀眾傳達信息。在某些情況下,您可能希望以編程方式向 PowerPoint 演示文稿添加視頻。為此,本文將教您 如何使用 C++ 在 PowerPoint 演示文稿中嵌入視頻。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Microsoft PowerPoint 使您能夠將視頻幀添加到 PowerPoint 演示文稿中。視頻可用于提高演示的質量,并有助于更好地向觀眾傳達信息。在某些情況下,您可能希望以編程方式向 PowerPoint 演示文稿添加視頻。為此,本文將教您 如何使用 C++ 在 PowerPoint 演示文稿中嵌入視頻。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
// File paths const String videoFilePath = u"SourceDirectory\\Video\\Wildlife.mp4"; const String outputFilePath = u"OutputDirectory\\EmbedVideo_out.pptx"; // Create an instance of the Presentation class SharedPtr<Presentation> presentation = MakeObject<Presentation>(); // Access the first slide SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0); // Load the video file to stream System::SharedPtr<System::IO::Stream> stream = System::MakeObject<System::IO::FileStream>(videoFilePath, System::IO::FileMode::Open, System::IO::FileAccess::Read); // Add the video to the presentation System::SharedPtr<IVideo> vid = presentation->get_Videos()->AddVideo(stream); // Add video frame System::SharedPtr<IVideoFrame> videoFrame = slide->get_Shapes()->AddVideoFrame(50, 150, 300, 150, vid); // Embed video inside the video frame videoFrame->set_EmbeddedVideo(vid); // Set the play mode and volume of the video videoFrame->set_PlayMode(VideoPlayModePreset::Auto); videoFrame->set_Volume(AudioVolumeMode::Loud); // Save the presentation presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File path const String outputFilePath = u"OutputDirectory\\EmbedVideoFromWeb_out.pptx"; // Create an instance of the Presentation class SharedPtr<Presentation> presentation = MakeObject<Presentation>(); // Access the first slide SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0); // Add the video frame from web source System::SharedPtr<IVideoFrame> videoFrame = slide->get_Shapes()->AddVideoFrame(10, 10, 427, 240, u"http://www.youtube.com/embed/sZJorZmHiIk"); // Set the play mode and volume of the video videoFrame->set_PlayMode(VideoPlayModePreset::Auto); // Save the presentation presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths const String sourceFilePath = u"OutputDirectory\\EmbedVideo_out.pptx"; const String outputFilePath = u"OutputDirectory\\ExtractVideoFromSlide_out."; // Load the presentation file System::SharedPtr<Presentation> presentation = System::MakeObject<Presentation>(sourceFilePath); { // Loop through the slides auto slide_enumerator = (presentation->get_Slides())->GetEnumerator(); decltype(slide_enumerator->get_Current()) slide; while (slide_enumerator->MoveNext() && (slide = slide_enumerator->get_Current(), true)) { // Loop through the shapes auto shape_enumerator = (presentation->get_Slides()->idx_get(0)->get_Shapes())->GetEnumerator(); decltype(shape_enumerator->get_Current()) shape; while (shape_enumerator->MoveNext() && (shape = shape_enumerator->get_Current(), true)) { // Check if the shape is a video frame if (System::ObjectExt::Is<VideoFrame>(shape)) { // Extract the video file System::SharedPtr<VideoFrame> vf = System::DynamicCast_noexcept<Aspose::Slides::VideoFrame>(shape); System::String type = vf->get_EmbeddedVideo()->get_ContentType(); int32_t ss = type.LastIndexOf(L'/'); type = type.Remove(0, type.LastIndexOf(L'/') + 1); System::ArrayPtr<uint8_t> buffer = vf->get_EmbeddedVideo()->get_BinaryData(); { System::SharedPtr<System::IO::FileStream> stream = System::MakeObject<System::IO::FileStream>(outputFilePath + type, System::IO::FileMode::Create, System::IO::FileAccess::Write, System::IO::FileShare::Read); // Clearing resources under 'using' statement //System::Details::DisposeGuard __dispose_guard_0{ stream, ASPOSE_CURRENT_FUNCTION }; // ------------------------------------------ stream->Write(buffer, 0, buffer->get_Length()); } } } } }
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn