Skip to content

Commit

Permalink
updating the formatting (#34)
Browse files Browse the repository at this point in the history
* updating the formatting

* doc update

* version bump
  • Loading branch information
LemurPwned authored Oct 22, 2024
1 parent 2038196 commit 6b28fe7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
build:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
outputs:
version: ${{ steps.get_version.outputs.version }}

steps:
- uses: actions/checkout@v3
Expand All @@ -37,3 +39,23 @@ jobs:
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}

- name: Get release version
id: get_version
run: |
echo "version=$(cat pyproject.toml | grep version | awk '{print $3}' | tr -d \"'\")" >> $GITHUB_OUTPUT
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ needs.build.outputs.version }}
run: |
gh release create "$RELEASE_VERSION" \
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} ${RELEASE_VERSION}" \
--generate-notes
3 changes: 3 additions & 0 deletions configs/hash_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ extractor_config: {}
summary_config: {}
# Number of workers (separate processes) to process the frames. Determines level of parallelism
n_workers: 3
save_format:
encode_time: true
include_filename: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "video_sampler"
description = "Video Sampler -- sample frames from a video file"
url = "https://github.com/LemurPwned/video-sampler"
version = "0.11.2"
version = "0.11.3"
authors = [
{ name = "LemurPwned", email = "lemurpwned@gmail.com" }
]
Expand Down
16 changes: 16 additions & 0 deletions video_sampler/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ class SamplerConfig(BaseModel):
summary_config: dict[str, Any] = field(default_factory=dict)
n_workers: int = 1

class SaveFormatConfig(BaseModel):
"""
Configuration options for the save format.
Args:
encode_time (bool, optional): Encode time as base64 string. Avoids `.`
in the filename. Defaults to False.
include_filename (bool, optional): Include filename in the output
path. Defaults to False.
"""

encode_time: bool = False # Encode time as base64 string
include_filename: bool = False # Include filename in the output path

save_format: SaveFormatConfig = field(default_factory=SaveFormatConfig)

def __str__(self) -> str:
return str(asdict(self))

Expand Down
18 changes: 15 additions & 3 deletions video_sampler/sampler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import os
import time
from collections import Counter
Expand Down Expand Up @@ -357,6 +358,18 @@ def launch(
style=f"bold {Color.magenta.value}",
)

def format_output_path(self, output_path: str, frame_time: float) -> str:
"""Format the output path for a frame."""
ft = str(frame_time)
if self.cfg.save_format.encode_time:
ft = base64.encodebytes(ft.encode()).decode()
if self.cfg.save_format.include_filename:
vbsn = os.path.basename(output_path)
# remove extension
vbsn = os.path.splitext(vbsn)[0]
ft = f"{vbsn}_TIMEB64_{ft}"
return os.path.join(output_path, f"{ft}.jpg")

def queue_reader(self, output_path, read_interval=0.1) -> None:
"""
Reads frames from the queue and saves them as JPEG images.
Expand All @@ -378,9 +391,8 @@ def queue_reader(self, output_path, read_interval=0.1) -> None:
not self.devnull and isinstance(frame_object.frame, Image.Image)
):
frame_object.frame.save(
os.path.join(
output_path,
f"{frame_object.metadata['frame_time']}.jpg",
self.format_output_path(
output_path, frame_object.metadata["frame_time"]
)
)
if self.pool:
Expand Down

0 comments on commit 6b28fe7

Please sign in to comment.