Skip to content

Instantly share code, notes, and snippets.

@olokobayusuf
Created June 20, 2019 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olokobayusuf/ba09d39c8b0e2bde4780ad11f69d73d7 to your computer and use it in GitHub Desktop.
Save olokobayusuf/ba09d39c8b0e2bde4780ad11f69d73d7 to your computer and use it in GitHub Desktop.
An example illustrating transcoding a video in Unity using NatExtractor and NatCorder.
using UnityEngine;
using NatCorder;
using NatExtractor;
public class TranscodeDemo : MonoBehaviour {
public string videoPath; // Path to video to be transcoded
void Start () {
// Create a frame extractor
var extractor = new FrameExtractor(videoPath);
// Create an MP4 recorder
var recorder = new MP4Recorder(
extractor.resolution.width,
extractor.resolution.height,
extractor.resolution.refreshRate,
0,
0,
OnTranscode
);
// Transcode
extractor.Extract(
(pixelBuffer, timestamp) => recorder.CommitFrame(pixelBuffer, timestamp),
() => recorder.Dispose()
);
}
void OnTranscode (string path) {
// Use transcoded video
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment