使用ffmpeg的overlay filter为视频增加跑马灯

2019-03-05 09:34:06 浏览数 (1)

在看视频时,图像上面有流动字幕,或者流动图片,这个效果一般名为跑马灯效果,可以通过overlay的filter实现该效果 overlay是ffmpeg的filter中常用的filter,可以深入的研究一下,先解决跑马灯问题:

点击(此处)折叠或打开

  1. overlay=x='if(gte(t,2), -w (t-2)*20, NAN)

点击(此处)折叠或打开

  1. ffmpeg -i ~/Movies/objectC/bbs.chinaffmpeg.com-孙悟空.mp4 -i ~/Movies/guanlangaoshou.mp4 -vcodec libx264 -an -filter_complex "overlay=x='if(gte(t,2), -w (t-2)*20, NAN)':y=0" -s 320x240 output.mp4

输出内容:

点击(此处)折叠或打开

  1. ffmpeg version N-79068-g6b7ce0e Copyright (c) 2000-2016 the FFmpeg bbs.chinaffmpeg.com 孙悟空
  2. built with Apple LLVM version 7.0.2 (clang-700.1.81)
  3. configuration: --enable-libass --enable-opengl --enable-libx265 --enable-libx264 --enable-libmp3lame --enable-gpl --enable-libfaac --enable-nonfree --prefix=/usr/local
  4. libavutil 55. 19.100 / 55. 19.100
  5. libavcodec 57. 28.103 / 57. 28.103
  6. libavformat 57. 28.102 / 57. 28.102
  7. libavdevice 57. 0.101 / 57. 0.101
  8. libavfilter 6. 39.102 / 6. 39.102
  9. libswscale 4. 0.100 / 4. 0.100
  10. libswresample 2. 0.101 / 2. 0.101
  11. libpostproc 54. 0.100 / 54. 0.100
  12. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/objectC/facebook.mp4':
  13. Metadata:
  14. major_brand : isom
  15. minor_version : 512
  16. compatible_brands: isomiso2avc1mp41
  17. encoder : Lavf55.22.102
  18. description : This File is Created by Easy RealMedia Tools@!
  19. Duration: 02:00:27.85, start: 0.000000, bitrate: 893 kb/s
  20. Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 797 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
  21. Metadata:
  22. handler_name : VideoHandler
  23. Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 87 kb/s (default)
  24. Metadata:
  25. handler_name : SoundHandler
  26. Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/guanlangaoshou.mp4':
  27. Metadata:
  28. major_brand : isom
  29. minor_version : 512
  30. compatible_brands: isomiso2avc1mp41
  31. encoder : Lavf56.36.100
  32. Duration: 00:05:29.67, start: 0.000000, bitrate: 1195 kb/s
  33. Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x268, 1038 kb/s, 24 fps, 24 tbr, 90k tbn, 48 tbc (default)
  34. Metadata:
  35. handler_name : VideoHandler
  36. Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 148 kb/s (default)
  37. Metadata:
  38. handler_name : SoundHandler
  39. File 'output.mp4' already exists. Overwrite ? [y/N] Y
  40. [libx264 @ 0x7fd4a281d200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
  41. [libx264 @ 0x7fd4a281d200] profile High, level 1.3
  42. [libx264 @ 0x7fd4a281d200] 264 - core 133 r2334M a3ac64b - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - [url]http://www.videolan.org/x264.html[/url] - 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=3 b_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
  43. Output #0, mp4, to 'output.mp4':
  44. Metadata:
  45. major_brand : isom
  46. minor_version : 512
  47. compatible_brands: isomiso2avc1mp41
  48. description : This File is Created by Easy RealMedia Tools@!
  49. encoder : Lavf57.28.102
  50. Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 320x240, q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
  51. Metadata:
  52. encoder : Lavc57.28.103 libx264
  53. Side data:
  54. cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
  55. Stream mapping:
  56. Stream #0:0 (h264) -> overlay:main
  57. Stream #1:0 (h264) -> overlay:overlay
  58. overlay -> Stream #0:0 (libx264)
  59. Press [q] to stop, [?] for help
  60. frame= 648 fps=288 q=-1.0 Lsize= 382kB time=00:00:25.84 bitrate= 121.2kbits/s speed=11.5x

截个图看看效果

0 人点赞