Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void method(HttpServletRequest request, HttpServletResponse response, String channel) throws InterruptedException, IOException {
- String url = "http://85.229.9.206:9981/stream/channel/" + channel;
- System.out.println(url);
- Path in = Paths.get(url);
- Path out = Paths.get("/momomo/Generated/Tv/" + channel + ".mp4");
- Files.deleteIfExists(out);
- ProcessBuilder builder = new ProcessBuilder(
- "ffmpeg",
- "-i", in.toString(),
- "-y",
- // "-s", "360x480", // stripped the extraneous "-1"
- "-vcodec", "libx264",
- out.toString()
- );
- builder.redirectErrorStream (true);
- builder.redirectOutput (out.toFile());
- final Process process = builder.start();
- response.setContentType("application/octet-stream");
- response.setHeader("Content-Type", "video/mp4");
- response.setHeader ("Content-Disposition", "attachment;filename=filename.mp4");
- // boolean code = process.waitFor(1000, TimeUnit.MILLISECONDS);
- int BUFFER_SIZE = 512;
- try (
- BufferedInputStream input = new BufferedInputStream(new FileInputStream(out.toFile()), BUFFER_SIZE);
- BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), BUFFER_SIZE);
- ) {
- byte[] bytes = new byte[BUFFER_SIZE];
- int length;
- while ((length = input.read(bytes)) > 0) {
- output.write(bytes, 0, length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment