How do I add a 1 second fade out effect to the end of a video with ffmpeg?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)
ffmpeg video-editor
add a comment |
How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)
ffmpeg video-editor
1
I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…
– LupusE
Mar 26 at 7:58
add a comment |
How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)
ffmpeg video-editor
How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)
ffmpeg video-editor
ffmpeg video-editor
asked Mar 26 at 7:41
llllll
367
367
1
I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…
– LupusE
Mar 26 at 7:58
add a comment |
1
I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…
– LupusE
Mar 26 at 7:58
1
1
I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…
– LupusE
Mar 26 at 7:58
I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…
– LupusE
Mar 26 at 7:58
add a comment |
2 Answers
2
active
oldest
votes
find out the number of frames in the video clip. Command:
ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
5130
Find the frames per second
it's 24
Add fade in/out
ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4
Done
add a comment |
For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:
ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4
If you want to fade audio too then add the afade filter:
ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4
To automate it use ffprobe
to get the duration and bc
to calculate the start time for the fade out at the end:
#!/bin/bash
mkdir fade
for f in *.mp4; do
dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
offset=$(bc -l <<< "$dur"-1)
ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
done
This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe
to determine if there is audio.
...and keep everything else the same (codec,quality)
Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf
option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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%2faskubuntu.com%2fquestions%2f1128754%2fhow-do-i-add-a-1-second-fade-out-effect-to-the-end-of-a-video-with-ffmpeg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
find out the number of frames in the video clip. Command:
ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
5130
Find the frames per second
it's 24
Add fade in/out
ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4
Done
add a comment |
find out the number of frames in the video clip. Command:
ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
5130
Find the frames per second
it's 24
Add fade in/out
ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4
Done
add a comment |
find out the number of frames in the video clip. Command:
ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
5130
Find the frames per second
it's 24
Add fade in/out
ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4
Done
find out the number of frames in the video clip. Command:
ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
5130
Find the frames per second
it's 24
Add fade in/out
ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4
Done
answered Mar 26 at 13:32
VijayVijay
2,1041822
2,1041822
add a comment |
add a comment |
For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:
ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4
If you want to fade audio too then add the afade filter:
ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4
To automate it use ffprobe
to get the duration and bc
to calculate the start time for the fade out at the end:
#!/bin/bash
mkdir fade
for f in *.mp4; do
dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
offset=$(bc -l <<< "$dur"-1)
ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
done
This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe
to determine if there is audio.
...and keep everything else the same (codec,quality)
Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf
option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.
add a comment |
For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:
ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4
If you want to fade audio too then add the afade filter:
ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4
To automate it use ffprobe
to get the duration and bc
to calculate the start time for the fade out at the end:
#!/bin/bash
mkdir fade
for f in *.mp4; do
dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
offset=$(bc -l <<< "$dur"-1)
ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
done
This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe
to determine if there is audio.
...and keep everything else the same (codec,quality)
Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf
option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.
add a comment |
For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:
ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4
If you want to fade audio too then add the afade filter:
ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4
To automate it use ffprobe
to get the duration and bc
to calculate the start time for the fade out at the end:
#!/bin/bash
mkdir fade
for f in *.mp4; do
dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
offset=$(bc -l <<< "$dur"-1)
ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
done
This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe
to determine if there is audio.
...and keep everything else the same (codec,quality)
Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf
option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.
For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:
ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4
If you want to fade audio too then add the afade filter:
ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4
To automate it use ffprobe
to get the duration and bc
to calculate the start time for the fade out at the end:
#!/bin/bash
mkdir fade
for f in *.mp4; do
dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
offset=$(bc -l <<< "$dur"-1)
ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
done
This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe
to determine if there is audio.
...and keep everything else the same (codec,quality)
Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf
option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.
edited Mar 26 at 17:51
answered Mar 26 at 17:43
lloganllogan
5,4251737
5,4251737
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1128754%2fhow-do-i-add-a-1-second-fade-out-effect-to-the-end-of-a-video-with-ffmpeg%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
1
I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…
– LupusE
Mar 26 at 7:58