Skip to content

Commit f632420

Browse files
committed
PITFALL 7: Transparent Background Video (VP9 alpha channel / yuva420p)
1 parent ab0cbeb commit f632420

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎.github/workflows/generate-test-videos.sh‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,37 @@ echo -e "\033[34m[*] Case 6.1: Generating Interlaced Video (interleave_top)...\0
160160
-t "${DURATION}" \
161161
-y "$OUTPUT_DIR/test_comb.mp4"
162162

163+
# ---------------------------------------------------------------------
164+
# PITFALL 7: Transparent Background Video (VP9 alpha channel / yuva420p)
165+
# ---------------------------------------------------------------------
166+
# NOTE: Currently DISABLED because $FFMPEG_BIN is built without the VP9
167+
# encoder (--enable-libvpx). The transparent sample is tiny, so a pre-generated
168+
# copy ships under tools/test_transparent.webm instead. Once the toolchain is
169+
# rebuilt with libvpx-vp9, uncomment the block below to generate it on the fly.
170+
#
171+
# Do NOT use the 'drawbox' filter on a fully transparent canvas -- it blends
172+
# against alpha=0 and silently yields an all-transparent (empty) video.
173+
# Composite an opaque shape onto the transparent base with 'overlay' instead.
174+
#
175+
# echo -e "\033[34m[*] Case 7.1: Generating Transparent WebM (VP9 yuva420p, alpha channel)...\033[0m"
176+
# "$FFMPEG_BIN" -f lavfi -i "color=c=black@0.0:s=640x480:rate=30,format=yuva420p" \
177+
# -f lavfi -i "color=c=red:s=80x80:rate=30,format=yuva420p" \
178+
# -filter_complex "[0][1]overlay=x='100+t*80':y=200:format=auto" \
179+
# -c:v libvpx-vp9 \
180+
# -pix_fmt yuva420p \
181+
# -auto-alt-ref 0 \
182+
# -t "${DURATION}" \
183+
# -y "$OUTPUT_DIR/test_transparent.webm"
184+
185+
# Ship the pre-generated transparent sample until the VP9 encoder is available.
186+
PREBUILT_TRANSPARENT="tools/test_transparent.webm"
187+
if [[ -f "$PREBUILT_TRANSPARENT" ]]; then
188+
echo -e "\033[34m[*] Case 7.1: Copying pre-generated Transparent WebM (VP9 encoder unavailable)...\033[0m"
189+
cp "$PREBUILT_TRANSPARENT" "$OUTPUT_DIR/test_transparent.webm"
190+
else
191+
echo -e "\033[33m[!] Skipping Transparent WebM: $PREBUILT_TRANSPARENT not found.\033[0m"
192+
fi
193+
163194
# ---------------------------------------------------------------------
164195
# VIRTUAL SOURCES: Generate showcase videos for virtual test sources
165196
# ---------------------------------------------------------------------

‎tools/publish-feature-html.sh‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ This test suite presents the most common video/audio encoding pitfalls in player
7777
| Test Sample MP4 | Filter Mode | Expected Player Behavior | FFmpeg Encoding Command |
7878
| :--- | :---: | :--- | :--- |
7979
| ⚠️ [test_comb.mp4](videos/test_comb.mp4) | `interleave_top` | **Comb Effect**: Interlaced video (top field first), requires deinterlacing | `ffmpeg -f lavfi -i "testsrc2=size=1280x720:rate=50" -vf "tinterlace=mode=interleave_top" -c:v libx264 -pix_fmt yuv420p -t 10 -y test_comb.mp4` |
80+
81+
## 7. Transparent Background Video (Alpha Channel / VP9 WebM)
82+
83+
WebM with a VP9 alpha channel (`yuva420p`) lets video composite over a page background — no green-screen keying required. **Chrome & Firefox** render the transparency correctly; **Safari/QuickTime** have poor support for alpha WebM and may show a black/opaque background instead.
84+
85+
> [!WARNING]
86+
> Do **not** use the `drawbox` filter to draw onto a fully transparent canvas — it blends against alpha=0 and silently produces an all-transparent (empty) video. Composite an opaque shape onto the transparent base with `overlay` instead, as shown below.
87+
88+
| Test Sample WebM | Pixel Format | Expected Player Behavior | FFmpeg Encoding Command |
89+
| :--- | :---: | :--- | :--- |
90+
| 💚 [test_transparent.webm](videos/test_transparent.webm) | `yuva420p` | **Transparent**: background shows through on Chrome/Firefox; opaque on Safari | `ffmpeg -f lavfi -i "color=c=black@0.0:s=640x480:r=30:d=5,format=yuva420p" -f lavfi -i "color=c=red:s=80x80:r=30:d=5,format=yuva420p" -filter_complex "[0][1]overlay=x='100+t*80':y=200:format=auto" -c:v libvpx-vp9 -pix_fmt yuva420p -auto-alt-ref 0 test_transparent.webm` |
91+
92+
**Visual Demo** (checkerboard shows through the transparent regions):
93+
94+
<div style="display:inline-block;padding:10px;border-radius:8px;background-color:#808080;background-image:linear-gradient(45deg,#ccc 25%,transparent 25%),linear-gradient(-45deg,#ccc 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#ccc 75%),linear-gradient(-45deg,transparent 75%,#ccc 75%);background-size:24px 24px;background-position:0 0,0 12px,12px -12px,-12px 0;">
95+
<video width="640" height="480" autoplay loop muted playsinline src="videos/test_transparent.webm"></video>
96+
</div>
8097
EOF
8198

8299
echo "=== 5. 生成 Virtual Test Sources Markdown 数据 ==="

‎tools/test_transparent.webm‎

13.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)