当前位置:   article > 正文

Mac 安装 FFmpeg

Mac 安装 FFmpeg

如果安装好了 Homebrew 那就好说了(Homebrew 介绍和使用),直接:

 brew install ffmpeg

可以简单玩一下,将一个为 MPEG-4 的视频转化为 H264:

  1. ➜ Downloads ffmpeg -i 测试无法显示画面.mp4 -vcodec h264 trans.mp4
  2. ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
  3. built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  4. configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
  5. libavutil 56. 22.100 / 56. 22.100
  6. libavcodec 58. 35.100 / 58. 35.100
  7. libavformat 58. 20.100 / 58. 20.100
  8. libavdevice 58. 5.100 / 58. 5.100
  9. libavfilter 7. 40.101 / 7. 40.101
  10. libavresample 4. 0. 0 / 4. 0. 0
  11. libswscale 5. 3.100 / 5. 3.100
  12. libswresample 3. 3.100 / 3. 3.100
  13. libpostproc 55. 3.100 / 55. 3.100
  14. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '测试无法显示画面.mp4':
  15. Metadata:
  16. major_brand : isom
  17. minor_version : 512
  18. compatible_brands: isomiso2mp41
  19. encoder : Lavf58.12.100
  20. Duration: 00:04:42.73, start: 0.000000, bitrate: 422 kb/s
  21. Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 303 kb/s, 10 fps, 10 tbr, 10240 tbn, 10 tbc (default)
  22. Metadata:
  23. handler_name : VideoHandler
  24. Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 115 kb/s (default)
  25. Metadata:
  26. handler_name : SoundHandler
  27. Stream mapping:
  28. Stream #0:0 -> #0:0 (mpeg4 (native) -> h264 (libx264))
  29. Stream #0:1 -> #0:1 (aac (native) -> aac (native))
  30. Press [q] to stop, [?] for help
  31. [libx264 @ 0x7f9e8480c800] using SAR=1/1
  32. [libx264 @ 0x7f9e8480c800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
  33. [libx264 @ 0x7f9e8480c800] profile High, level 2.2
  34. [libx264 @ 0x7f9e8480c800] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=11 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 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
  35. Output #0, mp4, to 'trans.mp4':
  36. Metadata:
  37. major_brand : isom
  38. minor_version : 512
  39. compatible_brands: isomiso2mp41
  40. encoder : Lavf58.20.100
  41. Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 10 fps, 10240 tbn, 10 tbc (default)
  42. Metadata:
  43. handler_name : VideoHandler
  44. encoder : Lavc58.35.100 libx264
  45. Side data:
  46. cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
  47. Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
  48. Metadata:
  49. handler_name : SoundHandler
  50. encoder : Lavc58.35.100 aac
  51. frame= 2827 fps=338 q=-1.0 Lsize= 4723kB time=00:04:42.70 bitrate= 136.8kbits/s speed=33.8x
  52. video:575kB audio:4000kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.215851%
  53. [libx264 @ 0x7f9e8480c800] frame I:15 Avg QP: 8.85 size: 25246
  54. [libx264 @ 0x7f9e8480c800] frame P:712 Avg QP:20.38 size: 128
  55. [libx264 @ 0x7f9e8480c800] frame B:2100 Avg QP:26.87 size: 57
  56. [libx264 @ 0x7f9e8480c800] consecutive B-frames: 0.8% 0.3% 0.7% 98.2%
  57. [libx264 @ 0x7f9e8480c800] mb I I16..4: 54.3% 19.3% 26.4%
  58. [libx264 @ 0x7f9e8480c800] mb P I16..4: 0.1% 0.1% 0.0% P16..4: 0.9% 0.1% 0.1% 0.0% 0.0% skip:98.8%
  59. [libx264 @ 0x7f9e8480c800] mb B I16..4: 0.1% 0.4% 0.0% B16..8: 1.4% 0.1% 0.0% direct: 0.0% skip:98.0% L0:59.9% L1:39.9% BI: 0.2%
  60. [libx264 @ 0x7f9e8480c800] 8x8 transform intra:44.1% inter:40.1%
  61. [libx264 @ 0x7f9e8480c800] coded y,uvDC,uvAC intra: 13.9% 14.0% 11.3% inter: 0.1% 0.1% 0.0%
  62. [libx264 @ 0x7f9e8480c800] i16 v,h,dc,p: 69% 27% 4% 0%
  63. [libx264 @ 0x7f9e8480c800] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 10% 69% 0% 0% 0% 0% 0% 0%
  64. [libx264 @ 0x7f9e8480c800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 32% 18% 3% 4% 3% 5% 3% 6%
  65. [libx264 @ 0x7f9e8480c800] i8c dc,h,v,p: 69% 20% 10% 1%
  66. [libx264 @ 0x7f9e8480c800] Weighted P-Frames: Y:0.0% UV:0.0%
  67. [libx264 @ 0x7f9e8480c800] ref P L0: 77.1% 1.8% 12.4% 8.7%
  68. [libx264 @ 0x7f9e8480c800] ref B L0: 57.9% 40.4% 1.8%
  69. [libx264 @ 0x7f9e8480c800] ref B L1: 95.1% 4.9%
  70. [libx264 @ 0x7f9e8480c800] kb/s:16.66
  71. [aac @ 0x7f9e8480e000] Qavg: 55327.031

转化成功:

Java 代码实现:

  1. private void transfer(String infile,String outfile) {
  2. String videoCommend = "ffmpeg -i " + infile + " -vcodec libx264 -r 29.97 -b 768k -ar 24000 -ab 64k -s 1280x720 "
  3. + outfile;
  4. try {
  5. Runtime rt = Runtime.getRuntime();
  6. Process proc = rt.exec(videoCommend);
  7. InputStream stderr = proc.getErrorStream();
  8. InputStreamReader isr = new InputStreamReader(stderr);
  9. BufferedReader br = new BufferedReader(isr);
  10. String line = null;
  11. while ( (line = br.readLine()) != null)
  12. System.out.println(line);
  13. int exitVal = proc.waitFor();
  14. System.out.println("Process exitValue: " + exitVal);
  15. } catch (Throwable t) {
  16. t.printStackTrace();
  17. }
  18. }

References:

https://www.cnblogs.com/shuaifing/p/9593808.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/970847
推荐阅读
相关标签
  

闽ICP备14008679号