This project is read-only.

Real time encoding

Topics: Developer Forum
Jun 12, 2009 at 5:28 PM

I am using Splicer in a project where RT encoding is needed. As of now, we have used it in an offline fashion, but we need to increase the encoding performance a lot. What we do is create a timetable with a series of System.Drawing.Image frames (code is in F#, but this should be irrelevant for the purpose of the discussion):

let create_pic (i:int) =
  let pg = new Bitmap(320, 240)
  let gr = Graphics.FromImage(pg)
  do gr.FillRectangle(new SolidBrush(Color.White), Rectangle(0, 0, 320, 240))
  do gr.DrawString("Frame " + i.ToString(),
      new Font("Comic Sans MS", 36.0f), new SolidBrush(Color.Black), 10.0f, 10.0f)
  pg

let pics = [1..100] |> map create_pic
let pair x y = (x,y)

let timeline = new DefaultTimeline()
let group = timeline.AddVideoGroup(32s, 320, 240);

let audioTrack = timeline.AddAudioGroup().AddTrack();
let videoTrack = group.AddTrack();

do pics |> map (fun pic -> pic :> System.Drawing.Image) 
        |> iter (fun pic -> ignore(videoTrack.AddImage(pic,0.0,0.1)))

then we load our profile

<profile version="589824"
             storageformat="1"
             name="SplicerHQVid"
             description="Default SplicerTranscoding Profile">
  <streamconfig majortype="{73647561-0000-0010-8000-00AA00389B71}"
  streamnumber="1"
  streamname="Audio Stream"
  inputname="Audio409"
  bitrate="22008"
  bufferwindow="-1"
  reliabletransport="0"
  decodercomplexity=""
  rfc1766langid="en-us">
    <wmmediatype subtype="{00000161-0000-0010-8000-00AA00389B71}"
          bfixedsizesamples="1"
          btemporalcompression="0"
          lsamplesize="894">
      <waveformatex wFormatTag="353"
                    nChannels="2"
                    nSamplesPerSec="22050"
                    nAvgBytesPerSec="2751"
                    nBlockAlign="894"
                    wBitsPerSample="16"
                    codecdata="004400000F00F90D0000"/>
    </wmmediatype>
  </streamconfig>
  <streamconfig majortype="{73646976-0000-0010-8000-00AA00389B71}"
  streamnumber="2"
  streamname="Video Stream"
  inputname="Video409"
  bitrate="232000"
  bufferwindow="-1"
  reliabletransport="0"
  decodercomplexity="AU"
  rfc1766langid="en-us"
 >
    <videomediaprops maxkeyframespacing="0"
                    quality="70"/>
    <wmmediatype subtype="{33564D57-0000-0010-8000-00AA00389B71}"
          bfixedsizesamples="0"
          btemporalcompression="0"
          lsamplesize="0">
      <videoinfoheader dwbitrate="232000"
                       dwbiterrorrate="0"
                       avgtimeperframe="333333">
        <rcsource left="0"
                  top="0"
                  right="320"
                  bottom="240"/>
        <rctarget left="0"
                  top="0"
                  right="320"
                  bottom="240"/>
        <bitmapinfoheader biwidth="320"
                          biheight="240"
                          biplanes="1"
                          bibitcount="24"
                          bicompression="WMV3"
                          bisizeimage="0"
                          bixpelspermeter="0"
                          biypelspermeter="0"
                          biclrused="0"
                          biclrimportant="0"/>
      </videoinfoheader>
    </wmmediatype>
  </streamconfig>
</profile>

and finally we encode our 100 frames:
let profile = (new StreamReader("WMVProfile.xml")).ReadToEnd()
let renderer = new WindowsMediaRenderer(timeline, @"output\vid.wmv", profile);
do renderer.Render();

do renderer.Dispose()
do timeline.Dispose()
only problem is, it takes about 20-30 seconds to encode  a measly hundred frames. We don't really care about the size of the video on disk, we just need it fast!
Thank you in advance!
Jun 13, 2009 at 10:53 AM

Create a JPG as a seperate file instead of creating the image by hand. I can't really tell from the code as I don't know f# well. But I take it that it is a white background with some text ontop of it?

You might also want to open the Windows Encoding profile in Windows Media Encoder SDK and tweak it as you are using the default rendering profile in splicer.

You can embed your own custom profile into the splicer dll by opening the splicer source, editing one of the .prx files (or adding in another one) and re-compiling.

HTH,

d3

 

Jun 13, 2009 at 1:50 PM

Will try that, thanks a lot!

BTW: you guessed right, white pic with some text :)