Guest User

Untitled

a guest
Feb 11th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. public static void method(HttpServletRequest request, HttpServletResponse response, String channel) throws InterruptedException, IOException {
  2.  
  3.                 String url = "http://85.229.9.206:9981/stream/channel/" + channel;
  4.        
  5.                 System.out.println(url);
  6.                
  7.                 Path in    = Paths.get(url);
  8.                            
  9.                 Path out   = Paths.get("/momomo/Generated/Tv/" + channel + ".mp4");
  10.        
  11.                 Files.deleteIfExists(out);
  12.                
  13.                 ProcessBuilder builder = new ProcessBuilder(
  14.                         "ffmpeg",
  15.                         "-i", in.toString(),
  16.                         "-y",
  17.                         // "-s", "360x480", // stripped the extraneous "-1"
  18.                         "-vcodec", "libx264",
  19.                         out.toString()
  20.                 );
  21.        
  22.                 builder.redirectErrorStream (true);
  23.                 builder.redirectOutput      (out.toFile());
  24.                
  25.                 final Process process = builder.start();
  26.                
  27.                 response.setContentType("application/octet-stream");
  28.                 response.setHeader("Content-Type", "video/mp4");
  29.                 response.setHeader  ("Content-Disposition", "attachment;filename=filename.mp4");
  30.        
  31.                 // boolean code = process.waitFor(1000, TimeUnit.MILLISECONDS);
  32.                
  33.                 int BUFFER_SIZE = 512;
  34.                 try (
  35.                         BufferedInputStream  input  = new BufferedInputStream(new FileInputStream(out.toFile()), BUFFER_SIZE);
  36.                         BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), BUFFER_SIZE);
  37.                 ) {
  38.                         byte[] bytes = new byte[BUFFER_SIZE];
  39.                         int length;
  40.                         while ((length = input.read(bytes)) > 0) {
  41.                                 output.write(bytes, 0, length);
  42.                         }
  43.                 }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment