Comments (7)
没错的啊。对于FIFO文件的写打开(open write)就是阻塞的,所以你需要分开两个线程去创建FileOutputStream。
另外,你的ffmpeg参数有问题,-f h264写重了,第二个要删掉。
另外,你这个问题我这的fifo分支已经处理过了啊。。。
from jtt1078-video-server.
嗯,非常感谢答复,第二个参数去掉了。另外我说卡死的意思是,第二个线程也就是AudioPublisher会卡 run 里 如下地方,后续publish进来的音频数据就一直在堆积,但VideoPublisher那个线程倒是没事
if (output == null)
{
output = new FileOutputStream(fifoPath); //卡这里,导到packets里的数据越来越多,
Thread.sleep(100);
}
另外,我使用你的VidePushTest push那个tcpdump.bin的数据也是这样的结果
还请教一个问题,这个方案,是不是一定要有音频数据推送上来,如只有视频数据的情况,ffmpeg是不是也会在等待?
from jtt1078-video-server.
我知道你那里会卡住,上面不是说了吗?对于FIFO文件的写打开,是阻塞的,需要你使用两个不同的线程去打开不同的FIFO,记得一定是要两个不同的线程去打开FIFO,然后打开FIFO前,是需要先要有对FIFO的读进程,就是在创建这两个线程前,确保已经开启了子进程,,,
FIFO文件这里,如果没有reader,那么writer会阻塞。。。你可以完全clone我的项目测试一下看看。
from jtt1078-video-server.
是完全克隆的fifo. 除app.properties改了一下rtmp的地址。上面的两个FileInpuStream只是验证演示一下。 可能我哪里理解的不对?看了代码,我觉得 videoPublisher 与 audioPublisher 是两个完全不同于主线程的独立子线程啊?现在只有audioPublisher这个线程在run里卡住了。在这两个线程执行创建之前,确实要先对FIFO有读进程,我看代码里也是这样的啊,一个ffmpeg读进程,然后是 video与audio两个子线程(写操作),我真有点怀疑是不是ffmpeg把第二个输入的文件锁死了?太奇怪了
// 打开推送通道(打开FIFO文件输出流)
public void open(String rtmpURL) throws Exception
{
String videoFifoPath = mkfifo();
String audioFifoPath = mkfifo();
process = Runtime.getRuntime().exec(
String.format("%s -report -re -r 25 -f h264 -i %s -f s16le -ar 8000 -ac 1 -i %s -vcodec copy -acodec aac -strict -2 "
+ " -map 0:v:0 -map 1:a:0 -probesize 512 -analyzeduration 100 -f flv %s",
Configs.get("ffmpeg.path"),
videoFifoPath,
audioFifoPath,
rtmpURL
)
);
if ("true".equalsIgnoreCase(Configs.get("ffmpeg.debug")))
StdoutCleaner.getInstance().watch(channel, process);
videoPublisher = new VideoPublisher(channel, "video", process);
audioPublisher = new AudioPublisher(channel, "audio", process);
videoPublisher.open(videoFifoPath);
audioPublisher.open(audioFifoPath);
logger.debug("audio/video publisher started for: {}", channel);
}
from jtt1078-video-server.
如果你完整的clone了我的项目的话,应该不至于会阻塞在那个地方啊,真是奇了个怪的了,我刚刚又试了一下,发现这个分支的双FIFO模式还是不大稳妥,我准备放弃掉这个分支上的功能了,你有兴趣的话,可以试试multimedia分支,晚点我会提供一个测试地址,以及将multimedia分支改为默认分支。
from jtt1078-video-server.
分享一下,我这边目前可以稳定运行合并推送音频与视频了,关键点是把第一个视频l输入fifo改为从标准输入读取(-),第二个音频输入还是用fifo, VideoPusblish构造中将output初始化为process的getOutputStream即可,如下:
/ffmpeg参数 改动一下*******/
process = Runtime.getRuntime().exec(
String.format("%s -report -fflags +genpts -re -f h264 -i - -f s16le -ar 8000 -ac 1 -i %s -c:v copy -c:a aac -strict experimental " +
"-map 0:v:0 -map 1:a:0 -f flv %s ",
Configs.get("ffmpeg.path"),
audioFifoPath,
rtmpURL
)
);
/VideoPublisher 改动一下*******/
public VideoPublisher(long channel, String tag, Process process)
{
super(channel, tag, process);
this.output = process.getOutputStream();
}
from jtt1078-video-server.
哦嚯嚯,非常感谢,我试一试。。。
from jtt1078-video-server.
Related Issues (20)
- qq群解了吗? HOT 1
- unknown directive "rtmp" HOT 2
- 转码之后播放的很快 HOT 1
- 请问本项目实现的是那种规范的ADPCM?IMA-ADPCM?MS-ADPCM? HOT 2
- 请教1078广播和对讲音频数据下发问题
- ADPCM测试正常,G711A杂音很大 HOT 1
- 請教一下 HOT 3
- G711 音頻 toPCM問題 HOT 3
- G726_40方式 播放只有杂音,求解 音频格式确实为G726_40 HOT 2
- qq群搜不到了 HOT 1
- G.726 codec bug HOT 2
- 内存泄漏 HOT 1
- 如何将流地址从http协议转到ws协议 HOT 3
- 请教一下,无法处理终端上来的1080p的视频流
- 我用我自己的设备发送数据会报错 HOT 60
- 长时间推流,会抛出异常 HOT 1
- 推流会出现broken pipe HOT 1
- 多摄像头同时推流,cpu占用接近100,导致卡死 HOT 7
- Connection to tcp://localhost:1935 failed HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jtt1078-video-server.