使用AVCONV或FFMPEG将movie.mov覆盖在图像文件上

时间:2014-02-06 14:16:36

标签: background ffmpeg mov avconv

我正在尝试将透明的mov或flv覆盖在图像上。

我对使用ffmpeg或avconv的两个选项持开放态度。

这是我的cmd:

ffmpeg -i bg.png -i input.mov -vf \
'[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; \
[1:v]setpts=PTS-STARTPTS,scale=720:400[fg]; [bg][fg]overlay=w' -vf yadif -pix_fmt rgba     -y -vcodec qtrle -an output.mov

我明白了:

ffmpeg version 0.8.9-4:0.8.9-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Nov  9 2013 19:08:00 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, image2, from '/home/socialvideos/public_html/public/images/blue_bg.png':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: png, rgb24, 720x400, 25 tbr, 25 tbn, 25 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/home/socialvideos/public_html/actor/opening/1.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2014-01-22 18:12:38
  Duration: 00:00:09.28, start: 0.000000, bitrate: 119710 kb/s
    Stream #1.0(eng): Video: qtrle, bgra, 1280x720, 120236 kb/s, PAR 1280:1280 DAR 16:9, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2014-01-22 18:12:38
    Stream #1.1(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      creation_time   : 2014-01-22 18:12:38
    Stream #1.2(eng): Data: tmcd / 0x64636D74, 0 kb/s
    Metadata:
      creation_time   : 2014-01-22 18:12:47
Incompatible pixel format 'rgba' for codec 'qtrle', auto-selecting format 'rgb24'
[buffer @ 0x10cf8c0] w:1280 h:720 pixfmt:bgra
[yadif @ 0x10c8980] mode:0 parity:-1 auto_enable:0
[avsink @ 0x10c8400] auto-inserting filter 'auto-inserted scaler 0' between the filter 'Parsed filter 0 yadif' and the filter 'out'
[yadif @ 0x10c8980] auto-inserting filter 'auto-inserted scaler 1' between the filter 'src' and the filter 'Parsed filter 0 yadif'
[scale @ 0x10cc9a0] w:1280 h:720 fmt:bgra -> w:1280 h:720 fmt:yuv420p flags:0x4
[scale @ 0x10cbdc0] w:1280 h:720 fmt:yuv420p -> w:1280 h:720 fmt:rgb24 flags:0x4
Output #0, mov, to 'out.mov':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0(eng): Video: qtrle, rgb24, 1280x720 [PAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2014-01-22 18:12:38
Stream mapping:
  Stream #1.0 -> #0.0
Press ctrl-c to stop encoding
frame=    2 fps=  0 q=0.0 size=     654kB time=0.08 bitrate=66996.3kbits/s    
frame=    5 fps=  4 q=0.0 size=    1213kB time=0.20 bitrate=49692.2kbits/s    
frame=    8 fps=  4 q=0.0 size=    2068kB time=0.32 bitrate=52952.9kbits/s    
frame=   10 fps=  4 q=0.0 size=    2826kB time=0.40 bitrate=57880.0kbits/s    
frame=   12 fps=  4 q=0.0 size=    3621kB time=0.48 bitrate=61805.2kbits/s    
frame=   14 fps=  4 q=0.0 size=    4433kB time=0.56 bitrate=64846.9kbits/s    
frame=   17 fps=  4 q=0.0 size=    5598kB time=0.68 bitrate=67435.6kbits/s    
frame=   19 fps=  4 q=0.0 size=    6368kB time=0.76 bitrate=68643.7kbits/s    
frame=   21 fps=  4 q=0.0 size=    7145kB time=0.84 bitrate=69683.8kbits/s    
frame=   23 fps=  4 q=0.0 size=    7901kB time=0.92 bitrate=70352.7kbits/s    
frame=   26 fps=  4 q=0.0 size=    9179kB time=1.04 bitrate=72298.4kbits/s    
frame=   28 fps=  4 q=0.0 size=    9743kB time=1.12 bitrate=71260.9kbits/s    
frame=   30 fps=  4 q=0.0 size=   10562kB time=1.20 bitrate=72100.4kbits/s    
frame=   32 fps=  4 q=0.0 size=   11375kB time=1.28 bitrate=72802.4kbits/s    
frame=   34 fps=  4 q=0.0 size=   12162kB time=1.36 bitrate=73256.3kbits/s    
frame=   37 fps=  4 q=0.0 size=   13404kB time=1.48 bitrate=74190.5kbits/s    
frame=   39 fps=  4 q=0.0 size=   14080kB time=1.56 bitrate=73936.2kbits/s    
frame=   41 fps=  4 q=0.0 size=   14763kB time=1.64 bitrate=73744.3kbits/s    
frame=   44 fps=  4 q=0.0 size=   15690kB time=1.76 bitrate=73030.4kbits/s    
frame=   47 fps=  4 q=0.0 size=   16660kB time=1.88 bitrate=72595.6kbits/s    
frame=   49 fps=  4 q=0.0 size=   17418kB time=1.96 bitrate=72798.4kbits/s    
frame=   51 fps=  4 q=0.0 size=   18060kB time=2.04 bitrate=72524.8kbits/s    
frame=   54 fps=  4 q=0.0 size=   18805kB time=2.16 bitrate=71320.3kbits/s    
frame=   56 fps=  4 q=0.0 size=   19498kB time=2.24 bitrate=71305.2kbits/s    
frame=   58 fps=  4 q=0.0 size=   20178kB time=2.32 bitrate=71247.7kbits/s    
frame=   60 fps=  4 q=0.0 size=   20892kB time=2.40 bitrate=71310.3kbits/s    
frame=   63 fps=  4 q=0.0 size=   22028kB time=2.52 bitrate=71609.8kbits/s    
frame=   65 fps=  4 q=0.0 size=   22729kB time=2.60 bitrate=71613.6kbits/s    
frame=   68 fps=  4 q=0.0 size=   23827kB time=2.72 bitrate=71762.8kbits/s    
frame=   71 fps=  4 q=0.0 size=   24865kB time=2.84 bitrate=71724.5kbits/s    
frame=   74 fps=  4 q=0.0 size=   26029kB time=2.96 bitrate=72035.8kbits/s    
frame=   76 fps=  4 q=0.0 size=   26746kB time=3.04 bitrate=72074.2kbits/s    
frame=   79 fps=  4 q=0.0 size=   27642kB time=3.16 bitrate=71659.3kbits/s    
frame=   82 fps=  4 q=0.0 size=   28743kB time=3.28 bitrate=71787.0kbits/s    
frame=   85 fps=  4 q=0.0 size=   29929kB time=3.40 bitrate=72111.4kbits/s    
frame=   87 fps=  4 q=0.0 size=   30602kB time=3.48 bitrate=72037.4kbits/s    
frame=   89 fps=  4 q=0.0 size=   31242kB time=3.56 bitrate=71892.2kbits/s    
frame=   92 fps=  4 q=0.0 size=   32091kB time=3.68 bitrate=71437.1kbits/s    
frame=   95 fps=  4 q=0.0 size=   32972kB time=3.80 bitrate=71080.2kbits/s    
frame=   98 fps=  4 q=0.0 size=   34038kB time=3.92 bitrate=71132.0kbits/s    
frame=  101 fps=  4 q=0.0 size=   35037kB time=4.04 bitrate=71046.2kbits/s    
frame=  104 fps=  4 q=0.0 size=   35901kB time=4.16 bitrate=70697.3kbits/s    
frame=  107 fps=  4 q=0.0 size=   36980kB time=4.28 bitrate=70780.7kbits/s    
frame=  109 fps=  4 q=0.0 size=   37800kB time=4.36 bitrate=71022.0kbits/s    
frame=  111 fps=  4 q=0.0 size=   38488kB time=4.44 bitrate=71011.5kbits/s    
frame=  114 fps=  4 q=0.0 size=   39415kB time=4.56 bitrate=70808.9kbits/s    
frame=  117 fps=  4 q=0.0 size=   40404kB time=4.68 bitrate=70725.0kbits/s    
frame=  119 fps=  4 q=0.0 size=   41076kB time=4.76 bitrate=70691.3kbits/s    
frame=  121 fps=  4 q=0.0 size=   41885kB time=4.84 bitrate=70892.5kbits/s    
frame=  123 fps=  4 q=0.0 size=   42622kB time=4.92 bitrate=70967.6kbits/s    
frame=  125 fps=  4 q=0.0 size=   43368kB time=5.00 bitrate=71054.0kbits/s    
frame=  127 fps=  4 q=0.0 size=   44161kB time=5.08 bitrate=71214.6kbits/s    
frame=  130 fps=  4 q=0.0 size=   45070kB time=5.20 bitrate=71002.5kbits/s    
frame=  132 fps=  4 q=0.0 size=   45782kB time=5.28 bitrate=71032.2kbits/s    
frame=  134 fps=  4 q=0.0 size=   46599kB time=5.36 bitrate=71220.3kbits/s    
frame=  136 fps=  4 q=0.0 size=   47270kB time=5.44 bitrate=71183.8kbits/s    
frame=  138 fps=  4 q=0.0 size=   47865kB time=5.52 bitrate=71034.5kbits/s    
frame=  140 fps=  4 q=0.0 size=   48449kB time=5.60 bitrate=70874.3kbits/s    
frame=  142 fps=  4 q=0.0 size=   49013kB time=5.68 bitrate=70689.4kbits/s    
frame=  144 fps=  4 q=0.0 size=   49613kB time=5.76 bitrate=70560.8kbits/s    
frame=  147 fps=  4 q=0.0 size=   50683kB time=5.88 bitrate=70610.9kbits/s    
frame=  149 fps=  4 q=0.0 size=   51231kB time=5.96 bitrate=70417.5kbits/s    
frame=  151 fps=  4 q=0.0 size=   51734kB time=6.04 bitrate=70166.0kbits/s    
frame=  153 fps=  4 q=0.0 size=   52097kB time=6.12 bitrate=69734.9kbits/s    
frame=  155 fps=  4 q=0.0 size=   52591kB time=6.20 bitrate=69487.4kbits/s    
frame=  157 fps=  4 q=0.0 size=   53374kB time=6.28 bitrate=69624.1kbits/s    
frame=  159 fps=  4 q=0.0 size=   54086kB time=6.36 bitrate=69665.9kbits/s    
frame=  161 fps=  4 q=0.0 size=   54805kB time=6.44 bitrate=69715.3kbits/s    
frame=  163 fps=  4 q=0.0 size=   55574kB time=6.52 bitrate=69826.0kbits/s    
frame=  166 fps=  4 q=0.0 size=   56683kB time=6.64 bitrate=69932.4kbits/s    
frame=  168 fps=  4 q=0.0 size=   57421kB time=6.72 bitrate=69999.1kbits/s    
frame=  170 fps=  4 q=0.0 size=   58230kB time=6.80 bitrate=70150.4kbits/s    
frame=  173 fps=  4 q=0.0 size=   59357kB time=6.92 bitrate=70268.0kbits/s    
frame=  176 fps=  4 q=0.0 size=   60482kB time=7.04 bitrate=70378.7kbits/s    
frame=  179 fps=  4 q=0.0 size=   61346kB time=7.16 bitrate=70187.7kbits/s    
frame=  181 fps=  4 q=0.0 size=   62171kB time=7.24 bitrate=70345.9kbits/s    
frame=  184 fps=  4 q=0.0 size=   63299kB time=7.36 bitrate=70454.0kbits/s    
frame=  186 fps=  4 q=0.0 size=   64031kB time=7.44 bitrate=70502.6kbits/s    
frame=  188 fps=  4 q=0.0 size=   64701kB time=7.52 bitrate=70482.4kbits/s    
frame=  191 fps=  4 q=0.0 size=   65731kB time=7.64 bitrate=70479.9kbits/s    
frame=  194 fps=  4 q=0.0 size=   66823kB time=7.76 bitrate=70543.2kbits/s    
frame=  197 fps=  4 q=0.0 size=   67568kB time=7.88 bitrate=70243.5kbits/s    
frame=  200 fps=  4 q=0.0 size=   68378kB time=8.00 bitrate=70018.6kbits/s    
frame=  203 fps=  4 q=0.0 size=   69112kB time=8.12 bitrate=69724.5kbits/s    
frame=  205 fps=  4 q=0.0 size=   69872kB time=8.20 bitrate=69804.1kbits/s    
frame=  207 fps=  4 q=0.0 size=   70548kB time=8.28 bitrate=69798.2kbits/s    
frame=  210 fps=  4 q=0.0 size=   71469kB time=8.40 bitrate=69699.4kbits/s    
frame=  213 fps=  4 q=0.0 size=   72386kB time=8.52 bitrate=69599.5kbits/s    
frame=  216 fps=  4 q=0.0 size=   73281kB time=8.64 bitrate=69480.8kbits/s    
frame=  219 fps=  4 q=0.0 size=   74241kB time=8.76 bitrate=69427.7kbits/s    
frame=  222 fps=  4 q=0.0 size=   75010kB time=8.88 bitrate=69198.2kbits/s    
frame=  225 fps=  4 q=0.0 size=   75861kB time=9.00 bitrate=69050.0kbits/s    
frame=  227 fps=  4 q=0.0 Lsize=   76442kB time=9.08 bitrate=68966.0kbits/s    
video:76439kB audio:0kB global headers:0kB muxing overhead 0.003299%

然而,生成的视频没有背景图像而是具有白色。请帮忙..

1 个答案:

答案 0 :(得分:0)

ffmpeg vs“ffmpeg

正如您在控制台输出中看到的那样,从rgbayuv420p的转换可能会丢失您的Alpha通道。我认为无法使用avconv或存储库中可用的假“ffmpeg”来避免这种情况(这些都来自Libav; FFmpeg的一个分支)。见Who can tell me the difference and relation between ffmpeg, libav, and avconv?

从FFmpeg

获取ffmpeg

现在你不应该感到困惑,你应该得到真正的ffmpeg。你可以:

如果你懒得做任何事情,那就这样做:

wget http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.$(date +"%F").tar.gz
tar xzvf ffmpeg.static.32bit.$(date +"%F").tar.gz

注意当你执行刚刚下载的二进制文件时,不要忘记用./作为./ffmpeg的前缀,或者使用完整路径,或者你可以运行假的“{{1 “而不是。

过滤

您可以使用overlay video filter中的ffmpeg选项;否则将使用默认值format=rgb

yuv420p
  • ffmpeg -y -i bg.png -i input.mov -filter_complex \ "[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; \ [1:v]yadif,setpts=PTS-STARTPTS,scale=720:-1,crop=iw:400[fg]; \ [bg][fg]overlay=w[out]" \ -map "[out]" -vcodec qtrle output.mov 使用-filter_complex代替-vf

  • 所有过滤都应在一个complex filtergraphs内进行,因此您应将filtergraph移至其他过滤器。这使您可以准确控制何时应使用yadif

  • 1280x720将扩展到720x405,同时保持方面。比例示例中的-1自动确定值405。然后,我添加了裁剪以移除额外的5个像素,以避免在您只是缩放到特定大小时会发生轻微的压扁。

  • 您现在也可以删除-pix_fmt rgba,因为所有内容都将保留在RGB中。如果您发现仍然需要它,请使用format视频过滤器,例如format=rgba,以便您可以准确控制过滤器的实施时间。

  • 我更喜欢在filtergraph中明确命名输出链接标签(在此示例中为[out],但您几乎可以使用任意名称),然后映射它以便默认行为不会给出任何名称惊喜。

  • -y是一个全局选项,应在输入选项之前声明。