99
1010namespace OKEGui
1111{
12- public class x265Encoder : CommandlineVideoEncoder
12+ public class X265Encoder : CommandlineVideoEncoder
1313 {
14- // public static readonly JobProcessorFactory Factory = new JobProcessorFactory(new ProcessorFactory(init), "x265Encoder");
14+ private readonly string x265Path = "" ;
15+ private readonly string vspipePath = "" ;
1516
16- private string x265Path = "" ;
17- private string vspipePath = "" ;
18-
19- public static IJobProcessor init ( Job j , string extractParam )
20- {
21- if ( j is VideoJob && ( ( j as VideoJob ) . CodecString == "X265" || ( j as VideoJob ) . CodecString == "HEVC" ) ) {
22- return new x265Encoder ( ( j as VideoJob ) , extractParam ) ;
23- }
24- return null ;
25- }
26-
27- public x265Encoder ( Job j , string extractParam )
28- : base ( )
17+ public X265Encoder ( Job j ) : base ( )
2918 {
3019 job = j as VideoJob ;
3120 getInputProperties ( job ) ;
3221
3322 executable = Path . Combine ( Environment . SystemDirectory , "cmd.exe" ) ;
3423
35- if ( File . Exists ( job . EncoderPath ) ) {
24+ if ( File . Exists ( job . EncoderPath ) )
25+ {
3626 this . x265Path = job . EncoderPath ;
3727 }
3828
3929 // 获取VSPipe路径
4030 this . vspipePath = ConfigManager . Config . vspipePath ;
4131
42- commandLine = BuildCommandline ( extractParam ) ;
32+ commandLine = BuildCommandline ( job . EncodeParam , job . NumaNode ) ;
4333 }
4434
4535 public override void ProcessLine ( string line , StreamType stream )
4636 {
47- //if (line.StartsWith("[")) // status update
48- //{
49- // int frameNumberStart = line.IndexOf("]", 4) + 2;
50- // int frameNumberEnd = line.IndexOf("/");
51- // if (frameNumberStart > 0 && frameNumberEnd > 0 && frameNumberEnd > frameNumberStart)
52- // if (base.setFrameNumber(line.Substring(frameNumberStart, frameNumberEnd - frameNumberStart).Trim()))
53- // return;
54- //}
5537 if ( line . Contains ( "x265 [error]:" ) )
5638 {
5739 OKETaskException ex = new OKETaskException ( Constants . x265ErrorSmr ) ;
@@ -66,15 +48,17 @@ public override void ProcessLine(string line, StreamType stream)
6648 throw ex ;
6749 }
6850
69- if ( line . ToLowerInvariant ( ) . Contains ( "encoded" ) ) {
51+ if ( line . ToLowerInvariant ( ) . Contains ( "encoded" ) )
52+ {
7053 Regex rf = new Regex ( "encoded ([0-9]+) frames in ([0-9]+.[0-9]+)s \\ (([0-9]+.[0-9]+) fps\\ ), ([0-9]+.[0-9]+) kb/s, Avg QP:(([0-9]+.[0-9]+))" ) ;
7154
7255 var result = rf . Split ( line ) ;
7356
7457 ulong reportedFrames = ulong . Parse ( result [ 1 ] ) ;
7558
7659 // 这里是平均速度
77- if ( ! base . setSpeed ( result [ 3 ] ) ) {
60+ if ( ! base . setSpeed ( result [ 3 ] ) )
61+ {
7862 return ;
7963 }
8064
@@ -86,32 +70,34 @@ public override void ProcessLine(string line, StreamType stream)
8670 Regex r = new Regex ( "([0-9]+) frames: ([0-9]+.[0-9]+) fps, ([0-9]+.[0-9]+) kb/s" , RegexOptions . IgnoreCase ) ;
8771
8872 var status = r . Split ( line ) ;
89- if ( status . Length < 3 ) {
73+ if ( status . Length < 3 )
74+ {
9075 return ;
9176 }
9277
93- if ( ! base . setFrameNumber ( status [ 1 ] , true ) ) {
78+ if ( ! base . setFrameNumber ( status [ 1 ] , true ) )
79+ {
9480 return ;
9581 }
9682
9783 base . setBitrate ( status [ 3 ] , "kb/s" ) ;
9884
99- if ( ! base . setSpeed ( status [ 2 ] ) ) {
85+ if ( ! base . setSpeed ( status [ 2 ] ) )
86+ {
10087 return ;
10188 }
10289
10390 base . ProcessLine ( line , stream ) ;
10491 }
10592
106- // TODO: 改为静态
107- public /*static*/ string BuildCommandline ( string extractParam )
93+ private string BuildCommandline ( string extractParam , int numaNode )
10894 {
10995 StringBuilder sb = new StringBuilder ( ) ;
11096
111- sb . Append ( "/c " ) ;
112- sb . Append ( " \" " ) ;
97+ sb . Append ( "/c \" start \" foo \" /b /wait /affinity 0xFFFFFFF /node " ) ;
98+ sb . Append ( numaNode . ToString ( ) ) ;
11399 // 构建vspipe参数
114- sb . Append ( "\" " + vspipePath + "\" " ) ;
100+ sb . Append ( " \" " + vspipePath + "\" " ) ;
115101 sb . Append ( " --y4m " ) ;
116102 sb . Append ( "\" " + job . Input + "\" " ) ;
117103 sb . Append ( " - | " ) ;
0 commit comments