How can I avoid a black background when fading in an overlay with ffmpeg?

slhck

I'm using ffmpeg to fade in an overlay from a non-transparent image (e.g. a JPEG or PNG without alpha channel):

$ ffmpeg -i big_buck_bunny_480p_surround-fix.avi -loop 1 -i logo.png \
-filter_complex "[1:v] fade=t=in:st=3:alpha=1 [logo]; \
[0:v][logo] overlay [outv]" \
-map "[outv]" -map 0:a -pix_fmt yuv420p -f matroska - | ffplay -

Output:

ffmpeg version 2.5.3 Copyright (c) 2000-2015 the FFmpeg developers
  built on Feb 12 2015 19:55:48 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfontconfig --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-openssl --enable-libopus --enable-frei0r --enable-libcaca --enable-libsoxr --enable-libquvi --enable-libvidstab --enable-libx265 --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 ' --enable-nonfree --enable-vda
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.102 / 56. 15.102
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, avi, from 'big_buck_bunny_480p_surround-fix.avi':
  Duration: 00:09:56.46, start: 0.000000, bitrate: 2957 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 2500 kb/s, 24 fps, 24 tbr, 24 tbn, 24 tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
ffplay version 2.5.3 Copyright (c) 2003-2015 the FFmpeg developers
  built on Feb 12 2015 19:55:48 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfontconfig --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-openssl --enable-libopus --enable-frei0r --enable-libcaca --enable-libsoxr --enable-libquvi --enable-libvidstab --enable-libx265 --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 ' --enable-nonfree --enable-vda
Input #1, png_pipe, from 'logo.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgb24, 400x300 [SAR 11811:11811 DAR 4:3],   libavutil      54. 15.100 / 54. 15.100
25 fps,   libavcodec     56. 13.100 / 56. 13.100
25 tbr, 25 tbn,   libavformat    56. 15.102 / 56. 15.102
25 tbc
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
[libx264 @ 0x7fa83d009200] using SAR=1/1
[libx264 @ 0x7fa83d009200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fa83d009200] profile High, level 3.0
[libx264 @ 0x7fa83d009200] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=12 lookahead_threads=2 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=24 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
Output #0, matroska, to 'pipe:':   0KB vq=    0KB sq=    0B f=0/0
  Metadata:
    encoder         : Lavf56.15.102
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 854x480 [SAR 1:1 DAR 427:240], q=-1--1, 24 fps, 1k tbn, 24 tbc (default)
    Metadata:
      encoder         : Lavc56.13.100 libx264
    Stream #0:1: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 48000 Hz, 5.1(side), fltp
    Metadata:
      encoder         : Lavc56.13.100 libvorbis
Stream mapping:
  Stream #0:0 (mpeg4) -> overlay:main (graph 0)
  Stream #1:0 (png) -> fade (graph 0)
  overlay (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (ac3 (native) -> vorbis (libvorbis))
Press [q] to stop, [?] for help

However, the logo background is black before it fades in. I've already set the fade to use alpha=1, but it doesn't work.

How can I avoid that?

slhck

One solution is to change the internal format of the overlay stream to include an alpha channel.

To do that, use the format filter:

-filter_complex \
"[1:v] format=pix_fmts=yuva420p, fade=t=in:st=3:alpha=1 [logo]; \
[0:v][logo] overlay [outv]"

This solution is also backwards compatible with input containing an alpha channel.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How can I give an image a black opaque overlay?

分類Dev

Black color is not visible when a overlay also have black background with opacity

分類Dev

how can I make a custom overlay filter?

分類Dev

How do I set the global nano background to black

分類Dev

FFmpeg: How to convert vertical video with black sides, to video 16:9, with blurred background sides

分類Dev

How can I avoid my program to keep running when I close my main frame?

分類Dev

How can I avoid Firefox's "you have chosen to open" dialog when I try to download a file?

分類Dev

How can i avoid a deadlock in Spring when creating a bean while triggering an application event?

分類Dev

How can i avoid a deadlock in Spring when creating a bean while triggering an application event?

分類Dev

How can i avoid a deadlock in Spring when creating a bean while triggering an application event?

分類Dev

How can I avoid "no input files" error from sed, when run from xargs?

分類Dev

When installing the MongoDB library in PHP, how can I avoid this error about a missing extension?

分類Dev

How can I avoid "environment hell" in postman?

分類Dev

How can I avoid losing precision with ftFmtBcd?

分類Dev

How can I avoid a circular reference situation

分類Dev

Django conditional queries: How can I avoid this?

分類Dev

How can I avoid duplicate templates in Meteor?

分類Dev

How i can avoid the distinct() of watchdog?

分類Dev

How can I avoid problems with CPU power?

分類Dev

How can I skip an image error when trimming an mp3 with ffmpeg

分類Dev

Matplotlib: How can I add an alternating background color when I have dates on the x-axis?

分類Dev

How can I embed subtitles into videos with ffmpeg?

分類Dev

How can I overlay a SKScene over a SCNScene in Swift?

分類Dev

How can I overlay a transparent video over an MP4?

分類Dev

Ffmpeg - How to merge gdigrab and audio with webcam overlay?

分類Dev

How can i dim the background when Bottomsheet is displayed, without using Dialog?

分類Dev

How can i dim the background when Bottomsheet is displayed, without using Dialog?

分類Dev

How can i dim the background when Bottomsheet is displayed, without using Dialog?

分類Dev

How can I get JQuery to replace the non URL parts of the string when fetching the background images url

Related 関連記事

  1. 1

    How can I give an image a black opaque overlay?

  2. 2

    Black color is not visible when a overlay also have black background with opacity

  3. 3

    how can I make a custom overlay filter?

  4. 4

    How do I set the global nano background to black

  5. 5

    FFmpeg: How to convert vertical video with black sides, to video 16:9, with blurred background sides

  6. 6

    How can I avoid my program to keep running when I close my main frame?

  7. 7

    How can I avoid Firefox's "you have chosen to open" dialog when I try to download a file?

  8. 8

    How can i avoid a deadlock in Spring when creating a bean while triggering an application event?

  9. 9

    How can i avoid a deadlock in Spring when creating a bean while triggering an application event?

  10. 10

    How can i avoid a deadlock in Spring when creating a bean while triggering an application event?

  11. 11

    How can I avoid "no input files" error from sed, when run from xargs?

  12. 12

    When installing the MongoDB library in PHP, how can I avoid this error about a missing extension?

  13. 13

    How can I avoid "environment hell" in postman?

  14. 14

    How can I avoid losing precision with ftFmtBcd?

  15. 15

    How can I avoid a circular reference situation

  16. 16

    Django conditional queries: How can I avoid this?

  17. 17

    How can I avoid duplicate templates in Meteor?

  18. 18

    How i can avoid the distinct() of watchdog?

  19. 19

    How can I avoid problems with CPU power?

  20. 20

    How can I skip an image error when trimming an mp3 with ffmpeg

  21. 21

    Matplotlib: How can I add an alternating background color when I have dates on the x-axis?

  22. 22

    How can I embed subtitles into videos with ffmpeg?

  23. 23

    How can I overlay a SKScene over a SCNScene in Swift?

  24. 24

    How can I overlay a transparent video over an MP4?

  25. 25

    Ffmpeg - How to merge gdigrab and audio with webcam overlay?

  26. 26

    How can i dim the background when Bottomsheet is displayed, without using Dialog?

  27. 27

    How can i dim the background when Bottomsheet is displayed, without using Dialog?

  28. 28

    How can i dim the background when Bottomsheet is displayed, without using Dialog?

  29. 29

    How can I get JQuery to replace the non URL parts of the string when fetching the background images url

ホットタグ

アーカイブ