Search code examples
javaffmpegvideo-streamingmediastreamsegmenter

Tell a java servlet when to return from an external command line call


I have a java servlet api, that when requested, starts a live conversion of a video file using ffmpeg and pipes it to mediastreamsegmenter to segment it for http live streaming. What I want is for the java servlet to return the url of the index file as soon as it has been generated (after the 4th transport stream file is written) so the user can start watching the video without waiting for it to fully finish converting.

How I was thinking of achieving this was to pass a command into the -file-complete-command argument of mediastreamsegmenter, and have it call some sort of a command that could tell the java servlet to return its response if the last file completed was the index file.

Another idea I had was to just segment the first 30 seconds or so of the video, and then return the response, and add the remainder of the video into some sort of a background task in the servlet. I'm not sure how this would be done though. Could I create a separate thread to do this conversion that will continue to run after the servlet returns? I'm sure there must be a better way of doing this. Any thoughts would be appreciated.


Solution

  • I'm not so much into video streaming but could you start a Thread (called PARSE_THREAD) that does the parsing and tell the servlet (living in SERVLET_THREAD) to wait for a reasonable amount of time? I would think that the ffmpeg conversion takes about the same amount of time to parse the first 30 seconds so you start the PARSE_THREAD, then sleep the SERVLET_THREAD for that time and then let the servlet start the streaming.

    Using a separate thread is a good solution for that problem.