Results 1 to 3 of 3

Thread: Use existing mp4 to schedule a live stream

  1. #1
    Join Date
    Feb 2015
    Posts
    3

    Default Use existing mp4 to schedule a live stream

    Hi,

    I'm developing a "Module/ServerListerner" which use an existing mp4 file to publish on live stream.

    First, I created a live stream whit uri : <ip>:1935/live/live.stream

    I register my ServerListener (like in wowza sample codes)
    public class ServerPublisherServerListener implements IServerNotify {
    	ServerPublisherWorker worker = null;
    
    	@Override
    	public void onServerInit(IServer server) {
    		worker = new ServerPublisherWorker();
    		worker.start();
    	}
    
    	@Override
    	public void onServerShutdownStart(IServer server) {
    		if (worker != null)
    			worker.quit();
    		worker = null;
    	}
    
    	@Override
    	public void onServerCreate(IServer arg0) {
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void onServerShutdownComplete(IServer arg0) {
    		// TODO Auto-generated method stub
    
    	}
    }
    And my Worker who call a Manager. This manager call database to get the next live (Object attr : dateStart, dateFinish, path, length)
    And If the next live match params (dateStart and dateFinish) and no live is currently playing, this worker publish the vodstreamname to the live stream
    public class ServerPublisherWorker extends Thread {
    	private long sleepTime = 1000;
    	private boolean running = true;
    	private Object lock = new Object();
    
    	private String applicationName = "live";
    	private String vodStreamName = "mp4:wait.mp4";
    	private String publishStreamName = "live.stream";
    	private IPublishingProvider provider = null;
    
    	private long startPlay;
    
    	public synchronized void quit() {
    		synchronized (lock) {
    			running = false;
    		}
    	}
    
    	public void run() {
    		WMSLoggerFactory.getLogger(ServerPublisherWorker.class).info(
    				"ServerPublisherWorker.run: START");
    
    		long startTime = System.currentTimeMillis();
    		long playStartTime = startTime;
    
    		try {
    			IVHost vhost = VHostSingleton.getInstance(VHost.VHOST_DEFAULT);
    			Publisher publisher = Publisher.createInstance(vhost,
    					applicationName);
    			publisher.publish(publishStreamName);
    
    			provider = new PublishingProviderMediaReader(publisher,
    					publisher.getMaxTimecode(), vodStreamName);
    			provider.setRealTimeStartTime(playStartTime);
    
    			while (true) {
    				boolean moreInFile = provider != null ? provider
    						.play(publisher) : false;
    
    				LiveScheduleManager manager = new LiveScheduleManager();
    				List<LiveSchedule> lstLive = manager.getNext();
    				if (lstLive.size() > 0) {
    					LiveSchedule live = lstLive.get(0);
    					long currentTime = System.currentTimeMillis();
    
    					if (!moreInFile) {
    						if (provider != null)
    							provider.close();
    						provider = null;
    
    						SimpleDateFormat format = new SimpleDateFormat(
    								"yyyy-MM-dd HH:mm:ss");
    						Date dateStart = format.parse(live.getDateStart());
    						Date dateFinish = format.parse(live.getDateFinish());
    
    						if (dateStart.getTime() <= currentTime
    								&& dateFinish.getTime() > currentTime) {
    							vodStreamName = "mp4:" + live.getPath();
    							provider = new PublishingProviderMediaReader(
    									publisher, publisher.getMaxTimecode(),
    									vodStreamName);
    							
    							provider.setRealTimeStartTime(currentTime);
    
    							if (dateStart.getTime() < currentTime) {
    								provider.seek(currentTime - dateStart.getTime());
    							}
    
    							manager.setPlay(live);
    							startPlay = System.currentTimeMillis();
    
    						        sleep(sleepTime);
    						} else {
    						        sleep(sleepTime);
    						}
    
    					} else {
    						sleep(sleepTime);
    					}
    				} else {
    					sleep(sleepTime);
    				}
    
    				synchronized (lock) {
    					if (!running)
    						break;
    				}
    			}
    
    			provider.close();
    
    			publisher.publish(null);
    
    			synchronized (lock) {
    				running = false;
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    		WMSLoggerFactory.getLogger(ServerPublisherWorker.class).info(
    				"ServerPublisherWorker.run: STOP");
    	}
    }

    This code works fine but in RTMP the stream forces a ratio in 4:3 and if I stream with hls or mpeg-dash the video keeps the original aspect ratio.
    I use Jwplayer6.

    How to keep the original aspect ratio with RTMP ? or is this RTMP who bug ?

    Thx a lot.

    PS: don't hesitate to ask me details. This is my first thread and i'm not fluent in english...

  2. #2

    Default

    Hi,

    The video size for RTMP is normally set from the stream metadata. This isn't normally sent through so you need to enable it.

    Call the following to turn on metadata

    provider.setSendOnMetadata(true);
    You need to set it each time you create a new provider.

    Roger.

  3. #3
    Join Date
    Feb 2015
    Posts
    3

    Default

    Nice !
    Thank you, this works fine.

Similar Threads

  1. Replies: 1
    Last Post: 04-17-2015, 05:37 PM
  2. Live and mp4 streaming schedule
    By krisisdnbdjmx in forum Live Streaming and Encoder Discussion
    Replies: 33
    Last Post: 09-25-2012, 05:07 AM
  3. Adding audio stream to existing Audio/Video Stream
    By peili7 in forum General Forum
    Replies: 2
    Last Post: 06-06-2012, 03:41 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
  •