0

I have the next scheme of tracks. I need to render that tracks to one track with ffmpeg.

enter image description here

After rendering it's should looks like

enter image description here

I want to use the next scheme:

  1. Rendering Track 001 to file.
  2. Rendering Track 002 to file.
  3. Overlay Track 002 on Track 001.

For the "Track 001" I can "concat" clips to one track without any problem.

But the question is how I should concat clips for the "Track 002"? The "Empty" places must be transparent for the overlaying on the 3 step.

I already tried to use for the Empty places input with transparent color. But on the overlaying step transparent doesn't work.

ffmpeg -f lavfi -i [email protected]:s=1920x1080:r=25:d=1 \
    -i Clip004.mp4 \
    -i Rendered_track_001.mp4 \
    -filter_complex "[0:v] [1:v] xfade=transition=fade:duration=2:offset=0.5[trak]; \
                    [2:v][trak]overlay[out]" \
     -map "[out]" -c:v vp9 -c:a copy test.webm

I also tried to use alphaextract and alphamerge like this

ffmpeg -f lavfi -i [email protected]:s=1920x1080:r=25:d=1 \
    -i Clip004.mp4 \
    -i Rendered_track_001.mp4 \
    -filter_complex "[0:v] [1:v] xfade=transition=fade:duration=2:offset=0.5[out]; \
                    [out]alphaextract[alpha];[2:v][alpha]alphamerge[out1]" \
     -map "[out1]" -c:v vp9 -c:a copy test.webm

But it's fail with error

[AVFilterGraph @ 0x556557d3ce00] The following filters could not choose their formats: 
Parsed_alphaextract_1
Consider inserting the (a)format filter near their input or output.
Error reinitializing filters!
Failed to inject frame into filter network: Input/output error
Error while processing the decoded data for stream #2:0

Any help would be appreciated.

1
  • @Rotem thank you for the reply. I tried this approach but in the result file I got the Rendered_track_001.mp4 on the top of other layers without transparency Commented Nov 17, 2022 at 18:40

1 Answer 1

0

There are few issues:

  • It looks like -f lavfi -i [email protected]:s=1920x1080:r=25:d=1 doesn't produce a transparent video.
    The solution is using color filter, instead of lavfi:
    -filter_complex "[email protected]:s=1920x1080:r=25:d=1,format=rgba[transparent]...

  • [2:v][alpha]alphamerge[out1] have no effect because vp9 codec does not support transparency.
    For testing video with transparency, we may use libvpx-vp9 codec and -pix_fmt yuva420p.


It's hard to tell if it's exactly what you want, but I hope it is close:

ffmpeg -y -i Clip004.mp4 -i Rendered_track_001.mp4 -filter_complex "[email protected]:s=1920x1080:r=25:d=1,format=rgba[transparent];[0:v]format=rgba[v0];[transparent][v0]xfade=transition=fade:duration=2:offset=0.5,format=rgba[trak];[1:v][trak]overlay=shortest=1[out]" -map "[out]" -c:v vp9 -c:a copy test.webm


Buildid synthetic input for testing:

Since you didn't post Clip004.mp4 and Rendered_track_001.mp4, I used synthetic pattern for testing:

ffmpeg -y -f lavfi -i mandelbrot=size=1920x1080:rate=25 -video_track_timescale 25 -t 5 Clip004.mp4

ffmpeg -y -f lavfi -i testsrc=size=1920x1080:rate=25:duration=5 -video_track_timescale 25 Rendered_track_001.mp4

  • Note: Without adding -video_track_timescale 25, there is an error message:

First input link main timebase (1/25) do not match the corresponding second input link xfade timebase (1/12800)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .