Spaces:
Running
Running
| from __future__ import annotations | |
| import shutil | |
| import subprocess | |
| import pytest | |
| from app.models.media import InputMedia, MediaSource | |
| from app.operations.convert import convert_audio | |
| from app.services.ffmpeg_service import FFmpegService | |
| async def test_ffmpeg_audio_conversion(settings, tmp_path) -> None: | |
| source = tmp_path / "tone.wav" | |
| subprocess.run( | |
| [ | |
| "ffmpeg", | |
| "-hide_banner", | |
| "-loglevel", | |
| "error", | |
| "-f", | |
| "lavfi", | |
| "-i", | |
| "sine=frequency=440:duration=0.2", | |
| "-y", | |
| str(source), | |
| ], | |
| check=True, | |
| ) | |
| media = InputMedia( | |
| source=MediaSource.MULTIPART, | |
| filename=source.name, | |
| mime_type="audio/wav", | |
| temp_path=source, | |
| size=source.stat().st_size, | |
| ) | |
| result = await convert_audio( | |
| FFmpegService(settings), [media], {"format": "mp3"}, tmp_path / "out" | |
| ) | |
| assert result.path is not None | |
| assert result.path.is_file() | |
| assert result.path.stat().st_size > 0 | |
| async def test_ffmpeg_codec_listing_is_structured(settings, monkeypatch) -> None: | |
| service = FFmpegService(settings) | |
| async def fake_capture(*args, **kwargs) -> str: | |
| return """Codecs: | |
| D..... = Decoding supported | |
| .E.... = Encoding supported | |
| ------- | |
| DEV.LS h264 H.264 / AVC / MPEG-4 AVC | |
| DEA.L. aac AAC (Advanced Audio Coding) | |
| """ | |
| monkeypatch.setattr(service, "_capture", fake_capture) | |
| codecs = await service.codecs() | |
| assert [codec["name"] for codec in codecs] == ["h264", "aac"] | |
| assert codecs[0]["decode"] is True | |
| assert codecs[0]["encode"] is True | |
| assert codecs[0]["type"] == "video" | |