菜单开关

周梦康 发表于 2021-01-22 1857 次浏览 标签 : ffmpeg

遇到的问题

ffmpeg concat 本地文件是没有问题的

ffmpeg -re -i "concat:1-hd.mp4|2-sd.mp4 -c:a aac -c:v copy -f flv rtmp://push.mengkang.net/xx\?auth_key=xxx"

如果是想读取网络 url 则提示协议不支持

ffmpeg -re -i "concat:http://mengkang.net/1-hd.mp4|http://mengkang.net/12-hd.mp4|http://mengkang.net/3-sd.mp4" -c:a aac -c:v copy -f flv rtmp://push.mengkang.net/xx\?auth_key=xxx

[http @ 0x68866c0] Protocol 'http' not on whitelist 'concat,file,subfile'!
concat:http://mengkang.net/1-hd.mp4|http://mengkang.net/12-hd.mp4|http://mengkang.net/3-sd.mp4: Invalid argument

解决方案

参考 https://stackoverflow.com/questions/49343174/can-ffmpeg-concatenate-files-from-a-different-domain 问题得到解决!

新建一个文件1.txt,里面包含

file 'http://mengkang.net/1-hd.mp4'
file 'http://mengkang.net/12-hd.mp4'

然后再把协议白名单加进去关闭安全选项,就可以推流了

ffmpeg -v verbose -f concat -safe 0 -protocol_whitelist file,http,tcp -re -i 1.txt -c:a aac -c:v h264 -f flv rtmp://push.mengkang.net/xx\?auth_key=xxx

实践测试

$$./ffmpeg -v verbose -f concat -safe 0 -protocol_whitelist file,http,tcp -re -i 1.txt -c:a aac -c:v h264 -f flv rtmp://xxx
...
[tcp @ 0x5c07cc0] Starting connection attempt to xxx.xxx.xxx.xxx port 80
[tcp @ 0x5c07cc0] Successfully connected to xxx.xxx.xxx.xxx port 80
[h264 @ 0x5c0b140] Reinit context to 1920x1088, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5c046c0] Auto-inserting h264_mp4toannexb bitstream filter
[h264 @ 0x5c10500] Reinit context to 1920x1088, pix_fmt: yuv420p
Input #0, concat, from '1.txt':
  Duration: N/A, start: -0.046440, bitrate: 1730 kb/s
    Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt709, left), 1920x1080 (1920x1088), 1601 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      handler_name    : SoundHandler
Matched encoder 'libx264' for codec 'h264'.
[tcp @ 0x5c41100] Starting connection attempt to 101.37.183.173 port 1935
[tcp @ 0x5c41100] Successfully connected to 101.37.183.173 port 1935
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 @ 0x5c3b3c0] Reinit context to 1920x1088, pix_fmt: yuv420p
[graph_1_in_0_1 @ 0x5e2c880] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3
[graph 0 input from stream 0:0 @ 0x61e8a80] w:1920 h:1080 pixfmt:yuv420p tb:1/12800 fr:25/1 sar:0/1
[libx264 @ 0x607b500] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x607b500] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0x607b500] 264 - core 161 r3018 db0d417 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://xxx':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0(und): Video: h264 (libx264), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p(left), 1920x1080, q=-1--1, 25 fps, 1k tbn, 25 tbc
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.91.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.91.100 aac
[AVIOContext @ 0x5c12380] Statistics: 1087724 bytes read, 0 seekste= 245.6kbits/s speed=0.995x
[tcp @ 0x63c4c40] Starting connection attempt to xxx.xxx.xxx.xxx port 80
[tcp @ 0x63c4c40] Successfully connected to xxx.xxx.xxx.xxx port 80
[h264 @ 0x5c11ac0] Reinit context to 1920x1088, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x6433580] Auto-inserting h264_mp4toannexb bitstream filter
[h264 @ 0x5c3b3c0] Reinit context to 1920x1088, pix_fmt: yuv420p
[AVIOContext @ 0x6488c40] Statistics: 485214 bytes read, 0 seeksate= 362.0kbits/s speed=0.997x
[tcp @ 0x6071540] Starting connection attempt to xxx.xxx.xxx.xxx port 80
[tcp @ 0x6071540] Successfully connected to xxx.xxx.xxx.xxx port 80
[h264 @ 0x5c0ab00] Reinit context to 1920x1088, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5c14c40] Auto-inserting h264_mp4toannexb bitstream filter
[h264 @ 0x5c3b3c0] Reinit context to 1920x1088, pix_fmt: yuv420p
[AVIOContext @ 0x6444700] Statistics: 14684794 bytes read, 0 seekse=2615.0kbits/s speed=0.801x
[tcp @ 0x61e3dc0] Starting connection attempt to xxx.xxx.xxx.xxx port 80
[tcp @ 0x61e3dc0] Successfully connected to xxx.xxx.xxx.xxx port 80
[h264 @ 0x64e2e80] Reinit context to 1920x1072, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5c14c40] Auto-inserting h264_mp4toannexb bitstream filter
[h264 @ 0x5cb8840] Reinit context to 1920x1072, pix_fmt: yuv420p
[graph 0 input from stream 0:0 @ 0x649b080] w:1920 h:1070 pixfmt:yuv420p tb:1/12800 fr:25/1 sar:1/1
[scaler_out_0_0 @ 0x6502680] w:1920 h:1080 flags:'bicubic' interl:0
[scaler_out_0_0 @ 0x6502680] w:1920 h:1070 fmt:yuv420p sar:1/1 -> w:1920 h:1080 fmt:yuv420p sar:108/107 flags:0x4
No more output streams to write to, finishing.e=00:01:06.73 bitrate=2123.7kbits/s speed=0.921x
[flv @ 0x5c36f00] Failed to update header with correct duration.
[flv @ 0x5c36f00] Failed to update header with correct filesize.
frame= 1673 fps= 23 q=-1.0 Lsize=   17652kB time=00:01:07.00 bitrate=2158.3kbits/s speed=0.907x
video:16608kB audio:963kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.460088%
Input file #0 (1.txt):
  Input stream #0:0 (video): 1673 packets read (19052065 bytes); 1673 frames decoded;
  Input stream #0:1 (audio): 2883 packets read (1220316 bytes); 2875 frames decoded (2944000 samples);
  Total: 4556 packets (20272381 bytes) demuxed
Output file #0 (rtmp://xxx):
  Output stream #0:0 (video): 1673 frames encoded; 1673 packets muxed (17006399 bytes);
  Output stream #0:1 (audio): 2875 frames encoded (2944000 samples); 2876 packets muxed (986455 bytes);
  Total: 4549 packets (17992854 bytes) muxed
[AVIOContext @ 0x5c38d00] Statistics: 0 seeks, 4790 writeouts
[libx264 @ 0x607b500] frame I:56    Avg QP:17.62  size: 79415
[libx264 @ 0x607b500] frame P:579   Avg QP:20.30  size: 16950
[libx264 @ 0x607b500] frame B:1038  Avg QP:23.49  size:  2644
[libx264 @ 0x607b500] consecutive B-frames: 11.5% 13.6% 10.8% 64.1%
[libx264 @ 0x607b500] mb I  I16..4: 23.8% 67.2%  9.0%
[libx264 @ 0x607b500] mb P  I16..4:  5.8% 15.6%  0.6%  P16..4: 16.8%  4.1%  1.3%  0.0%  0.0%    skip:55.8%
[libx264 @ 0x607b500] mb B  I16..4:  0.4%  0.7%  0.0%  B16..8: 10.6%  0.8%  0.1%  direct: 0.8%  skip:86.5%  L0:43.8% L1:52.9% BI: 3.3%
[libx264 @ 0x607b500] 8x8 transform intra:69.4% inter:83.4%
[libx264 @ 0x607b500] coded y,uvDC,uvAC intra: 34.1% 41.7% 10.0% inter: 2.7% 4.0% 0.1%
[libx264 @ 0x607b500] i16 v,h,dc,p: 35% 35%  9% 22%
[libx264 @ 0x607b500] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 25% 20%  3%  4%  4%  4%  4%  4%
[libx264 @ 0x607b500] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 28% 12%  4%  6%  5%  6%  4%  4%
[libx264 @ 0x607b500] i8c dc,h,v,p: 55% 22% 18%  5%
[libx264 @ 0x607b500] Weighted P-Frames: Y:4.0% UV:1.7%
[libx264 @ 0x607b500] ref P L0: 74.9%  9.9% 11.7%  3.4%  0.1%
[libx264 @ 0x607b500] ref B L0: 86.9% 11.4%  1.7%
[libx264 @ 0x607b500] ref B L1: 97.9%  2.1%
[libx264 @ 0x607b500] kb/s:2028.11
[aac @ 0x5c3f6c0] Qavg: 9987.016
[AVIOContext @ 0x6482180] Statistics: 4081507 bytes read, 0 seeks
[AVIOContext @ 0x5c03400] Statistics: 525 bytes read, 0 seeks

http://xdsnet.github.io/other-doc-cn-ffmpeg/

评论列表