def try_devices(): devices.scan() print(devices.list_sources()) print(devices.list_source_options("dshow", "v:0")) print(devices.list_source_options("dshow", "a:0")) fs, x = video.read("v:0", f_in="dshow", t=1, show_log=True) # capture 10 seconds of audio fs, x = audio.read("a:0", f_in="dshow", t=1, show_log=True) print(f"[a:0] rate={fs}, data={[*x.keys()]}") # stream webcam video feed for with open("v:0", "rv", f_in="dshow", show_log=True) as dev: print(f"[v:0] rate={dev.rate}") for i, frame in enumerate(dev): print(f"Frame {i}: {[*frame.keys()]}") break # save video and audio to mp4 file # - if a device support multiple streams, specify their enums separated by '|' with TemporaryDirectory() as tempdir: transcode( "v:0|a:0", path.join(tempdir, "captured.mp4"), f_in="dshow", t_in=1, show_log=True, )
def test_transcode_2pass(): url = "tests/assets/testmulti-1m.mp4" with tempfile.TemporaryDirectory() as tmpdirname: out_url = path.join(tmpdirname, path.basename(url)) transcode(url, out_url, show_log=True, two_pass=True, t=1, **{ "c:v": "libx264", "b:v": "1000k", "c:a": "aac", "b:a": "128k" }) transcode(url, out_url, show_log=True, two_pass=True, pass1_omits=["c:a", "b:a"], pass1_extras={"an": None}, overwrite=True, t=1, **{ "c:v": "libx264", "b:v": "1000k", "c:a": "aac", "b:a": "128k" })
def test_transcode_vf(): url = "tests/assets/testmulti-1m.mp4" with tempfile.TemporaryDirectory() as tmpdirname: # print(probe.audio_streams_basic(url)) out_url = path.join(tmpdirname, path.basename(url)) transcode(url, out_url, t="0.1", vf="scale=in_w:in_h*9/10", show_log=True) assert path.isfile(out_url)
def test_transcode_image(): url = "tests/assets/ffmpeg-logo.png" with tempfile.TemporaryDirectory() as tmpdirname: # print(probe.audio_streams_basic(url)) out_url = path.join(tmpdirname, path.basename(url) + ".jpg") transcode( url, out_url, show_log=True, remove_alpha=True, s=[300, -1], transpose=0, vframes=1, )
def test_square_pixels(): url = "tests/assets/testvideo-1m.mp4" with tempfile.TemporaryDirectory() as tmpdirname: out_url = path.join(tmpdirname, path.basename(url)) transcode(url, out_url, show_log=True, vf="setsar=11/13", t=0.5) B = image.read(out_url) Bu = image.read(out_url, square_pixels="upscale") Bd = image.read(out_url, square_pixels="downscale") Bue = image.read(out_url, square_pixels="upscale_even") Bde = image.read(out_url, square_pixels="downscale_even") print(B['shape']) print(Bu['shape']) print(Bd['shape']) print(Bue['shape']) print(Bde['shape'])
def test_transcode_from_filter(): with tempfile.TemporaryDirectory() as tmpdirname: out_url = path.join(tmpdirname, "test.png") transcode("color=r=1:d=1", out_url, f_in="lavfi", vframes=1, show_log=True) transcode( FilterGraph([[("color", { "r": 1, "d": 1 })]]), out_url, f_in="lavfi", vframes=1, show_log=True, overwrite=True, ) transcode( FilterGraph([[("color", { "r": 1, "d": 1 })]]), out_url, f_in="lavfi", pix_fmt="rgba", vframes=1, show_log=True, overwrite=True, )
def test_transcode(): url = "tests/assets/testmulti-1m.mp4" outext = ".flac" progress = lambda d, done: print(d, done) with tempfile.TemporaryDirectory() as tmpdirname: # print(probe.audio_streams_basic(url)) out_url = path.join(tmpdirname, re.sub(r"\..*?$", outext, path.basename(url))) # print(out_url) transcode(url, out_url, overwrite=True) # print(probe.audio_streams_basic(out_url)) # transcode(url, out_url) with pytest.raises(FFmpegError): transcode(url, out_url, overwrite=False) transcode(url, out_url, overwrite=True, show_log=True, progress=progress)
import ffmpegio from pprint import pprint import tempfile from os import path def progress(status, done): pprint(status) url = "tests/assets/testmulti-1m.mp4" with tempfile.TemporaryDirectory() as tmpdirname: # print(probe.audio_streams_basic(url)) out_url = path.join(tmpdirname, path.basename(url)) ffmpegio.transcode(url, out_url, progress=progress)
# [("overlay", "(t/5-1)*main_w", 0, {"eval": "frame"})], # [("overlay", 0, 720 - 30, {"shortest": 1})], # ], # input_labels={"0": (3, 0, 0)}, # output_labels={"out": (3, 0, 0)}, # links={(2, 0, 0): (0, 0, 0), (2, 0, 1): (1, 0, 0), (3, 0, 1): (2, 0, 0)}, # ) # vf = ffmpegio.FilterGraph( # [ # [("drawbox", 0, 720 - 30, 1280, 30, "white", "fill")], # [("color", {"c": "blue", "s": "1280x30"})], # [("overlay", "(t/5-1)*w", 720 - 30, {"eval": "frame", "shortest": 1})], # ], # input_labels={"in": (0, 0, 0)}, # output_labels={"out": (2, 0, 0)}, # links={(2, 0, 0): (0, 0, 0), (2, 0, 1): (1, 0, 0)}, # ) print(vf) ffmpegio.transcode( "color=c=black:s=1280x720:d=5", "sandbox/test.mp4", f_in="lavfi", t_in=5, vf=vf, show_log=True, overwrite=True, )