update
This commit is contained in:
@@ -25,3 +25,34 @@ def download_video(video_id: int, youtube_url: str):
|
||||
update_file_path(db, video_id, output_path)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def stream_video_live(youtube_url: str):
|
||||
result = subprocess.run(
|
||||
[
|
||||
"yt-dlp",
|
||||
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
|
||||
"-g", youtube_url,
|
||||
],
|
||||
capture_output=True, text=True, check=True,
|
||||
)
|
||||
urls = result.stdout.strip().split("\n")
|
||||
|
||||
cmd = ["ffmpeg"]
|
||||
for url in urls:
|
||||
cmd.extend(["-i", url])
|
||||
cmd.extend(["-c", "copy", "-movflags", "frag_keyframe+empty_moov", "-f", "mp4", "pipe:1"])
|
||||
|
||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
||||
try:
|
||||
while True:
|
||||
chunk = process.stdout.read(1024 * 1024)
|
||||
if not chunk:
|
||||
break
|
||||
yield chunk
|
||||
process.wait()
|
||||
except GeneratorExit:
|
||||
process.kill()
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.kill()
|
||||
|
||||
Reference in New Issue
Block a user