Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/basics/record_facecam.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
)
output = av.open("out.mkv", "w")

output_stream = output.add_stream("h264", rate=30)
# Prefer x264, but use Apple hardware if not available.
try:
encoder = av.Codec("libx264", "w").name
except av.FFmpegError:
encoder = "h264_videotoolbox"

output_stream = output.add_stream(encoder, rate=30)
output_stream.width = input_.streams.video[0].width
output_stream.height = input_.streams.video[0].height
output_stream.pix_fmt = "yuv420p"
Expand Down
18 changes: 14 additions & 4 deletions examples/basics/record_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@
input_ = av.open("1", format="avfoundation")
output = av.open("out.mkv", "w")

output_stream = output.add_stream("h264", rate=30)
# Prefer x264, but use Apple hardware if not available.
try:
encoder = av.Codec("libx264", "w").name
except av.FFmpegError:
encoder = "h264_videotoolbox"

output_stream = output.add_stream(encoder, rate=30)
output_stream.width = input_.streams.video[0].width
output_stream.height = input_.streams.video[0].height
output_stream.pix_fmt = "yuv420p"

try:
for frame in input_.decode(video=0):
packet = output_stream.encode(frame)
output.mux(packet)
while True:
try:
for frame in input_.decode(video=0):
packet = output_stream.encode(frame)
output.mux(packet)
except av.BlockingIOError:
pass
except KeyboardInterrupt:
print("Recording stopped by user")

Expand Down
Loading