@@ -203,7 +203,6 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
203203 while ( isRunning )
204204 {
205205 TaskDetail task = args . taskManager . GetNextTask ( ) ;
206- JobProfile profile = task . Profile ;
207206
208207 // 检查是否已经完成全部任务
209208 if ( task == null )
@@ -225,6 +224,7 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
225224 return ;
226225 }
227226
227+ JobProfile profile = task . Profile ;
228228 try
229229 {
230230 task . WorkerName = args . Name ;
@@ -240,7 +240,7 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
240240 ex . progress = 0.0 ;
241241 throw ex ;
242242 }
243- MediaFile srcTracks = new EACDemuxer ( eacInfo . FullName , task . InputFile ) . Extract (
243+ MediaFile srcTracks = new EACDemuxer ( eacInfo . FullName , task . InputFile , profile . AudioTracks ) . Extract (
244244 ( double progress , EACProgressType type ) =>
245245 {
246246 switch ( type )
@@ -266,39 +266,27 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
266266 } ) ;
267267
268268 // 新建音频处理工作
269- if ( srcTracks . AudioTracks . Count != profile . AudioTracks . Count )
270- {
271- OKETaskException ex = new OKETaskException ( Constants . audioNumMismatchSmr ) ;
272- ex . progress = 0.0 ;
273- ex . Data [ "SRC_TRACK" ] = srcTracks . AudioTracks . Count ;
274- ex . Data [ "DST_TRACK" ] = profile . AudioTracks . Count ;
275- throw ex ;
276- }
277- else
278- {
279- for ( int i = 0 ; i < srcTracks . AudioTracks . Count ; i ++ )
280- {
281- profile . AudioTracks [ i ] . DupOrEmpty |= srcTracks . AudioTracks [ i ] . Info . DupOrEmpty ;
282- }
283- }
284-
285269 for ( int id = 0 ; id < srcTracks . AudioTracks . Count ; id ++ )
286270 {
287271 AudioTrack track = srcTracks . AudioTracks [ id ] ;
288- MuxOption option = profile . AudioTracks [ id ] . MuxOption ;
289- if ( option != MuxOption . Default )
272+ OKEFile file = track . File ;
273+ AudioInfo info = track . Info as AudioInfo ;
274+ MuxOption option = info . MuxOption ;
275+ switch ( option )
290276 {
291- continue ;
277+ case MuxOption . Default :
278+ case MuxOption . Mka :
279+ case MuxOption . External :
280+ AudioJob audioJob = new AudioJob ( info ) ;
281+ audioJob . SetUpdate ( task ) ;
282+ audioJob . Input = file . GetFullPath ( ) ;
283+ audioJob . Output = Path . ChangeExtension ( audioJob . Input , "." + audioJob . CodecString . ToLower ( ) ) ;
284+
285+ task . JobQueue . Enqueue ( audioJob ) ;
286+ break ;
287+ default :
288+ break ;
292289 }
293-
294- AudioJob audioJob = new AudioJob ( profile . AudioTracks [ id ] . OutputCodec ) ;
295- audioJob . SetUpdate ( task ) ;
296-
297- audioJob . Input = track . File . GetFullPath ( ) ;
298- audioJob . Language = profile . AudioTracks [ id ] . Language ;
299- audioJob . Bitrate = profile . AudioTracks [ id ] . Bitrate ;
300-
301- task . JobQueue . Enqueue ( audioJob ) ;
302290 }
303291
304292 // 新建视频处理工作
@@ -353,46 +341,41 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
353341 if ( job is AudioJob )
354342 {
355343 AudioJob audioJob = job as AudioJob ;
344+ AudioInfo info = audioJob . Info as AudioInfo ;
356345 string srcFmt = Path . GetExtension ( audioJob . Input ) . ToUpper ( ) . Remove ( 0 , 1 ) ;
357346 if ( srcFmt == "FLAC" && audioJob . CodecString == "AAC" )
358347 {
359348 task . CurrentStatus = "音频转码中" ;
360349 task . IsUnKnowProgress = true ;
361350
362- AudioJob aEncode = new AudioJob ( "AAC" ) ;
363- aEncode . Input = audioJob . Input ;
364- aEncode . Output = Path . ChangeExtension ( audioJob . Input , ".aac" ) ;
365- QAACEncoder qaac = new QAACEncoder ( aEncode , audioJob . Bitrate > 0 ? audioJob . Bitrate : Utils . Constants . QAACBitrate ) ;
351+ QAACEncoder qaac = new QAACEncoder ( audioJob , info . Bitrate ) ;
366352
367353 qaac . start ( ) ;
368354 qaac . waitForFinish ( ) ;
369-
370- audioJob . Output = aEncode . Output ;
371355 }
372- else if ( srcFmt == audioJob . CodecString )
373- {
374- audioJob . Output = audioJob . Input ;
375- }
376- else
356+ else if ( srcFmt != audioJob . CodecString )
377357 {
378358 OKETaskException ex = new OKETaskException ( Constants . audioFormatMistachSmr ) ;
379359 ex . Data [ "SRC_FMT" ] = srcFmt ;
380360 ex . Data [ "DST_FMT" ] = audioJob . CodecString ;
381361 throw ex ;
382362 }
383363
384- var audioFileInfo = new FileInfo ( audioJob . Output ) ;
385- if ( audioFileInfo . Length < 1024 )
364+ OKEFile outputFile = new OKEFile ( job . Output ) ;
365+ switch ( info . MuxOption )
386366 {
387- // 无效音轨
388- File . Move ( audioJob . Output , Path . ChangeExtension ( audioJob . Output , ".bak" ) + audioFileInfo . Extension ) ;
389- continue ;
367+ case MuxOption . Default :
368+ task . MediaOutFile . AddTrack ( new AudioTrack ( outputFile , info ) ) ;
369+ break ;
370+ case MuxOption . Mka :
371+ task . MkaOutFile . AddTrack ( new AudioTrack ( outputFile , info ) ) ;
372+ break ;
373+ case MuxOption . External :
374+ outputFile . AddCRC32 ( ) ;
375+ break ;
376+ default :
377+ break ;
390378 }
391-
392- AudioInfo info = new AudioInfo ( ) ;
393- info . Language = audioJob . Language ;
394-
395- task . MediaOutFile . AddTrack ( new AudioTrack ( new OKEFile ( job . Output ) , info ) ) ;
396379 }
397380 else if ( job is VideoJob )
398381 {
@@ -452,6 +435,17 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
452435
453436 muxer . StartMuxing ( Path . GetDirectoryName ( task . InputFile ) + "\\ " + task . OutputFile , task . MediaOutFile ) ;
454437 }
438+ if ( task . MkaOutFile . Tracks . Count > 0 )
439+ {
440+ task . CurrentStatus = "封装MKA中" ;
441+ FileInfo mkvInfo = new FileInfo ( ".\\ tools\\ mkvtoolnix\\ mkvmerge.exe" ) ;
442+ FileInfo lsmash = new FileInfo ( ".\\ tools\\ l-smash\\ muxer.exe" ) ;
443+ AutoMuxer muxer = new AutoMuxer ( mkvInfo . FullName , lsmash . FullName ) ;
444+ muxer . ProgressChanged += progress => task . ProgressValue = progress ;
445+ string mkaOutputFile = task . InputFile + ".mka" ;
446+
447+ muxer . StartMuxing ( mkaOutputFile , task . MkaOutFile ) ;
448+ }
455449
456450 task . CurrentStatus = "完成" ;
457451 task . ProgressValue = 100 ;
0 commit comments