Я не могу получить Handbrake для работы на меня в C#. Он продолжает бросать ошибку «Значение не может быть пустым». , Как вы можете видеть на скриншоте ниже, я пробовал пару вещей, основываясь на том, что я знаю. Я был бы признателен за любые ваши рекомендации, которые помогут мне получить эту работу.Получение энкодера Handbrake для работы
То, что я пытался до сих пор (пункты не относятся к ошибке displayed..Just FYI):
- установлен ручной тормоз на моем компьютере
- Добавлена ссылка на HandBrakeInterop .dll
- Скопировал все остальные необходимые DLL в мою папку отладки и даже попытался добавить их в качестве ссылок
- Пробовал изменять версии отладки от x86/x6 4
Где я нахожусь на правильном пути?
Вот мой код:
HandBrake.Interop.HandBrakeInstance objHb = new HandBrake.Interop.HandBrakeInstance();
HandBrake.Interop.Model.EncodeJob objJob = new HandBrake.Interop.Model.EncodeJob();
objJob.SourceType = HandBrake.Interop.Model.SourceType.File;
EncodingProfile objProfile = new EncodingProfile();
objProfile.OutputFormat = Container.Mp4;
objProfile.VideoEncodeRateType = VideoEncodeRateType.ConstantQuality;
objProfile.IPod5GSupport = true;
objProfile.PreferredExtension = OutputExtension.Mp4;
// objJob.EncodingProfile = objProfile;
objJob.SourcePath = AppDomain.CurrentDomain.BaseDirectory + "1.flv";
objJob.OutputPath = AppDomain.CurrentDomain.BaseDirectory + "1.mp4";
//objHb.Titles.Add(new HandBrake.Interop.SourceData.Title());
XmlSerializer objSerializer = new XmlSerializer(typeof(EncodingProfile));
MemoryStream mem=new MemoryStream(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "normal.xml"));
var objPresetFromFile = objSerializer.Deserialize(mem) as EncodingProfile;
objJob.EncodingProfile = objPresetFromFile;
objJob.UseDefaultChapterNames = true;
// objJob.Title = 1;
//HandBrake.Interop.Model.Encoders
objHb.EncodeProgress += objHb_EncodeProgress;
objHb.EncodeCompleted += objHb_EncodeCompleted;
HandBrake.ApplicationServices.Parsing.Title title = new HandBrake.ApplicationServices.Parsing.Title();// new HandBrake.Interop.SourceData.Title();
objHb.Initialize(5);
//objHb.Titles = new System.Collections.Generic.List<HandBrake.Interop.SourceData.Title>();
objHb.StartScan(AppDomain.CurrentDomain.BaseDirectory + "1.flv", 0);
objJob.SourceType = HandBrake.Interop.Model.SourceType.File;
objJob.RangeType = HandBrake.Interop.Model.VideoRangeType.Frames;
objHb.StartEncode(objJob);
Console.ReadLine();
EDIT: В соответствии с просьбой, вот больше информации от исключения скопированный в буфер обмена
System.ArgumentNullException was unhandled
HResult=-2147467261
Message=Value cannot be null.
Parameter name: source
Source=System.Core
ParamName=source
StackTrace:
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at HandBrake.Interop.HandBrakeInstance.GetTitle(Int32 titleNumber) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 1604
at HandBrake.Interop.HandBrakeInstance.GetTitleIndex(Int32 titleNumber) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 1614
at HandBrake.Interop.HandBrakeInstance.StartEncode(EncodeJob job, Boolean preview, Int32 previewNumber, Int32 previewSeconds, Double overallSelectedLengthSeconds) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 411
at HandBrake.Interop.HandBrakeInstance.StartEncode(EncodeJob jobToStart) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 395
at HandBrakeTest.Program.Main(String[] args) in c:\Users\user\Documents\Visual Studio 2012\Projects\HandBrakeTest\HandBrakeTest\Program.cs:line 53
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Edit:
- Переехал handbrakeinstance и экземпляр encodingjob за пределами основной и сделал их статическими
- Вызов StartEncode в сканировании завершено событие
Теперь, исключение составляет NullReferenceException с этим в деталях:
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=HandBrakeInterop
StackTrace:
at HandBrake.Interop.InteropUtilities.ReadStructure[T](IntPtr structPtr) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\InteropUtilities.cs:line 31
at HandBrake.Interop.HandBrakeInstance.StartEncode(EncodeJob job, Boolean preview, Int32 previewNumber, Int32 previewSeconds, Double overallSelectedLengthSeconds) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 412
at HandBrake.Interop.HandBrakeInstance.StartEncode(EncodeJob jobToStart) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 395
at HandBrakeTest.Program.objHb_ScanCompleted(Object sender, EventArgs e) in c:\Users\user\Documents\Visual Studio 2012\Projects\HandBrakeTest\HandBrakeTest\Program.cs:line 65
at HandBrake.Interop.HandBrakeInstance.PollScanProgress() in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 811
at HandBrake.Interop.HandBrakeInstance.<StartScan>b__2(Object o, ElapsedEventArgs e) in c:\HandBrake\Hudson\workspace\Release_WindowsGui64\0.9.9\win\CS\HandBrake.Interop\HandBrakeInterop\HandBrakeInstance.cs:line 752
at System.Timers.Timer.MyTimerCallback(Object state)
InnerException:
Спасибо заранее.
В этом всплывающем окне есть ссылка: «Скопировать детали исключения в буфер обмена». Вставьте эту информацию в свой вопрос. –
Отредактировано. Надеюсь, что это поможет ... Спасибо. – Josh