AVBlocks for C++  2.1
Audio and Video Software Development Kit
Using Transcoder::push

Common Steps

  1. 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
  2. Configure output MediaSocket, MediaPin, and VideoStreamInfo
  3. Read data from your input and attach it to a new MediaBuffer object
  4. Create a new MediaSample object, and set its buffer property
  5. Pass the MediaSample object to Transcoder::push

JPEG

1. Configure input `MediaSocket`, `MediaPin`, and `VideoStreamInfo`

primo::ref<MediaSocket> createInputSocket(int width, int height)
{
auto socket = primo::make_ref(Library::createMediaSocket());
socket->setFile(nullptr);
socket->setStream(nullptr);
socket->setStreamType(StreamType::JPEG);
auto pin = primo::make_ref(Library::createMediaPin());
socket->pins()->add(pin.get());
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
pin->setStreamInfo(vsi.get());
vsi->setStreamType(StreamType::JPEG);
vsi->setScanType(ScanType::Progressive);
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)
{
auto socket = primo::make_ref(Library::createMediaSocket());
socket->setFile(fileName);
socket->setStreamType(StreamType::UncompressedVideo);
auto pin = primo::make_ref(Library::createMediaPin());
socket->pins()->add(pin.get());
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
pin->setStreamInfo(vsi.get());
vsi->setStreamType(StreamType::UncompressedVideo);
vsi->setScanType(ScanType::Progressive);
vsi->setColorFormat(ColorFormat::YUV420);
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);
auto buffer = primo::make_ref(Library::createMediaBuffer(inputData.size()));
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

auto sample = primo::make_ref(Library::createMediaSample());
sample->setBuffer(buffer.get());

5. Pass the sample to `Transcoder::push`

transcoder->push(0, sample.get());