How can I extract a good quality JPEG image from an H264 video file with ffmpeg?
Currently I am using this command to extract the images:
ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.jpeg
But how can I improve the JPEG image quality?
video graphics ffmpeg computer-vision sharpffmpeg
add a comment |
Currently I am using this command to extract the images:
ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.jpeg
But how can I improve the JPEG image quality?
video graphics ffmpeg computer-vision sharpffmpeg
1
What is wrong with the current quality, apart from that it is not "good"?
– bjoernz
Apr 19 '12 at 11:05
add a comment |
Currently I am using this command to extract the images:
ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.jpeg
But how can I improve the JPEG image quality?
video graphics ffmpeg computer-vision sharpffmpeg
Currently I am using this command to extract the images:
ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.jpeg
But how can I improve the JPEG image quality?
video graphics ffmpeg computer-vision sharpffmpeg
video graphics ffmpeg computer-vision sharpffmpeg
asked Apr 19 '12 at 9:39
Daniel GartmannDaniel Gartmann
2,56853347
2,56853347
1
What is wrong with the current quality, apart from that it is not "good"?
– bjoernz
Apr 19 '12 at 11:05
add a comment |
1
What is wrong with the current quality, apart from that it is not "good"?
– bjoernz
Apr 19 '12 at 11:05
1
1
What is wrong with the current quality, apart from that it is not "good"?
– bjoernz
Apr 19 '12 at 11:05
What is wrong with the current quality, apart from that it is not "good"?
– bjoernz
Apr 19 '12 at 11:05
add a comment |
1 Answer
1
active
oldest
votes
Use -qscale:v
Use -qscale:v
(or the alias -q:v
) as an output option. Effective range for JPEG is 2-31 with 31 being the worst quality. I recommend trying values of 2-5.
To output a series of images:
ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
To output a single image at ~60 seconds duration:
ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg
This will work with any video input. See below if your input is MJPEG.
MJPEG
If you input is MJPEG (Motion JPEG) then the images can be extracted without any quality loss.
The ffmpeg
or ffprobe
console output can tell you if your input is MJPEG:
$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1 input.avi
codec_name=mjpeg
Then you can extract the frames using the mjpeg2jpeg
bitstream filter:
$ ffmpeg -i input.avi -codec:v copy -bsf:v mjpeg2jpeg output_%03d.jpg
Also see
- FFmpeg FAQ: How do I encode movie to single pictures?
- FFmpeg Wiki: Create a thumbnail image every X seconds of the video
This seems to have no effect for me-- qscale 1 and 2 both give identical file sizes and (to my naked eye) appear the same as without qscale at all.
– felwithe
Jan 28 '15 at 23:03
Can you post the complete commandline you're using? Also please post the complete, uncut output from ffmpeg on the commandline. Note that placement of options is relevant, so -qscale:v 2 needs to be placed after the -i inputfile option, but before the output file option, to have any effect.
– Ronald S. Bultje
Apr 12 '15 at 12:10
1
For me adding-qmin 1 -qmax 1
in addition to-q:v 1
doubled the file size. And I can seem to see a very slight improvement also.
– complistic
Jun 27 '15 at 0:43
1
@complistic:-qmin 1 -qmax 1
resulted in larger file, but gives me an exact same image. I validated this via photoshop, 2 layers and difference filter. The pixels are the same.
– cherouvim
Nov 30 '15 at 15:41
@Kostanos You can try-qmin 1 -q:v 1
.
– llogan
Oct 14 '17 at 23:00
|
show 2 more comments
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%2f10225403%2fhow-can-i-extract-a-good-quality-jpeg-image-from-an-h264-video-file-with-ffmpeg%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 -qscale:v
Use -qscale:v
(or the alias -q:v
) as an output option. Effective range for JPEG is 2-31 with 31 being the worst quality. I recommend trying values of 2-5.
To output a series of images:
ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
To output a single image at ~60 seconds duration:
ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg
This will work with any video input. See below if your input is MJPEG.
MJPEG
If you input is MJPEG (Motion JPEG) then the images can be extracted without any quality loss.
The ffmpeg
or ffprobe
console output can tell you if your input is MJPEG:
$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1 input.avi
codec_name=mjpeg
Then you can extract the frames using the mjpeg2jpeg
bitstream filter:
$ ffmpeg -i input.avi -codec:v copy -bsf:v mjpeg2jpeg output_%03d.jpg
Also see
- FFmpeg FAQ: How do I encode movie to single pictures?
- FFmpeg Wiki: Create a thumbnail image every X seconds of the video
This seems to have no effect for me-- qscale 1 and 2 both give identical file sizes and (to my naked eye) appear the same as without qscale at all.
– felwithe
Jan 28 '15 at 23:03
Can you post the complete commandline you're using? Also please post the complete, uncut output from ffmpeg on the commandline. Note that placement of options is relevant, so -qscale:v 2 needs to be placed after the -i inputfile option, but before the output file option, to have any effect.
– Ronald S. Bultje
Apr 12 '15 at 12:10
1
For me adding-qmin 1 -qmax 1
in addition to-q:v 1
doubled the file size. And I can seem to see a very slight improvement also.
– complistic
Jun 27 '15 at 0:43
1
@complistic:-qmin 1 -qmax 1
resulted in larger file, but gives me an exact same image. I validated this via photoshop, 2 layers and difference filter. The pixels are the same.
– cherouvim
Nov 30 '15 at 15:41
@Kostanos You can try-qmin 1 -q:v 1
.
– llogan
Oct 14 '17 at 23:00
|
show 2 more comments
Use -qscale:v
Use -qscale:v
(or the alias -q:v
) as an output option. Effective range for JPEG is 2-31 with 31 being the worst quality. I recommend trying values of 2-5.
To output a series of images:
ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
To output a single image at ~60 seconds duration:
ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg
This will work with any video input. See below if your input is MJPEG.
MJPEG
If you input is MJPEG (Motion JPEG) then the images can be extracted without any quality loss.
The ffmpeg
or ffprobe
console output can tell you if your input is MJPEG:
$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1 input.avi
codec_name=mjpeg
Then you can extract the frames using the mjpeg2jpeg
bitstream filter:
$ ffmpeg -i input.avi -codec:v copy -bsf:v mjpeg2jpeg output_%03d.jpg
Also see
- FFmpeg FAQ: How do I encode movie to single pictures?
- FFmpeg Wiki: Create a thumbnail image every X seconds of the video
This seems to have no effect for me-- qscale 1 and 2 both give identical file sizes and (to my naked eye) appear the same as without qscale at all.
– felwithe
Jan 28 '15 at 23:03
Can you post the complete commandline you're using? Also please post the complete, uncut output from ffmpeg on the commandline. Note that placement of options is relevant, so -qscale:v 2 needs to be placed after the -i inputfile option, but before the output file option, to have any effect.
– Ronald S. Bultje
Apr 12 '15 at 12:10
1
For me adding-qmin 1 -qmax 1
in addition to-q:v 1
doubled the file size. And I can seem to see a very slight improvement also.
– complistic
Jun 27 '15 at 0:43
1
@complistic:-qmin 1 -qmax 1
resulted in larger file, but gives me an exact same image. I validated this via photoshop, 2 layers and difference filter. The pixels are the same.
– cherouvim
Nov 30 '15 at 15:41
@Kostanos You can try-qmin 1 -q:v 1
.
– llogan
Oct 14 '17 at 23:00
|
show 2 more comments
Use -qscale:v
Use -qscale:v
(or the alias -q:v
) as an output option. Effective range for JPEG is 2-31 with 31 being the worst quality. I recommend trying values of 2-5.
To output a series of images:
ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
To output a single image at ~60 seconds duration:
ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg
This will work with any video input. See below if your input is MJPEG.
MJPEG
If you input is MJPEG (Motion JPEG) then the images can be extracted without any quality loss.
The ffmpeg
or ffprobe
console output can tell you if your input is MJPEG:
$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1 input.avi
codec_name=mjpeg
Then you can extract the frames using the mjpeg2jpeg
bitstream filter:
$ ffmpeg -i input.avi -codec:v copy -bsf:v mjpeg2jpeg output_%03d.jpg
Also see
- FFmpeg FAQ: How do I encode movie to single pictures?
- FFmpeg Wiki: Create a thumbnail image every X seconds of the video
Use -qscale:v
Use -qscale:v
(or the alias -q:v
) as an output option. Effective range for JPEG is 2-31 with 31 being the worst quality. I recommend trying values of 2-5.
To output a series of images:
ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
To output a single image at ~60 seconds duration:
ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg
This will work with any video input. See below if your input is MJPEG.
MJPEG
If you input is MJPEG (Motion JPEG) then the images can be extracted without any quality loss.
The ffmpeg
or ffprobe
console output can tell you if your input is MJPEG:
$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1 input.avi
codec_name=mjpeg
Then you can extract the frames using the mjpeg2jpeg
bitstream filter:
$ ffmpeg -i input.avi -codec:v copy -bsf:v mjpeg2jpeg output_%03d.jpg
Also see
- FFmpeg FAQ: How do I encode movie to single pictures?
- FFmpeg Wiki: Create a thumbnail image every X seconds of the video
edited Oct 31 '18 at 21:54
answered Apr 19 '12 at 18:03
lloganllogan
47.3k14108139
47.3k14108139
This seems to have no effect for me-- qscale 1 and 2 both give identical file sizes and (to my naked eye) appear the same as without qscale at all.
– felwithe
Jan 28 '15 at 23:03
Can you post the complete commandline you're using? Also please post the complete, uncut output from ffmpeg on the commandline. Note that placement of options is relevant, so -qscale:v 2 needs to be placed after the -i inputfile option, but before the output file option, to have any effect.
– Ronald S. Bultje
Apr 12 '15 at 12:10
1
For me adding-qmin 1 -qmax 1
in addition to-q:v 1
doubled the file size. And I can seem to see a very slight improvement also.
– complistic
Jun 27 '15 at 0:43
1
@complistic:-qmin 1 -qmax 1
resulted in larger file, but gives me an exact same image. I validated this via photoshop, 2 layers and difference filter. The pixels are the same.
– cherouvim
Nov 30 '15 at 15:41
@Kostanos You can try-qmin 1 -q:v 1
.
– llogan
Oct 14 '17 at 23:00
|
show 2 more comments
This seems to have no effect for me-- qscale 1 and 2 both give identical file sizes and (to my naked eye) appear the same as without qscale at all.
– felwithe
Jan 28 '15 at 23:03
Can you post the complete commandline you're using? Also please post the complete, uncut output from ffmpeg on the commandline. Note that placement of options is relevant, so -qscale:v 2 needs to be placed after the -i inputfile option, but before the output file option, to have any effect.
– Ronald S. Bultje
Apr 12 '15 at 12:10
1
For me adding-qmin 1 -qmax 1
in addition to-q:v 1
doubled the file size. And I can seem to see a very slight improvement also.
– complistic
Jun 27 '15 at 0:43
1
@complistic:-qmin 1 -qmax 1
resulted in larger file, but gives me an exact same image. I validated this via photoshop, 2 layers and difference filter. The pixels are the same.
– cherouvim
Nov 30 '15 at 15:41
@Kostanos You can try-qmin 1 -q:v 1
.
– llogan
Oct 14 '17 at 23:00
This seems to have no effect for me-- qscale 1 and 2 both give identical file sizes and (to my naked eye) appear the same as without qscale at all.
– felwithe
Jan 28 '15 at 23:03
This seems to have no effect for me-- qscale 1 and 2 both give identical file sizes and (to my naked eye) appear the same as without qscale at all.
– felwithe
Jan 28 '15 at 23:03
Can you post the complete commandline you're using? Also please post the complete, uncut output from ffmpeg on the commandline. Note that placement of options is relevant, so -qscale:v 2 needs to be placed after the -i inputfile option, but before the output file option, to have any effect.
– Ronald S. Bultje
Apr 12 '15 at 12:10
Can you post the complete commandline you're using? Also please post the complete, uncut output from ffmpeg on the commandline. Note that placement of options is relevant, so -qscale:v 2 needs to be placed after the -i inputfile option, but before the output file option, to have any effect.
– Ronald S. Bultje
Apr 12 '15 at 12:10
1
1
For me adding
-qmin 1 -qmax 1
in addition to -q:v 1
doubled the file size. And I can seem to see a very slight improvement also.– complistic
Jun 27 '15 at 0:43
For me adding
-qmin 1 -qmax 1
in addition to -q:v 1
doubled the file size. And I can seem to see a very slight improvement also.– complistic
Jun 27 '15 at 0:43
1
1
@complistic:
-qmin 1 -qmax 1
resulted in larger file, but gives me an exact same image. I validated this via photoshop, 2 layers and difference filter. The pixels are the same.– cherouvim
Nov 30 '15 at 15:41
@complistic:
-qmin 1 -qmax 1
resulted in larger file, but gives me an exact same image. I validated this via photoshop, 2 layers and difference filter. The pixels are the same.– cherouvim
Nov 30 '15 at 15:41
@Kostanos You can try
-qmin 1 -q:v 1
.– llogan
Oct 14 '17 at 23:00
@Kostanos You can try
-qmin 1 -q:v 1
.– llogan
Oct 14 '17 at 23:00
|
show 2 more comments
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%2f10225403%2fhow-can-i-extract-a-good-quality-jpeg-image-from-an-h264-video-file-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
What is wrong with the current quality, apart from that it is not "good"?
– bjoernz
Apr 19 '12 at 11:05