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 nullptr 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`
primo::ref<MediaSocket> createInputSocket(int width, int height)
{
socket->setFile(nullptr);
socket->setStream(nullptr);
socket->pins()->add(pin.get());
pin->setStreamInfo(vsi.get());
vsi->setFrameWidth(width);
vsi->setFrameHeight(height);
return socket;
}
2. Configure output `MediaSocket`, `MediaPin`, and `VideoStreamInfo`
primo::ref<MediaSocket> createOutputSocket(const wchar_t* fileName, int width, int height)
{
socket->setFile(fileName);
socket->pins()->add(pin.get());
pin->setStreamInfo(vsi.get());
vsi->setFrameWidth(width);
vsi->setFrameHeight(height);
return socket;
}
3. Create a new `MediaBuffer` and attach the JPEG data to it
vector<uint8_t> inputData = readFileBytes(inputFile);
buffer->attach(inputData.data(), inputData.size(), 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
sample->setBuffer(buffer.get());
5. Pass the sample to `Transcoder::push`
transcoder->push(0, sample.get());