steam-server/app/services/ffmpeg_service.py
2024-12-12 20:04:36 +08:00

22 lines
800 B
Python

# app/services/ffmpeg_service.py
import subprocess
import asyncio
from app.config import ffmpeg_path
async def log_output(process, output_url):
while True:
output = await asyncio.to_thread(process.stderr.readline)
if output == "" and process.poll() is not None:
break
if output:
print(f"ffmpeg output for {output_url}: {output.strip()}")
async def stream_rtsp_to_flv(stream_id: str):
input_url = "rtsp://admin:jitu0818@192.168.4.102:554/Streaming/Channels/101"
command = [
ffmpeg_path, "-i", input_url, "-c:v", "libx264", "-c:a", "aac", "-f", "flv", "-"
]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
asyncio.create_task(log_output(process, stream_id))
return process.stdout