孙悟空 发表于 2014-8-4 20:30:35

使用avfilter为视频添加水印

使用avfilter对视频增加台标
使用使用ffmpeg可以采集摄像头数据,在采集摄像头数据的同时,希望增加台标,可以通过avfilter来画出字体以增加台标,使用命令行如下:
$ 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.
using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
profile High 4:2:2, level 3.1, 4:2:2 8-bit
264 - core 133 r2334M a3ac64b - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - 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) ( / 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 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 孙悟空”,录像完成后,可以看到视频的内容如下:


再来一个例子
$ 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
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 , 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
using SAR=1/1
using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
profile Constrained Baseline, level 3.0
264 - core 133 r2334M a3ac64b - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - 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) ( / 0x0021), yuv420p, 640x360 , 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 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%
frame I:9   Avg QP:12.33size: 56910
frame P:2223Avg QP:14.84size:5775
mb II16..4: 100.0%0.0%0.0%
mb PI16..4:4.1%0.0%0.0%P16..4: 34.2%0.0%0.0%0.0%0.0%    skip:61.7%
final ratefactor: 19.40
coded y,uvDC,uvAC intra: 39.4% 37.9% 15.6% inter: 17.7% 12.4% 2.5%
i16 v,h,dc,p: 48% 34% 10%8%
i8c dc,h,v,p: 48% 28% 18%6%
kb/s:1196.23

播放时图像如下:

攻城狮 发表于 2015-3-4 16:42:20

收藏一下。:lol

xuz0917 发表于 2016-8-18 09:06:06

如果文字是变化的应该怎么做呢

阴先生 发表于 2017-9-15 23:09:26

安卓手机怎么找到字库?

阴先生 发表于 2017-9-26 15:57:43

我也想问安卓字库设置了怎么报错呢

阴先生 发表于 2017-10-2 10:00:52

终于知道安卓文字怎么弄了,原来是我把字库弄错了

沉成林 发表于 2018-3-7 14:53:12

阴先生 发表于 2017-10-2 10:00
终于知道安卓文字怎么弄了,原来是我把字库弄错了

请问Android怎么实现用ffmpeg把文字画到视频内容上去?

孙悟空 发表于 2018-3-7 16:40:30

沉成林 发表于 2018-3-7 14:53
请问Android怎么实现用ffmpeg把文字画到视频内容上去?

参考我的主题帖子

沉成林 发表于 2018-3-8 09:31:40

孙悟空 发表于 2018-3-7 16:40
参考我的主题帖子

我意思是在android上用ffmpeg 的drawtext方法实现文字水印

孙悟空 发表于 2018-3-8 10:07:49

沉成林 发表于 2018-3-8 09:31
我意思是在android上用ffmpeg 的drawtext方法实现文字水印

重新实现一个drawtext.c?
页: [1]
查看完整版本: 使用avfilter为视频添加水印