Skip to content

Commit

Permalink
refactor: camm module (#693)
Browse files Browse the repository at this point in the history
* move modules

* fix imports in tests
  • Loading branch information
ptpt authored Dec 12, 2024
1 parent 8bcc73d commit 1aa5b41
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
from ..mp4 import (
construct_mp4_parser as cparser,
mp4_sample_parser as sample_parser,
)

from . import (
camm_parser,
simple_mp4_builder as builder,
)
from .simple_mp4_builder import BoxDict

from . import camm_parser


def build_camm_sample(point: geo.Point) -> bytes:
Expand All @@ -31,7 +28,7 @@ def _create_edit_list(
point_segments: T.Sequence[T.Sequence[geo.Point]],
movie_timescale: int,
media_timescale: int,
) -> BoxDict:
) -> builder.BoxDict:
entries: T.List[T.Dict] = []

for idx, points in enumerate(point_segments):
Expand Down Expand Up @@ -116,7 +113,9 @@ def convert_points_to_raw_samples(
)


def _create_camm_stbl(raw_samples: T.Iterable[sample_parser.RawSample]) -> BoxDict:
def _create_camm_stbl(
raw_samples: T.Iterable[sample_parser.RawSample],
) -> builder.BoxDict:
descriptions = [
{
"format": b"camm",
Expand All @@ -137,10 +136,10 @@ def _create_camm_stbl(raw_samples: T.Iterable[sample_parser.RawSample]) -> BoxDi
def create_camm_trak(
raw_samples: T.Sequence[sample_parser.RawSample],
media_timescale: int,
) -> BoxDict:
) -> builder.BoxDict:
stbl = _create_camm_stbl(raw_samples)

hdlr: BoxDict = {
hdlr: builder.BoxDict = {
"type": b"hdlr",
"data": {
"handler_type": b"camm",
Expand All @@ -152,7 +151,7 @@ def create_camm_trak(
assert media_timescale <= builder.UINT64_MAX

# Media Header Box
mdhd: BoxDict = {
mdhd: builder.BoxDict = {
"type": b"mdhd",
"data": {
# use 64-bit version
Expand All @@ -168,7 +167,7 @@ def create_camm_trak(
},
}

dinf: BoxDict = {
dinf: builder.BoxDict = {
"type": b"dinf",
"data": [
# self reference dref box
Expand All @@ -189,15 +188,15 @@ def create_camm_trak(
],
}

minf: BoxDict = {
minf: builder.BoxDict = {
"type": b"minf",
"data": [
dinf,
stbl,
],
}

tkhd: BoxDict = {
tkhd: builder.BoxDict = {
"type": b"tkhd",
"data": {
# use 32-bit version of the box
Expand All @@ -215,7 +214,7 @@ def create_camm_trak(
},
}

mdia: BoxDict = {
mdia: builder.BoxDict = {
"type": b"mdia",
"data": [
mdhd,
Expand All @@ -236,7 +235,7 @@ def create_camm_trak(
def camm_sample_generator2(video_metadata: types.VideoMetadata):
def _f(
fp: T.BinaryIO,
moov_children: T.List[BoxDict],
moov_children: T.List[builder.BoxDict],
) -> T.Generator[io.IOBase, None, None]:
movie_timescale = builder.find_movie_timescale(moov_children)
# make sure the precision of timedeltas not lower than 0.001 (1ms)
Expand All @@ -249,15 +248,15 @@ def _f(
[video_metadata.points], movie_timescale, media_timescale
)
if T.cast(T.Dict, elst["data"])["entries"]:
T.cast(T.List[BoxDict], camm_trak["data"]).append(
T.cast(T.List[builder.BoxDict], camm_trak["data"]).append(
{
"type": b"edts",
"data": [elst],
}
)
moov_children.append(camm_trak)

udta_data: T.List[BoxDict] = []
udta_data: T.List[builder.BoxDict] = []
if video_metadata.make:
udta_data.append(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import construct as C

from . import geo
from ..mp4 import simple_mp4_parser as sparser, mp4_sample_parser as sample_parser
from .. import geo
from ..mp4 import mp4_sample_parser as sample_parser, simple_mp4_parser as sparser


LOG = logging.getLogger(__name__)
Expand Down
9 changes: 2 additions & 7 deletions mapillary_tools/geotag/geotag_videos_from_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
from tqdm import tqdm

from .. import exceptions, geo, types
from . import (
blackvue_parser,
camm_parser,
gpmf_gps_filter,
gpmf_parser,
utils as video_utils,
)
from ..camm import camm_parser
from ..mp4 import simple_mp4_parser as sparser
from . import blackvue_parser, gpmf_gps_filter, gpmf_parser, utils as video_utils
from .geotag_from_generic import GeotagVideosFromGeneric

LOG = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion mapillary_tools/geotag/gpmf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import construct as C

from .. import geo, imu
from ..mp4.mp4_sample_parser import TrackBoxParser, MovieBoxParser, Sample
from ..mp4.mp4_sample_parser import MovieBoxParser, Sample, TrackBoxParser

"""
Parsing GPS from GPMF data format stored in GoPros. See the GPMF spec: https://github.com/gopro/gpmf-parser
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import io
import typing as T

from . import io_utils
from ..mp4 import (
from . import (
construct_mp4_parser as cparser,
io_utils,
mp4_sample_parser as sample_parser,
simple_mp4_parser as sparser,
)
from ..mp4.construct_mp4_parser import BoxDict
from ..mp4.mp4_sample_parser import RawSample
from .construct_mp4_parser import BoxDict
from .mp4_sample_parser import RawSample

"""
Variable naming conventions:
Expand Down
10 changes: 3 additions & 7 deletions mapillary_tools/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@
utils,
VERSION,
)
from .geotag import (
blackvue_parser,
camm_builder,
camm_parser,
simple_mp4_builder,
utils as video_utils,
)
from .camm import camm_builder, camm_parser
from .geotag import blackvue_parser, utils as video_utils
from .mp4 import simple_mp4_builder
from .types import FileType

JSONDict = T.Dict[str, T.Union[str, int, float, None]]
Expand Down
12 changes: 6 additions & 6 deletions mapillary_tools/video_data_extraction/extract_video_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

import mapillary_tools.geotag.utils as video_utils

from mapillary_tools import exceptions, geo, utils
from mapillary_tools.geotag import gpmf_gps_filter
from mapillary_tools.types import (
from .. import exceptions, geo, utils
from ..geotag import gpmf_gps_filter
from ..types import (
ErrorMetadata,
FileType,
MetadataOrError,
VideoMetadata,
VideoMetadataOrError,
)
from mapillary_tools.video_data_extraction import video_data_parser_factory
from mapillary_tools.video_data_extraction.cli_options import CliOptions
from mapillary_tools.video_data_extraction.extractors.base_parser import BaseParser
from . import video_data_parser_factory
from .cli_options import CliOptions
from .extractors.base_parser import BaseParser


LOG = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import typing as T
from pathlib import Path

from mapillary_tools import geo
from mapillary_tools.video_data_extraction.cli_options import (
CliOptions,
CliParserOptions,
)
from ... import geo
from ..cli_options import CliOptions, CliParserOptions

LOG = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing as T

from ... import geo
from ...geotag import camm_parser
from ...camm import camm_parser
from ...mp4 import simple_mp4_parser as sparser
from .base_parser import BaseParser

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
import typing as T
from pathlib import Path

from mapillary_tools import constants, exceptions, geo
from mapillary_tools.video_data_extraction.cli_options import (
CliOptions,
CliParserOptions,
)
from mapillary_tools.video_data_extraction.extractors.base_parser import BaseParser
from mapillary_tools.video_data_extraction.extractors.exiftool_xml_parser import (
ExiftoolXmlParser,
)
from ... import constants, exceptions, geo
from ..cli_options import CliOptions, CliParserOptions
from .base_parser import BaseParser
from .exiftool_xml_parser import ExiftoolXmlParser


class ExiftoolRuntimeParser(BaseParser):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

from pathlib import Path

from mapillary_tools import geo
from mapillary_tools.exiftool_read import EXIFTOOL_NAMESPACES
from mapillary_tools.exiftool_read_video import ExifToolReadVideo
from mapillary_tools.geotag.geotag_videos_from_exiftool_video import _DESCRIPTION_TAG
from mapillary_tools.video_data_extraction.cli_options import (
CliOptions,
CliParserOptions,
)
from mapillary_tools.video_data_extraction.extractors.base_parser import BaseParser
from ... import geo
from ...exiftool_read import EXIFTOOL_NAMESPACES
from ...exiftool_read_video import ExifToolReadVideo
from ...geotag.geotag_videos_from_exiftool_video import _DESCRIPTION_TAG
from ..cli_options import CliOptions, CliParserOptions
from .base_parser import BaseParser


class ExiftoolXmlParser(BaseParser):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import typing as T
from pathlib import Path

from mapillary_tools import geo
from mapillary_tools.video_data_extraction.cli_options import (
CliOptions,
CliParserOptions,
)
from mapillary_tools.video_data_extraction.extractors.base_parser import BaseParser
from mapillary_tools.video_data_extraction.extractors.blackvue_parser import (
BlackVueParser,
)
from mapillary_tools.video_data_extraction.extractors.camm_parser import CammParser
from mapillary_tools.video_data_extraction.extractors.gopro_parser import GoProParser
from ... import geo
from ..cli_options import CliOptions, CliParserOptions
from .base_parser import BaseParser
from .blackvue_parser import BlackVueParser
from .camm_parser import CammParser
from .gopro_parser import GoProParser


class GenericVideoParser(BaseParser):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typing as T

from mapillary_tools import geo
from mapillary_tools.geotag import geotag_images_from_gpx_file
from mapillary_tools.video_data_extraction.extractors.base_parser import BaseParser
from ... import geo
from ...geotag import geotag_images_from_gpx_file
from .base_parser import BaseParser


class GpxParser(BaseParser):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typing as T

from mapillary_tools import geo
from mapillary_tools.geotag import geotag_images_from_nmea_file
from mapillary_tools.video_data_extraction.extractors.base_parser import BaseParser
from ... import geo
from ...geotag import geotag_images_from_nmea_file
from .base_parser import BaseParser


class NmeaParser(BaseParser):
Expand Down
29 changes: 12 additions & 17 deletions mapillary_tools/video_data_extraction/video_data_parser_factory.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import typing as T
from pathlib import Path

from mapillary_tools.video_data_extraction.cli_options import CliOptions

from mapillary_tools.video_data_extraction.extractors.base_parser import BaseParser

from mapillary_tools.video_data_extraction.extractors.blackvue_parser import (
BlackVueParser,
)
from mapillary_tools.video_data_extraction.extractors.camm_parser import CammParser
from mapillary_tools.video_data_extraction.extractors.exiftool_runtime_parser import (
ExiftoolRuntimeParser,
)
from mapillary_tools.video_data_extraction.extractors.exiftool_xml_parser import (
ExiftoolXmlParser,
)
from mapillary_tools.video_data_extraction.extractors.generic_video_parser import (
GenericVideoParser,
)
from mapillary_tools.video_data_extraction.extractors.gopro_parser import GoProParser
from mapillary_tools.video_data_extraction.extractors.gpx_parser import GpxParser
from mapillary_tools.video_data_extraction.extractors.nmea_parser import NmeaParser

from .cli_options import CliOptions

from .extractors.base_parser import BaseParser

from .extractors.blackvue_parser import BlackVueParser
from .extractors.camm_parser import CammParser
from .extractors.exiftool_xml_parser import ExiftoolXmlParser
from .extractors.generic_video_parser import GenericVideoParser
from .extractors.gopro_parser import GoProParser
from .extractors.gpx_parser import GpxParser
from .extractors.nmea_parser import NmeaParser


known_parsers = {
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def readme():
python_requires=">=3.8",
packages=[
"mapillary_tools",
"mapillary_tools.camm",
"mapillary_tools.commands",
"mapillary_tools.geotag",
"mapillary_tools.mp4",
Expand Down
3 changes: 2 additions & 1 deletion tests/cli/camm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import gpxpy.gpx

from mapillary_tools import utils
from mapillary_tools.geotag import camm_parser, utils as geotag_utils
from mapillary_tools.camm import camm_parser
from mapillary_tools.geotag import utils as geotag_utils


def _convert(path: pathlib.Path):
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/gpmf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import mapillary_tools.geotag.gpmf_parser as gpmf_parser
import mapillary_tools.geotag.gps_filter as gps_filter
from mapillary_tools.mp4 import mp4_sample_parser
import mapillary_tools.utils as utils
from mapillary_tools.mp4 import mp4_sample_parser


def _convert_points_to_gpx_track_segment(
Expand Down
Loading

0 comments on commit 1aa5b41

Please sign in to comment.