Difference between revisions of "Ogg"

From GiderosMobile
(Created page with "__NOTOC__ <!-- GIDEROSOBJ:Ogg --> '''<translate>Supported platforms</translate>:''' File:Platform android.pngFile:Platform ios.pngFile:Platform mac.pngFile:Pla...")
 
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
 
<!-- GIDEROSOBJ:Ogg -->
 
<!-- GIDEROSOBJ:Ogg -->
 +
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/>
 +
'''Available since:''' Gideros 2017.10<br/>
  
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/>
+
=== Description ===
'''<translate>Available since</translate>:''' Gideros 2017.10<br/>
+
Adds support for Ogg audio and video (Theora).
  
=== Description ===
+
There are two ways to use the Ogg plugin:
Adds support for Ogg audio and Theora video.
+
* to read Ogg files use:
 +
<syntaxhighlight lang="lua">
 +
local theora = require "Theora"
 +
</syntaxhighlight>
 +
* to encode/decode Ogg files use:
 +
<syntaxhighlight lang="lua">
 +
-- Theora system
 +
local theora = require "theora.core"
 +
</syntaxhighlight>
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
'''Recording your mic and camera to an .ogg video file'''
Theora=require "Theora"
+
<syntaxhighlight lang="lua">
local videoSource = Theora.new("videos/file_example_OGG_480_1_7mg.ogg")
+
-- Microphone plugin, for recording in gideros
local videoStream = videoSource:play()
+
require "microphone"
local videoSprite = videoStream:getVideo()
+
-- Camera plugin, to get images from
videoSprite:setPosition(0, 64)
+
require "camera"
stage:addChild(videoSprite)
+
-- Theora system (from ogg plugin)
</source>
+
local theora = require "theora.core"
 +
 
 +
--Locate available cameras
 +
lst=Camera.availableDevices()
 +
for k,cam in ipairs(lst) do
 +
print("#"..k.." Desc:"..cam.description.." Pos:"..cam.position.." Dev:"..cam.name)
 +
end
 +
-- Pick the first available
 +
local cname=lst[1].name
 +
 
 +
cw,ch=640,480
 +
--Theora needs full 16x16 blocks
 +
ch=(ch+15)&~15
 +
cw=(cw+15)&~15
 +
--Create texture and start camera
 +
Camera.texture=RenderTarget.new(cw,ch)
 +
Camera.start(Camera.texture,cname)
 +
 
 +
--Set our stage size
 +
application:setLogicalDimensions(cw,ch)
 +
--Show our live video
 +
local b=Bitmap.new(Camera.texture)
 +
stage:addChild(b)
 +
 
 +
--Prepare for recording
 +
local mic=Microphone.new("",24000,2,16)
 +
mic:setOutputFile("|T|mic.ogg")
 +
 
 +
--Launch recording process
 +
Core.asyncCall(function()
 +
--Wait a frame and disable auto yield
 +
Core.yield(true)
 +
--Start recording and get recording stream id
 +
mic:start()
 +
local id=mic:getStreamId()
 +
--Encode video header immediately, before audio data gets encoded
 +
--Parameters are:
 +
-- stream id, codec name, frame rate, image width, image height,
 +
-- image format (use 3 for now, nothing else is supported), image quality
 +
theora.beginVideo(id,"theora",30,cw,ch,3,0.6)
 +
-- Now encode 120 video frames, every other gideros frame (60fps->30fps)
 +
for i=1,120 do
 +
--Parameters:
 +
-- stream id, frame id (zero based), image texture, end of stream indicator
 +
theora.encodeVideoFrame(id,(i-1),Camera.texture,(i==120))
 +
Core.yield(true)
 +
Core.yield(true)
 +
end
 +
-- Stop recording
 +
mic:stop()
 +
-- For testing, read encoded file and print its size
 +
local f=io.open("|T|mic.ogg","rb")
 +
local ct=f:read("*all")
 +
f:close()
 +
print("Ended",#ct)
 +
end)
 +
</syntaxhighlight>
  
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
=== Methods ===
 
=== Methods ===
<!-- [[Special:MyLanguage/Theora.new|Theora.new]] ''<translate>Creates a new Ogg/Theora object.</translate>''<br/> -->
+
[[Theora.new]] ''creates a new Ogg/Theora object''<br/><!--GIDEROSMTD:Theora.new(path) creates a new Ogg/Theora object-->
<!-- GIDEROSMTD:Theora.new(path) Creates a new Ogg/Theora object. -->
+
[[Theora:getVideo]] ''reads video from an Ogg/Theora stream object''<br/><!--GIDEROSMTD:Theora:getVideo() reads video from an Ogg/Theora stream object-->
 +
[[Theora:play]] ''creates a new Ogg/Theora stream object''<br/><!--GIDEROSMTD:Theora:play() creates a new Ogg/Theora stream object-->
  
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|

Latest revision as of 06:56, 26 August 2024

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.png
Available since: Gideros 2017.10

Description

Adds support for Ogg audio and video (Theora).

There are two ways to use the Ogg plugin:

  • to read Ogg files use:
local theora = require "Theora"
  • to encode/decode Ogg files use:
-- Theora system
local theora = require "theora.core"

Example

Recording your mic and camera to an .ogg video file

-- Microphone plugin, for recording in gideros
require "microphone"
-- Camera plugin, to get images from
require "camera"
-- Theora system (from ogg plugin)
local theora = require "theora.core"

--Locate available cameras
lst=Camera.availableDevices()
for k,cam in ipairs(lst) do
	print("#"..k.." Desc:"..cam.description.." Pos:"..cam.position.." Dev:"..cam.name)
end
-- Pick the first available
local cname=lst[1].name

cw,ch=640,480
--Theora needs full 16x16 blocks
ch=(ch+15)&~15
cw=(cw+15)&~15
--Create texture and start camera
Camera.texture=RenderTarget.new(cw,ch)
Camera.start(Camera.texture,cname)

--Set our stage size
application:setLogicalDimensions(cw,ch)
--Show our live video
local b=Bitmap.new(Camera.texture)
stage:addChild(b)

--Prepare for recording
local mic=Microphone.new("",24000,2,16)
mic:setOutputFile("|T|mic.ogg")

--Launch recording process
Core.asyncCall(function()
	--Wait a frame and disable auto yield
	Core.yield(true)
	--Start recording and get recording stream id
	mic:start()
	local id=mic:getStreamId()
	--Encode video header immediately, before audio data gets encoded
	--Parameters are:
	-- stream id, codec name, frame rate, image width, image height,
	-- image format (use 3 for now, nothing else is supported), image quality
	theora.beginVideo(id,"theora",30,cw,ch,3,0.6)
	-- Now encode 120 video frames, every other gideros frame (60fps->30fps)
	for i=1,120 do
		--Parameters:
		-- stream id, frame id (zero based), image texture, end of stream indicator
		theora.encodeVideoFrame(id,(i-1),Camera.texture,(i==120))
		Core.yield(true)
		Core.yield(true)
	end
	-- Stop recording
	mic:stop()
	-- For testing, read encoded file and print its size
	local f=io.open("|T|mic.ogg","rb")
	local ct=f:read("*all")
	f:close()
	print("Ended",#ct) 
end)

Methods

Theora.new creates a new Ogg/Theora object
Theora:getVideo reads video from an Ogg/Theora stream object
Theora:play creates a new Ogg/Theora stream object

Events

Constants