我正在尝试将我的桌面屏幕流式传输到 HLS 服务器(nginx RTMP 模块),但我不知道该怎么做。我试过
ffmpeg -f x11grab -i :0.0 -f hls http://192.168.1.68/tmp/hls
但这又回来了
ffmpeg version N-60313-g6d7119d Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 2 2014 16:01:55 with gcc 4.7 (Debian 4.7.3-4)
configuration: --enable-indev=alsa --enable-gpl --enable-x11grab --enable-libpulse --enable-libopus --enable-libmp3lame --enable-libvpx --enable-libx264 --enable-pthreads
libavutil 52. 63.100 / 52. 63.100
libavcodec 55. 49.101 / 55. 49.101
libavformat 55. 29.100 / 55. 29.100
libavdevice 55. 7.100 / 55. 7.100
libavfilter 4. 1.102 / 4. 1.102
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
[x11grab @ 0x2823900] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 640 height: 480
[x11grab @ 0x2823900] shared memory extension found
Input #0, x11grab, from ':0.0':
Duration: N/A, start: 1391370026.581568, bitrate: 294617 kb/s
Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480, 294617 kb/s, 29.97 tbr, 1000k tbn, 29.97 tbc
[tcp @ 0x28854c0] Failed to resolve hostname 192.168.10.ts: Name or service not known
Output #0, hls, to 'http://192.168.1.68/tmp/hls':
Metadata:
encoder : Lavf55.29.100
Stream #0:0: Video: mpeg2video, yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo -> mpeg2video)
Could not write header for output file #0 (incorrect codec parameters ?): Input/output error
我的nginx.conf
包含:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live
{
live on;
record off;
hls on;
hls_path /tmp/hls;
hls_fragment 12s;
}
}
}
答案1
不,事实上你应该通过 RTMP 协议流式传输到 nginx-rtmp。
ffmpeg -f x11grab -i :0.0 -vcodec libx264 -b:v 1024k -an -f flv rtmp:/192.168.1.68/live/test
你应该在 nginx.conf 中添加类似这样的内容
http {
...
server {
...
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
}
root /tmp;
add_header Cache-Control no-cache;
}
}
...
}
然后将播放器配置为流源网址http://192.168.1.68/hls/test.m3u8
祝你好运。