| 1 |
from av import ContainerFormat, formats_available, open |
| 2 |
|
| 3 |
from .common import fate_suite |
| 4 |
|
| 5 |
|
| 6 |
def test_matroska() -> None: |
| 7 |
with open("test.mkv", "w") as container: |
| 8 |
assert container.default_video_codec != "none" |
| 9 |
assert container.default_audio_codec != "none" |
| 10 |
assert container.default_subtitle_codec == "ass" |
| 11 |
assert "ass" in container.supported_codecs |
| 12 |
|
| 13 |
fmt = ContainerFormat("matroska") |
| 14 |
assert fmt.is_input and fmt.is_output |
| 15 |
assert fmt.name == "matroska" |
| 16 |
assert fmt.long_name == "Matroska" |
| 17 |
assert "mkv" in fmt.extensions |
| 18 |
assert not fmt.no_file |
| 19 |
|
| 20 |
|
| 21 |
def test_mov() -> None: |
| 22 |
with open("test.mov", "w") as container: |
| 23 |
assert container.default_video_codec != "none" |
| 24 |
assert container.default_audio_codec != "none" |
| 25 |
assert container.default_subtitle_codec == "none" |
| 26 |
assert "h264" in container.supported_codecs |
| 27 |
|
| 28 |
fmt = ContainerFormat("mov") |
| 29 |
assert fmt.is_input and fmt.is_output |
| 30 |
assert fmt.name == "mov" |
| 31 |
assert fmt.long_name == "QuickTime / MOV" |
| 32 |
assert "mov" in fmt.extensions |
| 33 |
assert not fmt.no_file |
| 34 |
|
| 35 |
|
| 36 |
def test_gif() -> None: |
| 37 |
with open("test.gif", "w") as container: |
| 38 |
assert container.default_video_codec == "gif" |
| 39 |
assert container.default_audio_codec == "none" |
| 40 |
assert container.default_subtitle_codec == "none" |
| 41 |
assert "gif" in container.supported_codecs |
| 42 |
|
| 43 |
|
| 44 |
def test_stream_segment() -> None: |
| 45 |
# This format goes by two names, check both. |
| 46 |
fmt = ContainerFormat("stream_segment") |
| 47 |
assert not fmt.is_input and fmt.is_output |
| 48 |
assert fmt.name == "stream_segment" |
| 49 |
assert fmt.long_name == "streaming segment muxer" |
| 50 |
assert fmt.extensions == set() |
| 51 |
assert fmt.no_file |
| 52 |
|
| 53 |
fmt = ContainerFormat("ssegment") |
| 54 |
assert not fmt.is_input and fmt.is_output |
| 55 |
assert fmt.name == "ssegment" |
| 56 |
assert fmt.long_name == "streaming segment muxer" |
| 57 |
assert fmt.extensions == set() |
| 58 |
assert fmt.no_file |
| 59 |
|
| 60 |
|
| 61 |
def test_video_codec_id() -> None: |
| 62 |
# Regression test for https://github.com/PyAV-Org/PyAV/issues/2243 |
| 63 |
# video_codec_id allows overriding the codec used when opening a container. |
| 64 |
AV_CODEC_ID_NONE = 0 |
| 65 |
AV_CODEC_ID_H264 = 27 |
| 66 |
|
| 67 |
with open(fate_suite("h264/interlaced_crop.mp4")) as container: |
| 68 |
assert container.video_codec_id == AV_CODEC_ID_NONE |
| 69 |
container.video_codec_id = AV_CODEC_ID_H264 |
| 70 |
assert container.video_codec_id == AV_CODEC_ID_H264 |
| 71 |
|
| 72 |
with open("test.mkv", "w") as container: |
| 73 |
assert container.video_codec_id == AV_CODEC_ID_NONE |
| 74 |
container.video_codec_id = AV_CODEC_ID_H264 |
| 75 |
assert container.video_codec_id == AV_CODEC_ID_H264 |
| 76 |
|
| 77 |
|
| 78 |
def test_formats_available() -> None: |
| 79 |
assert formats_available |