File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 18
18
)
19
19
output = av .open ("out.mkv" , "w" )
20
20
21
- output_stream = output .add_stream ("h264" , rate = 30 )
21
+ # Prefer x264, but use Apple hardware if not available.
22
+ try :
23
+ encoder = av .Codec ("libx264" , "w" ).name
24
+ except av .FFmpegError :
25
+ encoder = "h264_videotoolbox"
26
+
27
+ output_stream = output .add_stream (encoder , rate = 30 )
22
28
output_stream .width = input_ .streams .video [0 ].width
23
29
output_stream .height = input_ .streams .video [0 ].height
24
30
output_stream .pix_fmt = "yuv420p"
Original file line number Diff line number Diff line change 13
13
input_ = av .open ("1" , format = "avfoundation" )
14
14
output = av .open ("out.mkv" , "w" )
15
15
16
- output_stream = output .add_stream ("h264" , rate = 30 )
16
+ # Prefer x264, but use Apple hardware if not available.
17
+ try :
18
+ encoder = av .Codec ("libx264" , "w" ).name
19
+ except av .FFmpegError :
20
+ encoder = "h264_videotoolbox"
21
+
22
+ output_stream = output .add_stream (encoder , rate = 30 )
17
23
output_stream .width = input_ .streams .video [0 ].width
18
24
output_stream .height = input_ .streams .video [0 ].height
19
25
output_stream .pix_fmt = "yuv420p"
20
26
21
27
try :
22
- for frame in input_ .decode (video = 0 ):
23
- packet = output_stream .encode (frame )
24
- output .mux (packet )
28
+ while True :
29
+ try :
30
+ for frame in input_ .decode (video = 0 ):
31
+ packet = output_stream .encode (frame )
32
+ output .mux (packet )
33
+ except av .BlockingIOError :
34
+ pass
25
35
except KeyboardInterrupt :
26
36
print ("Recording stopped by user" )
27
37
You can’t perform that action at this time.
0 commit comments