How can I extract a good quality JPEG image from an H264 video file with ffmpeg?












76















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?










share|improve this question


















  • 1





    What is wrong with the current quality, apart from that it is not "good"?

    – bjoernz
    Apr 19 '12 at 11:05
















76















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?










share|improve this question


















  • 1





    What is wrong with the current quality, apart from that it is not "good"?

    – bjoernz
    Apr 19 '12 at 11:05














76












76








76


33






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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












1 Answer
1






active

oldest

votes


















160














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






share|improve this answer


























  • 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












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
});


}
});














draft saved

draft discarded


















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









160














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






share|improve this answer


























  • 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
















160














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






share|improve this answer


























  • 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














160












160








160







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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas