# Use existing mp4 to schedule a live stream

**URL:** https://community.wowza.com/t/use-existing-mp4-to-schedule-a-live-stream/44722
**Category:** Wowza Developer Dojo
**Tags:** wowza-streaming-server-java-api
**Created:** [May 12, 2015, 4:35pm UTC](https://community.wowza.com/t/use-existing-mp4-to-schedule-a-live-stream/44722 "2015-05-12T16:35:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Remi\_Heens](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Remi\_Heens](https://community.wowza.com/u/Remi_Heens)
#### Post date: [May 12, 2015, 4:35pm UTC](https://community.wowza.com/t/use-existing-mp4-to-schedule-a-live-stream/44722/1 "2015-05-12T16:35:48Z")

</div>

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)

```auto
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

```auto
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…

---

<div class="post-metadata">

### Author: ![Roger\_Littin1](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@Roger\_Littin1](https://community.wowza.com/u/Roger_Littin1)
#### Post date: [May 19, 2015, 2:03pm UTC](https://community.wowza.com/t/use-existing-mp4-to-schedule-a-live-stream/44722/2 "2015-05-19T14:03:38Z")

</div>

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

```auto
provider.setSendOnMetadata(true);

```

You need to set it each time you create a new provider.

Roger.

---

<div class="post-metadata">

### Author: ![Remi\_Heens](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Remi\_Heens](https://community.wowza.com/u/Remi_Heens)
#### Post date: [May 27, 2015, 10:36am UTC](https://community.wowza.com/t/use-existing-mp4-to-schedule-a-live-stream/44722/3 "2015-05-27T10:36:48Z")

</div>

Nice !

Thank you, this works fine.
