FFmpeg:如何流式传输多个http输出



我被指派搜索一个解决方案,以流式传输ffmpeg中的多个http输出。我尝试了下面使用管道的代码,但只有最后一个输出有效,其他输出无效。我在tee muxer中尝试的解决方案也不起作用。知道我该怎么做吗?

ffmpeg -re -i sample1.mp3 -i sample2.mp3 -filter_complex amix=inputs=2 -f mp3 pipe:1 | ffmpeg -f mp3 -re -i pipe:0 -c copy -listen 1 -f mp3 http://127.0.0.1:4000 -c copy -listen 1 -f mp3 http://127.0.0.1:4010

我用tee muxer尝试的代码如下:

ffmpeg -re -i sample1.mp3 -i sample2.mp3 -filter_complex amix=inputs=2 -c:a mp3 -f tee "[listen=1:f=mp3]http://127.0.0.1:4000|[listen=1:f=mp3]http://127.0.0.1:4010"

edit:使用代码共享日志。

ffmpeg -loglevel debug -hide_banner -re -i sample1.mp3 -filter_complex asplit=2 -c:a mp3 -listen 1 -f mp3 http://127.0.0.1:4000 -c:a mp3 -listen 1 -f mp3 http://127.0.0.1:4010
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-hide_banner' ... matched as option 'hide_banner' (do not show program banner) with argument '1'.
Reading option '-re' ... matched as option 're' (read input at native frame rate; equivalent to -readrate 1) with argument '1'.
Reading option '-i' ... matched as input url with argument 'sample1.mp3'.
Reading option '-filter_complex' ... matched as option 'filter_complex' (create a complex filtergraph) with argument 'asplit=2'.
Reading option '-c:a' ... matched as option 'c' (codec name) with argument 'mp3'.
Reading option '-listen' ... matched as AVOption 'listen' with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'mp3'.
Reading option 'http://127.0.0.1:4000' ... matched as output url.
Reading option '-c:a' ... matched as option 'c' (codec name) with argument 'mp3'.
Reading option '-listen' ... matched as AVOption 'listen' with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'mp3'.
Reading option 'http://127.0.0.1:4010' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Applying option hide_banner (do not show program banner) with argument 1.
Applying option filter_complex (create a complex filtergraph) with argument asplit=2.
Successfully parsed a group of options.
Parsing a group of options: input url sample1.mp3.
Applying option re (read input at native frame rate; equivalent to -readrate 1) with argument 1.
Successfully parsed a group of options.
Opening an input file: sample1.mp3.
[NULL @ 00000216ab345b80] Opening 'sample1.mp3' for reading
[file @ 00000216ab346180] Setting default whitelist 'file,crypto,data'
[mp3 @ 00000216ab345b80] Format mp3 probed with size=4096 and score=51
id3v2 ver:4 flags:00 len:134
[mp3 @ 00000216ab345b80] pad 576 576
[mp3 @ 00000216ab345b80] Skipping 0 bytes of junk at 561.
[mp3 @ 00000216ab345b80] Before avformat_find_stream_info() pos: 561 bytes read:32768 seeks:0 nb_streams:1
[mp3 @ 00000216ab345b80] demuxer injecting skip 1105 / discard 0
[mp3float @ 00000216ab34f3c0] skip 1105 / discard 0 samples due to side data
[mp3float @ 00000216ab34f3c0] skip 1105/1152 samples
[mp3 @ 00000216ab345b80] All info found
[mp3 @ 00000216ab345b80] After avformat_find_stream_info() pos: 22065 bytes read:32768 seeks:0 frames:50
Input #0, mp3, from 'sample1.mp3':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2mp41
encoder         : Lavf58.45.100
Duration: 00:12:58.48, start: 0.025057, bitrate: 128 kb/s
Stream #0:0, 50, 1/14112000: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder         : Lavc58.91
Successfully opened the file.
[Parsed_asplit_0 @ 00000216ab34fc80] Setting 'outputs' to value '2'
Parsing a group of options: output url http://127.0.0.1:4000.
Applying option c:a (codec name) with argument mp3.
Applying option f (force format) with argument mp3.
Successfully parsed a group of options.
Opening an output file: http://127.0.0.1:4000.
Matched encoder 'libmp3lame' for codec 'mp3'.
Last message repeated 1 times
[http @ 00000216ab44d980] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy,data'

FFmpeg默认情况下可以输出多个输出(使用tee复用器输出(:

ffmpeg -re -i sample1.mp3 -i sample2.mp3 
-filter_complex amix=inputs=2,asplit 
-c:a mp3 -listen 1 f=mp3 http://127.0.0.1:4000 
-c:a mp3 -listen 1 f=mp3 http://127.0.0.1:4010

因为需要将filtergraph输出路由到2个流,所以需要将asplit过滤器添加到图中,并且所需要做的就是将2个输出选项序列串联起来。

编辑:固定了操作指出的-listen选项

最新更新