ffmpeg h264指令使用

来源:11-12 x264参数详解

慕虎3278424

2023-12-06

#进行压缩
y@zhangMacBook-Pro player % ffmpeg -i lizi.mp4 -c:v libx264 lizi.h264
ffmpeg version 5.0.3 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.3)
  configuration: --prefix=/usr/local/ffmpeg/ --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'lizi.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2023-08-31T12:02:58Z
    encoder         : Lavf58.76.100
  Duration: 00:02:25.58, start: 0.000000, bitrate: 5302 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080, 5300 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      creation_time   : 2023-08-31T12:02:58.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
File 'lizi.h264' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x14a006470] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x14a006470] profile High, level 4.0, 4:2:0, 8-bit
Output #0, h264, to 'lizi.h264':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.16.100
  Stream #0:0(und): Video: h264, yuv420p(progressive), 1920x1080, q=2-31, 29.97 fps, 29.97 tbn (default)
    Metadata:
      creation_time   : 2023-08-31T12:02:58.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.18.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 4363 fps=152 q=-1.0 Lsize=   95326kB time=00:02:25.51 bitrate=5366.7kbits/s dup=1 drop=0 speed=5.08x    
video:95326kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
[libx264 @ 0x14a006470] frame I:25    Avg QP:17.96  size:395204
[libx264 @ 0x14a006470] frame P:1102  Avg QP:21.09  size: 69424
[libx264 @ 0x14a006470] frame B:3236  Avg QP:25.22  size:  3470
[libx264 @ 0x14a006470] consecutive B-frames:  0.8%  0.7%  0.3% 98.1%
[libx264 @ 0x14a006470] mb I  I16..4: 15.8% 26.2% 58.0%
[libx264 @ 0x14a006470] mb P  I16..4:  2.4%  4.0%  0.4%  P16..4: 25.5% 19.6% 18.7%  0.0%  0.0%    skip:29.5%
[libx264 @ 0x14a006470] mb B  I16..4:  0.1%  0.1%  0.0%  B16..8: 17.4%  2.0%  0.2%  direct: 1.2%  skip:79.0%  L0:31.2% L1:49.2% BI:19.6%
[libx264 @ 0x14a006470] 8x8 transform intra:50.5% inter:38.0%
[libx264 @ 0x14a006470] coded y,uvDC,uvAC intra: 28.6% 47.9% 15.0% inter: 10.1% 5.7% 0.0%
[libx264 @ 0x14a006470] i16 v,h,dc,p: 23% 50% 17% 10%
[libx264 @ 0x14a006470] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 32% 48%  1%  1%  1%  1%  0%  1%
[libx264 @ 0x14a006470] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 16% 13%  7%  9%  7% 11%  6% 13%
[libx264 @ 0x14a006470] i8c dc,h,v,p: 57% 26% 14%  3%
[libx264 @ 0x14a006470] Weighted P-Frames: Y:3.1% UV:0.2%
[libx264 @ 0x14a006470] ref P L0: 85.8% 10.6%  2.7%  0.9%  0.0%
[libx264 @ 0x14a006470] ref B L0: 96.9%  2.7%  0.4%
[libx264 @ 0x14a006470] ref B L1: 99.4%  0.6%
[libx264 @ 0x14a006470] kb/s:5364.19
#压缩完成之后将lizi.h264推流媒体服务器
y@zhangMacBook-Pro player %  ffmpeg -re -i lizi.h264 -c copy -f flv  rtmp://localhost/live/livestream
ffmpeg version 5.0.3 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.3)
  configuration: --prefix=/usr/local/ffmpeg/ --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
Input #0, h264, from 'lizi.h264':
  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 29.97 fps, 29.97 tbr, 1200k tbn
Output #0, flv, to 'rtmp://localhost/live/livestream':
  Metadata:
    encoder         : Lavf59.16.100
  Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p(progressive), 1920x1080, q=2-31, 29.97 fps, 29.97 tbr, 1k tbn
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[flv @ 0x15460f200] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
------ ## 报错------
[flv @ 0x15460f200] Packet is missing PTS
av_interleaved_write_frame(): Invalid argument
[flv @ 0x15460f200] Failed to update header with correct duration.te=N/A speed=N/A    
[flv @ 0x15460f200] Failed to update header with correct filesize.
frame=    1 fps=0.0 q=-1.0 Lsize=       0kB time=-00:00:00.06 bitrate=N/A speed=N/A    
video:205kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

### 这个是什么原因?怎么使用ffmpeg lib264,是不是参数没设置?


写回答

1回答

李超

2023-12-07

在ffmpeg 命令的 -i 参数之前 加上 -fflags +genpts 试试

0
0

音视频小白系统入门课 音视频基础+ffmpeg原理

掌握音视频采集、编解码、RTMP传输协议等核心基础

2326 学习 · 813 问题

查看课程