实时视频转码质量下降


4

我需要将输入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,对于每个高质量的输入流,视频的质量越来越差。就是这样,我只能以最低的质量在输入流上获得预期的播放。我在TCP上使用RTSP,因此网络不是问题。

我的感觉是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播放器播放来自RTMP的相同流,则该视频很好。但是一旦我通过RTSP用ffmpeg获取它,似乎就会出现问题。


为什么4线程?你有什么CPU?
大卫施瓦茨2014年

处理器名称:Intel Core i7处理器速度:1.8 GHz处理器数量:1总核心数:2
Andrei Varanovich 2014年

有两个核心,为什么四个线程?(另外,实际上知道你拥有的CPU会有所帮助。一些规格并不像型号那么有用。)
David Schwartz

Intel(R)Core(TM)i7-2677M CPU @ 1.80GHz我切换到-threads 0,应该是最佳设置吗?
Andrei Varanovich

@AndreiVaranovich您找到了解决方案吗?
Dr.jacky 2015年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.