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 : :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…

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.

Nice !

Thank you, this works fine.