Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
preview-generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaflix
preview-generator
Commits
168bf14d
Verified
Commit
168bf14d
authored
5 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Improve code readability
parent
0ea1013b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ffmpeg_api/api.rs
+17
-43
17 additions, 43 deletions
src/ffmpeg_api/api.rs
with
17 additions
and
43 deletions
src/ffmpeg_api/api.rs
+
17
−
43
View file @
168bf14d
...
...
@@ -104,13 +104,16 @@ impl<'a> AVInputFormat<'a> {
let
raw
:
*
const
::
std
::
os
::
raw
::
c_char
=
self
.base.long_name
;
if
raw
.is_null
()
{
Err
(
failure
::
format_err!
(
"No
mime type found
"
))
Err
(
failure
::
format_err!
(
"No
long name found for input format
"
))
}
else
{
Ok
(
String
::
from
(
unsafe
{
std
::
ffi
::
CStr
::
from_ptr
(
raw
)
}
.to_str
()
.map_err
(|
err
|
{
failure
::
format_err!
(
"Could not convert mime type to string: {}"
,
err
)
failure
::
format_err!
(
"Could not convert long name for input format to string: {}"
,
err
)
})
?
,
))
}
...
...
@@ -120,67 +123,38 @@ impl<'a> AVInputFormat<'a> {
let
raw
:
*
const
::
std
::
os
::
raw
::
c_char
=
self
.base.name
;
if
raw
.is_null
()
{
Err
(
failure
::
format_err!
(
"No mime type found"
))
}
else
{
Ok
(
String
::
from
(
unsafe
{
std
::
ffi
::
CStr
::
from_ptr
(
raw
)
}
.to_str
()
.map_err
(|
err
|
{
failure
::
format_err!
(
"Could not convert mime type to string: {}"
,
err
)
})
?
,
))
}
}
pub
fn
mime
(
&
self
)
->
Result
<
String
,
failure
::
Error
>
{
let
raw
:
*
const
::
std
::
os
::
raw
::
c_char
=
self
.base.mime_type
;
if
raw
.is_null
()
{
Err
(
failure
::
format_err!
(
"No mime type found"
))
Err
(
failure
::
format_err!
(
"No name found for input format"
))
}
else
{
Ok
(
String
::
from
(
unsafe
{
std
::
ffi
::
CStr
::
from_ptr
(
raw
)
}
.to_str
()
.map_err
(|
err
|
{
failure
::
format_err!
(
"Could not convert mime type to string: {}"
,
err
)
failure
::
format_err!
(
"Could not convert name for input format to string: {}"
,
err
)
})
?
,
))
}
}
pub
fn
determine_mime
<
T
:
AsRef
<
str
>>
(
&
self
,
stream_codec
:
T
)
->
Result
<
String
,
failure
::
Error
>
{
pub
fn
determine_mime
<
T
:
AsRef
<
str
>>
(
&
self
,
stream_codec
:
T
)
->
Result
<
&
str
,
failure
::
Error
>
{
let
containers
=
self
.name
()
?
;
let
stream_codec
=
stream_codec
.as_ref
();
for
container
in
containers
.split
(
","
)
{
match
container
{
"mp4"
=>
match
stream_codec
{
"h264"
=>
{
return
Ok
(
String
::
from
(
"video/mp4"
));
}
_
=>
{
// Do nothing
}
},
"webm"
=>
match
stream_codec
{
"vp8"
|
"vp9"
|
"av1"
=>
{
return
Ok
(
String
::
from
(
"video/webm"
));
}
_
=>
{
// Do nothing
}
},
_
=>
{
// Do nothing
}
match
(
container
,
stream_codec
)
{
(
"mp4"
,
"h264"
)
=>
return
Ok
(
"video/mp4"
),
(
"webm"
,
"vp8"
)
|
(
"webm"
,
"vp9"
)
|
(
"webm"
,
"av1"
)
=>
return
Ok
(
"video/webm"
),
_
=>
{}
}
}
return
Err
(
failure
::
format_err
!
(
bail
!
(
"Could not determine mime type: {} video in {} container"
,
stream_codec
,
containers
)
);
)
}
}
...
...
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