Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "musicalgestures/gopromax-conversion-tools"]
path = musicalgestures/gopromax-conversion-tools
url = https://github.com/alexarje/gopromax-conversion-tools.git
7 changes: 4 additions & 3 deletions docs/musicalgestures/_360video.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## Mg360Video

[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_360video.py#L91)
[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_360video.py#L94)

```python
class Mg360Video(MgVideo):
Expand All @@ -30,13 +30,14 @@ Class for 360 videos.

### Mg360Video().convert_projection

[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_360video.py#L123)
[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_360video.py#L126)

```python
def convert_projection(
target_projection: Union[Projection, str],
options: Dict[str, str] = None,
print_cmd: bool = False,
test: bool = False,
):
```

Expand All @@ -54,7 +55,7 @@ options (Dict[str, str], optional): Options for the conversion. Defaults to None

## Projection

[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_360video.py#L9)
[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_360video.py#L11)

```python
class Projection(Enum):
Expand Down
6 changes: 3 additions & 3 deletions docs/musicalgestures/_video.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Creates an average image of all frames in the video.

### MgVideo().extract_frame

[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_video.py#L330)
[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_video.py#L331)

```python
def extract_frame(**kwargs):
Expand All @@ -101,7 +101,7 @@ see _utils.extract_frame for details.

### MgVideo().from_numpy

[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_video.py#L290)
[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_video.py#L291)

```python
def from_numpy(array, fps, target_name=None):
Expand All @@ -119,7 +119,7 @@ Creates a video attribute to the Musical Gestures object with the given correct

### MgVideo().numpy

[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_video.py#L277)
[[find in source code]](https://github.com/fourMs/MGT-python/blob/master/musicalgestures/_video.py#L278)

```python
def numpy():
Expand Down
69 changes: 68 additions & 1 deletion musicalgestures/_360video.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import subprocess
from enum import Enum
from functools import partial
from typing import Dict, Union
from pathlib import Path
from functools import partial
from musicalgestures._video import MgVideo
from musicalgestures._utils import ffmpeg_cmd, get_length, generate_outfilename

Expand Down Expand Up @@ -44,6 +46,7 @@ class Projection(Enum):

equirectangular = 30 # extra option for equirectangular
erp = 31
gopro_360 = 32 # special gopro .360 format

def __str__(self):
# collapse all aliases of erp
Expand Down Expand Up @@ -125,6 +128,7 @@ def convert_projection(
target_projection: Union[Projection, str],
options: Dict[str, str] = None,
print_cmd: bool = False,
test: bool = False,
):
"""
Convert the video to a different projection.
Expand All @@ -138,6 +142,48 @@ def convert_projection(
if target_projection == self.projection:
print(f"{self} is already in target projection {target_projection}.")
return
elif self.projection == Projection.gopro_360:
if test:
print(
f"=> Test mode: would convert {self.filename} to {target_projection} with options {options}."
)

# use special gopro conversion scripts
assert target_projection in [
Projection.equirect,
Projection.equirectangular,
Projection.dfisheye,
], (
f"Invalid target projection from gopro_360: {target_projection}, only equirect, equirectangular, and dfisheye are supported."
)

output_name = generate_outfilename(
f"{self.filename.split('.')[0]}_{target_projection}.mp4"
)
if target_projection == Projection.dfisheye:
script = "ffmpeg-convert-dual-fisheye.sh"
else:
script = "ffmpeg-convert-v3.sh"
script_path = Path(__file__).parent / "gopromax-conversion-tools/scripts" / script

cmds = [
script_path,
"-i",
self.filename,
"-n",
output_name,
]
if options:
for k, v in options.items():
cmds.append(k)
cmds.append(v)

if test:
print(f"=> Command: {' '.join([str(cmd) for cmd in cmds])}")
subprocess.run(cmds)
self.filename = output_name
self.projection = target_projection

else:
output_name = generate_outfilename(
f"{self.filename.split('.')[0]}_{target_projection}.mp4"
Expand Down Expand Up @@ -191,3 +237,24 @@ def _parse_projection(self, projection: Union[str, Projection]):
return projection
else:
raise TypeError(f"Unsupported projection type: '{type(projection)}'.")


## testing gopro_360 conversion
if __name__ == "__main__":
video = Mg360Video("2023-01-01-GS010008.360", Projection.gopro_360)
video.convert_projection(
Projection.equirect,
options={"-r": "0:180:0", "-s": "00:01:10", "-t": "00:01:20"},
test=True,
)
print(f"=> Converted video path: {video.filename}")
print(f"=> Converted video projection: {video.projection}")

video = Mg360Video("2023-01-01-GS010008.360", Projection.gopro_360)
video.convert_projection(
Projection.dfisheye,
options={"-s": "00:01:10", "-t": "00:01:20"},
test=True,
)
print(f"=> Converted video path: {video.filename}")
print(f"=> Converted video projection: {video.projection}")
1 change: 1 addition & 0 deletions musicalgestures/_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def get_video(self):
".ts",
".wmv",
".3gp",
".360",
]
if self.fex not in video_formats:
# Check if it is an image file
Expand Down
1 change: 1 addition & 0 deletions musicalgestures/gopromax-conversion-tools
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name='musicalgestures',
packages=['musicalgestures'],
version='v1.3.2',
version='v1.3.3',
license='GNU General Public License v3 (GPLv3)',
description='Musical Gestures Toolbox for Python',
long_description=README,
Expand Down
Loading