![实时视频转码质量下降](https://linux22.com/image/1392838/%E5%AE%9E%E6%97%B6%E8%A7%86%E9%A2%91%E8%BD%AC%E7%A0%81%E8%B4%A8%E9%87%8F%E4%B8%8B%E9%99%8D.png)
我需要将输入的 rtsp 流转码为一定质量的 HLS 输出。
输入流可能有 3 种不同的质量
2000kbs 30fps 1920x1080
500kbs 30fps 1280x720
192kbs 30fps 320x240
但对于输出流,我需要 640x360 的 H.264 基线配置文件
以下是我使用的 ffmpeg 的相关选项
-analyzeduration 10 -bufsize 14000 -threads 4
-preset ultrafast -vcodec libx264 -s 640x360 -flags -global_header -tune zerolatency
-profile:v baseline -level 3.1 -pix_fmt yuv420p -r 25 -g 72 -f hls
Hoverer,对于每个更高质量的输入流,视频质量都在变差。就是这样,我只能在质量最低的输入流上获得预期的播放。我使用 RTSP over TCP,因此网络不是问题。
我的感觉是 HQ 输入流的帧数在下降。有什么想法可以调整我的 ffmpeg 参数吗?
更新:
我刚刚意识到,如果我像这样启动 ffmpeg
ffmpeg -i rtsp://localhost:1935/52b98d3e69702d72e0010000.sdp -v verbose -vcodec libx264 -analyzeduration 10 -bufsize 14000 -threads 4 -vf transpose=2,transpose=2 -flags -global_header -tune zerolatency -v verbose -pix_fmt yuv420p -f hls -hls_time 2 -hls_wrap 5 -hls_list_size 5 -start_number 1 -y m.m3u8
我明白了
ffmpeg version 2.1.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Nov 26 2013 08:41:46 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --arch=x86_64 --enable-runtime-cpudetect
libavutil 52. 48.101 / 52. 48.101
libavcodec 55. 39.101 / 55. 39.101
libavformat 55. 19.104 / 55. 19.104
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 90.100 / 3. 90.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
[rtsp @ 0x7fd863007800] SDP:
v=0
o=- 1050476060 1050476060 IN IP4 54.228.16.134
s=52b98d3e69702d72e0010000.sdp
c=IN IP4 0.0.0.0
t=0 0
a=sdplang:en
a=range:npt=now-
a=control:*
m=video 0 RTP/AVP 97
a=rtpmap:97 H264/90000
a=fmtp:97 packetization-mode=1;profile-level-id=424029;sprop-parameter-sets=J0JAKYuVAKALcg==,KN4JiA==
a=cliprect:0,0,720,1280
a=framesize:97 1280-720
a=control:trackID=1
Input #0, rtsp, from 'rtsp://localhost:1935/52b98d3e69702d72e0010000.sdp':
Metadata:
title : 52b98d3e69702d72e0010000.sdp
Duration: N/A, start: 0.669000, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1280x720, 29.92 tbr, 90k tbn, 180k tbc
[graph 0 input from stream 0:0 @ 0x7fd862501a40] w:1280 h:720 pixfmt:yuv420p tb:1/90000 fr:359/12 sar:0/1 sws_param:flags=2
[Parsed_transpose_0 @ 0x7fd862500100] w:1280 h:720 dir:2 -> w:720 h:1280 rotation:counterclockwise vflip:0
[Parsed_transpose_1 @ 0x7fd8625016a0] w:720 h:1280 dir:2 -> w:1280 h:720 rotation:counterclockwise vflip:0
[libx264 @ 0x7fd863801c00] VBV bufsize set but maxrate unspecified, ignored
[libx264 @ 0x7fd863801c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fd863801c00] profile High, level 3.1
[mpegts @ 0x7fd864308600] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, hls, to 'm.m3u8':
Metadata:
title : 52b98d3e69702d72e0010000.sdp
encoder : Lavf55.19.104
Stream #0:0: Video: h264 (libx264), yuv420p, 1280x720, q=-1--1, 90k tbn, 29.92 tbc
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Press [q] to stop, [?] for help
[h264 @ 0x7fd863801600] RTP: missed 1 packets0:01.73 bitrate=N/A
[h264 @ 0x7fd863801600] RTP: missed 20 packets
[h264 @ 0x7fd863801600] RTP: missed 25 packets
[h264 @ 0x7fd863801600] RTP: missed 4 packets
[h264 @ 0x7fd863801600] RTP: missed 3 packets
[h264 @ 0x7fd864306e00] Cannot use next picture in error concealment
[h264 @ 0x7fd864306e00] concealing 1326 DC, 1326 AC, 1326 MV errors in P frame
[h264 @ 0x7fd863801600] RTP: missed 4 packets0:01.97 bitrate=N/A
[h264 @ 0x7fd863801600] RTP: missed 1 packets
[h264 @ 0x7fd863801600] RTP: missed 2 packets
[h264 @ 0x7fd864306e00] concealing 1074 DC, 1074 AC, 1074 MV errors in I frame
*** 28 dup!
[h264 @ 0x7fd863801600] RTP: missed 4 packets
[h264 @ 0x7fd863801600] RTP: missed 3 packets0:02.97 bitrate=N/A dup=28 drop=0
[h264 @ 0x7fd863801600] RTP: missed 1 packets
Last message repeated 4 times
[h264 @ 0x7fd863801600] RTP: missed 5 packets
[h264 @ 0x7fd863801600] RTP: missed 1 packets
有很多丢失的数据包。流来自 Wowza,如果我使用例如 flash player 播放来自 RTMP 的相同流,视频效果很好。但是一旦我通过 RTSP 使用 ffmpeg 获取它,似乎就会出现问题。