Skip to content

Filter configuration (command-line mode)

This chapter describes the FFmpeg command-line mode

For an encoding that the encoder settings already express, the encoder mode is simpler and requires none of this.

The filter is configured with a single call: SetCommandLine. Two filters are registered, one for each kind of input.

Filter Input CLSID
Datastead Multipurpose Encoder the uncompressed video and/or audio pins of a DirectShow source, e.g. a webcam {39E3007B-6185-47FC-9839-C4B8621AC065}
Datastead Multipurpose Encoder (From File) a media file, passed through IFileSourceFilter; the filter has no pin to connect {A4EEBEBE-A375-4995-8DBC-F4E42A189D6A}

If the source is a live DirectShow source (e.g. a webcam)

  1. create the filter graph,
  2. add the camera video device to the graph,
  3. add the camera audio device to the graph (if audio is needed),
  4. create the Datastead Multipurpose Encoder instance and add it to the graph,
  5. query its IDatasteadMultipurposeDirectShowEncoder interface and set the command line,
  6. connect the video and/or audio pins,
  7. run the graph.
// ... create the filter graph ...
// ... add the video and/or audio capture devices ...

IBaseFilter *DatasteadMPE = NULL;

HRESULT hr = CoCreateInstance (CLSID_DatasteadMultipurposeDirectShowEncoder, NULL,
                               CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &DatasteadMPE);
if (SUCCEEDED (hr)) {

   hr = pGraph->AddFilter (DatasteadMPE, L"Datastead Multipurpose Encoder");

   if (SUCCEEDED (hr)) {
      IDatasteadMultipurposeDirectShowEncoder *MPEConfig = NULL;

      hr = DatasteadMPE->QueryInterface (IID_IDatasteadMultipurposeDirectShowEncoder, (void**) &MPEConfig);
      if (SUCCEEDED (hr)) {

         hr = MPEConfig->SetCommandLine (L"ffmpegLGPL.exe -i %PIPE% ...");
         if (SUCCEEDED (hr)) {
            // ... connect the pins, render them if needed, and run the graph ...
         }
         MPEConfig->Release();
      }
   }
   DatasteadMPE->Release();
}

If the source is a video file (or an audio file)

The (From File) filter has no input pin: the input file is passed through the standard IFileSourceFilter interface, and the command line is set exactly as above.

  1. create the filter graph,
  2. create the Datastead Multipurpose Encoder (From File) instance and add it to the graph,
  3. query IFileSourceFilter and invoke Load with the path of the file to encode,
  4. query the IDatasteadMultipurposeDirectShowEncoder interface and set the command line,
  5. run the graph.
IBaseFilter *DatasteadMPE = NULL;

HRESULT hr = CoCreateInstance (CLSID_DatasteadMultipurposeDirectShowEncoderFromFile, NULL,
                               CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &DatasteadMPE);
if (SUCCEEDED (hr)) {

   hr = pGraph->AddFilter (DatasteadMPE, L"Datastead Multipurpose Encoder (From File)");

   if (SUCCEEDED (hr)) {
      IFileSourceFilter *FileSource = NULL;
      if (SUCCEEDED (DatasteadMPE->QueryInterface (IID_IFileSourceFilter, (void**) &FileSource))) {
         FileSource->Load (L"c:\\folder\\theinputclip.mp4", NULL);
         FileSource->Release();
      }

      IDatasteadMultipurposeDirectShowEncoder *MPEConfig = NULL;
      if (SUCCEEDED (DatasteadMPE->QueryInterface (IID_IDatasteadMultipurposeDirectShowEncoder, (void**) &MPEConfig))) {
         MPEConfig->SetCommandLine (L"ffmpegLGPL.exe -i %PIPE% -c:v h264 -b:v 2M -f mp4 myoutputfile.mp4");
         // ... run the graph ...
         MPEConfig->Release();
      }
   }
   DatasteadMPE->Release();
}

Note

In this mode, %PIPE% is replaced by the path of the file passed to IFileSourceFilter::Load instead of by the name of the pipe, so the same command line works with both filters.

Real-time mode

The filter adapts the FFmpeg command line depending on whether the input is a live source or a file. The mode is normally detected automatically; it can be forced through SetCommandLine, in its own call, before the call that sets the command line itself:

MPEConfig->SetCommandLine (L"RT:1");   // force the real-time mode
MPEConfig->SetCommandLine (L"RT:0");   // force the non-real-time mode

A call of this form only sets the mode: it returns S_OK and leaves the current command line unchanged. See also the NOTREALTIME and LIVETIMING keywords.

License key

The licensed version is activated at run time with the license key supplied with the licensing information. The key is passed through SetCommandLine, in its own call, before the call that sets the actual FFmpeg command line:

MPEConfig->SetCommandLine (L"MPELIC:the license key");           // activates the filter
MPEConfig->SetCommandLine (L"ffmpegLGPL.exe -i %PIPE% ...");     // the real command line

The activation call returns S_OK when the key is valid, and E_INVALIDARG when it is not; it does not change the command line currently configured, and the key is not passed to FFmpeg.

Without a valid key, the filter runs in evaluation mode: each encoding session stops after 1 minute and the video frames are marked.

The command-line syntax itself is described in the Command-line syntax chapter.