Skip to main content

Simple, modern, and type-safe recording library for P-AMI<Q>

Project description

🎬 pamiq-recorder

Formatter & Linter / Tests / Type Check Python 3.12+ License: MIT Document Style

pamiq-recorder is a simple, modern, and type-safe recording library for P-AMI<Q>, providing easy and consistent interfaces for video, audio, and CSV data recording.

✨ Features

  • 📹 Video recording via OpenCV with support for multiple formats
  • 🎵 Audio recording via SoundFile with various audio formats
  • 📊 CSV recording with automatic timestamping
  • 🔍 Type-safe interfaces with complete type annotations
  • 🧪 Comprehensive test coverage

📦 Installation

# Install with pip
pip install pamiq-recorder

# For development setup
git clone https://github.com/MLShukai/pamiq-recorder.git
cd pamiq-recorder
make venv  # Sets up virtual environment with all dependencies

🧰 Requirements

  • Python 3.12+
  • OpenCV (for video recording, libopencv-dev for Ubuntu.)
  • SoundFile (for audio recording, libsndfile1 for Ubuntu.)

📝 Usage

Video Recording

from pamiq_recorder import VideoRecorder
import numpy as np

# Create a video recorder for RGB video
recorder = VideoRecorder(
    file_path="output.mp4",
    fps=30.0,
    height=480,
    width=640,
    channels=3  # RGB format
)

# Create a sample frame (RGB gradient)
frame = np.zeros((480, 640, 3), dtype=np.uint8)
for i in range(480):
    for j in range(640):
        frame[i, j, 0] = i * 255 // 480  # Red gradient
        frame[i, j, 1] = j * 255 // 640  # Green gradient
        frame[i, j, 2] = (i + j) * 255 // 1120  # Blue gradient

# Write the frame to the video
recorder.write(frame)

# Close when done
recorder.close()

Audio Recording

from pamiq_recorder import AudioRecorder
import numpy as np

# Create an audio recorder for stereo audio
recorder = AudioRecorder(
    file_path="output.wav",
    sample_rate=44100,
    channels=2
)

# Create a simple stereo sine wave
duration = 5.0  # seconds
t = np.linspace(0, duration, int(duration * 44100), endpoint=False)

# Left channel: 440 Hz, Right channel: 880 Hz
left = np.sin(2 * np.pi * 440 * t)
right = np.sin(2 * np.pi * 880 * t)

# Combine into stereo data with shape (samples, channels)
data = np.column_stack((left, right)).astype(np.float32)

# Write the audio data
recorder.write(data)

# Close when done
recorder.close()

CSV Recording

from pamiq_recorder import CSVRecorder
import time

# Create a CSV recorder with custom headers
recorder = CSVRecorder(
    file_path="sensor_data.csv",
    headers=["temperature", "humidity", "pressure"],
    timestamp_header="time"
)

# Write some sample data rows
recorder.write([25.4, 60.2, 1013.25])
time.sleep(1)
recorder.write([25.5, 60.0, 1013.20])
time.sleep(1)
recorder.write([25.6, 59.8, 1013.15])

# Close when done
recorder.close()

Using Context Managers

All recorders support the context manager protocol for automatic resource cleanup:

import numpy as np
from pamiq_recorder import AudioRecorder

# Audio data to write
data = np.random.rand(44100, 2).astype(np.float32)  # 1 second of random stereo audio

# Use with statement for automatic closing
with AudioRecorder("output.wav", sample_rate=44100, channels=2) as recorder:
    recorder.write(data)
    # No need to call close() - it happens automatically

🔧 Supported Formats

Video Formats

  • MP4 (mp4v codec)
  • AVI (XVID codec)
  • MOV (mp4v codec)
  • MKV (X264 codec)

Audio Formats

  • WAV
  • FLAC
  • OGG/Vorbis
  • OGG/Opus
  • MP3
  • M4A/ALAC
  • MOV/ALAC

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run all workflow (make run)
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pamiq_recorder-0.1.0.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pamiq_recorder-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file pamiq_recorder-0.1.0.tar.gz.

File metadata

  • Download URL: pamiq_recorder-0.1.0.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pamiq_recorder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1f9cd1a0a36b848170446d079b0866bd4210407011d2cb8a142febd4fda91cf5
MD5 740fa68411f638eb33d700f2d4abe66d
BLAKE2b-256 82f7b48d775dbd882d418c2b59a6251841fdc97452fd232e728ec5e1a907747e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pamiq_recorder-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on MLShukai/pamiq-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pamiq_recorder-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pamiq_recorder-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pamiq_recorder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54c639b66141bec08ab33f21df497e7f7f2299a55031dc371d89e99fe65cb01a
MD5 2e17d3f2869fad8cfd669f418d83dfd3
BLAKE2b-256 0965df7eb66606146cabb63f99e6f9c941bb4e4e136dd511520c0a35b88807aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pamiq_recorder-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on MLShukai/pamiq-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page