ffmpeg use complex_filter with alphamerge only for a part of the videoRotating videos with FFmpegTranscoding FLV to MP4 with ffmpeg very slowXuggler can't open IContainer of icecast server [Webm live video stream]ffmpeg - Convert MP4 to WebM, poor resultsFFMPEG command runs forever even on using timelimitffmpeg encoding with VP8 producing bad looking videoffmpeg prores with alpha to webm vp9 renders greyCorrect syntax for ffmpeg filter combination?How to keep transparency when converting .avi to .webm with ffmpeghow do I only output a single video stream per HLS output
Increase performance creating Mandelbrot set in python
What is the opposite of 'gravitas'?
What would happen if the UK refused to take part in EU Parliamentary elections?
What is difference between behavior and behaviour
Is there any reason not to eat food that's been dropped on the surface of the moon?
Do I need a multiple entry visa for a trip UK -> Sweden -> UK?
How to verify if g is a generator for p?
Why "be dealt cards" rather than "be dealing cards"?
Curses work by shouting - How to avoid collateral damage?
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?
The baby cries all morning
How will losing mobility of one hand affect my career as a programmer?
Hide Select Output from T-SQL
Teaching indefinite integrals that require special-casing
Confused about a passage in Harry Potter y la piedra filosofal
Is it correct to write "is not focus on"?
Products and sum of cubes in Fibonacci
Is there a problem with hiding "forgot password" until it's needed?
Is expanding the research of a group into machine learning as a PhD student risky?
How to be diplomatic in refusing to write code that breaches the privacy of our users
Your magic is very sketchy
Was Spock the First Vulcan in Starfleet?
How do I keep an essay about "feeling flat" from feeling flat?
ffmpeg use complex_filter with alphamerge only for a part of the video
Rotating videos with FFmpegTranscoding FLV to MP4 with ffmpeg very slowXuggler can't open IContainer of icecast server [Webm live video stream]ffmpeg - Convert MP4 to WebM, poor resultsFFMPEG command runs forever even on using timelimitffmpeg encoding with VP8 producing bad looking videoffmpeg prores with alpha to webm vp9 renders greyCorrect syntax for ffmpeg filter combination?How to keep transparency when converting .avi to .webm with ffmpeghow do I only output a single video stream per HLS output
I am trying to apply a filter to only the first few seconds of a video clip - and leave the rest of the video unchanged.
why?
I got some video clips that I wanted to put on a website - unfortunatelly those clips are starting with a black background, which does not fit the website's design. Therefor I was changing the background to transparent.
I got that filter working from many of the great answers here (thanks to Gyan) and those videos are playing fine in common browsers:
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
the problem now: of course this replaces all black pixels during the video, which leads to many artefacts later on. Therefor I am searching for a way to apply that filter only to the first 5-ish seconds.
I think I need a second split and a crop or a trim and a concat filter with a timestamp - but I can't make it work :(
ffmpeg -i $1 -filter_complex "[0]split[f][s];
[f]trim=start=0,duration=5[ft];
[s]trim=start=6[st];
[st]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p[mal];
[ft][mal]concat" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
/edit: I am changing the subject slighty, to reflect the actual problem.
filter ffmpeg
add a comment |
I am trying to apply a filter to only the first few seconds of a video clip - and leave the rest of the video unchanged.
why?
I got some video clips that I wanted to put on a website - unfortunatelly those clips are starting with a black background, which does not fit the website's design. Therefor I was changing the background to transparent.
I got that filter working from many of the great answers here (thanks to Gyan) and those videos are playing fine in common browsers:
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
the problem now: of course this replaces all black pixels during the video, which leads to many artefacts later on. Therefor I am searching for a way to apply that filter only to the first 5-ish seconds.
I think I need a second split and a crop or a trim and a concat filter with a timestamp - but I can't make it work :(
ffmpeg -i $1 -filter_complex "[0]split[f][s];
[f]trim=start=0,duration=5[ft];
[s]trim=start=6[st];
[st]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p[mal];
[ft][mal]concat" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
/edit: I am changing the subject slighty, to reflect the actual problem.
filter ffmpeg
add a comment |
I am trying to apply a filter to only the first few seconds of a video clip - and leave the rest of the video unchanged.
why?
I got some video clips that I wanted to put on a website - unfortunatelly those clips are starting with a black background, which does not fit the website's design. Therefor I was changing the background to transparent.
I got that filter working from many of the great answers here (thanks to Gyan) and those videos are playing fine in common browsers:
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
the problem now: of course this replaces all black pixels during the video, which leads to many artefacts later on. Therefor I am searching for a way to apply that filter only to the first 5-ish seconds.
I think I need a second split and a crop or a trim and a concat filter with a timestamp - but I can't make it work :(
ffmpeg -i $1 -filter_complex "[0]split[f][s];
[f]trim=start=0,duration=5[ft];
[s]trim=start=6[st];
[st]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p[mal];
[ft][mal]concat" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
/edit: I am changing the subject slighty, to reflect the actual problem.
filter ffmpeg
I am trying to apply a filter to only the first few seconds of a video clip - and leave the rest of the video unchanged.
why?
I got some video clips that I wanted to put on a website - unfortunatelly those clips are starting with a black background, which does not fit the website's design. Therefor I was changing the background to transparent.
I got that filter working from many of the great answers here (thanks to Gyan) and those videos are playing fine in common browsers:
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
the problem now: of course this replaces all black pixels during the video, which leads to many artefacts later on. Therefor I am searching for a way to apply that filter only to the first 5-ish seconds.
I think I need a second split and a crop or a trim and a concat filter with a timestamp - but I can't make it work :(
ffmpeg -i $1 -filter_complex "[0]split[f][s];
[f]trim=start=0,duration=5[ft];
[s]trim=start=6[st];
[st]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
[m][al]alphamerge,format=yuva420p[mal];
[ft][mal]concat" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
/edit: I am changing the subject slighty, to reflect the actual problem.
filter ffmpeg
filter ffmpeg
edited Mar 7 at 20:32
Andy P
asked Mar 7 at 11:42
Andy PAndy P
10316
10316
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Use
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='gte(t,6)'[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
Since we're adding an alpha plane, it has to be added to all frames. We just want to skip transparency after a certain point, so we use the drawbox filter to fill it with white starting at 6 seconds, before merging with the main video.
I was not even close ...
– Andy P
Mar 7 at 19:20
a follow: is there a way to aply the filter to the end of the video as well?t=fill:enable='if(gte(t,6)*lte(t,-1),1,0)
e.g. for the last second?
– Andy P
Mar 7 at 20:37
I think i found a way using ffprobe:DURATION=`ffprobe -i "$1" -show_entries stream=codec_type,duration -of compact=p=0:nk=1 2> /dev/null | grep 'video|' | sed -E 's/^video.([0-9]*).[0-9]*$/1/g'`` then: `DURATION=$(expr $DURATION - 1)
and use this as parameter in between:ffmpeg-static -i "$1" -filter_complex "[0]split[m][a]; [a]geq='if(lt(lum(X,Y),16.001),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='between(t,6,$DURATION)'[al]; [m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -pix_fmt yuva420p -auto-alt-ref 0 "$1.webm"
– Andy P
Mar 7 at 21:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042966%2fffmpeg-use-complex-filter-with-alphamerge-only-for-a-part-of-the-video%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='gte(t,6)'[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
Since we're adding an alpha plane, it has to be added to all frames. We just want to skip transparency after a certain point, so we use the drawbox filter to fill it with white starting at 6 seconds, before merging with the main video.
I was not even close ...
– Andy P
Mar 7 at 19:20
a follow: is there a way to aply the filter to the end of the video as well?t=fill:enable='if(gte(t,6)*lte(t,-1),1,0)
e.g. for the last second?
– Andy P
Mar 7 at 20:37
I think i found a way using ffprobe:DURATION=`ffprobe -i "$1" -show_entries stream=codec_type,duration -of compact=p=0:nk=1 2> /dev/null | grep 'video|' | sed -E 's/^video.([0-9]*).[0-9]*$/1/g'`` then: `DURATION=$(expr $DURATION - 1)
and use this as parameter in between:ffmpeg-static -i "$1" -filter_complex "[0]split[m][a]; [a]geq='if(lt(lum(X,Y),16.001),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='between(t,6,$DURATION)'[al]; [m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -pix_fmt yuva420p -auto-alt-ref 0 "$1.webm"
– Andy P
Mar 7 at 21:38
add a comment |
Use
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='gte(t,6)'[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
Since we're adding an alpha plane, it has to be added to all frames. We just want to skip transparency after a certain point, so we use the drawbox filter to fill it with white starting at 6 seconds, before merging with the main video.
I was not even close ...
– Andy P
Mar 7 at 19:20
a follow: is there a way to aply the filter to the end of the video as well?t=fill:enable='if(gte(t,6)*lte(t,-1),1,0)
e.g. for the last second?
– Andy P
Mar 7 at 20:37
I think i found a way using ffprobe:DURATION=`ffprobe -i "$1" -show_entries stream=codec_type,duration -of compact=p=0:nk=1 2> /dev/null | grep 'video|' | sed -E 's/^video.([0-9]*).[0-9]*$/1/g'`` then: `DURATION=$(expr $DURATION - 1)
and use this as parameter in between:ffmpeg-static -i "$1" -filter_complex "[0]split[m][a]; [a]geq='if(lt(lum(X,Y),16.001),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='between(t,6,$DURATION)'[al]; [m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -pix_fmt yuva420p -auto-alt-ref 0 "$1.webm"
– Andy P
Mar 7 at 21:38
add a comment |
Use
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='gte(t,6)'[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
Since we're adding an alpha plane, it has to be added to all frames. We just want to skip transparency after a certain point, so we use the drawbox filter to fill it with white starting at 6 seconds, before merging with the main video.
Use
ffmpeg -i $1 -filter_complex "[0]split[m][a];
[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='gte(t,6)'[al];
[m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -auto-alt-ref 0 $1.webm
Since we're adding an alpha plane, it has to be added to all frames. We just want to skip transparency after a certain point, so we use the drawbox filter to fill it with white starting at 6 seconds, before merging with the main video.
answered Mar 7 at 12:12
GyanGyan
33.8k22971
33.8k22971
I was not even close ...
– Andy P
Mar 7 at 19:20
a follow: is there a way to aply the filter to the end of the video as well?t=fill:enable='if(gte(t,6)*lte(t,-1),1,0)
e.g. for the last second?
– Andy P
Mar 7 at 20:37
I think i found a way using ffprobe:DURATION=`ffprobe -i "$1" -show_entries stream=codec_type,duration -of compact=p=0:nk=1 2> /dev/null | grep 'video|' | sed -E 's/^video.([0-9]*).[0-9]*$/1/g'`` then: `DURATION=$(expr $DURATION - 1)
and use this as parameter in between:ffmpeg-static -i "$1" -filter_complex "[0]split[m][a]; [a]geq='if(lt(lum(X,Y),16.001),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='between(t,6,$DURATION)'[al]; [m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -pix_fmt yuva420p -auto-alt-ref 0 "$1.webm"
– Andy P
Mar 7 at 21:38
add a comment |
I was not even close ...
– Andy P
Mar 7 at 19:20
a follow: is there a way to aply the filter to the end of the video as well?t=fill:enable='if(gte(t,6)*lte(t,-1),1,0)
e.g. for the last second?
– Andy P
Mar 7 at 20:37
I think i found a way using ffprobe:DURATION=`ffprobe -i "$1" -show_entries stream=codec_type,duration -of compact=p=0:nk=1 2> /dev/null | grep 'video|' | sed -E 's/^video.([0-9]*).[0-9]*$/1/g'`` then: `DURATION=$(expr $DURATION - 1)
and use this as parameter in between:ffmpeg-static -i "$1" -filter_complex "[0]split[m][a]; [a]geq='if(lt(lum(X,Y),16.001),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='between(t,6,$DURATION)'[al]; [m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -pix_fmt yuva420p -auto-alt-ref 0 "$1.webm"
– Andy P
Mar 7 at 21:38
I was not even close ...
– Andy P
Mar 7 at 19:20
I was not even close ...
– Andy P
Mar 7 at 19:20
a follow: is there a way to aply the filter to the end of the video as well?
t=fill:enable='if(gte(t,6)*lte(t,-1),1,0)
e.g. for the last second?– Andy P
Mar 7 at 20:37
a follow: is there a way to aply the filter to the end of the video as well?
t=fill:enable='if(gte(t,6)*lte(t,-1),1,0)
e.g. for the last second?– Andy P
Mar 7 at 20:37
I think i found a way using ffprobe:
DURATION=`ffprobe -i "$1" -show_entries stream=codec_type,duration -of compact=p=0:nk=1 2> /dev/null | grep 'video|' | sed -E 's/^video.([0-9]*).[0-9]*$/1/g'`` then: `DURATION=$(expr $DURATION - 1)
and use this as parameter in between: ffmpeg-static -i "$1" -filter_complex "[0]split[m][a]; [a]geq='if(lt(lum(X,Y),16.001),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='between(t,6,$DURATION)'[al]; [m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -pix_fmt yuva420p -auto-alt-ref 0 "$1.webm"
– Andy P
Mar 7 at 21:38
I think i found a way using ffprobe:
DURATION=`ffprobe -i "$1" -show_entries stream=codec_type,duration -of compact=p=0:nk=1 2> /dev/null | grep 'video|' | sed -E 's/^video.([0-9]*).[0-9]*$/1/g'`` then: `DURATION=$(expr $DURATION - 1)
and use this as parameter in between: ffmpeg-static -i "$1" -filter_complex "[0]split[m][a]; [a]geq='if(lt(lum(X,Y),16.001),0,255)',hue=s=0,drawbox=c=white:t=fill:enable='between(t,6,$DURATION)'[al]; [m][al]alphamerge,format=yuva420p" -c:v libvpx-vp9 -b:v 0 -crf 18 -an -pix_fmt yuva420p -auto-alt-ref 0 "$1.webm"
– Andy P
Mar 7 at 21:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042966%2fffmpeg-use-complex-filter-with-alphamerge-only-for-a-part-of-the-video%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown