1

この分野で経験のある人はいますか?

これまで、udp を介して ffmpeg (libx264 と libaacplus を使用) を mpegts に多重化しようとしましたが、その mpegts マルチプレクサーは明らかに壊れています (いくつかの異なるソースから確認されています)。vlc も試してみましたが、AAC-LC しかエンコードできず、HE-AAC v2 (aacplus) はエンコードできません。

とにかく、私が解決する必要がある問題は、ウェブカメラで覆われたいくつかの異なる地理的な場所を持つことです。ネットワークのアップとダウンを心配せずに、常に着信ストリームを保持できるようにするために udp が必要です (udp は、ネットワークは再び稼働しています)。それで、h264を使用してaacplus over udpプロトコルを使用してストリーミングライブメディアを使用した経験がある人はいますか?

よろしくお願いします。

4

1 に答える 1

4

私は、ビデオ デバイスから定期的に h264 ファイルを記録し、同時にビデオ パラメータとカメラ ビューを調整できるようにローカル プレビューを提供する必要がある DVR のようなシステムを開発しています。私はこの分野の専門家ではありませんが、UDP 経由で h264 をストリーミングすることに比較的成功しました。そのため、サーバーとしてffmpegに基づいて、うまくいかなかったこととうまくいったことを共有しようと思います(私の場合は音声なし)。

最初に、ビデオをファイルに同時に記録し、それを ffserver の .ffm ファイルにフィードして、カメラのプレビュー用に RTP/UDP を使用してストリーミングするようにアプリケーションをセットアップしました。このアプローチの問題は、フィード ffmpeg プロセスがビデオ ファイルを変更するために停止したときに、後続の ffmpeg プロセスがすでに ffserver へのフィードを開始しているにもかかわらず、プレビューが停止して再開されないことでした。RTP を使用すると、ffserver は、フレームのタイムスタンプが、停止した場所から続行するのではなく、0 から始まったと明らかに不平を言います。次に、純粋なUDPを介してh264パケットを送信できれば、説明したのとまったく同じ効果が得られ、次のffmpegプロセスが引き継がれるとすぐにプレビューが再開されることに気付きました.

ffmpeg のドキュメントを理解しようとしているときに、mpegts 形式も使用してみましたが、それを行うと、反対側のプレーヤーで MPEG2 ビデオを取得していました (これはマルチキャスト アドレスを示していますが、特定のターゲットに対しても機能しました)。

$ ffmpeg -y -f video4linux2 -i /dev/video2 -vcodec libx264 -preset ultrafast /mnt/hd/video.mp4 -an -f mpegts udp://224.124.0.1:5000
ffmpeg version N-35860-g62adc60, Copyright (c) 2000-2011 the FFmpeg developers
  built on Dec 16 2011 09:47:41 with gcc 4.5.3
  configuration: --prefix=/usr --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/man --disable-debug --enable-shared --disable-static --enab
le-pthreads --enable-libtheora --enable-libvorbis --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable
-libx264 --enable-libvpx --enable-librtmp --disable-indev='v4l,dv1394'
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 46. 0 / 53. 46. 0
  libavformat  53. 26. 0 / 53. 26. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0x8a96b00] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video2':
  Duration: N/A, start: 1325538250.366878, bitrate: 27620 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240, 27620 kb/s, 29.97 tbr, 1000k tbn, 29.97 tbc
[buffer @ 0x8a9d8c0] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[buffer @ 0x8a9c860] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0x8a97780] using cpu capabilities: MMX2 Cache64
[libx264 @ 0x8a97780] profile Constrained Baseline, level 1.3
[libx264 @ 0x8a97780] 264 - core 120 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=0 ref=
1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 
fast_pskip=1 chroma_qp_offset=0 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=
0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
[mpegts @ 0x8a98100] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mp4, to '/mnt/hd/video.mp4':
  Metadata:
    encoder         : Lavf53.26.0
    Stream #0:0: Video: h264 (![0][0][0] / 0x0021), yuv420p, 320x240, q=-1--1, 30k tbn, 29.97 tbc
Output #1, mpegts, to 'udp://224.124.0.1:5000':
  Metadata:
    encoder         : Lavf53.26.0
    Stream #1:0: Video: mpeg2video, yuv420p, 320x240, q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #0:0 -> #1:0 (rawvideo -> mpeg2video)
Press [q] to stop, [?] for help

クライアント PC でffplayを使用してビデオを見ることができましたが、実際には MPEG2 形式でした。

$ ffplay -f mpegts udp://224.124.0.1:5000
ffplay version N-35860-g62adc60, Copyright (c) 2003-2011 the FFmpeg developers
  built on Dec 16 2011 09:47:41 with gcc 4.5.3
  configuration: --prefix=/usr --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/man --disable-debug --enable-shared --disable-static --enable-pthreads --enable-libtheora --enable-libvorbis --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable-libx264 --enable-libvpx --enable-librtmp --disable-indev='v4l,dv1394'
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 46. 0 / 53. 46. 0
  libavformat  53. 26. 0 / 53. 26. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[mpegts @ 0x80f02e0] Unable to seek back to the start
[mpeg2video @ 0x8111a00] mpeg_decode_postinit() failure
    Last message repeated 6 times                                                                                                             
[mpegts @ 0x80f02e0] max_analyze_duration 5000000 reached at 5005000
[mpegts @ 0x80f02e0] Estimating duration from bitrate, this may be inaccurate                                                                 
Input #0, mpegts, from 'udp://224.124.0.1:5000':                                                                                              
  Duration: N/A, start: 255.420433, bitrate: 104857 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 104857 kb/s, 30.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc

VLCもストリームを再生するために機能しましたが、スイッチ--demux ffmpegを指定した後でのみです(これのおかげです):

vlc -vv --demux ffmpeg udp://@224.124.0.1:5000

プレビューも h264 にしたかったので、既にファイルをエンコードしていたので、UDP ストリーミングにコピー コーデックを使用しようとしましたが、ffmpeg は segfault で失敗しました (参照用に含まれるバージョン):

ffmpeg -y -f video4linux2 -i /dev/video2 -vcodec libx264 -preset ultrafast /mnt/hd/video.mp4 -an -vcodec cop
y -f h264 udp://224.124.0.1:5000
ffmpeg version N-35860-g62adc60, Copyright (c) 2000-2011 the FFmpeg developers
  built on Dec 16 2011 09:47:41 with gcc 4.5.3
  configuration: --prefix=/usr --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/man --disable-debug --enable-shared --disable-static --enab
le-pthreads --enable-libtheora --enable-libvorbis --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable
-libx264 --enable-libvpx --enable-librtmp --disable-indev='v4l,dv1394'
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 46. 0 / 53. 46. 0
  libavformat  53. 26. 0 / 53. 26. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0x92c7b00] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video2':                                                                                              
  Duration: N/A, start: 1325539132.411691, bitrate: 27620 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240, 27620 kb/s, 29.97 tbr, 1000k tbn, 29.97 tbc
[buffer @ 0x92ce860] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0x92c8780] using cpu capabilities: MMX2 Cache64
[libx264 @ 0x92c8780] profile Constrained Baseline, level 1.3
[libx264 @ 0x92c8780] 264 - core 120 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=0 ref=
1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 
fast_pskip=1 chroma_qp_offset=0 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=
0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to '/mnt/hd/video.mp4':
  Metadata:
    encoder         : Lavf53.26.0
    Stream #0:0: Video: h264 (![0][0][0] / 0x0021), yuv420p, 320x240, q=-1--1, 30k tbn, 29.97 tbc
Output #1, h264, to 'udp://224.124.0.1:5000':
  Metadata:
    encoder         : Lavf53.26.0
    Stream #1:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240, q=2-31, 27620 kb/s, 90k tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #0:0 -> #1:0 (copy)
Press [q] to stop, [?] for help
Segmentation fault

理想的とは言えませんが、UDP ストリーミング部分に形式 h264 を指定すると、2 回目の同時 h264 変換が発生しましたが、うまくいきました。

$ ffmpeg -y -f video4linux2 -i /dev/video2 -vcodec libx264 -preset ultrafast /mnt/hd/video.mp4 -an -f h264 -preset ultrafast udp://224.124.0.1:5000
ffmpeg version N-35860-g62adc60, Copyright (c) 2000-2011 the FFmpeg developers
  built on Dec 16 2011 09:47:41 with gcc 4.5.3
  configuration: --prefix=/usr --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/man --disable-debug --enable-shared --disable-static --enab
le-pthreads --enable-libtheora --enable-libvorbis --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable
-libx264 --enable-libvpx --enable-librtmp --disable-indev='v4l,dv1394'
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 46. 0 / 53. 46. 0
  libavformat  53. 26. 0 / 53. 26. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[video4linux2,v4l2 @ 0x913ab00] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video2':                                                                                              
  Duration: N/A, start: 1325539689.729735, bitrate: 27620 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240, 27620 kb/s, 29.97 tbr, 1000k tbn, 29.97 tbc
[buffer @ 0x9141840] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[buffer @ 0x913e480] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0x913b780] using cpu capabilities: MMX2 Cache64
[libx264 @ 0x913b780] profile Constrained Baseline, level 1.3
[libx264 @ 0x913b780] 264 - core 120 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=0 ref=
1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 
fast_pskip=1 chroma_qp_offset=0 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=
0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
[libx264 @ 0x913c820] using cpu capabilities: MMX2 Cache64
[libx264 @ 0x913c820] profile Constrained Baseline, level 1.3
Output #0, mp4, to '/mnt/hd/video.mp4':
  Metadata:
    encoder         : Lavf53.26.0
    Stream #0:0: Video: h264 (![0][0][0] / 0x0021), yuv420p, 320x240, q=-1--1, 30k tbn, 29.97 tbc
Output #1, h264, to 'udp://224.124.0.1:5000':
  Metadata:
    encoder         : Lavf53.26.0
    Stream #1:0: Video: h264, yuv420p, 320x240, q=-1--1, 90k tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #0:0 -> #1:0 (rawvideo -> libx264)
Press [q] to stop, [?] for help

クライアント側では、ffplayはいくつかの欠落情報について繰り返し不平を言いましたが、数秒後にようやくビデオが表示されました。

$ ffplay -f h264 udp://224.124.0.1:5000
[h264 @ 0xa0be740] non-existing PPS referenced               
[h264 @ 0xa0be740] non-existing PPS 0 referenced                              
[h264 @ 0xa0be740] decode_slice_header error
[h264 @ 0xa0be740] no frame!                             

(...)

[h264 @ 0xa0be740] non-existing PPS referenced               
[h264 @ 0xa0be740] non-existing PPS 0 referenced                              
[h264 @ 0xa0be740] decode_slice_header error
[h264 @ 0xa0be740] no frame!
[h264 @ 0xa0e72e0] max_analyze_duration 5000000 reached at 5013967                  
[h264 @ 0xa0e72e0] Estimating duration from bitrate, this may be inaccurate
Input #0, h264, from 'udp://224.124.0.1:5000':                                              
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 320x240, 47.27 fps, 29.97 tbr, 1200k tbn, 59.94 tbc
[h264 @ 0xa0be740] Missing reference picture
[h264 @ 0xa0be740] decode_slice_header error            
[h264 @ 0xa0be740] concealing 300 DC, 300 AC, 300 MV errors
[h264 @ 0xa0be740] Missing reference picture  0KB sq=    0B f=0/0   0/0   
[h264 @ 0xa0be740] decode_slice_header error
[h264 @ 0xa0be740] mmco: unref short failure
[h264 @ 0xa0be740] concealing 300 DC, 300 AC, 300 MV errors
  10.78 A-V:  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0 

次に、同じ「--demux ffmpeg」スイッチでVLCを試しました。また、SPS/PPS についても不満を述べていましたが (それが何なのかはまだわかりません)、最終的にはビデオを非常にスムーズに再生しました。

$ vlc -v --demux ffmpeg udp/h264://@224.124.0.1:5000 
VLC media player 1.1.12 The Luggage (revision exported)
Blocked: call to unsetenv("DBUS_ACTIVATION_ADDRESS")
Blocked: call to unsetenv("DBUS_ACTIVATION_BUS_TYPE")
[0x943346c] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Blocked: call to setlocale(6, "")
Blocked: call to setlocale(6, "")
[0x94cde8c] qt4 interface error: Unable to load extensions module
[0x96720e4] h264 demux error: this doesn't look like a H264 ES stream, continuing anyway
[0x963989c] access_udp access warning: unimplemented query in control
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x967328c] packetizer_h264 demux packetizer warning: waiting for SPS/PPS
[0x94be644] main input error: Invalid PCR value in ES_OUT_SET_(GROUP_)PCR !
[0xb2a325f4] avcodec decoder warning: disabling direct rendering
[0x96dfac4] main video output warning: vlc_object_find_name(postproc) is not safe!
[0x94c2474] signals interface warning: signal 17 overridden (0xb6f31030)
[0x94c2474] signals interface warning:  /usr/lib/qt/lib/libQtCore.so.4(?)[(nil)]
[0x96dfac4] main video output warning: late picture skipped (32703 > -4)

私はまだ何が欠けているのかを理解しようとしていますが、結果はすでに満足しています. VLC の再生後、もう一方の端で ffmpeg を再起動すると、再生が一時停止してすぐに再開する ffmpeg のフィードを停止できます。

mpegts の代わりに選択した形式として h264 を使用することに関する追加情報があればお知らせください - この欠落している SPS/PPS 情報はそれと関係があるのではないかと思います。

于 2012-01-02T22:11:59.107 に答える