请选择 进入手机版 | 继续访问电脑版
设为首页收藏本站
开启辅助访问
切换到宽版

ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

用新浪微博登录

只需一步,快速搞定

搜索
热搜: 活动 交友 discuz
查看: 2338|回复: 5

使用avfilter为视频添加水印

[复制链接]
扫一扫,手机访问本帖
发表于 2014-8-4 20:30:35 | 显示全部楼层 |阅读模式
使用avfilter对视频增加台标

使用使用ffmpeg可以采集摄像头数据,在采集摄像头数据的同时,希望增加台标,可以通过avfilter来画出字体以增加台标,使用命令行如下:

[C] 纯文本查看 复制代码
[StevenLiu@liudeMacBook-Pro ffmpeg]$ ffmpeg -f avfoundation -pix_fmt yuyv422 -r 25 -i 0 -vcodec libx264 -an -vf "drawtext=fontfile=/System/Library/Fonts/STHeiti\ Medium.ttc: text='来源:bbs.chinaffmpeg.com 孙悟空':x=100:y=x/dar:fontsize=24:fontcolor=yellow@0.5:shadowy=2" -preset ultrafast -s 1280x720 -b:v 1200k a.mp4
ffmpeg version N-65018-gad91bf8 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 27 2014 20:36:24 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --enable-opengl --enable-libx265 --enable-libx264 --enable-libmp3lame --enable-gpl --enable-libfaac --enable-nonfree --prefix=/usr/ --enable-libfreetype --enable-libass
  libavutil      52. 92.101 / 52. 92.101
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 49.100 / 55. 49.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, avfoundation, from '0':
  Duration: N/A, start: 5.330000, bitrate: N/A
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 100 tbr, 100 tbn, 100 tbc
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x7ffd7a005400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7ffd7a005400] profile High 4:2:2, level 3.1, 4:2:2 8-bit
[libx264 @ 0x7ffd7a005400] 264 - core 133 r2334M a3ac64b - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - [url=http://www.videolan.org/x264.html]http://www.videolan.org/x264.html[/url] - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=abr mbtree=0 bitrate=1200 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'a.mp4':
  Metadata:
    encoder         : Lavf55.49.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv422p, 1280x720, q=-1--1, 1200 kb/s, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc55.69.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 2661 fps= 13 q=24.0 size=   15645kB time=00:01:46.16 bitrate=1207.2kbits/s  
想要画出字体,首先要找到字体库,根据字体库中的字模才能画出来字的图像,否则显示会有异常;
以上命令行内容为,使用avfoundation来获得MacBook下面的摄像头数据,将数据转码成为H264,并在画面的左上角增加台标,台标的内容为:“来源:bbs.chinaffmpeg.com 孙悟空”,录像完成后,可以看到视频的内容如下:



再来一个例子

[AppleScript] 纯文本查看 复制代码
[StevenLiu@liudeMacBook-Pro ffmpeg]$ ffmpeg -i ~/Movies/objectC/1.mp4 -vcodec libx264 -an -vf "drawtext=fontfile=/System/Library/Fonts/STHeiti\ Medium.ttc: text='来源:bbs.chinaffmpeg.com 孙悟空':x=20:y=5:fontsize=16:fontcolor=Red@0.5:shadowy=2" -preset ultrafast -b:v 1200k a.mp4
ffmpeg version N-65018-gad91bf8 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 27 2014 20:36:24 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --enable-opengl --enable-libx265 --enable-libx264 --enable-libmp3lame --enable-gpl --enable-libfaac --enable-nonfree --prefix=/usr/ --enable-libfreetype --enable-libass
  libavutil      52. 92.101 / 52. 92.101
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 49.100 / 55. 49.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fbdd9005200] multiple edit list entries, a/v desync might occur, patch welcome
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/objectC/1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2013-02-28 08:19:50
    encoder         : mp4creator 1.6.1d
  Duration: 01:01:33.92, start: 0.000000, bitrate: 510 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 446 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2013-02-28 08:19:50
      encoder         : VC Coding
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 61 kb/s (default)
    Metadata:
      creation_time   : 2013-02-28 08:19:59
File 'a.mp4' already exists. Overwrite ? [y/N] y
[libx264 @ 0x7fbdd98ec000] using SAR=1/1
[libx264 @ 0x7fbdd98ec000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fbdd98ec000] profile Constrained Baseline, level 3.0
[libx264 @ 0x7fbdd98ec000] 264 - core 133 r2334M a3ac64b - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - [url]http://www.videolan.org/x264.html[/url] - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=abr mbtree=0 bitrate=1200 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'a.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    encoder         : Lavf55.49.100
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 1200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2013-02-28 08:19:50
      encoder         : Lavc55.69.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 2232 fps=916 q=-1.0 Lsize=   13047kB time=00:01:29.28 bitrate=1197.2kbits/s    
video:13038kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.074678%
[libx264 @ 0x7fbdd98ec000] frame I:9     Avg QP:12.33  size: 56910
[libx264 @ 0x7fbdd98ec000] frame P:2223  Avg QP:14.84  size:  5775
[libx264 @ 0x7fbdd98ec000] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x7fbdd98ec000] mb P  I16..4:  4.1%  0.0%  0.0%  P16..4: 34.2%  0.0%  0.0%  0.0%  0.0%    skip:61.7%
[libx264 @ 0x7fbdd98ec000] final ratefactor: 19.40
[libx264 @ 0x7fbdd98ec000] coded y,uvDC,uvAC intra: 39.4% 37.9% 15.6% inter: 17.7% 12.4% 2.5%
[libx264 @ 0x7fbdd98ec000] i16 v,h,dc,p: 48% 34% 10%  8%
[libx264 @ 0x7fbdd98ec000] i8c dc,h,v,p: 48% 28% 18%  6%
[libx264 @ 0x7fbdd98ec000] kb/s:1196.23


播放时图像如下:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

发表于 2016-8-18 09:06:06 | 显示全部楼层
如果文字是变化的应该怎么做呢
回复 支持 反对

使用道具 举报

黑户  发表于 2017-9-15 23:09:26
安卓手机怎么找到字库?
回复 支持 反对

使用道具

发表于 2017-9-26 15:57:43 来自手机 | 显示全部楼层
我也想问安卓字库设置了怎么报错呢
回复 支持 反对

使用道具 举报

发表于 2017-10-2 10:00:52 来自手机 | 显示全部楼层
终于知道安卓文字怎么弄了,原来是我把字库弄错了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg    

GMT+8, 2017-10-18 09:43 , Processed in 0.029178 second(s), 22 queries .

Powered by ChinaFFmpeg

© 2013 www.chinaffmpeg.com

快速回复 返回顶部 返回列表