Skip to content

Commit

Permalink
Apply black and isort to examples, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Nov 23, 2023
1 parent 5d628cf commit c01335f
Show file tree
Hide file tree
Showing 16 changed files with 13 additions and 33 deletions.
3 changes: 0 additions & 3 deletions examples/basics/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import av
import av.datasets


# We want an H.264 stream in the Annex B byte-stream format.
# We haven't exposed bitstream filters yet, so we're gonna use the `ffmpeg` CLI.
h264_path = "night-sky.h264"
Expand All @@ -29,14 +28,12 @@
codec = av.CodecContext.create("h264", "r")

while True:

chunk = fh.read(1 << 16)

packets = codec.parse(chunk)
print(f"Parsed {len(packets)} packets from {len(chunk)} bytes:")

for packet in packets:

print(" ", packet)

frames = codec.decode(packet)
Expand Down
2 changes: 0 additions & 2 deletions examples/basics/remux.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import av
import av.datasets


input_ = av.open(av.datasets.curated("pexels/time-lapse-video-of-night-sky-857195.mp4"))
output = av.open("remuxed.mkv", "w")

Expand All @@ -11,7 +10,6 @@
out_stream = output.add_stream(template=in_stream)

for packet in input_.demux(in_stream):

print(packet)

# We need to skip the "flushing" packets that `demux` generates.
Expand Down
2 changes: 0 additions & 2 deletions examples/basics/save_keyframes.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import av
import av.datasets


content = av.datasets.curated("pexels/time-lapse-video-of-night-sky-857195.mp4")
with av.open(content) as container:
# Signal that we only want to look at keyframes.
stream = container.streams.video[0]
stream.codec_context.skip_frame = "NONKEY"

for frame in container.decode(stream):

print(frame)

# We use `frame.pts` as `frame.index` won't make must sense with the `skip_frame`.
Expand Down
1 change: 0 additions & 1 deletion examples/basics/thread_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import av
import av.datasets


print("Decoding with default (slice) threading...")

container = av.open(
Expand Down
4 changes: 1 addition & 3 deletions examples/numpy/barcode.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from PIL import Image
import numpy as np
from PIL import Image

import av
import av.datasets


container = av.open(
av.datasets.curated("pexels/time-lapse-video-of-sunset-by-the-sea-854400.mp4")
)
container.streams.video[0].thread_type = "AUTO" # Go faster!

columns = []
for frame in container.decode(video=0):

print(frame)
array = frame.to_ndarray(format="rgb24")

Expand Down
2 changes: 0 additions & 2 deletions examples/numpy/generate_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import av


duration = 4
fps = 24
total_frames = duration * fps
Expand All @@ -15,7 +14,6 @@
stream.pix_fmt = "yuv420p"

for frame_i in range(total_frames):

img = np.empty((480, 320, 3))
img[:, :, 0] = 0.5 + 0.5 * np.sin(2 * np.pi * (0 / 3 + frame_i / total_frames))
img[:, :, 1] = 0.5 + 0.5 * np.sin(2 * np.pi * (1 / 3 + frame_i / total_frames))
Expand Down
4 changes: 1 addition & 3 deletions examples/numpy/generate_video_with_pts.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python3

from fractions import Fraction
import colorsys
from fractions import Fraction

import numpy as np

import av


(width, height) = (640, 360)
total_frames = 20
fps = 30
Expand Down Expand Up @@ -43,7 +42,6 @@
block_h2 = int(0.5 * height / 4)

for frame_i in range(total_frames):

# move around the color wheel (hue)
nice_color = colorsys.hsv_to_rgb(frame_i / total_frames, 1.0, 1.0)
nice_color = (np.array(nice_color) * 255).astype(np.uint8)
Expand Down
3 changes: 1 addition & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from unittest import TestCase as _Base
import datetime
import errno
import functools
import os
import types
from unittest import TestCase as _Base

from av.datasets import fate as fate_suite


try:
import PIL.Image as Image
import PIL.ImageFilter as ImageFilter
Expand Down
1 change: 0 additions & 1 deletion tests/test_audioformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from .common import TestCase


postfix = "le" if sys.byteorder == "little" else "be"


Expand Down
1 change: 0 additions & 1 deletion tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from .common import TestCase


# some older ffmpeg versions have no native opus encoder
try:
opus_c = Codec("opus", "w")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from fractions import Fraction
from unittest import SkipTest
import os
import warnings
from fractions import Fraction
from unittest import SkipTest

import av
from av import AudioResampler, Codec, Packet
from av.codec.codec import UnknownCodecError
from av.video.frame import PictureType
import av

from .common import TestCase, fate_suite

Expand Down
5 changes: 2 additions & 3 deletions tests/test_encode.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import math
from fractions import Fraction
from unittest import SkipTest
import math

import av
from av import AudioFrame, VideoFrame
from av.audio.stream import AudioStream
from av.video.stream import VideoStream
import av

from .common import Image, TestCase, fate_suite


WIDTH = 320
HEIGHT = 240
DURATION = 48
Expand Down
1 change: 0 additions & 1 deletion tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from .common import TestCase


# This must be at the top-level.
PickleableFooBar = define_enum("PickleableFooBar", __name__, [("FOO", 1)])

Expand Down
4 changes: 2 additions & 2 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import errno
from fractions import Fraction
from unittest import SkipTest
import errno

import numpy as np

import av
from av import AudioFrame, VideoFrame
from av.audio.frame import format_dtypes
from av.filter import Filter, Graph
import av

from .common import Image, TestCase, fate_suite

Expand Down
2 changes: 1 addition & 1 deletion tests/test_subtitles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from av.subtitles.subtitle import AssSubtitle, BitmapSubtitle
import av
from av.subtitles.subtitle import AssSubtitle, BitmapSubtitle

from .common import TestCase, fate_suite

Expand Down
5 changes: 2 additions & 3 deletions tests/test_timeout.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from http.server import BaseHTTPRequestHandler
from socketserver import TCPServer
import threading
import time
from http.server import BaseHTTPRequestHandler
from socketserver import TCPServer

import av

from .common import TestCase, fate_suite


PORT = 8002
CONTENT = open(fate_suite("mpeg2/mpeg2_field_encoding.ts"), "rb").read()
# Needs to be long enough for all host OSes to deal.
Expand Down

0 comments on commit c01335f

Please sign in to comment.