Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
Nicolas Pope
ftl
Commits
a48b5c69
Commit
a48b5c69
authored
5 years ago
by
Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
python module
parent
9fe74b62
No related branches found
No related tags found
2 merge requests
!155
Feature/python
,
!141
Python module for reading .ftl files
Pipeline
#15835
passed
5 years ago
Stage: all
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
python/ftl/__init__.py
+1
-0
1 addition, 0 deletions
python/ftl/__init__.py
python/ftl/ftlstream.py
+125
-0
125 additions, 0 deletions
python/ftl/ftlstream.py
python/ftl/libde265.py
+0
-0
0 additions, 0 deletions
python/ftl/libde265.py
python/ftlstream.py
+0
-31
0 additions, 31 deletions
python/ftlstream.py
with
126 additions
and
31 deletions
python/ftl/__init__.py
0 → 100644
+
1
−
0
View file @
a48b5c69
from
.
ftlstream
import
FTLStream
\ No newline at end of file
This diff is collapsed.
Click to expand it.
python/ftl/ftlstream.py
0 → 100644
+
125
−
0
View file @
a48b5c69
import
msgpack
from
collections
import
namedtuple
from
.
libde265
import
Decoder
_packet
=
namedtuple
(
"
Packet
"
,
[
"
codec
"
,
"
definition
"
,
"
block_total
"
,
"
block_number
"
,
"
flags
"
,
"
data
"
])
_stream_packet
=
namedtuple
(
"
StreamPacket
"
,
[
"
timestamp
"
,
"
streamID
"
,
"
chanel_count
"
,
"
channel
"
])
_definition_t
=
{
0
:
(),
1
:
(),
2
:
(
1080
,
1920
),
3
:
(
720
,
1280
),
4
:
(),
5
:
(),
6
:
(),
7
:
(),
8
:
()
}
class
FTLStream
:
def
__init__
(
self
,
file
):
self
.
_file
=
open
(
file
,
"
br
"
)
self
.
_decoders
=
{}
self
.
_frames
=
{}
try
:
magic
=
self
.
_file
.
read
(
5
)
if
magic
[:
4
]
!=
bytearray
(
ord
(
c
)
for
c
in
"
FTLF
"
):
raise
Exception
(
"
wrong magic
"
)
self
.
_unpacker
=
msgpack
.
Unpacker
(
self
.
_file
,
raw
=
True
,
use_list
=
False
)
except
Exception
as
ex
:
self
.
_file
.
close
()
raise
ex
self
.
_packets_read
=
0
def
__del__
(
self
):
self
.
_file
.
close
()
def
_read_next
(
self
):
v1
,
v2
=
self
.
_unpacker
.
unpack
()
return
_stream_packet
.
_make
(
v1
),
_packet
.
_make
(
v2
)
def
_update_calib
(
self
,
sp
,
p
):
'''
Update calibration
'''
pass
def
_update_pose
(
self
,
sp
,
p
):
'''
Update pose
'''
pass
def
_decode_frame_hevc
(
self
,
sp
,
p
):
'''
Decode HEVC frame
'''
k
=
(
sp
.
streamID
,
sp
.
channel
)
if
k
not
in
self
.
_decoders
:
self
.
_decoders
[
k
]
=
Decoder
(
_definition_t
[
p
.
definition
])
decoder
=
self
.
_decoders
[
k
]
decoder
.
push_data
(
p
.
data
)
decoder
.
decode
()
img
=
decoder
.
get_next_picture
()
if
img
is
not
None
:
self
.
_frames
[
k
]
=
img
def
read
(
self
):
'''
Reads data for until the next timestamp. Returns False if there is no
more data to read, otherwise returns True.
'''
if
self
.
_packets_read
==
0
:
self
.
_sp
,
self
.
_p
=
self
.
_read_next
()
self
.
_packets_read
+=
1
self
.
_frames
=
{}
ts
=
self
.
_sp
.
timestamp
ex
=
None
while
self
.
_sp
.
timestamp
==
ts
:
try
:
if
self
.
_p
.
codec
==
100
:
# JSON
NotImplementedError
(
"
json decoding not implemented
"
)
elif
self
.
_p
.
codec
==
101
:
# CALIBRATION
self
.
_update_calib
(
self
.
_sp
,
self
.
_p
)
elif
self
.
_p
.
codec
==
102
:
# POSE
self
.
_update_pose
(
self
.
_sp
,
self
.
_p
)
elif
self
.
_p
.
codec
==
3
:
# HEVC
self
.
_decode_frame_hevc
(
self
.
_sp
,
self
.
_p
)
else
:
raise
ValueError
(
"
unkowno codec %i
"
%
p
.
codec
)
except
Exception
as
e
:
ex
=
e
try
:
self
.
_sp
,
self
.
_p
=
self
.
_read_next
()
self
.
_packets_read
+=
1
except
msgpack
.
OutOfData
:
return
False
if
ex
is
not
None
:
raise
ex
return
True
def
get_frames
(
self
):
'''
Returns all frames
'''
return
self
.
_frames
def
get_frame
(
self
,
source
,
channel
):
k
=
(
source
,
channel
)
if
k
in
self
.
_frames
:
return
self
.
_frames
[
k
]
else
:
return
None
This diff is collapsed.
Click to expand it.
python/libde265.py
→
python/
ftl/
libde265.py
+
0
−
0
View file @
a48b5c69
File moved
This diff is collapsed.
Click to expand it.
python/ftlstream.py
deleted
100644 → 0
+
0
−
31
View file @
9fe74b62
import
msgpack
from
collections
import
namedtuple
_packet
=
namedtuple
(
"
Packet
"
,
[
"
codec
"
,
"
definition
"
,
"
block_total
"
,
"
block_number
"
,
"
flags
"
,
"
data
"
])
_stream_packet
=
namedtuple
(
"
StreamPacket
"
,
[
"
timestamp
"
,
"
streamID
"
,
"
chanel_count
"
,
"
channel
"
])
class
FTLStream
:
def
__init__
(
self
,
file
):
self
.
_file
=
open
(
file
,
"
br
"
)
try
:
magic
=
self
.
_file
.
read
(
5
)
if
magic
[:
4
]
!=
bytearray
(
ord
(
c
)
for
c
in
"
FTLF
"
):
raise
Exception
(
"
wrong magic
"
)
self
.
_unpacker
=
msgpack
.
Unpacker
(
self
.
_file
,
raw
=
True
,
use_list
=
False
)
except
Exception
as
ex
:
self
.
_file
.
close
()
raise
ex
def
__del__
(
self
):
self
.
_file
.
close
()
def
read
(
self
):
# TODO: Different methods for reading different types?
return
self
.
_read_next
()
def
_read_next
(
self
):
v1
,
v2
=
self
.
_unpacker
.
unpack
()
return
_stream_packet
.
_make
(
v1
),
_packet
.
_make
(
v2
)
\ No newline at end of file
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