Metadata-Version: 2.5
Name: livephoto-to-photo
Version: 0.1.0
Summary: Python library to extract a still JPEG from a Live Photo
Project-URL: Homepage, https://github.com/sherotree/livephoto-to-photo-py
Project-URL: Repository, https://github.com/sherotree/livephoto-to-photo-py
Project-URL: Web Tool, https://www.uwarp.design/livephoto-to-photo
Author-email: Sherotree <sherotree@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Keywords: apple,heic,image-conversion,jpeg,live-photo,photo
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Multimedia :: Video
Requires-Python: >=3.8
Requires-Dist: pillow-heif>=0.10.0
Requires-Dist: pillow>=9.0.0
Provides-Extra: dev
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: ffmpeg-python>=0.2.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Provides-Extra: video
Requires-Dist: ffmpeg-python>=0.2.0; extra == 'video'
Description-Content-Type: text/markdown

# livephoto-to-photo

[**Live Photo to Photo**](https://www.uwarp.design/livephoto-to-photo) — free browser tool for extracting still JPEGs from Apple Live Photos (the reference UI for this library).

Offline Python library for extracting still JPEG images from Apple Live Photo components.

Package: **`livephoto-to-photo`** on PyPI (`0.1.0`).

## Install

```bash
pip install livephoto-to-photo
```

For video component support (MOV/MP4/M4V), install the optional extra **and** the system `ffmpeg` binary:

```bash
pip install livephoto-to-photo[video]
```

## System dependencies

| Input | Python package | System requirement |
| --- | --- | --- |
| HEIC / HEIF still | `pillow-heif`, `Pillow` (installed by default) | **libheif** — usually bundled in the `pillow-heif` wheel; if decoding fails, install libheif for your OS |
| `.livp` container | stdlib `zipfile` + HEIC stack above | Same as HEIC when the still inside is HEIC |
| MOV / MP4 / M4V video | `ffmpeg-python` (`[video]` extra) | **ffmpeg** binary on `PATH` |

Install ffmpeg:

- macOS: `brew install ffmpeg`
- Ubuntu/Debian: `sudo apt install ffmpeg`
- Windows / others: [https://ffmpeg.org/download.html](https://ffmpeg.org/download.html)

If a required dependency is missing, the library raises a clear `ImportError` or `RuntimeError` explaining what to install.

## Quick start

```python
from livephoto_to_photo import extract_still_jpeg

# Extract from any Live Photo component
extract_still_jpeg("IMG_0001.HEIC", "output.jpg")
extract_still_jpeg("IMG_0001.MOV", "output.jpg")
extract_still_jpeg("livephoto.livp", "output.jpg")

# Or get as bytes
jpeg_data = extract_still_jpeg("IMG_0001.HEIC")
```

## Supported formats

- **HEIC/HEIF** still images (the key photo from a Live Photo)
- **MOV/MP4/M4V** video components (extracts the first frame; requires ffmpeg)
- **.livp** container files (ZIP archives containing a still + video)

Output is always JPEG (default quality 92).

## API

### Main function

| Function | Description |
| --- | --- |
| `extract_still_jpeg(source, output=None, quality=92)` | Detect input type and extract a still JPEG |

```python
from livephoto_to_photo import extract_still_jpeg

extract_still_jpeg("IMG_0001.HEIC", "output.jpg", quality=95)
jpeg_data = extract_still_jpeg("IMG_0001.HEIC")
```

### Type-specific functions

| Function | Description |
| --- | --- |
| `extract_photo_from_heic(source, output=None, quality=92)` | HEIC/HEIF → JPEG |
| `extract_photo_from_video(source, output=None, quality=92)` | First video frame → JPEG (needs ffmpeg) |
| `extract_photo_from_livp(source, output=None, quality=92)` | `.livp` still → JPEG |

### Class API

| Method | Description |
| --- | --- |
| `LivePhotoExtractor(source, quality=92)` | Create an extractor |
| `.extract()` | Return JPEG bytes (cached) |
| `.save(output)` | Write JPEG to a path or file-like object |
| `.to_bytes()` | Alias for `.extract()` |

```python
from livephoto_to_photo import LivePhotoExtractor

extractor = LivePhotoExtractor("IMG_0001.HEIC", quality=95)
extractor.save("output.jpg")
```

### Helpers

| Function | Description |
| --- | --- |
| `is_heic_file(file)` | True for `.heic` / `.heif` (or HEIC bytes) |
| `is_video_file(file)` | True for `.mov` / `.mp4` / `.m4v` |
| `is_livp_file(file)` | True for `.livp` (or ZIP bytes) |
| `is_live_photo_input(file)` | True for any supported Live Photo input |

## CLI

```bash
livephoto-to-photo INPUT OUTPUT [--quality N]
```

```bash
livephoto-to-photo IMG_0001.HEIC output.jpg
livephoto-to-photo IMG_0001.MOV output.jpg --quality 95
livephoto-to-photo livephoto.livp output.jpg
```

## Error handling

```python
from livephoto_to_photo import extract_still_jpeg

try:
    extract_still_jpeg("file.mov", "output.jpg")
except ImportError as e:
    # Missing Python package (e.g. ffmpeg-python or pillow-heif)
    print(e)
except RuntimeError as e:
    # Missing system tool (e.g. ffmpeg binary / libheif init failure)
    print(e)
except ValueError as e:
    # Unsupported type or invalid quality
    print(e)
except OSError as e:
    # Read / decode / write failure
    print(e)
```

## Tests

```bash
pip install -e ".[dev]"
pytest
# or with coverage
pytest --cov=livephoto_to_photo
```

Fixtures under `tests/fixtures/` include a sample HEIC, MP4, and `.livp` containers.

## Development

```bash
pip install -e ".[dev]"
pytest
black src/ tests/
ruff check src/ tests/
```

## License

MIT. See [LICENSE](./LICENSE).
