0

I am using a Java Servlet and Tomcat to create a video file(HLS-m3u8). I am using a JSP to try and view that file using a hls.js .

CODE

 File folder = (File) getServletContext().getAttribute(req.getServletContext().TEMPDIR);
    File result = new File(folder, "cam.m3u8");

    FFmpeg ffmpeg = new FFmpeg("ffmpeg");
    FFprobe ffprobe = new FFprobe("ffprobe");



    FFmpegBuilder builder =
            new FFmpegBuilder()
                    .setInput("rtsp://xx:xx@192.168.86.00/live")
                    .addOutput(result.getAbsolutePath())
                    .addExtraArgs("-acodec", "copy")
                    .addExtraArgs("-vcodec", "copy")
                    .addExtraArgs("-f", "hls")
                    .addExtraArgs("-safe", "0")
                    .addExtraArgs("-hls_flags", "delete_segments+append_list")
                    .done();
    builder.setVerbosity(FFmpegBuilder.Verbosity.DEBUG);

    FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);

    // Run a one-pass encode
    executor.createJob(builder).run();

JSP

var name; <% File folder = (File) request.getServletContext().getAttribute(request.getServletContext().TEMPDIR); File result = new File(folder, "cam.m3u8"); %> window.onload = function() { name = '<%= result.getCanonicalPath()%>' var video = document.getElementById('video-player'); if(Hls.isSupported()) { var hls = new Hls(); hls.loadSource( '<%= result.getCanonicalPath()%>'); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED,function() { video.play(); }); } else if (video.canPlayType('application/vnd.apple.mpegurl')) { video.src ='<%= result.getCanonicalPath()%>'; video.addEventListener('loadedmetadata',function() { video.play(); }); } }

The file is being created at

"/Users/ari.sprung/Library/Caches/IntelliJIdea2018.1/tomcat/Unnamed_webappRunnerSample_6/work/Catalina/localhost/ROOT/"

When I debug the console I see an error 404 when the player tries to load the m3u8 file. I think its adding http://localhost:8080 to the address of the file. Any idea?

enter image description here

enter image description here

user1163234
  • 2,407
  • 6
  • 35
  • 63
  • Hey dude, just saw your question on Upwork. You must make the file accessible to the web server and stream it, the way you wants it works only works on the local server not on your browser. – Jahan Zinedine Dec 05 '19 at 20:49
  • I presume that moving the file to tomcat static directory will fix the problem. Read up on this answer and you will learn how to map a folder out of your webapp to a path and make it accessible https://stackoverflow.com/a/30601023/316343 – Jahan Zinedine Dec 05 '19 at 21:06
  • Thx ! How do I make it accessible on the web server? Does Heroku have a function like that?Or do I have to go thru AWS of some sort? – user1163234 Dec 05 '19 at 21:29
  • I haven't worked with Heroku for a while, but I don't think it has anything to do with platform as long as you have access to change tomcat configuration as instructed on the link shared in my previous comment. – Jahan Zinedine Dec 05 '19 at 21:32
  • Hey dude, Have you been successful with the instruction provided? If not I'd be happy to help you. – Jahan Zinedine Dec 06 '19 at 05:03
  • @jahan Need help contact me. – user1163234 Dec 06 '19 at 06:53

0 Answers0