3 ms·
One could write a small Python server in one day which receives a chunked POST request and transcodes the video on the fly. The same server could also offer a
by qwertox 2y ago
One could write a small Python server in one day which receives a chunked POST request and transcodes the video on the fly.
The same server could also offer a download link for the transcoded video, and also receive URL parameters for the transcoding options. Or the transcoded video itself is returned after the subprocess finishes.
Something along the lines of:
Server
import asyncio
import subprocess
from aiohttp import web
async def transcode_video(request):
cmd = [
"ffmpeg",
"-i", "pipe:0",
"-f", "mp4",
"-preset", "fast",
"output_file.mp4"
]
process = await asyncio.create_subprocess_exec(
*cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
async for chunk in request.content.iter_any():
process.stdin.write(chunk)
await process.stdin.drain()
await process.stdin.close()
await process.wait()
return web.Response(text="Video transcoded successfully!")
app = web.Application()
app.router.add_post('/upload', transcode_video)
if __name__ == '__main__':
web.run_app(app, port=8080)
Client
curl -X POST http://<server_ip>:8080/upload \
--header "Content-Type: application/octet-stream" \
--data-binary @video.mp4
This way no shared filesystem is required.
- steelbrain 2y agoThis and the other solutions in this thread wont work with plex or the media servers. The way it works with the media servers is that there’s a variable number of outputs, and you just cant emulate that on the client side without a virtual filesystem or by some creative hacks that use multiple file descriptors (even then how do you handle dynamic?). As for why the variable number of outputs exist in the first place, it’s because when you’re a media server, you dont want to wait until the full file is converted before serving it to the user. You want to start playing immediately so the output is chunked into multiple files