ffmpeg
Logitech C920 웹캠으로 H.264 인코딩을 사용/수행하는 동안 웹캐스트에 문제가 있습니다 ffserver
.
이것은 내가 사용하는 구성 파일입니다 ffserver
.
# Port on which the server is listening. You must select a different
# port from your standard HTTP web server if it is running on the same
# computer.
Port 8090
# Address on which the server is bound. Only useful if you have
# several network interfaces.
BindAddress 0.0.0.0
# Number of simultaneous HTTP connections that can be handled. It has
# to be defined *before* the MaxClients parameter, since it defines the
# MaxClients maximum limit.
MaxHTTPConnections 2000
# Number of simultaneous requests that can be handled. Since FFServer
# is very fast, it is more likely that you will want to leave this high
# and use MaxBandwidth, below.
MaxClients 1000
# This the maximum amount of kbit/sec that you are prepared to
# consume when streaming to clients.
MaxBandwidth 1000
# Access log file (uses standard Apache log file format)
# '-' is the standard output.
CustomLog -
##################################################################
# Definition of the live feeds. Each live feed contains one video
# and/or audio sequence coming from an ffmpeg encoder or another
# ffserver. This sequence may be encoded simultaneously with several
# codecs at several resolutions.
<Feed feed.ffm>
# You must use 'ffmpeg' to send a live feed to ffserver. In this
# example, you can type:
#
File /tmp/feed.ffm
FileMaxSize 100M
# You could specify
# ReadOnlyFile /saved/specialvideo.ffm
# This marks the file as readonly and it will not be deleted or updated.
# Only allow connections from localhost to the feed.
ACL allow 127.0.0.1
</Feed>
##################################################################
# Now you can define each stream which will be generated from the
# original audio and video stream. Each format has a filename (here
# 'test1.mpg'). FFServer will send this stream when answering a
# request containing this filename.
<stream stream.mp4>
Feed feed.ffm
Format mp4
# Audio settings
NoAudio
# Video Settings
#VideoSize 1280x720 # Video resolution
#VideoFrameRate 30 # Video FPS
#AVOptionVideo flags +global_header # Parameters passed to encoder
#AVOptionVideo cpu-used 0
#AVOptionVideo qmin 10
#AVOptionVideo qmax 42
#AVOptionVideo quality good
PreRoll 0
StartSendOnKey
#VideoBitRate 400 # Video bitrate
</stream>
# Server status
<Stream stat.html>
Format status
# Only allow local people to get the status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
명령줄을 통해 실행한 명령과 해당 출력은 다음과 같습니다.
$ ffmpeg -s 1280x720 -f video4linux2 -r 30 -vcodec h264 -re -i /dev/video0 \
-copyinkf -codec copy h**p://localhost:8090/feed.ffm
ffmpeg version N-67036-g04a4fb8 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 20 2014 17:39:50 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --enable-gpl --enable-libx264
libavutil 54. 10.100 / 54. 10.100
libavcodec 56. 8.102 / 56. 8.102
libavformat 56. 9.101 / 56. 9.101
libavdevice 56. 1.100 / 56. 1.100
libavfilter 5. 2.100 / 5. 2.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 12614.859199, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuvj420p(pc), 1280x720 [SAR 1:1 DAR 16:9], -5 kb/s, 30 fps, 30 tbr, 1000k tbn, 60 tbc
Output #0, ffm, to 'h**p://localhost:8090/feed.ffm':
Metadata:
creation_time : now
encoder : Lavf56.9.101
Stream #0:0: Video: h264, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, -5 kb/s, 30 fps, 1000k tbn, 30 tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 0, current: -166263; changing to 1. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 1, current: -134365; changing to 2. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 2, current: -102381; changing to 3. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 3, current: -66434; changing to 4. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 4, current: -34548; changing to 5. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 5, current: -2645; changing to 6. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 232857, current: 138514; changing to 232858. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 232858, current: 167942; changing to 232859. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 232859, current: 197415; changing to 232860. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 232860, current: 227037; changing to 232861. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 997959, current: 938599; changing to 997960. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 997960, current: 995052; changing to 997961. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 1240745, current: 1232841; changing to 1240746. This may result in incorrect timestamps in the output file.
[ffm @ 0x28c7ea0] Non-monotonous DTS in output stream 0:0; previous: 1293561, current: 1282157; changing to 1293562. This may result in incorrect timestamps in the output file.
frame= 69 fps= 34 q=-1.0 Lsize= 912kB time=00:00:02.01 bitrate=3702.1kbits/s
예를 들어 VLC를 사용하여 스트림을 재생하려고 하면 vlc h**p://localhost:8090/stream.mp4
다음 오류가 발생합니다.
[00007f5234003948] 코어 스트리밍 오류: 버퍼를 미리 채울 수 없습니다.
웹 브라우저 측에서도 스트림을 볼 수 없습니다.
누군가 나에게 힌트를 줄 수 있습니까?
답변1
저는 OpenWRT 라우터(TP-Link WDR3600, MIPS CPU, 560mHz)에서 ffmpeg 및 Logitech C920 카메라와 함께 귀하의 구성을 사용해 왔습니다. 내 시스템이 640x480 이상에서 안정적으로 실행되지 않습니다. 트랜스코딩 없이 ffmpeg만 시작하고(내 라우터는 트랜스코딩을 전혀 수행할 수 없으며 CPU가 너무 약함) VLC를 사용하여 스트림을 시청해 보았습니다.
ffmpeg -f v4l2 -input_format h264 -video_size 320x400 -i /dev/video0 -copyinkf -codec 복사 -f mpegts udp://192.168.1.100:20000
640x480의 비디오는 왜곡되고, 800x600 이상은 전혀 작동하지 않으며, ffmpeg는 "비단조적인 DTS..." 메시지를 많이 표시합니다. 320x400이면 됩니다. MJPEG 비디오 출력이 더 좋습니다. 50Mbit/s보다 높은 데이터 속도로 1920x1080 및 15fps에서 C920을 실행할 수 있었지만 MJPEG도 100% 오류가 없는 것은 아닙니다. 적어도 ffmpeg에서는 카메라가 H264에 몇 가지 문제가 있는 것 같습니다. H264에서 카메라는 내가 설정하려고 하는 해상도/프레임 속도에 관계없이 약 3.2Mbit/s의 일정한 비트 전송률을 제공합니다.
그러나 요점으로 돌아갑니다. h264가 ffserver와 함께 작동하도록 하려면 "형식"을 변경하고 "스트림" 섹션에서 StartSendOnKey를 주석 처리하여 피드 섹션을 수정했습니다.
mpegt 형식 ... #StartSendOnKey
"피드" 섹션에 ffmpeg "Launch" 문자열을 추가하면 다음과 같습니다.
ffmpeg -f v4l2 -input_format h264 -video_size 320x400 -i /dev/video0 -copyinkf -codec copy 시작
MaxBandwidth를 50000으로 변경합니다.
vlc를 클라이언트 소프트웨어로 사용합니다.
답변2
나는 이 구성을 사용하고 있으며 server.conf 파일이 제대로 작동합니다.
HTTPPort 1235
RTSPPort 1234
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 100000
#CustomLog –
#########################################
## usb cam: logitec c920
#########################################
<Feed camfeed.ffm>
File /tmp/camfeed.ffm
FileMaxSize 500K
#allow only localhost to publish feed
ACL allow 192.168.1.149
</Feed>
<Stream usbcam.mov>
Feed camfeed.ffm
Format rtp
#cam defaults:
VideoSize 800x600
VideoFrameRate 24
VideoBitRate 400
VideoCodec libx264
NoLoop
NoAudio
Preroll 0
StartSendOnKey
</Stream>
######################################
# ffmpeg cmd:
######################################
# ffmpeg -y -s 800x600 -f video4linux2 -i /dev/video0 -c:v libx264 -tune zerolatency -an http://192.168.1.149:1235/camfeed.ffm