Results 1 to 8 of 8

Thread: Live Stream to File

  1. #1

    Default Live Stream to File

    I have a Wowza server that accepts live streams from users via NetStream.publish function in flash. I've setup the application.xml to record the stream to a flv file. The idea is after the live stream recording is complete, Wowza will pass off the flv to another piece of software for post processing.

    My question is: Is there a way to know what the file name of the flv is? Or to specify the name of the file before the recording starts?

  2. #2

    Default

    Hi,

    The name of the recorded file will be the name used in the netstream.publish call with .flv appended.

    You can use the LiveStreamRecord functionality built into Wowza >= 3.5.0 (plugin for pervious versions) to have more control over record settings.

    Roger.

  3. #3

    Default

    Well if my stream is called "livestream" or something and I have like 30 recordings "livestream.flv" - "livestream_30.flv". Is there a way to know if I'm currently recording to "livestream_30.flv" or "livestream_31.flv" with out checking the file system to see what the highest number is?

    I've seen LiveStreamRecord, doesn't it require that the flash client use something other then NetStream.publish? We had hoped to leave the flash client intact so that it could work with any media server.
    Last edited by Pickysalamander; 02-27-2013 at 03:42 PM.

  4. #4

    Default

    If you have file versioning enabled the following will happen.

    The new stream will be recorded using the published name. eg livestream.flv.
    The versioning system will check to see if the filename already exists and if so, it will rename the existing recording to the next name in the sequence. eg. livesteam_1.flv, livestream_2.flv etc.

    The file that is currently being recorded or the last one recorded will be un-sequenced.

    Roger.

  5. #5

    Default

    Ah ok, I didn't realize that's how it works. Thanks! I'll see if I can get that working.

  6. #6

    Default

    So I'm still working on this. At the end of the day I decided on LiveStreamRecord, but I can't seem to get it working. Basically I'm trying to get it so all the streams that a user is listening (can be a lot of streams) to and publishing on is recorded. I have a class that starts up when the user requests the recording to start and listens to onStreamCreate and onStreamDestroy to attach a LiveStreamRecorderFLV to the stream. I have several problems with this:

    1. When onStreamCreate is called, the IClient isn't always instantiated. So, I don't know if this is the correct user to start recording.
    2. When I attach a IMediaStreamActionNotify listener to the stream created in onStreamCreate and wait till onPlay, the LiveStreamRecorderFLV will not record the FLV properly. The FLV will be one kb large and will have not audio data and no errors or warnings are in the log.
    4. LiveStreamRecorderFLV only seems to work if I record the stream right when onStreamCreate is called, but as said before: I don't know if it's the correct user.
    3. I can't seem to find LiveStreamRecord documentation anywhere to figure out what functions I need to call to get this recording properly.

    Please let me know if I'm on the wrong track or if there is something else I should be doing. I'm completely lost.

    Here is some code below that I'm using:

    public class ShowRecorder implements IMediaStreamNotify, IMediaStreamActionNotify {	
    	private IClient client;
    	private File storageDir;
    	private ArrayList<IMediaStream> waitingForPlay;
    	private HashMap<IMediaStream, ShowElement> recording;
    	private ArrayList<ShowElement> finished;
    	
    	public ShowRecorder(IClient client, File appStorageDir) {
    		this.client = client;
    		
    		waitingForPlay = new ArrayList<IMediaStream>();
    		recording = new HashMap<IMediaStream, ShowElement>();
    		finished = new ArrayList<ShowElement>();
    		timeStart = System.currentTimeMillis();
    		storageDir = new File(appStorageDir.getAbsoluteFile() + "//show-" + System.currentTimeMillis()); 
    		storageDir.mkdirs();
    		
    		client.getAppInstance().addMediaStreamListener(this);
    	}
    	
    	public void recordStream(IMediaStream stream) {	
    		try {			
    			if(!isStreamValid(stream)) {
    				return;
    			}
    			
    			long start = System.currentTimeMillis();
    			File file = new File(storageDir + "//" + start + ".flv");
    			
    			ILiveStreamRecord recorder = new LiveStreamRecorderFLV();
    			recorder.startRecording(stream, file.getAbsolutePath(), false);
    			ShowElement elem = new ShowElement(recorder, file, start);
    			recording.put(stream, elem);
    		}
    		catch(Exception e) {
    			logger.error("Failed to start recording " + stream.getName(), e);
    		}
    	}
    	
    	public void stopRecordingStream(IMediaStream stream) {
    		try {
    			ShowElement elem = recording.remove(stream);
    			if(elem != null) {
    				closeRecorder(elem);
    			}
    		}
    		catch(Exception e) {
    			logger.error("Failed to remove recording " + stream.getName(), e);
    		}
    	}
    	
    	private void closeRecorder(ShowElement elem) {
    		elem.getRecorder().stopRecording();
    		elem.setRecorder(null);
    		
    		finished.add(elem);
    	}
    	
    	public void shutDown() {
    		try {
    			Iterator<ShowElement> elemIt = recording.values().iterator();
    			while(elemIt.hasNext()) {
    				ShowElement element = elemIt.next();
    				closeRecorder(element);
    				elemIt.remove();
    			}
    			
    			client.getAppInstance().removeMediaStreamListener(this);
    			
    			for(IMediaStream stream : waitingForPlay) {
    				stream.removeClientListener(this);
    			}
    			
    			waitingForPlay = null;
    		}
    		catch(Exception e) {
    		}
    	}
    	
    	private void testStream(IMediaStream stream) {
    		if(isStreamReady(stream) && isStreamValid(stream)) {
    			recordStream(stream);
    		}
    		
    		waitingForPlay.remove(stream);
    		stream.removeClientListener(this);
    	}
    	
    	private boolean isStreamValid(IMediaStream stream) {
    		return stream.getClientId() == client.getClientId();
    	}
    	
    	private boolean isStreamReady(IMediaStream stream) {
    		return stream.getClient() != null && !stream.getName().isEmpty();
    	}
    
    	public void onMediaStreamCreate(IMediaStream stream) {
    		if(!isStreamReady(stream)) { 
    			waitingForPlay.add(stream);
    			stream.addClientListener(this);
    		}
    		else { recordStream(stream); }
    	}
    
    	public void onMediaStreamDestroy(IMediaStream stream) {
    		stopRecordingStream(stream);
    		waitingForPlay.remove(stream);
    	}
    
    	public void onPause(IMediaStream stream, boolean isPause, double location) {
    		testStream(stream);
    	}
    
    	public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset)  {
    		testStream(stream);
    	}
    
    	public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
    		testStream(stream);
    	}
    
    	public void onSeek(IMediaStream stream, double location) {
    		testStream(stream);
    	}
    
    	public void onStop(IMediaStream stream)  {
    		testStream(stream);
    	}
    
    	public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)  {
    		testStream(stream);
    	}
    }

  7. #7

    Default

    Nevermind I was able to solve my problem, apparently an external piece of code was preventing the correct streams from starting. Also, I hadn't quite understood how media streams worked.

  8. #8
    Join Date
    Sep 2011
    Posts
    1,933

    Default

    Hi
    I'm glad you got it working, thanks for the update.

    Jason

Similar Threads

  1. Does wowza change source file 16:9 to live stream 4:3 in rmtp stream?
    By Denny Lee in forum Live Streaming and Encoders
    Replies: 1
    Last Post: 08-25-2014, 06:28 AM
  2. Live stream record only 1 KB file
    By bizkit1 in forum AddOn: Other AddOns
    Replies: 10
    Last Post: 11-04-2012, 07:43 AM
  3. Stream video file with cuepoints as live and then switch to live stream
    By notreemedia in forum Live Streaming and Encoder Discussion
    Replies: 4
    Last Post: 02-28-2012, 08:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •