Common Steps
- Detect the input stream using MediaInfo and create a MediaSocket from it, or configure the input MediaSocket manually. Make sure you set the MediaSocket.File, and MediaSocket.Stream properties to null to indicate that data will be provided manually using Transcoder.Push
- Configure output MediaSocket, MediaPin, and VideoStreamInfo
- Read data from your input and attach it to a new MediaBuffer object
- Create a new MediaSample object, and set its Buffer property
- Pass the MediaSample object to Transcoder.Push
JPEG
1. Configure input MediaSocket, MediaPin, and VideoStreamInfo
static MediaSocket createInputSocket(int frameWidth, int frameHeight)
{
MediaSocket socket = new MediaSocket();
socket.StreamType = StreamType.Jpeg;
socket.Stream = null;
socket.File = null;
MediaPin pin = new MediaPin();
socket.Pins.Add(pin);
VideoStreamInfo vsi = new VideoStreamInfo();
pin.StreamInfo = vsi;
vsi.StreamType = StreamType.Jpeg;
vsi.ScanType = ScanType.Progressive;
vsi.FrameWidth = frameWidth;
vsi.FrameHeight = frameHeight;
return socket;
}
2. Configure output MediaSocket, MediaPin, and VideoStreamInfo
static MediaSocket createOutputSocket(string outputFile, int frameWidth, int frameHeight)
{
MediaSocket socket = new MediaSocket();
socket.File = outputFile;
socket.StreamType = StreamType.UncompressedVideo;
MediaPin pin = new MediaPin();
socket.Pins.Add(pin);
VideoStreamInfo vsi = new VideoStreamInfo();
pin.StreamInfo = vsi;
vsi.StreamType = StreamType.UncompressedVideo;
vsi.ScanType = ScanType.Progressive;
vsi.ColorFormat = ColorFormat.YUV420;
vsi.FrameWidth = frameWidth;
vsi.FrameHeight = frameHeight;
return socket;
}
3. Create a new MediaBuffer and attach the JPEG data to it
csharp
byte[] inputData = System.IO.File.ReadAllBytes(inputFile);
MediaBuffer buffer = new MediaBuffer();
buffer.Attach(inputData, true);
- The buffer must contain the data for at least one JPEG image, including the start marker (0xFF 0xD8) and the end marker (0xFF 0xD9). See
ISO/IEC 10918-1
for more information about JPEG
header structure.
- If the buffer contains more than one image, use the MediaBuffer.SetData to indicate the offset and the size of the data.
4. Create a new MediaSample and set its buffer
MediaSample sample = new MediaSample();
sample.Buffer = buffer;
5. Pass the sample to Transcoder.Push
transcoder.Push(0, sample);