![为什么ffmpeg不能用于进程替换?](https://linux22.com/image/190113/%E4%B8%BA%E4%BB%80%E4%B9%88ffmpeg%E4%B8%8D%E8%83%BD%E7%94%A8%E4%BA%8E%E8%BF%9B%E7%A8%8B%E6%9B%BF%E6%8D%A2%EF%BC%9F.png)
为什么这个命令行不起作用:
vim <(ffmpeg -i vid.mp4 2>&1)
我希望它具有与(工作)相同的行为
vim <(ffprobe -i vid.mp4 2>&1)
但实际上该ffmpeg
版本只是清除了我的屏幕(我假设 bc vim/ncurses 已启动)并导致我的终端冻结,对 ctrl-c ctrl-d 和 ctrl-z 的所有内容完全没有响应。左上角有一个闪烁的光标。运行此命令行后我必须退出该终端窗口/选项卡
cat <(ffmpeg -i vid.mp4 2>&1)
也永远不会完成,它只是输出一些预期的内容,然后冻结
预期行为:
因为ffmpeg
这个输出通常是
$ ffmpeg -i vid.mp4
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.2_4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:01:05.59, start: 0.000000, bitrate: 1668 kb/s
Stream #0:0(und): Video: h264 (High 10) (avc1 / 0x31637661), yuv420p10le, 1920x1080 [SAR 1:1 DAR 16:9], 1532 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(jpn): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
At least one output file must be specified
我希望vim <(ffmpeg -i vid.mp4 2>&1)
打开一个包含内容的缓冲区
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.2_4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:01:05.59, start: 0.000000, bitrate: 1668 kb/s
Stream #0:0(und): Video: h264 (High 10) (avc1 / 0x31637661), yuv420p10le, 1920x1080 [SAR 1:1 DAR 16:9], 1532 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(jpn): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
At least one output file must be specified
答案1
ffmpeg
默认情况下打开标准输入以供交互式使用。从文档:
-stdin
启用标准输入交互。除非使用标准输入作为输入,否则默认打开。要显式禁用交互,您需要指定
-nostdin
.禁用标准输入上的交互很有用,例如,如果
ffmpeg
它位于后台进程组中。可以实现大致相同的结果,ffmpeg ... < /dev/null
但它需要一个外壳。
Vim 也打开 stdin 进行交互使用,这可能就是冲突发生的地方。使用-nostdin
或重定向ffmpeg
如上所述应该有效:
vim <(ffmpeg -i vid.mp4 -nostdin 2>&1)
vim <(ffmpeg -i vid.mp4 <&- 2>&1)
vim <(ffmpeg -i vid.mp4 </dev/null 2>&1)