Ogg (.ogg,.oga,...)
予備知識
-
- 登録MIMEタイプ:video/ogg
- マルチメディアコンテナ形式.
- 複数の動画・音声トラックを含むことができる.
- 効率的なストリーミングで使用されるように設計された.
- さまざまな動画・音声コーデックをサポートする.
- Xiph.Org Foundationによって開発され,保守されている.
ImportとExport
- Import["file.ogg"]はOggファイルをインポートし,Videoオブジェクトを返す.
- Import["file.ogg",elem]は指定された要素をインポートする.
- インポート形式はImport["file","Ogg"]またはImport["file",{"Ogg",elem,…}]で指定できる.
- Export["file.ogg",expr]は expr をOgg形式にエキスポートする.
- 以下の式はOgg形式にエキスポートできる:
-
video 任意のVideoオブジェクト AnimatedImage[…] AnimatedImageオブジェクトのフレーム Manipulate[…] Manipulate式から生成されたフレーム {expr1,expr2,…} 画像,グラフィックス,ラスタライズされた式のリスト - 任意の式のリストをエキスポートするとき,それぞれの式はライスタライズされ,表示されている形式と同じラスターサイズとなる.
- Ogg動画の長さは,フレーム数と指定のフレーム率により決まる.
- Manipulateオブジェクトの中でブックマークが設定されている場合,Exportは各ブックマークの間を補間したOggファイルを作成する.このとき,Manipulateの速度と長さは維持される.
- Export["file.ogg",{elem1expr1,elem2expr2,…},"Rules"]は規則を使ってエキスポートする要素を指定する.
- サポートされている動画エンコーダのリストは$VideoEncodersで見ることができる.
- 一般的な情報は,以下の関数ページを参照のこと.
-
Import, Export ファイルからインポートする,あるいはファイルへエキスポートする CloudImport, CloudExport クラウドオブジェクトからインポートする,あるいはクラウドオブジェクトへエキスポートする ImportString, ExportString 文字列からインポートする,あるいは文字列へエキスポートする ImportByteArray, ExportByteArray バイト配列からインポートする,あるいはバイト配列へエキスポートする
要素
- 一般的なImport要素:
-
"Elements" ファイル中の有効な要素とオプションのリスト "Summary" ファイルの概要 "Rules" 使用可能なすべての要素の規則のリスト - 動画表現要素:
-
"ImageList" 画像のリストで表されたフレーム "Video" Videoオブジェクトで表された動画ファイル "VideoData" 各フレームの生のビットマップデータの配列 "VideoStream" VideoStreamオブジェクトで表された動画ファイルへのハンドル - 音声表現要素:
-
"Audio" インコアのAudioオブジェクト "AudioData" 音声サンプルの配列 "AudioFile" アウトオブコアのAudioオブジェクト - Importはファイルに動画トラックがある場合は"Video"要素を,ない場合は"Audio"要素をデフォルトで使用する.
- 動画ファイルには複数の動画,音声,または字幕のトラックが含まれていることがある.トラック数を返す要素:
-
"AudioTrackCount" 音声トラック数 "VideoTrackCount" 動画トラック数 - 動画メタデータ要素:
-
"BitDepth" ファイルの各色チャンネルを表すのに使用するビット "ColorSpace" ファイルで使用する色符号 "FrameCount" ファイル中のフレーム数 "FrameDurations" 各フレームに与えられた表示時間のリスト "FrameRate" 1秒あたりに表示されるフレーム数 "RasterSize" ラスタサイズ "VideoEncoding" ファイルで使用する動画コーデック - 音声メタデータ要素:
-
"AudioChannels" 音声チャンネル数 "AudioBitDepth" 各音声サンプルを表すのに使用されるビット "AudioEncoding" ファイルで使用されている音声コーデック "AudioLength" 音声サンプル数 "BitRate" 秒あたりのビット数 "SampleRate" 秒あたりの音声サンプル数 - その他のメタデータ要素:
-
"ExactDurations" 動画,音声,字幕すべてのトラックの厳密な継続時間の連想 "ExactTimeBoundaries" すべての動画,音声,字幕トラックの厳密な開始・終了時間の連想 "Duration" 動画のおよその継続時間(秒) "MetaInformation" 数量,場所,日付,数等として解釈されるメタデータ "RawMetaInformation" 文字列または数の未解釈メタデータ "Summary" ファイルの概要 "TrackStartTimes" 各トラックの開始時間の連想 - $VideoDecodersと$AudioDecodersは使用中のコンピュータシステムで利用できるデコーダのリストを与える.
要素
- Export["file.ogg",{elem1->expr1,…},"Rules"]は規則を使ってエキスポートする要素を指定する.
- 使用できるExport要素:
-
"Audio" 音声トラック "Frames" リストまたはManipulateまたは AnimatedImageオブジェクトとして与えられた動画フレーム
オプション
- 一般的なImportオプション:
-
AudioTrackSelection 1 関心のある音声トラック "ImageTopOrientation" Automatic ファイルに保存された動画の向き RasterSize Automatic ラスタ次元 VideoTrackSelection 1 関心のある動画トラック - "Audio"要素のImportオプション:
-
"AudioChannels" Automatic 音声チャンネル数 SampleRate Automatic 各チャンネルの秒あたりのサンプル数 - ImportおよびExportのオプション:
-
IncludeMetaInformation All インポート・エキスポートするメタデータのタイプ - IncludeMetaInformationのサポートされている設定は"Xiph","RawXiph",All,およびNoneである.
- 一般的なExportオプション:
-
AudioEncoding Automatic ファイルの音声符号化 Background Automatic 背景色 BitRate Automatic 使用するおおよそのビットレート CompressionLevel Automatic 使用する圧縮レベル FrameRate Automatic 表示される秒あたりのフレーム数 MetaInformation Automatic エキスポートするメタデータ RasterSize Automatic 画素による次元 SampleRate Automatic 各チャンネルの秒あたりの音声サンプル数 SubtitleEncoding Automatic ファイルの字幕符号化 VideoEncoding Automatic ファイルの動画符号化 - "Video"要素と"VideoStream"要素のExportオプション:
-
AudioTrackSelection All 関心のある音声トラック VideoTrackSelection All 関心のある動画トラック - Manipulate式のエキスポート時のExportオプション:
-
"AnimationDuration" Automatic アニメーションの全継続時間 "ControlAppearance" Automatic Manipulate のコントロール要素がエキスポートされたファイルで描画される方法 - "ControlAppearance"には以下の設定が使用できる:
-
Automatic ローカルのコンピュータシステムのスタイル要素を使って,ユーザコントロールがノートブックインターフェースと全く同じに見えるようにする "Generic" 一般的なスタイルでグラフィカルコントロールを描画する None アニメーションのエキスポート時にコントロール要素は除外する - $VideoEncodersと$AudioEncodersは使用中のコンピュータシステムで利用できるエンコーダのリストを与える.
例題
すべて開く すべて閉じる例 (4)
OggファイルをVideoオブジェクトとしてインポートする:
URLDownload["http://exampledata.wolfram.com/musician.ogg", "musician.ogg"]Import["musician.ogg"]OggファイルをAudioオブジェクトとしてインポートする:
Import["ExampleData/drums.ogg"]Import["ExampleData/drums.ogg", "Summary"]VideoオブジェクトをOggファイルにエキスポートする:
Export["file.ogg", Video["ExampleData/bullfinch.mkv"]]スコープ (6)
Import (2)
URLDownload["http://exampledata.wolfram.com/musician.ogg", "musician.ogg"]Import["musician.ogg", {"ImageList", {100, 200}}]Import["musician.ogg", {"Audio", Quantity[0, "Seconds"] ;; Quantity[10, "Seconds"]}]Export (4)
t = Table[ImageTransformation[[image], n Floor[# / n] + 1&, DataRange -> Full], {n, 1, 30}];Export["mosaic.ogg", t, FrameRate -> 15]VideoFrameList[Video["mosaic.ogg"], 3]Manipulateで作成したものをOggにエキスポートする:
m = Manipulate[Graphics[{Red, Disk[{0, 0}, r]}, PlotRange -> {{-1, 1}, {-1, 1}}, Background -> Black, ImageSize -> 100], {r, 1, 0}];Export["file.ogg", m]Import["file.ogg", "Summary"]AnimatedImageオブジェクトをエキスポートする:
Export["file.ogg", AnimatedImage["ExampleData/pearls.png"]]Import["file.ogg", "Summary"]Manipulateで作成したものに音声をつけてエキスポートする;
m = Manipulate[Graphics[{Red, Disk[{0, 0}, r]}, PlotRange -> {{-1, 1}, {-1, 1}}, Background -> Black, ImageSize -> 100], {r, 1, 0}];a = ExampleData[{"Audio", "Drums"}];Export["file.ogg", {"Frames" -> m, "Audio" -> a}, "Rules", {...}]Import["file.ogg", "Summary"]Import要素 (28)
マルチトラックOggファイルの生成 (1)
動画要素 (3)
"Video" (1)
Videoオブジェクトとしてインポートする:
Import["bullfinch.ogg", "Video"]これは動画トラックが少なくとも1つある場合のデフォルトのインポート要素である:
Import["bullfinch.ogg"]"VideoData" (1)
data = Import["bullfinch.ogg", {"VideoData", {1, 9}}]NumericArrayオブジェクトに保存されている動画データを画像に変換する:
Image /@ data"VideoStream" (1)
VideoStreamオブジェクトとしてインポートする:
str = Import["bullfinch.ogg", "VideoStream"]VideoPlay[str]str["CurrentFrame"]トラック数 (2)
メタデータ要素 (7)
"Duration" (2)
"ExactDurations" (2)
"MetaInformation" (1)
"RawMetaInformation" (1)
動画トラック (7)
"FrameDurations" (1)
"RasterSize" (1)
"VideoEncoding" (1)
Import["bullfinch.ogg", "VideoEncoding"]各プラットフォームでサポートされているデコーダは,$VideoDecodersを使って抽出できる:
$VideoDecoders["Ogg"][[All, 1]]音声トラック (7)
"Audio" (1)
"AudioChannels" (1)
"AudioData" (1)
Oggファイルから音声データをNumericArrayとしてインポートする:
data = Import["bullfinch.ogg", "AudioData"]保存された音声データをAudioオブジェクトに変換する:
Audio[data, SampleRate -> 48000]"AudioEncoding" (1)
Import["bullfinch.ogg", "AudioEncoding"]利用できる音声デコーダは$AudioDecodersから抽出できる:
$AudioDecoders["Ogg"][[All, 1]]"AudioFile" (1)
Importオプション (10)
マルチトラックOggファイルの生成 (1)
"AudioChannels" (1)
AudioTrackSelection (1)
デフォルトではImportは最初の音声トラックからのみデータを抽出する:
Import["bullfinch.ogg", {{"SampleRate", "AudioChannels"}}]AudioTrackSelectionオプションを使って指定の音声トラックからデータを抽出する:
Import["bullfinch.ogg", {{"SampleRate", "AudioChannels"}}, AudioTrackSelection -> {1, 2}]"ImageTopOrientation" (1)
IncludeMetaInformation (3)
デフォルトでは利用可能なすべてのメタデータがインポートされる:
Options[Import["ExampleData/drums.ogg", "Audio"], MetaInformation]Options[Import["ExampleData/drums.ogg", "Audio", IncludeMetaInformation -> None], MetaInformation]Options[Import["ExampleData/drums.ogg", "Audio", IncludeMetaInformation -> {"RawXiph"}], MetaInformation]RasterSize (1)
SampleRate (1)
VideoTrackSelection (1)
デフォルトではImportは最初の動画トラックからのみデータを抽出する:
Import["bullfinch.ogg", {{"FrameRate", "RasterSize"}}]VideoTrackSelectionオプションを使って指定の動画トラックからデータを抽出する:
Import["bullfinch.ogg", {{"FrameRate", "RasterSize"}}, VideoTrackSelection -> {1}]Exportオプション (19)
"AnimationDuration" (1)
エキスポートされたManipulate式の継続時間を指定する:
animation = Manipulate[Plot3D[Sin[x y + a], {x, 0, 3}, {y, 0, 3}, Mesh -> False, Boxed -> False, Axes -> None, ColorFunction -> "IslandColors"], {a, 0, 2 Pi}];Export["test.ogg", animation, "AnimationDuration" -> 7]Import[%, "ExactDurations"]AudioEncoding (1)
AudioTrackSelection (1)
Export["test.ogg", Video["ExampleData/bullfinch.mkv"]]Import[%, "AudioTrackCount"]Export["test.ogg", Video["ExampleData/bullfinch.mkv"], AudioTrackSelection -> {1, 2}]Import[%, "AudioTrackCount"]Export["test.ogg", Video["ExampleData/bullfinch.mkv"], AudioTrackSelection -> None]Import[%, "AudioTrackCount"]Background (1)
デフォルトでは,透明なグラフィックスと画像の背景色と,大きさの異なる画像をエキスポート前に充填する際の背景色に白が使われる:
list = {[image], [image], [image]};Export["test.ogg", list]Import[%, "ImageList"]Export["test.ogg", list, Background -> Blue]Import[%, "ImageList"]BitRate (4)
動画ファイルにエキスポートするときは,デフォルトで自動ビットレートが使用される:
Export["test.ogg", Video["ExampleData/bullfinch.mkv"]];Import["test.ogg", "BitRate"]Export["test.ogg", Video["ExampleData/bullfinch.mkv"], BitRate -> Quantity[500, "Kilobits"/"Seconds"]];おおよそのビットレートを確認するが,提案したビットレートと少し異なる可能性がある:
Import["test.ogg", "BitRate"]vrate = Quantity[500, "Kilobits"/"Seconds"];
arate = Quantity[50, "Kilobits"/"Seconds"];
Export["test.ogg", Video["ExampleData/bullfinch.mkv"], BitRate -> {vrate, arate}];Import["test.ogg", "BitRate"]ビットレートが低いと結果のファイルサイズが小さくなるが,生成された動画の質も低くなる:
FileSize[Export["test.ogg", Video["ExampleData/bullfinch.mkv"], BitRate -> #]]& /@ {Quantity[500, "Kilobits"/"Seconds"], Quantity[300, "Kilobits"/"Seconds"], Quantity[100, "Kilobits"/"Seconds"]}CompressionLevel (2)
CompressionLevelオプションを使って,生成された動画のファイルサイズと画質を制御する:
FileSize[Export["test.ogg", Video["ExampleData/bullfinch.mkv"], CompressionLevel -> #]]& /@ {0.2, 0.5, 0.8}動画と音声の両方のBitRateが指定されているときは,CompressionLevelの値は無視される:
FileSize[Export["test.ogg", Video["ExampleData/bullfinch.mkv"], BitRate -> {500000, 50000}, CompressionLevel -> 1]]FileSize[Export["test.ogg", Video["ExampleData/bullfinch.mkv"], BitRate -> {500000, 50000}, CompressionLevel -> 0]]"ControlAppearance" (1)
デフォルトの設定"ControlAppearance"Automaticでエキスポートされたアニメーションは,そのアニメーションが生成されたコンピュータシステムに応じて外観が異なる:
animation = Manipulate[Plot3D[Sin[x y + a], {x, 0, 3}, {y, 0, 3}, Mesh -> False, Boxed -> False, Axes -> None, ColorFunction -> "IslandColors"], {a, 0, 2 Pi}];Export["test.ogg", animation]Import[%, {"ImageList", {1, 2}}]"ControlAppearance"Noneとすると,エキスポートされた動画にユーザコントロールは含まれない:
Export["test.ogg", animation, "ControlAppearance" -> None]Import[%, {"ImageList", {1, 2}}]FrameRate (1)
デフォルトではVideoオブジェクトまたはVideoStreamオブジェクトのエキスポート時にフレームレートは維持される:
video = Video["ExampleData/caminandes.mp4"];Export["test.ogg", video]{Information[video]["VideoTracks"][1]["FrameRate"], Import[%, "FrameRate"]}Export["test.ogg", video, FrameRate -> 25]Import[%, "FrameRate"]IncludeMetaInformation (2)
デフォルトではAudioオブジェクトに存在するすべてのメタ情報がエキスポートされる:
a = Audio["ExampleData/drums.ogg", MetaInformation -> <|"Xiph" -> <|"Artist" -> {"qubodup aka Iwan Gabovitch | qubodup@gmail.com"}, "COMMENTS" -> {"I release this file into the public domain"}, "RecordingDate" -> {DateObject[{2008, 1, 1, 0, 0, 0}, "Instant", "Gregorian", 1.]}|>|>];Export["test.ogg", a]Options[Import[%], MetaInformation]Export["test.ogg", a, IncludeMetaInformation -> None]Options[Import[%], MetaInformation]v = Video["ExampleData/bullfinch.mkv"];Import[Information[v, "ResourcePath"], "MetaInformation"]"Language"や"Title"等のメタデータはエキスポートしない:
Import[Export["test.ogg", v, IncludeMetaInformation -> None], "MetaInformation"]MetaInformation (1)
v = Video["ExampleData/bullfinch.mkv"];Import[Information[v, "ResourcePath"], "MetaInformation"]デフォルトでは,サポートされているすべてのメタデータが入力の動画ファイルからエキスポートされる:
Import[Export["test.ogg", v], "MetaInformation"]選択されたタグだけが"Ogg"についてサポートされている.指定のメタデータをエキスポートする:
metadata = <|"Comments" -> "my comments", "Title" -> "my title", "VideoTracks" -> <|1 -> <|"Language" -> "eng"|>|>|>;Lookup[Import[Export["test.ogg", v, MetaInformation -> metadata], "MetaInformation"], "VideoTracks"]RasterSize (1)
デフォルトではVideoオブジェクトまたはVideoStreamオブジェクトのエキスポート時にラスタサイズは維持される:
video = Video["ExampleData/bullfinch.mkv"];Export["test.ogg", video]{Information[video]["VideoTracks"][1]["OriginalRasterSize"]//Normal, Import[%, "RasterSize"]}Export["test.ogg", video, RasterSize -> 320]Import[%, "RasterSize"]SampleRate (1)
デフォルトではVideo,VideoStream,Audioオブジェクトのエキスポート時にサンプルレートは維持される:
video = Video["ExampleData/bullfinch.mkv"];Export["test.ogg", video]{Information[video]["AudioTracks"][1]["SampleRate"], Import[%, "SampleRate"]}Export["test.ogg", video, SampleRate -> 44100]Import[%, "SampleRate"]VideoEncoding (1)
VideoTrackSelection (1)
Export["test.ogg", Video["ExampleData/bullfinch.mkv"]]Import[%, "VideoTrackCount"]Export["test.ogg", Video["ExampleData/bullfinch.mkv"], VideoTrackSelection -> 1]Import[%, "VideoTrackCount"]Export["test.ogg", Video["ExampleData/bullfinch.mkv"], VideoTrackSelection -> None]Import[%, {"Ogg", "VideoTrackCount"}]関連するガイド
-
▪
- 動画処理 ▪
- インポートとエキスポート ▪
- 全形式のリスト ▪
- マルチメディア形式 ▪
- Web形式