Я использую ffmpeg с компьютера Debian в моей локальной сети. Эта машина прослушивает входящие потоки:
$ ffmpeg -i udp://192.168.1.3:8080 /path/to/out.avi
А из моего macbook отправляю видео в формате avi:
$ ffmpeg -f <input> -i "1" -f avi udp://192.168.1.3:8080
Вышеприведенные команды работают, но я надеюсь, что некоторые гуру ffmpeg могли бы предложить некоторые советы и рекомендации по оптимизации для минимизации загрузки процессора на моем macbook при сохранении качества вывода видео.
нажмите, чтобы увидеть изображение
Любые аргументы оптимизации, такие как битрейт (я не знаю, что это такое), альтернативы форматов файлов (что-то лучше, чем avi?), Разрешение, протокол (альтернативы udp?) - все, что может поддерживать использование процессора на абсолютном уровне. минимум без полного разрушения качества видео выхода.
Для ясного вопроса:
Как я могу минимизировать использование CPU/MEM на MacBook без ущерба для качества видео?
Здесь я попытался с помощью -threads
спор с -f mpegts
формата , но загрузка процессора была еще около 45%.
$ cat ffmpeg-20180529-103103.log
ffmpeg started on 2018-05-29 at 10:31:03
Report written to "ffmpeg-20180529-103103.log"
Command line:
./ffmpeg -threads 1 -f avfoundation -i 1 -f mpegts -report udp://192.168.1.33:8080
ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.1)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-appkit --enable-avfoundation --enable-coreimage --enable-audiotoolbox
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Splitting the commandline.
Reading option '-threads' ... matched as AVOption 'threads' with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'avfoundation'.
Reading option '-i' ... matched as input url with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'mpegts'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option 'udp://192.168.1.33:8080' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url 1.
Applying option f (force format) with argument avfoundation.
Successfully parsed a group of options.
Opening an input file: 1.
[avfoundation @ 0x7f9f56800000] '<AVCaptureScreenInput: 0x7f9f55532240>' opened
[avfoundation @ 0x7f9f56800000] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7f9f56800000] Supported pixel formats:
[avfoundation @ 0x7f9f56800000] uyvy422
[avfoundation @ 0x7f9f56800000] yuyv422
[avfoundation @ 0x7f9f56800000] nv12
[avfoundation @ 0x7f9f56800000] 0rgb
[avfoundation @ 0x7f9f56800000] bgr0
[avfoundation @ 0x7f9f56800000] Overriding selected pixel format to use uyvy422 instead.
[avfoundation @ 0x7f9f56800000] Probe buffer size limit of 5000000 bytes reached
[avfoundation @ 0x7f9f56800000] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, avfoundation, from '1':
Duration: N/A, start: 11870.909500, bitrate: N/A
Stream #0:0, 2, 1/1000000: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1440x900, 1000k tbr, 1000k tbn, 1000k tbc
Successfully opened the file.
Parsing a group of options: output url udp://192.168.1.33:8080.
Applying option f (force format) with argument mpegts.
Successfully parsed a group of options.
Opening an output file: udp://192.168.1.33:8080.
[udp @ 0x7f9f55551c80] No default whitelist set
Successfully opened the file.
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg2video (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
detected 4 logical cores
[graph 0 input from stream 0:0 @ 0x7f9f55551d00] Setting 'video_size' to value '1440x900'
[graph 0 input from stream 0:0 @ 0x7f9f55551d00] Setting 'pix_fmt' to value '15'
[graph 0 input from stream 0:0 @ 0x7f9f55551d00] Setting 'time_base' to value '1/1000000'
[graph 0 input from stream 0:0 @ 0x7f9f55551d00] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0x7f9f55551d00] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x7f9f55551d00] Setting 'frame_rate' to value '1000000/1'
[graph 0 input from stream 0:0 @ 0x7f9f55551d00] w:1440 h:900 pixfmt:uyvy422 tb:1/1000000 fr:1000000/1 sar:0/1 sws_param:flags=2
[format @ 0x7f9f555522c0] Setting 'pix_fmts' to value 'yuv420p|yuv422p'
[auto_scaler_0 @ 0x7f9f55552a80] Setting 'flags' to value 'bicubic'
[auto_scaler_0 @ 0x7f9f55552a80] w:iw h:ih flags:'bicubic' interl:0
[format @ 0x7f9f555522c0] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[AVFilterGraph @ 0x7f9f55729240] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
[auto_scaler_0 @ 0x7f9f55552a80] picking yuv422p out of 2 ref:uyvy422 alpha:0
[auto_scaler_0 @ 0x7f9f55552a80] w:1440 h:900 fmt:uyvy422 sar:0/1 -> w:1440 h:900 fmt:yuv422p sar:0/1 flags:0x4
[mpeg2video @ 0x7f9f56071a00] intra_quant_bias = 96 inter_quant_bias = 0
[mpegts @ 0x7f9f5606f600] muxrate VBR, pcr every 24 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'udp://192.168.1.33:8080':
Metadata:
encoder : Lavf58.12.100
Stream #0:0, 0, 1/90000: Video: mpeg2video (4:2:2), yuv422p, 1440x900, q=2-31, 200 kb/s, 240 fps, 90k tbn, 240 tbc
Metadata:
encoder : Lavc58.18.100 mpeg2video
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Clipping frame in rate conversion by 0.000008
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918trate=8818.0kbits/s speed=1.01x
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918trate=5789.9kbits/s speed=0.996x
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
---[ a lot of these rawvideo lines; omitted for superuser ]---
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918trate=3320.8kbits/s speed=0.999x
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7f9f5606f000] PACKET SIZE: 2626592, STRIDE: 2918
frame= 744 fps= 30 q=31.0 Lsize= 9909kB time=00:00:24.73 bitrate=3282.0kbits/s speed=0.999x
video:9113kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.732401%
Input file #0 (1):
Input stream #0:0 (video): 744 packets read (1954184448 bytes); 744 frames decoded;
Total: 744 packets (1954184448 bytes) demuxed
Output file #0 (udp://192.168.1.33:8080):
Output stream #0:0 (video): 744 frames encoded; 744 packets muxed (9332015 bytes);
Total: 744 packets (9332015 bytes) muxed
744 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x7f9f5543ef80] Statistics: 0 seeks, 7244 writeouts
Снова используя формат -f avi
и убрав аргумент -threads, загрузка ЦП осталась неизменной - 45%.
$ cat ffmpeg-20180529-105147.log
ffmpeg started on 2018-05-29 at 10:51:47
Report written to "ffmpeg-20180529-105147.log"
Command line:
./ffmpeg -f avfoundation -i 1 -f avi -report udp://192.168.1.33:8080
ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.1)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-appkit --enable-avfoundation --enable-coreimage --enable-audiotoolbox
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Splitting the commandline.
Reading option '-f' ... matched as option 'f' (force format) with argument 'avfoundation'.
Reading option '-i' ... matched as input url with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'avi'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option 'udp://192.168.1.33:8080' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url 1.
Applying option f (force format) with argument avfoundation.
Successfully parsed a group of options.
Opening an input file: 1.
[avfoundation @ 0x7fd46a80fe00] '<AVCaptureScreenInput: 0x7fd46a52e640>' opened
[avfoundation @ 0x7fd46a80fe00] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7fd46a80fe00] Supported pixel formats:
[avfoundation @ 0x7fd46a80fe00] uyvy422
[avfoundation @ 0x7fd46a80fe00] yuyv422
[avfoundation @ 0x7fd46a80fe00] nv12
[avfoundation @ 0x7fd46a80fe00] 0rgb
[avfoundation @ 0x7fd46a80fe00] bgr0
[avfoundation @ 0x7fd46a80fe00] Overriding selected pixel format to use uyvy422 instead.
[avfoundation @ 0x7fd46a80fe00] Probe buffer size limit of 5000000 bytes reached
[avfoundation @ 0x7fd46a80fe00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, avfoundation, from '1':
Duration: N/A, start: 13115.322833, bitrate: N/A
Stream #0:0, 2, 1/1000000: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1440x900, 1000k tbr, 1000k tbn, 1000k tbc
Successfully opened the file.
Parsing a group of options: output url udp://192.168.1.33:8080.
Applying option f (force format) with argument avi.
Successfully parsed a group of options.
Opening an output file: udp://192.168.1.33:8080.
[udp @ 0x7fd46a4319c0] No default whitelist set
Successfully opened the file.
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
detected 4 logical cores
[graph 0 input from stream 0:0 @ 0x7fd46a463080] Setting 'video_size' to value '1440x900'
[graph 0 input from stream 0:0 @ 0x7fd46a463080] Setting 'pix_fmt' to value '15'
[graph 0 input from stream 0:0 @ 0x7fd46a463080] Setting 'time_base' to value '1/1000000'
[graph 0 input from stream 0:0 @ 0x7fd46a463080] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0x7fd46a463080] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x7fd46a463080] Setting 'frame_rate' to value '1000000/1'
[graph 0 input from stream 0:0 @ 0x7fd46a463080] w:1440 h:900 pixfmt:uyvy422 tb:1/1000000 fr:1000000/1 sar:0/1 sws_param:flags=2
[format @ 0x7fd46a4645c0] Setting 'pix_fmts' to value 'yuv420p'
[auto_scaler_0 @ 0x7fd46a464c00] Setting 'flags' to value 'bicubic'
[auto_scaler_0 @ 0x7fd46a464c00] w:iw h:ih flags:'bicubic' interl:0
[format @ 0x7fd46a4645c0] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[AVFilterGraph @ 0x7fd46a42f2c0] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
[auto_scaler_0 @ 0x7fd46a464c00] w:1440 h:900 fmt:uyvy422 sar:0/1 -> w:1440 h:900 fmt:yuv420p sar:0/1 flags:0x4
[avi @ 0x7fd46b81aa00] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
[mpeg4 @ 0x7fd46b977200] intra_quant_bias = 0 inter_quant_bias = -64
[avi @ 0x7fd46b81aa00] reserve_index_space:0 master_index_max_size:256
[avi @ 0x7fd46b81aa00] duration_est:36000.000, filesize_est:0.9GiB, master_index_max_size:256
Output #0, avi, to 'udp://192.168.1.33:8080':
Metadata:
ISFT : Lavf58.12.100
Stream #0:0, 0, 1/600: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1440x900, q=2-31, 200 kb/s, 65535 fps, 600 tbn, 65535 tbc
Metadata:
encoder : Lavc58.18.100 mpeg4
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Clipping frame in rate conversion by 0.000008
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918trate=6100.5kbits/s speed=1.16x
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
---[ a lot of these rawvideo lines; omitted for superuser ]---
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918trate=2806.4kbits/s speed=1.01x
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
[rawvideo @ 0x7fd46a840800] PACKET SIZE: 2626592, STRIDE: 2918
frame= 340 fps= 30 q=31.0 Lsize= 3879kB time=00:00:11.33 bitrate=2803.6kbits/s speed= 1x
video:3825kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.425499%
Input file #0 (1):
Input stream #0:0 (video): 340 packets read (893041280 bytes); 340 frames decoded;
Total: 340 packets (893041280 bytes) demuxed
Output file #0 (udp://192.168.1.33:8080):
Output stream #0:0 (video): 340 frames encoded; 340 packets muxed (3916524 bytes);
Total: 340 packets (3916524 bytes) muxed
340 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x7fd46a56ffc0] Statistics: 0 seeks, 2923 writeouts
Использование -s 1024x576
кажется, помогает снизить нагрузку на процессор, но текст в видеовыходе начинает становиться практически нечитаемым.