This project is read-only.

Generating more than one video concurrently - multithreading please help!

Topics: Developer Forum
May 12, 2015 at 11:28 PM
Hi, I have 12 threading CPU so I wanted to generate at least 3 videos at the same time. I found that generating one video (running Renderer) utilize only 4 threads (checked Task manager). Unfortunatelly when I tried to generate 3 videos at the same time on separate threads I got exception.

Code:
public async void Generate3Videos()
{
  Task.Run(() => GenerateSingleVideoConcurrently(1), token);
  Task.Run(() => GenerateSingleVideoConcurrently(2), token);
  Task.Run(() => GenerateSingleVideoConcurrently(3), token);
}
In every GenerateSingleVideoConcurrently() I'm doing:
using (var renderer = new WindowsMediaRenderer(timeline, videoFileFullPath, WindowsMediaProfiles.LowQualityVideo))
{
   renderer.Render();
   return renderer.State == RendererState.GraphCompleted;
}
Exception: System.NullReferenceException
Stack trace:
   in Splicer.Utilities.FilterGraphTools.IsVideo(IPin pin) in c:\SplicerProject\Splicer\Utilities\FilterGraphTools.cs:line 957
   in Splicer.Renderer.AbstractRenderer.RenderGroups(ICaptureGraphBuilder2 graphBuilder, IBaseFilter audioCompressor, IBaseFilter videoCompressor, IBaseFilter audioDestination, IBaseFilter videoDestination, ICallbackParticipant[] audioParticipants, ICallbackParticipant[] videoParticipants) in c:\SplicerProject\Splicer\Renderer\AbstractRenderer.cs:line 556
   in Splicer.Renderer.AbstractRenderer.RenderGroups(ICaptureGraphBuilder2 graphBuilder, IBaseFilter audioCompressor, IBaseFilter videoCompressor, IBaseFilter multiplexer, ICallbackParticipant[] audioParticipants, ICallbackParticipant[] videoParticipants) in c:\SplicerProject\Splicer\Renderer\AbstractRenderer.cs:line 502
   in Splicer.Renderer.WindowsMediaRenderer.RenderToAsfWriter(String file, String profileData, ICallbackParticipant[] videoParticipants, ICallbackParticipant[] audioParticipants) in c:\SplicerProject\Splicer\Renderer\WindowsMediaRenderer.cs:line 117
   in Splicer.Renderer.WindowsMediaRenderer..ctor(ITimeline timeline, String file, String profileData, ICallbackParticipant[] videoParticipants, ICallbackParticipant[] audioParticipants) in c:\SplicerProject\Splicer\Renderer\WindowsMediaRenderer.cs:line 40
   in Splicer.Renderer.WindowsMediaRenderer..ctor(ITimeline timeline, String file, String profileData) in c:\SplicerProject\Splicer\Renderer\WindowsMediaRenderer.cs:line 28
   in YTM.VideosManagers.VideosManager.CreateVideo(String videoFileFullPath, Int32 videoHight, Int32 videoWidth, Image image, Definition definition, Double imageHalfDuration, Double imageFadingTimeDurationInSec, Double imageNoTransitionTimeInSec, Double& videoDuration) in c:\YTM\VideosManagers\VideosManager.cs:line 320
   in YTM.VideosManagers.VideosManager.GenerateSingleVideo(Definition definition, String videoFileFullPath, Double& videoDuration) in c:\YTM\VideosManagers\VideosManager.cs:line 276
   in YTM.VideosManagers.VideosManager.GenerateSingleVideoConcurrently(Definition definition, String resultFolderPath, Int32 actuallTotalGeneratedVideos) in c:\YTM\VideosManagers\VideosManager.cs:line 227
   in YTM.VideosManagers.VideosManager.<>c__DisplayClass14.<GenerateEveryVideo>b__f() in c:\YTM\VideosManagers\VideosManager.cs:line 165
   in System.Threading.Tasks.Task.InnerInvoke()
   in System.Threading.Tasks.Task.Execute()
I found that some issues might come from this part of Splicer:
protected void DisableClock()
{
            int hr = ((IMediaFilter)Graph).SetSyncSource(null); //this line maybe
            DsError.ThrowExceptionForHR(hr);
}
I was trying custom ReferenceClock but with no success.

Please help me! How to generate more than one video concurrently using Splicer?