Skip to content

Commit

Permalink
標準出力動作をつくってパイプでつないでみたところ次のエラーがでたので、対策とってみた。
Browse files Browse the repository at this point in the history
Application provided invalid, non monotonically 
increasing dts to muxer in stream 0:
というエラー。ためしにpacketの順番を整頓してやれば、問題でないっぽいです。
なお、このエラー、新しいffmpegの場合は発生しない模様です。
ffmpeg0.10以降なら問題ないみたい。
あまり興味ないので、プログラム作成→出力ファイル作成→コンバートためし、で問題でなかったので、ここでやめる。
  • Loading branch information
taktod committed Jun 7, 2012
1 parent 335b627 commit 39c1e95
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions src/com/ttProject/flazr/StdoutWriter.java
@@ -1,15 +1,15 @@
package com.ttProject.flazr;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.jboss.netty.buffer.ChannelBuffer;
import org.red5.io.utils.HexDump;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.flazr.io.flv.FlvAtom;
import com.flazr.io.flv.VideoTag;
import com.flazr.io.flv.VideoTag.FrameType;
import com.flazr.rtmp.RtmpHeader;
import com.flazr.rtmp.RtmpMessage;
import com.flazr.rtmp.RtmpWriter;
Expand All @@ -24,6 +24,8 @@ public class StdoutWriter implements RtmpWriter {
private static final Logger logger = LoggerFactory.getLogger(StdoutWriter.class);
private final int[] channelTimes = new int[RtmpHeader.MAX_CHANNEL_ID];
private int primaryChannel = -1;
private ConcurrentLinkedQueue<FlvAtom> dataQueue = new ConcurrentLinkedQueue<FlvAtom>();
private FileOutputStream fos;
/**
* コンストラクタ
*/
Expand Down Expand Up @@ -72,28 +74,60 @@ public void write(RtmpMessage message) {
private void write(final FlvAtom flvAtom) {
if(flvAtom.getHeader().isVideo()) {
VideoTag videoTag = new VideoTag(flvAtom.encode().getByte(0));
if(videoTag.getFrameType() == FrameType.DISPOSABLE_INTER) {
// TODO red5のときにxuggleに渡さなかったdisposable interframe. flazrならいけるか?
// よくわからんDTSエラーがでる。timestampがひっくり返るデータができることはHttpTakStreamingをつくったときにわかっているので、その兼ね合いですかね?
return;
// queueの中身をすべて外にだして、現在のタイムスタンプ以前のものなら、書き込みを実施する。
ConcurrentLinkedQueue<FlvAtom> queue = new ConcurrentLinkedQueue<FlvAtom>();
while(dataQueue.size() > 0) {
FlvAtom data = dataQueue.poll();
if(data.getHeader().getTime() <= flvAtom.getHeader().getTime()) {
try {
// このデータをFlvDataQueueに渡せばOK
logger.info("audioTimestamp:" + data.getHeader().getTime());
ByteBuffer buffer = data.write().toByteBuffer();
byte[] dat = new byte[buffer.limit()];
buffer.get(dat);
System.out.write(dat);
}
catch (Exception e) {
logger.error("", e);
}
}
else {
queue.add(data);
}
}
dataQueue = queue;
logger.info("queueSize:" + dataQueue.size());
logger.info("videoTimestamp:" + flvAtom.getHeader().getTime());
try {
ByteBuffer buffer = flvAtom.write().toByteBuffer();
byte[] dat = new byte[buffer.limit()];
buffer.get(dat);
System.out.write(dat);
}
catch (Exception e) {

}
}
try {
// このデータをFlvDataQueueに渡せばOK
ByteBuffer buffer = flvAtom.write().toByteBuffer();
byte[] data = new byte[buffer.limit()];
buffer.get(data);
System.out.write(data);
// System.out.println(HexDump.toHexString(data));
}
catch (Exception e) {
logger.error("", e);
else if(flvAtom.getHeader().isAudio()) {
// audioデータはすべてqueueにいれる。
try {
// このデータをFlvDataQueueに渡せばOK
dataQueue.add(flvAtom);
}
catch (Exception e) {
logger.error("", e);
}
}
}
/**
* 閉じる
*/
@Override
public void close() {
try {
fos.close();
}
catch (Exception e) {
}
}
}

0 comments on commit 39c1e95

Please sign in to comment.