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
b1905755
Commit
b1905755
authored
5 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
allow setting minimal distance
parent
e6a0429f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main.rs
+39
-36
39 additions, 36 deletions
src/main.rs
src/media_time.rs
+17
-1
17 additions, 1 deletion
src/media_time.rs
src/spritesheet.rs
+7
-1
7 additions, 1 deletion
src/spritesheet.rs
with
63 additions
and
38 deletions
src/main.rs
+
39
−
36
View file @
b1905755
...
...
@@ -7,7 +7,7 @@ pub(crate) mod spritesheet;
use
crate
::
ffmpeg_api
::
enums
::
*
;
use
crate
::
ffmpeg_api
::
api
::
*
;
use
image
::{
ImageBuffer
}
;
use
crate
::
media_time
::
MediaTime
;
fn
main
()
->
Result
<
(),
std
::
io
::
Error
>
{
let
mut
before
=
std
::
time
::
SystemTime
::
now
();
...
...
@@ -25,6 +25,7 @@ fn main() -> Result<(), std::io::Error> {
let
mut
spritesheet_manager
=
spritesheet
::
SpritesheetManager
::
new
(
160
,
5
,
5
,
MediaTime
::
from_seconds
(
10
),
output
,
);
...
...
@@ -89,6 +90,7 @@ fn main() -> Result<(), std::io::Error> {
println!
(
"Reading Time: {:#?}"
,
before
.elapsed
()
.unwrap
());
before
=
std
::
time
::
SystemTime
::
now
();
if
spritesheet_manager
.fulfils_frame_interval
(
stream
.timestamp
(
frame
.pts
()))
{
if
!
spritesheet_manager
.initialized
()
{
spritesheet_manager
.initialize
(
frame
.width
()
as
u32
,
frame
.height
()
as
u32
);
output_frame
.init
(
...
...
@@ -114,7 +116,7 @@ fn main() -> Result<(), std::io::Error> {
spritesheet_manager
.add_image
(
stream
.timestamp
(
frame
.pts
()),
ImageBuffer
::
from_raw
(
image
::
ImageBuffer
::
from_raw
(
output_frame
.width
()
as
u32
,
output_frame
.height
()
as
u32
,
output_frame
.data
(
0
)
.to_vec
(),
...
...
@@ -128,6 +130,7 @@ fn main() -> Result<(), std::io::Error> {
}
}
}
}
spritesheet_manager
.end_frame
(
stream
.duration
());
spritesheet_manager
.save
();
...
...
This diff is collapsed.
Click to expand it.
src/media_time.rs
+
17
−
1
View file @
b1905755
use
fraction
::
Fraction
;
#[derive(Copy,Clone,Debug)]
#[derive(Copy,
Clone,
Debug
,
Eq,
PartialEq,
Ord,
PartialOrd
)]
pub
struct
MediaTime
(
time
::
Duration
);
impl
MediaTime
{
...
...
@@ -41,3 +41,19 @@ impl std::fmt::Display for MediaTime {
}
}
}
impl
std
::
ops
::
Add
for
MediaTime
{
type
Output
=
Self
;
fn
add
(
self
,
other
:
Self
)
->
Self
{
Self
(
self
.0
+
other
.0
)
}
}
impl
std
::
ops
::
Sub
for
MediaTime
{
type
Output
=
Self
;
fn
sub
(
self
,
other
:
Self
)
->
Self
{
Self
(
self
.0
-
other
.0
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/spritesheet.rs
+
7
−
1
View file @
b1905755
...
...
@@ -11,13 +11,14 @@ pub struct SpritesheetManager {
spritesheet
:
RgbImage
,
current_image
:
u32
,
last_timestamp
:
MediaTime
,
frame_interval
:
MediaTime
,
metadata
:
WebVTTFile
,
output_path
:
std
::
string
::
String
,
initialized
:
bool
,
}
impl
SpritesheetManager
{
pub
fn
new
<
T
:
AsRef
<
str
>>
(
max_side
:
u32
,
num_horizontal
:
u32
,
num_vertical
:
u32
,
output_path
:
T
)
->
SpritesheetManager
{
pub
fn
new
<
T
:
AsRef
<
str
>>
(
max_side
:
u32
,
num_horizontal
:
u32
,
num_vertical
:
u32
,
frame_interval
:
MediaTime
,
output_path
:
T
)
->
SpritesheetManager
{
SpritesheetManager
{
num_horizontal
,
num_vertical
,
...
...
@@ -27,6 +28,7 @@ impl SpritesheetManager {
spritesheet
:
ImageBuffer
::
new
(
0
,
0
),
current_image
:
0
,
last_timestamp
:
MediaTime
::
from_millis
(
0
),
frame_interval
,
metadata
:
WebVTTFile
::
new
(),
output_path
:
std
::
string
::
String
::
from
(
output_path
.as_ref
()),
initialized
:
false
,
...
...
@@ -82,6 +84,10 @@ impl SpritesheetManager {
index
*
self
.sprite_height
}
pub
fn
fulfils_frame_interval
(
&
self
,
timestamp
:
MediaTime
)
->
bool
{
timestamp
-
self
.last_timestamp
>
self
.frame_interval
}
pub
fn
add_image
(
&
mut
self
,
timestamp
:
MediaTime
,
image
:
RgbImage
)
{
if
image
.width
()
!=
self
.sprite_width
||
image
.height
()
!=
self
.sprite_height
{
panic!
(
...
...
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