How to capture first X frames every X seconds into a PNG with FFmpeg?
I am new to using the command line. It is pretty cool and exciting to learn, but I am stuck.
I have a video where, for example, I want to capture the first 8 frames every 5 seconds into an image.
I've written this command:
ffmpeg -i video.mp4 -vf fps=8/20 out%04d.png
I see it captures 8 frames every 20 seconds, and not the first 8 frames. Is there a way I could specify this in the command?
video ffmpeg mp4 screenshot
add a comment |
I am new to using the command line. It is pretty cool and exciting to learn, but I am stuck.
I have a video where, for example, I want to capture the first 8 frames every 5 seconds into an image.
I've written this command:
ffmpeg -i video.mp4 -vf fps=8/20 out%04d.png
I see it captures 8 frames every 20 seconds, and not the first 8 frames. Is there a way I could specify this in the command?
video ffmpeg mp4 screenshot
I was trying to get the direct video link from my Dropbox folder instead of downloading. I was using the wrong link, but I figured it out!
– AFG
Dec 30 '18 at 16:52
add a comment |
I am new to using the command line. It is pretty cool and exciting to learn, but I am stuck.
I have a video where, for example, I want to capture the first 8 frames every 5 seconds into an image.
I've written this command:
ffmpeg -i video.mp4 -vf fps=8/20 out%04d.png
I see it captures 8 frames every 20 seconds, and not the first 8 frames. Is there a way I could specify this in the command?
video ffmpeg mp4 screenshot
I am new to using the command line. It is pretty cool and exciting to learn, but I am stuck.
I have a video where, for example, I want to capture the first 8 frames every 5 seconds into an image.
I've written this command:
ffmpeg -i video.mp4 -vf fps=8/20 out%04d.png
I see it captures 8 frames every 20 seconds, and not the first 8 frames. Is there a way I could specify this in the command?
video ffmpeg mp4 screenshot
video ffmpeg mp4 screenshot
edited Dec 30 '18 at 16:51
AFG
asked Dec 30 '18 at 1:06
AFGAFG
11
11
I was trying to get the direct video link from my Dropbox folder instead of downloading. I was using the wrong link, but I figured it out!
– AFG
Dec 30 '18 at 16:52
add a comment |
I was trying to get the direct video link from my Dropbox folder instead of downloading. I was using the wrong link, but I figured it out!
– AFG
Dec 30 '18 at 16:52
I was trying to get the direct video link from my Dropbox folder instead of downloading. I was using the wrong link, but I figured it out!
– AFG
Dec 30 '18 at 16:52
I was trying to get the direct video link from my Dropbox folder instead of downloading. I was using the wrong link, but I figured it out!
– AFG
Dec 30 '18 at 16:52
add a comment |
2 Answers
2
active
oldest
votes
You can use the select
filter to select frames that match an expression. If the expression evaluates to a nonzero number or true
, it'll select those frames. For example, if your filter is -vf select="between(n, 0, 7)"
, it'd select the first eight frames. The frame number is n
, and it starts at zero.
Combining this with the mod
(modulo) operator, you can select the first eight frames of every group of, say, 24 frames, so every second for a video of 24 fps:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 24), 0, 7), setpts=N/24/TB" output.mp4
The setpts
filter is needed to adjust the timestamps of the frames so that you don't have gaps in your video.
To get the first eight frames every five seconds, multiply the 24 by 5:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 120), 0, 7), setpts=N/24/TB" output.mp4
To output everything into PNGs, change the output from output.mp4
to output-%04d.png
— you'll get sequentially numbered PNGs.
add a comment |
This is a generalized version of the select filter to pick 8 frames every 5 seconds.
ffmpeg -i in.mp4 -vf "select='if(not(floor(mod(t,5)))*lt(ld(1),1),st(1,1)+st(2,n)+st(3,t));if(eq(ld(1),1)*lt(n,ld(2)+8),1,if(trunc(t-ld(3)),st(1,0)))'" -vsync 0 out%d.png
This will work for videos with any frame-rate, constant or variable.
Change the 5
in mod(t,5)
for the interval, in seconds. And the 8
in ld(2)+8
for the number of frames to select.
Pretty complex expression. Had to translate that to pseudocode to figure out what was going on.
– slhck
Dec 30 '18 at 22:00
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f1388870%2fhow-to-capture-first-x-frames-every-x-seconds-into-a-png-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
You can use the select
filter to select frames that match an expression. If the expression evaluates to a nonzero number or true
, it'll select those frames. For example, if your filter is -vf select="between(n, 0, 7)"
, it'd select the first eight frames. The frame number is n
, and it starts at zero.
Combining this with the mod
(modulo) operator, you can select the first eight frames of every group of, say, 24 frames, so every second for a video of 24 fps:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 24), 0, 7), setpts=N/24/TB" output.mp4
The setpts
filter is needed to adjust the timestamps of the frames so that you don't have gaps in your video.
To get the first eight frames every five seconds, multiply the 24 by 5:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 120), 0, 7), setpts=N/24/TB" output.mp4
To output everything into PNGs, change the output from output.mp4
to output-%04d.png
— you'll get sequentially numbered PNGs.
add a comment |
You can use the select
filter to select frames that match an expression. If the expression evaluates to a nonzero number or true
, it'll select those frames. For example, if your filter is -vf select="between(n, 0, 7)"
, it'd select the first eight frames. The frame number is n
, and it starts at zero.
Combining this with the mod
(modulo) operator, you can select the first eight frames of every group of, say, 24 frames, so every second for a video of 24 fps:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 24), 0, 7), setpts=N/24/TB" output.mp4
The setpts
filter is needed to adjust the timestamps of the frames so that you don't have gaps in your video.
To get the first eight frames every five seconds, multiply the 24 by 5:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 120), 0, 7), setpts=N/24/TB" output.mp4
To output everything into PNGs, change the output from output.mp4
to output-%04d.png
— you'll get sequentially numbered PNGs.
add a comment |
You can use the select
filter to select frames that match an expression. If the expression evaluates to a nonzero number or true
, it'll select those frames. For example, if your filter is -vf select="between(n, 0, 7)"
, it'd select the first eight frames. The frame number is n
, and it starts at zero.
Combining this with the mod
(modulo) operator, you can select the first eight frames of every group of, say, 24 frames, so every second for a video of 24 fps:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 24), 0, 7), setpts=N/24/TB" output.mp4
The setpts
filter is needed to adjust the timestamps of the frames so that you don't have gaps in your video.
To get the first eight frames every five seconds, multiply the 24 by 5:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 120), 0, 7), setpts=N/24/TB" output.mp4
To output everything into PNGs, change the output from output.mp4
to output-%04d.png
— you'll get sequentially numbered PNGs.
You can use the select
filter to select frames that match an expression. If the expression evaluates to a nonzero number or true
, it'll select those frames. For example, if your filter is -vf select="between(n, 0, 7)"
, it'd select the first eight frames. The frame number is n
, and it starts at zero.
Combining this with the mod
(modulo) operator, you can select the first eight frames of every group of, say, 24 frames, so every second for a video of 24 fps:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 24), 0, 7), setpts=N/24/TB" output.mp4
The setpts
filter is needed to adjust the timestamps of the frames so that you don't have gaps in your video.
To get the first eight frames every five seconds, multiply the 24 by 5:
ffmpeg -i input.mp4 -vf "select=between(mod(n, 120), 0, 7), setpts=N/24/TB" output.mp4
To output everything into PNGs, change the output from output.mp4
to output-%04d.png
— you'll get sequentially numbered PNGs.
answered Dec 30 '18 at 15:34
slhckslhck
160k47445467
160k47445467
add a comment |
add a comment |
This is a generalized version of the select filter to pick 8 frames every 5 seconds.
ffmpeg -i in.mp4 -vf "select='if(not(floor(mod(t,5)))*lt(ld(1),1),st(1,1)+st(2,n)+st(3,t));if(eq(ld(1),1)*lt(n,ld(2)+8),1,if(trunc(t-ld(3)),st(1,0)))'" -vsync 0 out%d.png
This will work for videos with any frame-rate, constant or variable.
Change the 5
in mod(t,5)
for the interval, in seconds. And the 8
in ld(2)+8
for the number of frames to select.
Pretty complex expression. Had to translate that to pseudocode to figure out what was going on.
– slhck
Dec 30 '18 at 22:00
add a comment |
This is a generalized version of the select filter to pick 8 frames every 5 seconds.
ffmpeg -i in.mp4 -vf "select='if(not(floor(mod(t,5)))*lt(ld(1),1),st(1,1)+st(2,n)+st(3,t));if(eq(ld(1),1)*lt(n,ld(2)+8),1,if(trunc(t-ld(3)),st(1,0)))'" -vsync 0 out%d.png
This will work for videos with any frame-rate, constant or variable.
Change the 5
in mod(t,5)
for the interval, in seconds. And the 8
in ld(2)+8
for the number of frames to select.
Pretty complex expression. Had to translate that to pseudocode to figure out what was going on.
– slhck
Dec 30 '18 at 22:00
add a comment |
This is a generalized version of the select filter to pick 8 frames every 5 seconds.
ffmpeg -i in.mp4 -vf "select='if(not(floor(mod(t,5)))*lt(ld(1),1),st(1,1)+st(2,n)+st(3,t));if(eq(ld(1),1)*lt(n,ld(2)+8),1,if(trunc(t-ld(3)),st(1,0)))'" -vsync 0 out%d.png
This will work for videos with any frame-rate, constant or variable.
Change the 5
in mod(t,5)
for the interval, in seconds. And the 8
in ld(2)+8
for the number of frames to select.
This is a generalized version of the select filter to pick 8 frames every 5 seconds.
ffmpeg -i in.mp4 -vf "select='if(not(floor(mod(t,5)))*lt(ld(1),1),st(1,1)+st(2,n)+st(3,t));if(eq(ld(1),1)*lt(n,ld(2)+8),1,if(trunc(t-ld(3)),st(1,0)))'" -vsync 0 out%d.png
This will work for videos with any frame-rate, constant or variable.
Change the 5
in mod(t,5)
for the interval, in seconds. And the 8
in ld(2)+8
for the number of frames to select.
answered Dec 30 '18 at 20:16
GyanGyan
14.8k21845
14.8k21845
Pretty complex expression. Had to translate that to pseudocode to figure out what was going on.
– slhck
Dec 30 '18 at 22:00
add a comment |
Pretty complex expression. Had to translate that to pseudocode to figure out what was going on.
– slhck
Dec 30 '18 at 22:00
Pretty complex expression. Had to translate that to pseudocode to figure out what was going on.
– slhck
Dec 30 '18 at 22:00
Pretty complex expression. Had to translate that to pseudocode to figure out what was going on.
– slhck
Dec 30 '18 at 22:00
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1388870%2fhow-to-capture-first-x-frames-every-x-seconds-into-a-png-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
I was trying to get the direct video link from my Dropbox folder instead of downloading. I was using the wrong link, but I figured it out!
– AFG
Dec 30 '18 at 16:52