Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Parser
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anduin Xue
Parser
Commits
71ec7b7b
There was an error fetching the commit references. Please try again later.
Commit
71ec7b7b
authored
2 years ago
by
Anduin Xue
Browse files
Options
Downloads
Patches
Plain Diff
Release 0.0.3
parent
63e2e68c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Parser.FFmpeg/FFmpegEntry.cs
+40
-26
40 additions, 26 deletions
src/Parser.FFmpeg/FFmpegEntry.cs
src/Parser.FFmpeg/Services/CommandService.cs
+1
-1
1 addition, 1 deletion
src/Parser.FFmpeg/Services/CommandService.cs
src/Parser/Parser.csproj
+1
-1
1 addition, 1 deletion
src/Parser/Parser.csproj
with
42 additions
and
28 deletions
src/Parser.FFmpeg/FFmpegEntry.cs
+
40
−
26
View file @
71ec7b7b
...
@@ -9,6 +9,7 @@ namespace Aiursoft.Parser.FFmpeg
...
@@ -9,6 +9,7 @@ namespace Aiursoft.Parser.FFmpeg
private
readonly
ILogger
<
FFmpegEntry
>
_logger
;
private
readonly
ILogger
<
FFmpegEntry
>
_logger
;
private
readonly
FFmpegOptions
_options
;
private
readonly
FFmpegOptions
_options
;
private
readonly
CommandService
_commandService
;
private
readonly
CommandService
_commandService
;
private
const
long
MbToBytes
=
1024
*
1024
;
public
FFmpegEntry
(
public
FFmpegEntry
(
ILogger
<
FFmpegEntry
>
logger
,
ILogger
<
FFmpegEntry
>
logger
,
...
@@ -34,45 +35,58 @@ namespace Aiursoft.Parser.FFmpeg
...
@@ -34,45 +35,58 @@ namespace Aiursoft.Parser.FFmpeg
foreach
(
var
file
in
videos
)
foreach
(
var
file
in
videos
)
{
{
_logger
.
LogTrace
(
"Parsing video file: "
+
file
);
_logger
.
LogTrace
(
"Parsing video file: "
+
file
);
await
Parse
(
file
,
coder
:
_options
.
UseGpu
?
"hevc_nvenc"
:
"libx265"
);
await
this
.
ProcessVideoAsync
(
file
);
}
}
}
}
private
async
Task
P
arse
(
string
filePath
,
string
coder
)
private
async
Task
P
rocessVideoAsync
(
string
filePath
)
{
{
var
folder
=
Path
.
GetDirectoryName
(
filePath
)
??
throw
new
Exception
(
$"
{
filePath
}
is invalid!"
);
var
folder
=
Path
.
GetDirectoryName
(
filePath
)
??
throw
new
Exception
(
$"
{
filePath
}
is invalid!"
);
var
baseFileInfo
=
await
_commandService
.
RunCommand
(
"ffmpeg"
,
$@"-i ""
{
filePath
}
"""
,
folder
);
var
baseFileInfo
=
await
_commandService
.
RunCommand
Async
(
"ffmpeg"
,
$@"-i ""
{
filePath
}
"""
,
folder
);
var
fileInfo
=
new
FileInfo
(
filePath
);
var
fileInfo
=
new
FileInfo
(
filePath
);
var
shouldParse
=
fileInfo
.
Length
>
20
*
1024
*
1024
&&
// 20MB
(
if
(
ShouldParseVideo
(
baseFileInfo
,
fileInfo
))
!
baseFileInfo
.
Contains
(
"Video: hevc"
)
||
// Not HEVC
!
filePath
.
EndsWith
(
".mp4"
)
||
// Or not MP4
baseFileInfo
.
Contains
(
"creation_time"
)
// Or contains privacy info (Never parsed before)
);
var
bareName
=
Path
.
GetFileNameWithoutExtension
(
filePath
);
var
newFileName
=
$"
{
fileInfo
.
Directory
}{
Path
.
DirectorySeparatorChar
}{
bareName
}
_265.mp4"
;
if
(
shouldParse
)
{
{
_logger
.
LogWarning
(
$"
{
filePath
}
WILL be parsed, with codec:
{
coder
}
, crf is
{
_options
.
Crf
}
"
);
var
newFileName
=
GetNewFileName
(
fileInfo
);
await
ParseVideoAsync
(
filePath
,
newFileName
,
folder
,
coder
:
_options
.
UseGpu
?
"hevc_nvenc"
:
"libx265"
,
crf
:
_options
.
Crf
);
}
else
{
_logger
.
LogInformation
(
$"
{
filePath
}
don't have to be parsed..."
);
}
}
File
.
Delete
(
newFileName
);
private
bool
ShouldParseVideo
(
string
baseFileInfo
,
FileInfo
fileInfo
)
await
_commandService
.
RunCommand
(
"ffmpeg"
,
$@"-i ""
{
filePath
}
"" -codec:a copy -codec:v
{
coder
}
-crf
{
_options
.
Crf
}
""
{
newFileName
}
"""
,
folder
,
getOutput
:
false
);
{
return
fileInfo
.
Length
>
20
*
MbToBytes
&&
(!
baseFileInfo
.
Contains
(
"Video: hevc"
)
||
!
fileInfo
.
Name
.
EndsWith
(
".mp4"
)
||
baseFileInfo
.
Contains
(
"creation_time"
));
}
if
(
File
.
Exists
(
newFileName
)
&&
new
FileInfo
(
newFileName
).
Length
>
8
*
1024
*
1024
)
// Larger than 8MB.
private
string
GetNewFileName
(
FileInfo
fileInfo
)
{
{
// Delete old file.
var
bareName
=
Path
.
GetFileNameWithoutExtension
(
fileInfo
.
FullName
);
File
.
Delete
(
filePath
);
return
$"
{
fileInfo
.
Directory
}{
Path
.
DirectorySeparatorChar
}{
bareName
}
_265.mp4"
;
}
}
else
{
private
async
Task
ParseVideoAsync
(
string
sourceFilePath
,
string
targetFilePath
,
string
folder
,
string
coder
,
int
crf
)
throw
new
Exception
(
"After parsing, still couldn't locate the converted file: "
+
newFileName
);
{
}
_logger
.
LogWarning
(
$"
{
sourceFilePath
}
WILL be parsed, with codec:
{
coder
}
, crf is
{
crf
}
"
);
if
(
File
.
Exists
(
targetFilePath
))
{
File
.
Delete
(
targetFilePath
);
}
await
_commandService
.
RunCommandAsync
(
"ffmpeg"
,
$@"-i ""
{
sourceFilePath
}
"" -preset slower -codec:a copy -codec:v
{
coder
}
-crf
{
crf
}
""
{
targetFilePath
}
"""
,
folder
,
getOutput
:
false
);
var
targetFileInfo
=
new
FileInfo
(
targetFilePath
);
if
(
targetFileInfo
.
Exists
&&
targetFileInfo
.
Length
>
8
*
MbToBytes
)
{
File
.
Delete
(
sourceFilePath
);
}
}
else
else
{
{
_logger
.
LogInformation
(
$"
{
filePath
}
don't have to be parsed..."
);
throw
new
Exception
(
"After parsing, still couldn't locate the converted file: "
+
targetFilePath
);
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Parser.FFmpeg/Services/CommandService.cs
+
1
−
1
View file @
71ec7b7b
...
@@ -4,7 +4,7 @@ namespace Aiursoft.Parser.FFmpeg.Services
...
@@ -4,7 +4,7 @@ namespace Aiursoft.Parser.FFmpeg.Services
{
{
public
class
CommandService
public
class
CommandService
{
{
public
async
Task
<
string
>
RunCommand
(
string
bin
,
string
arg
,
string
path
,
bool
getOutput
=
true
)
public
async
Task
<
string
>
RunCommand
Async
(
string
bin
,
string
arg
,
string
path
,
bool
getOutput
=
true
)
{
{
var
p
=
new
Process
var
p
=
new
Process
{
{
...
...
This diff is collapsed.
Click to expand it.
src/Parser/Parser.csproj
+
1
−
1
View file @
71ec7b7b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<PropertyGroup>
<PropertyGroup>
<!--Build and code-->
<!--Build and code-->
<OutputType>Exe</OutputType>
<OutputType>Exe</OutputType>
<Version>0.0.
2
</Version>
<Version>0.0.
3
</Version>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>parser</AssemblyName>
<AssemblyName>parser</AssemblyName>
<RootNamespace>Aiursoft.Parser</RootNamespace>
<RootNamespace>Aiursoft.Parser</RootNamespace>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment