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
38a6bc5f
Commit
38a6bc5f
authored
5 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Fixing explicit lifetime issues
parent
02ac49cf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ffmpeg_api/api.rs
+6
-7
6 additions, 7 deletions
src/ffmpeg_api/api.rs
src/thumbnail/extract.rs
+12
-7
12 additions, 7 deletions
src/thumbnail/extract.rs
with
18 additions
and
14 deletions
src/ffmpeg_api/api.rs
+
6
−
7
View file @
38a6bc5f
...
...
@@ -45,7 +45,7 @@ impl<'a> AVFormatContext {
)
}
)
.iter
()
.map
(|
stream
|
{
AVStream
::
new
(
unsafe
{
(
*
stream
)
.as_mut
()
}
.expect
(
"not null"
)
,
&
self
)
AVStream
::
new
(
unsafe
{
(
*
stream
)
.as_mut
()
}
.expect
(
"not null"
))
})
.collect
()
}
...
...
@@ -59,11 +59,11 @@ impl<'a> AVFormatContext {
)
}
)
.iter
()
.map
(|
stream
|
{
AVStream
::
new
(
unsafe
{
(
*
stream
)
.as_mut
()
}
.expect
(
"not null"
)
,
&
self
)
AVStream
::
new
(
unsafe
{
(
*
stream
)
.as_mut
()
}
.expect
(
"not null"
))
})
.find
(
predicate
)
}
pub
fn
read_frame
(
&
self
,
packet
:
&
mut
AVPacket
)
->
Result
<
(),
failure
::
Error
>
{
pub
fn
read_frame
(
&
mut
self
,
packet
:
&
mut
AVPacket
)
->
Result
<
(),
failure
::
Error
>
{
match
unsafe
{
ffi
::
av_read_frame
(
self
.base
,
packet
.base
)
}
{
0
=>
Ok
(()),
errno
=>
Err
(
failure
::
format_err!
(
"Error while decoding frame: {}"
,
errno
))
...
...
@@ -273,13 +273,12 @@ impl Drop for AVFrame {
}
pub
struct
AVStream
<
'a
>
{
base
:
&
'a
mut
ffi
::
AVStream
,
phantom
:
PhantomData
<&
'a
AVFormatContext
>
,
base
:
&
'a
mut
ffi
::
AVStream
}
impl
<
'a
>
AVStream
<
'a
>
{
fn
new
(
base
:
&
'a
mut
ffi
::
AVStream
,
_
:
&
'a
AVFormatContext
)
->
Self
{
return
AVStream
{
base
,
phantom
:
PhantomData
};
fn
new
(
base
:
&
'a
mut
ffi
::
AVStream
)
->
Self
{
return
AVStream
{
base
};
}
pub
fn
index
(
self
:
&
AVStream
<
'a
>
)
->
i32
{
...
...
This diff is collapsed.
Click to expand it.
src/thumbnail/extract.rs
+
12
−
7
View file @
38a6bc5f
...
...
@@ -32,15 +32,18 @@ pub fn extract<T: AsRef<str>, U: AsRef<str>>(
})
.ok_or_else
(||
{
format_err!
(
"Could not find video stream"
)
})
?
;
stream
.set_discard
(
AVDiscard
::
NonKey
);
let
index
=
stream
.index
();
let
time_base
=
stream
.time_base
();
let
duration
=
stream
.duration
()
?
;
let
codec_parameters
=
stream
.codec_parameters
();
let
local_codec
=
codec_parameters
.find_decoder
();
println!
(
"Stream #{}, type: {:#?}, codec: {:#?}"
,
stream
.
index
()
,
index
,
codec_parameters
.codec_type
(),
local_codec
.name
()
);
...
...
@@ -71,19 +74,21 @@ pub fn extract<T: AsRef<str>, U: AsRef<str>>(
let
mut
scale_context
=
SwsContext
::
new
();
while
avformat_context
.read_frame
(
&
mut
packet
)
.is_ok
()
{
if
packet
.stream_index
()
==
stream
.
index
()
{
if
packet
.stream_index
()
==
index
{
codec_context
.in_packet
(
&
mut
packet
)
.map_err
(|
error
|
{
format_err!
(
"Could not load packet: {:?}"
,
error
)
})
?
;
while
codec_context
.out_frame
(
&
mut
frame
)
.is_ok
()
{
let
timestamp
=
MediaTime
::
from_rational
(
frame
.pts
(),
time_base
)
?
;
println!
(
"Frame {}: {} @ {}"
,
frame
.coded_picture_number
(),
stream
.
timestamp
(
frame
.pts
())
?
,
timestamp
,
frame
.key_frame
()
);
if
spritesheet_manager
.fulfils_frame_interval
(
stream
.
timestamp
(
frame
.pts
())
?
)
{
if
spritesheet_manager
.fulfils_frame_interval
(
timestamp
)
{
if
!
spritesheet_manager
.initialized
()
{
spritesheet_manager
.initialize
(
frame
.width
()
as
u32
,
frame
.height
()
as
u32
);
output_frame
.init
(
...
...
@@ -105,7 +110,7 @@ pub fn extract<T: AsRef<str>, U: AsRef<str>>(
scale_context
.scale
(
&
frame
,
&
mut
output_frame
);
spritesheet_manager
.add_image
(
stream
.
timestamp
(
frame
.pts
())
?
,
timestamp
,
image
::
ImageBuffer
::
from_raw
(
output_frame
.width
()
as
u32
,
output_frame
.height
()
as
u32
,
...
...
@@ -119,7 +124,7 @@ pub fn extract<T: AsRef<str>, U: AsRef<str>>(
}
}
spritesheet_manager
.end_frame
(
stream
.
duration
()
?
);
spritesheet_manager
.end_frame
(
duration
);
spritesheet_manager
.save
()
?
;
}
...
...
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