ffmpeg 从具有多个通道的输入中输出单独的通道

Posted

技术标签:

【中文标题】ffmpeg 从具有多个通道的输入中输出单独的通道【英文标题】:ffmpeg output separate channel from an input with multiple channels 【发布时间】:2017-07-04 01:25:44 【问题描述】:

我运行此命令能够将 udp 直播流传输到可使用正在构建的移动应用程序播放的 http 直播流。 它只是一个只有音频流的流。

ffmpeg -i udp://@localhost:1111 -map 0:a http://localhost:8090/feed1.ffm

Input #0, mpegts, from 'udp://@localhost:1111':
  Duration: N/A, start: 54616.264622, bitrate: 768 kb/s
  Program 1
    Metadata:
  service_name    : Service 1
  service_provider: TLK
    Stream #0:0[0x101]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
  Program 2
Metadata:
  service_name    : Service 2
  service_provider: TLK
Stream #0:1[0x111]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
 Program 3
Metadata:
  service_name    : Service 3
  service_provider: TLK
Stream #0:2[0x121]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
 Program 4
Metadata:
  service_name    : Service 4
  service_provider: TLK
Stream #0:3[0x131]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
  Program 5
Metadata:
  service_name    : Service 5
  service_provider: TLK
Stream #0:4[0x141]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
  Program 6
Metadata:
  service_name    : Service 6
  service_provider: TLK
Stream #0:5[0x151]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
  Program 7
Metadata:
  service_name    : Service 7
  service_provider: TLK
Stream #0:6[0x161]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
 Program 8
Metadata:
  service_name    : Service 1
  service_provider: TLK
Stream #0:7[0x171]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s

我得到这个输出

Stream mapping:
  Stream #0:0 -> #0:0 (mp2 (native) -> mp2 (native))
  Stream #0:0 -> #0:1 (mp2 (native) -> mp2 (native))
Press [q] to stop, [?] for help
size=     100kB time=00:00:07.19 bitrate= 113.8kbits/s speed=3.01x
video:0kB audio:84kB subtitle:0kB other streams:0kB global headers:0kB  muxing overhead: 18.358242%

我真的想要一种方法,我可以将每个输入流映射到一个输出流,该输出流可以与另一个流分开访问,比如如果我需要第一个流,也许我会

ffplay http://localhost:8090/feed1.ffm 

如果我需要第 7 个流,我将只需要

ffplay http://localhost:8090/feed7.ffm

请有人帮我解决这个问题。 FFmpeg 没有针对我目前情况的复杂示例。

这是我的标题信息

ubuntu@ip-localhost:~$ \ 
ffmpeg -i udp://@localhost:4000 \
  -map 0:a:0     http://localhost:8090/feed1.ffm 
  -map 0:a:1 http://localhost:8090/feed2.ffm 
  -map 0:a:2 http://localhost:8090/feed3.ffm 
  -map 0:a:3 http://localhost:8090/feed4.ffm 
  -map 0:a:4 http://localhost:8090/feed5.ffm 
  -map 0:a:5 http://localhost:8090/feed6.ffm 
  -map 0:a:6 http://localhost:8090/feed7.ffm 
  -map 0:a:7 http://localhost:8090/feed8.ffm

ffmpeg 版本 3.2.4-1~16.04.york0 版权所有 (c) 2000-2017 FFmpeg 开发人员使用 gcc 5.4.1 (Ubuntu 5.4.1-5ubuntu2~16.04.york1) 20170210 构建 配置: --prefix=/usr --extra-version='1~16.04.york0' -- toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64 -linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b - -enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame - -enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh - -enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi - -enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 34.101 / 55. 34.101 libavcodec 57. 64.101 / 57. 64.101 libavformat 57. 56.101 / 57. 56.101 libav 设备 57. 1.100 / 57. 1.100 libavfilter 6. 65.100 / 6. 65.100 libavresample 3. 1. 0 / 3. 1. 0 libswscale 4. 2.100 / 4. 2.100 libswresample 2. 3.100 / 2. 3.100 libpostproc 54. 1.100 / 54. 1.100

Input #0, mpegts, from 'udp://@localhost:1111':
  Duration: N/A, start: 60047.944622, bitrate: 768 kb/s
  Program 1
    Metadata:
  service_name    : Service 1
  service_provider: TKL
Stream #0:0[0x101]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
 Program 2
Metadata:
  service_name    : Service 2
  service_provider: TKL
Stream #0:1[0x111]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
 Program 3
Metadata:
  service_name    : Service 3
  service_provider: TKL
Stream #0:2[0x121]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
Program 4
Metadata:
  service_name    : Service 4
  service_provider: TKL
Stream #0:3[0x131]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
Program 5
Metadata:
  service_name    : Service 5
  service_provider: TKL
Stream #0:4[0x141]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
Program 6
Metadata:
  service_name    : Service 6
  service_provider: TKL
Stream #0:5[0x151]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
Program 7
Metadata:
  service_name    : Service 7
  service_provider: TKL
Stream #0:6[0x161]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
Program 8
Metadata:
  service_name    : Service 8
  service_provider: TKL
Stream #0:7[0x171]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 96 kb/s
Output #0, ffm, to 'http://localhost:8090/feed1.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #0:0: Audio: mp2, 44100 Hz, mono, s16, 32 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Stream #0:1: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Output #1, ffm, to 'http://localhost:8090/feed2.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #1:0: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Output #2, ffm, to 'http://localhost:8090/feed3.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #2:0: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Output #3, ffm, to 'http://localhost:8090/feed4.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #3:0: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Output #4, ffm, to 'http://localhost:8090/feed5.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #4:0: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Output #5, ffm, to 'http://localhost:8090/feed6.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #5:0: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Output #6, ffm, to 'http://localhost:8090/feed7.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #6:0: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Output #7, ffm, to 'http://localhost:8090/feed8.ffm':
Metadata:
creation_time   : now
encoder         : Lavf57.56.101
Stream #7:0: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s
Metadata:
  encoder         : Lavc57.64.101 mp2
Stream mapping:
Stream #0:0 -> #0:0 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #0:1 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #1:0 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #2:0 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #3:0 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #4:0 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #5:0 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #6:0 (mp2 (native) -> mp2 (native))
Stream #0:0 -> #7:0 (mp2 (native) -> mp2 (native))
Press [q] to stop, [?] for help

这就是我的完整控制台。

【问题讨论】:

【参考方案1】:

基本语法是ffmpeg -i input1 -i input2 switches output1 switches output2...,所以

ffmpeg -i udp://@localhost:1111 -map 0:a:0 http://localhost:8090/feed1.ffm 
                                -map 0:a:1 http://localhost:8090/feed2.ffm
                                -map 0:a:2 http://localhost:8090/feed3.ffm
                                ...

【讨论】:

我已经尝试过,它将第一个流复制到所有其他流映射:流 #0:0 -> #0:0 (mp2 (native) -> mp2 (native)) Stream #0: 0 -> #0:1 (mp2 (native) -> mp2 (native)) Stream #0:0 -> #1:0 (mp2 (native) -> mp2 (native)) Stream #0:0 -> # 2:0 (mp2 (native) -> mp2 (native)) Stream #0:0 -> #3:0 (mp2 (native) -> mp2 (native)) Stream #0:0 -> #4:0 ( mp2 (native) -> mp2 (native)) Stream #0:0 -> #5:0 (mp2 (native) -> mp2 (native)) Stream #0:0 -> #6:0 (mp2 (native) -> mp2 (native)) Stream #0:0 -> #7:0 (mp2 (native) -> mp2 (native)) 按 [q] 停止,按 [?] 寻求帮助 显示完整的控制台输出。 这是简短示例的链接。它具有所有 8 个流通道。请下载并尝试模拟我的情况。 drive.google.com/open?id=0B12_TxWYu6LzMlBsTDVMN2RjZ1E【参考方案2】:

您可以通过同时运行 7 个不同的 ffmpeg 实例作为并行进程来做到这一点;如果你愿意的话。

让 ffmpeg 的每个实例解复用单个音频流并输出到各自的端​​口。

会有点像这样:

(ffmpeg -i udp://@localhost:1111 -map 0:a:0 http://localhost:8090/feed1.ffm ) & (ffmpeg -i udp://@localhost:1111 -map 0:a:1 http://localhost:8090/feed2.ffm ) & (ffmpeg -i udp://@localhost:1111 -map 0:a:2 http://localhost:8090/feed3.ffm ) & and so on.

虽然不推荐,但会消耗 CPU 的容量。

【讨论】:

以上是关于ffmpeg 从具有多个通道的输入中输出单独的通道的主要内容,如果未能解决你的问题,请参考以下文章

卷积的理解 python代码实现 pytorch 多输入多输出通道的理解

CNN卷积层里的多输入多输出通道channel 动手学深度学习v2 pytorch

如何从聚合 CoreAudio 设备中排除输入或输出通道?

是否可以使用 ffmpeg 从 ASIO 设备捕获音频?

nio再学习之通道channel

在 PyTorch 中创建具有多个通道的简单 1D CNN