我們有一堆.mp4文件及其關聯的.ttml打開的字幕文件。我們正在使用Wowza來動態加載和流式傳輸這些文件,而不會中斷流。wowza java api注入字幕
我能夠按照教程在這裏(https://www.wowza.com/docs/how-to-use-ipublishingprovider-api-to-publish-server-side-live-streams)在指定的時間流個別mp4文件。
但是,我找不到一個Java API命令來注入關聯的標題文件。我找到了這個頁面(https://www.wowza.com/docs/how-to-configure-closed-captioning-for-live-streaming),它沒有談論Java API,而是一個配置設置。在頁面的最後是一個示例包,顯示了一些API調用,但該部分被描述爲「遺留」。我可以擴展它,但由於它是「遺留」,所以我擔心模塊依賴的任何API可能在更高版本的WMS中不可用。
在PublishingProviderMediaReader調用之後,是否有一種低級方式(在「傳統」方式旁邊)告訴系統加載ttml文件(或者只是手動注入文本)?
下面是從鏈接粘貼上述
package com.wowza.wms.plugin.test.integration;
import com.wowza.wms.stream.publish.*;
import com.wowza.wms.vhost.*;
import com.wowza.wms.logging.*;
public class ServerPublisherWorker extends Thread
{
private long sleepTime = 75;
private boolean running = true;
private Object lock = new Object();
private String applicationName = "live";
private String vodStreamName = "mp4:sample.mp4";
private String liveStreamName = "myStream";
private String publishStreamName = "publishstream";
private int cycleTime = 10000;
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);
long nextSwitch = playStartTime + cycleTime;
long nextType = 0;
IPublishingProvider provider = new PublishingProviderMediaReader(publisher, playStartTime, vodStreamName);
//provider.seek(20000);
provider.setRealTimeStartTime(startTime);
WMSLoggerFactory.getLogger(ServerPublisherWorker.class).info("ServerPublisherWorker.run: Start with vod stream: "+vodStreamName);
while(true)
{
boolean moreInFile = provider!=null?provider.play(publisher):false;
long currentTime = System.currentTimeMillis();
if (!moreInFile || currentTime > nextSwitch)
{
if (provider != null)
provider.close();
provider = null;
if ((nextType % 2) == 0)
{
provider = new PublishingProviderLive(publisher, publisher.getMaxTimecode(), liveStreamName);
//((PublishingProviderLive)provider).setStartOnPreviousKeyFrame(false);
provider.setRealTimeStartTime(currentTime);
WMSLoggerFactory.getLogger(ServerPublisherWorker.class).info("ServerPublisherWorker.run: Switch to live stream: "+liveStreamName);
}
else
{
provider = new PublishingProviderMediaReader(publisher, publisher.getMaxTimecode(), vodStreamName);
//provider.seek(20000);
provider.setRealTimeStartTime(currentTime);
WMSLoggerFactory.getLogger(ServerPublisherWorker.class).info("ServerPublisherWorker.run: Switch to vod stream: "+vodStreamName);
}
nextSwitch = currentTime + cycleTime;
nextType++;
if (nextType == 100)
break;
}
else
sleep(sleepTime);
synchronized(lock)
{
if (!running)
break;
}
}
provider.close();
publisher.publish(null);
synchronized(lock)
{
running = false;
}
}
catch (Exception e)
{
WMSLoggerFactory.getLogger(ServerPublisherWorker.class).error("ServerPublisherWorker.run: "+e.toString());
e.printStackTrace();
}
WMSLoggerFactory.getLogger(ServerPublisherWorker.class).info("ServerPublisherWorker.run: STOP");
}
}
代碼並調用上述代碼的基礎聽者:
package com.wowza.wms.plugin.test.integration;
import com.wowza.wms.server.*;
public class ServerPublisherServerListener implements IServerNotify
{
ServerPublisherWorker worker = null;
public void onServerCreate(IServer server)
{
}
public void onServerInit(IServer server)
{
worker = new ServerPublisherWorker();
worker.start();
}
public void onServerShutdownComplete(IServer server)
{
}
public void onServerShutdownStart(IServer server)
{
if (worker != null)
worker.quit();
worker = null;
}
}
任何援助或輸入是非常讚賞。先謝謝你。
謝謝。 setCaption函數直接放入併爲rtmp工作 – nanytech