AVBlocks for .NET  2.3
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 null 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`

1 static MediaSocket createInputSocket(int frameWidth, int frameHeight)
2 {
3  MediaSocket socket = new MediaSocket();
4  socket.StreamType = StreamType.Jpeg;
5  socket.Stream = null;
6  socket.File = null;
7 
8  MediaPin pin = new MediaPin();
9  socket.Pins.Add(pin);
10  VideoStreamInfo vsi = new VideoStreamInfo();
11  pin.StreamInfo = vsi;
12 
13  vsi.StreamType = StreamType.Jpeg;
14  vsi.ScanType = ScanType.Progressive;
15 
16  vsi.FrameWidth = frameWidth;
17  vsi.FrameHeight = frameHeight;
18 
19  return socket;
20 }

2. Configure output `MediaSocket`, `MediaPin`, and `VideoStreamInfo`

1 static MediaSocket createOutputSocket(string outputFile, int frameWidth, int frameHeight)
2 {
3  MediaSocket socket = new MediaSocket();
4  socket.File = outputFile;
5  socket.StreamType = StreamType.UncompressedVideo;
6 
7  MediaPin pin = new MediaPin();
8  socket.Pins.Add(pin);
9  VideoStreamInfo vsi = new VideoStreamInfo();
10  pin.StreamInfo = vsi;
11 
12  vsi.StreamType = StreamType.UncompressedVideo;
13  vsi.ScanType = ScanType.Progressive;
14  vsi.ColorFormat = ColorFormat.YUV420;
15 
16  vsi.FrameWidth = frameWidth;
17  vsi.FrameHeight = frameHeight;
18 
19  return socket;
20 }

3. Create a new `MediaBuffer` and attach the JPEG data to it

1 byte[] inputData = System.IO.File.ReadAllBytes(inputFile);
2 
3 MediaBuffer buffer = new MediaBuffer();
4 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

1 MediaSample sample = new MediaSample();
2 sample.Buffer = buffer;

5. Pass the sample to `Transcoder.Push`

1 transcoder.Push(0, sample);