Android でのプレゼンテーションにおけるビデオ フレームの管理
プレゼンテーションに適切に配置されたビデオは、メッセージをより説得力のあるものにし、聴衆とのエンゲージメントレベルを高めます。
PowerPointでは、プレゼンテーションのスライドにビデオを追加する方法が2つあります。
- ローカルビデオを追加または埋め込む(マシンに保存されているもの)
- オンラインビデオを追加する(YouTubeなどのウェブソースから)
プレゼンテーションにビデオ(ビデオ オブジェクト)を追加できるように、Aspose.SlidesはIVideoインターフェイス、IVideoFrameインターフェイス、およびその他の関連型を提供します。
埋め込みビデオ フレームの作成
スライドに追加したいビデオ ファイルがローカルに保存されている場合、プレゼンテーションにビデオを埋め込むためのビデオ フレームを作成できます。
- Presentation クラスのインスタンスを作成します。
- インデックスを使用してスライドの参照を取得します。
- IVideoオブジェクトを追加し、ビデオ ファイルのパスを渡してプレゼンテーションにビデオを埋め込みます。
- ビデオ用のフレームを作成するためにIVideoFrameオブジェクトを追加します。
- 変更されたプレゼンテーションを保存します。
This Java code shows you how to add a video stored locally to a presentation:
// Presentation クラスのインスタンスを作成
Presentation pres = new Presentation("pres.pptx");
try {
// ビデオをロード
FileInputStream fileStream = new FileInputStream("Wildlife.mp4");
IVideo video = pres.getVideos().addVideo(fileStream, LoadingStreamBehavior.KeepLocked);
// 最初のスライドを取得し、ビデオフレームを追加
pres.getSlides().get_Item(0).getShapes().addVideoFrame(10, 10, 150, 250, video);
// プレゼンテーションをディスクに保存
pres.save("pres-with-video.pptx", SaveFormat.Pptx);
} catch (IOException e) {
} finally {
if (pres != null) pres.dispose();
}
代わりに、ファイル パスを直接addVideoFrame(float x, float y, float width, float height, IVideo video)メソッドに渡してビデオを追加することもできます:
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 150, "video1.avi");
} finally {
if (pres != null) pres.dispose();
}
Web ソースからのビデオでビデオ フレームを作成
Microsoft PowerPoint 2013 and newerはプレゼンテーションでYouTubeビデオをサポートしています。使用したいビデオがオンラインで利用可能な場合(例:YouTube)、そのウェブリンクを介してプレゼンテーションに追加できます。
- Presentation クラスのインスタンスを作成します。
- インデックスを使用してスライドの参照を取得します。
- IVideoオブジェクトを追加し、ビデオへのリンクを渡します。
- ビデオ フレームのサムネイルを設定します。
- プレゼンテーションを保存します。
This Java code shows you how to add a video from the web to a slide in a PowerPoint presentation:
// プレゼンテーション ファイルを表す Presentation オブジェクトをインスタンス化
Presentation pres = new Presentation();
try {
addVideoFromYouTube(pres, "Tj75Arhq5ho");
pres.save("out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
private static void addVideoFromYouTube(Presentation pres, String videoID)
{
// ビデオフレームを追加
IVideoFrame videoFrame = pres.getSlides().get_Item(0).getShapes().addVideoFrame(
10, 10, 427, 240, "https://www.youtube.com/embed/" + videoID);
videoFrame.setPlayMode(VideoPlayModePreset.Auto);
// サムネイルをロード
String thumbnailUri = "http://img.youtube.com/vi/" + videoID + "/hqdefault.jpg";
URL url;
try {
url = new URL(thumbnailUri);
videoFrame.getPictureFormat().getPicture().setImage(pres.getImages().addImage(url.openStream()));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
ビデオ キャプションの管理
Aspose.Slidesを使用すると、PowerPoint プレゼンテーションのビデオ フレームに対してクローズド キャプションを管理できます。キャプションは WebVTT 形式で保存され、IVideoFrame.getCaptionTracksメソッドで取得できます。
ビデオ フレームにキャプションを追加
ビデオ フレームにキャプションを追加するには:
- Presentationクラスのインスタンスを作成します。
- プレゼンテーションにビデオを追加します。
- スライドにIVideoFrameオブジェクトを追加します。
- getCaptionTracksが返すICaptionsCollectionを使用して WebVTT キャプショントラックを追加します。
- 変更されたプレゼンテーションを保存します。
The following code shows you how to add captions to a video frame:
Presentation presentation = new Presentation();
try {
byte[] videoData = // "video.mp4";
IVideo video = presentation.getVideos().addVideo(videoData);
ISlide slide = presentation.getSlides().get_Item(0);
IVideoFrame videoFrame = slide.getShapes().addVideoFrame(0, 0, 100, 100, video);
// WebVTT ファイルから新しいキャプショントラックを追加します。
videoFrame.getCaptionTracks().add("English", "track.vtt");
presentation.save("video_with_captions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ICaptionsCollectionインターフェイスは、ストリームからキャプションを追加できるオーバーロードも提供します。
ビデオ フレームからキャプションを抽出
ビデオ フレームからキャプションを抽出するには:
- ビデオが含まれるプレゼンテーションをロードします。
- 対象のIVideoFrameオブジェクトを見つけます。
- getCaptionTracksが返すキャプショントラックを反復処理します。
- 各キャプショントラックを
.vttファイルとして保存します。
The following code shows you how to extract captions from a video frame:
Presentation presentation = new Presentation("video_with_captions.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
for (IShape shape : slide.getShapes()) {
if (shape instanceof IVideoFrame) {
IVideoFrame videoFrame = (IVideoFrame) shape;
for (ICaptions captionTrack : videoFrame.getCaptionTracks()) {
// キャプショントラックを WebVTT ファイルに保存します。
FileOutputStream outputStream = new FileOutputStream(captionTrack.getCaptionId() + ".vtt");
outputStream.write(captionTrack.getBinaryData());
outputStream.close();
}
}
}
} finally {
presentation.dispose();
}
各ICaptionsオブジェクトは、キャプション識別子、ラベル、バイナリ データ、および UTF-8 文字列としてのキャプション データを公開します。
ビデオ フレームからキャプションを削除
ビデオ フレームからキャプションを削除するには:
- ビデオが含まれるプレゼンテーションをロードします。
- 対象のIVideoFrameオブジェクトを取得します。
- getCaptionTracksが返すコレクションからキャプショントラックを削除します。
- 変更されたプレゼンテーションを保存します。
Presentation presentation = new Presentation("video_with_captions.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IVideoFrame videoFrame = (IVideoFrame) slide.getShapes().get_Item(0);
// ビデオフレームからすべてのキャプションを削除します。
videoFrame.getCaptionTracks().clear();
presentation.save("video_without_captions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
1つのキャプショントラックだけを削除する必要がある場合は、clearの代わりにremoveまたはremoveAtメソッドを使用してください。
スライドからビデオを抽出
スライドにビデオを追加するだけでなく、Aspose.Slidesではプレゼンテーションに埋め込まれたビデオを抽出することもできます。
- ビデオを含むプレゼンテーションをロードするためにPresentationクラスのインスタンスを作成します。
- すべてのISlideオブジェクトを反復処理します。
- すべてのIShapeオブジェクトを反復処理し、VideoFrameを見つけます。
- ビデオをディスクに保存します。
This Java code shows you how to extract the video on a presentation slide:
// プレゼンテーション ファイルを表す Presentation オブジェクトをインスタンス化
Presentation pres = new Presentation("VideoSample.pptx");
try {
for (ISlide slide : pres.getSlides())
{
for (IShape shape : slide.getShapes())
{
if (shape instanceof VideoFrame)
{
IVideoFrame vf = (IVideoFrame) shape;
String type = vf.getEmbeddedVideo().getContentType();
int ss = type.lastIndexOf('-');
byte[] buffer = vf.getEmbeddedVideo().getBinaryData();
//ファイル拡張子を取得
int charIndex = type.indexOf("/");
type = type.substring(charIndex + 1);
FileOutputStream fop = new FileOutputStream("testing2." + type);
fop.write(buffer);
fop.flush();
fop.close();
}
}
}
} catch (IOException e) {
} finally {
if (pres != null) pres.dispose();
}
よくある質問
VideoFrameで変更できるビデオ再生パラメータは何ですか?
再生モード(自動またはクリック時)とループ設定(looping)を制御できます。これらのオプションはVideoFrameオブジェクトのプロパティで利用可能です。
ビデオを追加するとPPTXファイルのサイズに影響しますか?
はい。ローカルビデオを埋め込むと、バイナリ データがドキュメントに含まれるため、ファイルサイズに比例してプレゼンテーションのサイズが増加します。オンラインビデオを追加すると、リンクとサムネイルが埋め込まれるだけなので、サイズ増加は小さくなります。
既存のVideoFrame内のビデオを位置やサイズを変更せずに置き換えることはできますか?
はい。フレーム内のvideo contentを入れ替えることで、シェイプのジオメトリを保持したままビデオを置き換えることができます。これは既存のレイアウトでメディアを更新する一般的なシナリオです。
埋め込まれたビデオのコンテンツタイプ(MIME)を取得できますか?
はい。埋め込まれたビデオにはcontent typeがあり、例えばディスクに保存する際などに読み取って使用できます。