[FFmpeg-user] xfade works perfectly on any videosrc or video file, but not for images?

Paul B Mahol onemda at gmail.com
Fri Sep 24 20:38:34 EEST 2021


On Fri, Sep 24, 2021 at 7:31 PM Arif Driessen <arifd86 at gmail.com> wrote:

> Hi everyone,
>
> So I'm still working on my filter_complex graph that xfades an image to the
> beginning of another video.
>
> And I managed to figure it out, it works for any input source, except for
> the two different .png files I have tried. - where the video just stays
> stuck on the thumbnail and doesn't xfade.
>


Note that images are single frame, and thus. xfade will not work unless you
extend single frame to multiple frames.
One possible way is using loop video filter, which will work with single
images fine.



>
> Does anyone know why? I think it may have something to do with timebase?
>
> Here's a bash script you can use to test it:
>
> #!/bin/bash
>
> IN_VIDEO="input.avi"
> THUMBNAIL="thumbnail.png" # <-- use a video source here and it works fine
>
> THUMBNAIL_HOLD_SECONDS=0.4 # INVARIANT: HOLD MUST >= FADE_IN_SECONDS
> FADE_IN_SECONDS=0.2
> FADE_OUT_SECONDS=0.15
>
> VIDEO_RESOLUTION=$(ffprobe -v error -select_streams v -show_entries
> stream=width,height -of csv=s=x:p=0 "${IN_VIDEO}")
> PIXEL_FORMAT=$(ffprobe -v error -select_streams v -show_entries
> stream=pix_fmt -of csv=s=x:p=0 "${IN_VIDEO}")
> SAR=$(ffprobe -v error -select_streams v -show_entries
> format=sample_aspect_ratio -of csv=s=x:p=0 "${IN_VIDEO}")
>
> # `bc` doesn't print leading zeros, so let's fix it
> calc() { echo "$1" | bc | sed -e 's/^-\./-0./' -e 's/^\./0./'; }
>
> ffmpeg \
>   -hide_banner \
>   -filter_complex \
>   "
>     `### DECLARE SOURCES ###`
>
>     `# thumbnail_hold`
>     movie=
>       filename=${THUMBNAIL},
>     scale=${VIDEO_RESOLUTION},
>     format=pix_fmts=${PIXEL_FORMAT},
>     setsar=${SAR},
>     trim=
>       start=0:
>       duration=${THUMBNAIL_HOLD_SECONDS}
>     [thumbnail_hold_v];
>
>     `# intro_a`
>     aevalsrc=-2+random(0),
>     atrim=
>       start=0:
>       duration=${THUMBNAIL_HOLD_SECONDS}
>     [intro_a];
>
>     `# main_v`
>     movie=
>       filename=${IN_VIDEO},
>     trim=
>       start=${TRIM_START_SECONDS}:
>       end=${TRIM_END_SECONDS}
>     [main_v];
>
>   `# main_a`
>     amovie=
>     filename=${IN_VIDEO},
>     atrim=
>       start=${TRIM_START_SECONDS}:
>         end=${TRIM_END_SECONDS}
>     [main_a];
>
>     `### COMBINE AND OUTPUT ###`
>
>     [thumbnail_hold_v][main_v]
>     xfade=
>       duration=${FADE_IN_SECONDS}:
>       offset=$(calc "${THUMBNAIL_HOLD_SECONDS} - ${FADE_IN_SECONDS}");
>
>     [intro_a][main_a]
>     acrossfade=
>       duration=${FADE_IN_SECONDS}
>       `# (offset not needed here because acrossfade always starts from the
> end)`
>   " \
>   -vcodec libx264 \
>   -preset veryfast \
>   -crf 18 \
>   -pix_fmt yuv420p \
>   -acodec aac \
>   -b:a 192k \
>   -f nut - | ffplay -v error -f nut -
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-user mailing list