Discussion:
[FFmpeg-user] output jpeg quality
Green Koopa
2015-01-11 07:21:42 UTC
Permalink
This creates one image for each second of video:
ffmpeg -i 00020.MTS -vf fps=fps=1 -f image2 stills-%03d.png

When I change the output format to jpeg, it does the same:
ffmpeg -i 00020.MTS -vf fps=fps=1 -f image2 stills-%03d.jpeg
But there is a problem. The quality of the jpegs begin okay, but quickly
deteriorate. By the tenth image or so, they are unusable. This seems
strange to me, but this is my first day with ffmpeg.

Same problem when I tried this:
ffmpeg -i 00020.MTS -vsync 1 -r 1 -f image2 stills-%03d.jpeg

I found -qmin 1 -qmax 1 in an old post. It helped all but the last two
images. I can just use png, but I was wondering what is going on here.
Thanks for any insight.

Console output and sample images:
https://googledrive.com/host/0B0-UKhirpea7Sml5OVJpc241bVE/

FFmpeg Win64 static build on 2014-01-22
http://ffmpeg.zeranoe.com/builds/
Lou
2015-01-12 18:08:20 UTC
Permalink
On Sat, 10 Jan 2015 23:21:42 -0800
Post by Green Koopa
ffmpeg -i 00020.MTS -vf fps=fps=1 -f image2 stills-%03d.png
ffmpeg -i 00020.MTS -vf fps=fps=1 -f image2 stills-%03d.jpeg
But there is a problem. The quality of the jpegs begin okay, but quickly
deteriorate. By the tenth image or so, they are unusable. This seems
strange to me, but this is my first day with ffmpeg.
Does it look better if you use -qscale:v (or -q:v)? It's a linear scale
of 1-31. A doubling of the value will probably (very) roughly halve the
bitrate. 2-5 are good values to try, but you can experiment.

You don't need the "-f image2".
Lou
2015-01-12 18:16:38 UTC
Permalink
On Mon, 12 Jan 2015 09:08:20 -0900
It's a linear scale of 1-31.
...for most FFmpeg M(J)PEG* encoders.
Green Koopa
2015-01-15 08:05:51 UTC
Permalink
Post by Lou
Post by Green Koopa
ffmpeg -i 00020.MTS -vf fps=fps=1 -f image2 stills-%03d.png
ffmpeg -i 00020.MTS -vf fps=fps=1 -f image2 stills-%03d.jpeg
But there is a problem. The quality of the jpegs begin okay, but quickly
deteriorate. By the tenth image or so, they are unusable. This seems
strange to me, but this is my first day with ffmpeg.
Does it look better if you use -qscale:v (or -q:v)? It's a linear scale
of 1-31. A doubling of the value will probably (very) roughly halve the
bitrate. 2-5 are good values to try, but you can experiment.
You don't need the "-f image2".
-q did set the jpeg compression level, making it consistent across frames.
(It had no affect on the png compression level.) Thanks for the tips Lou.

When outputting frames like this, is there a way to put the frame
number/time in the output file name? Otherwise, it looks like I have to use
the drawtext filter to add it to the images.
Moritz Barsnick
2015-01-15 08:19:36 UTC
Permalink
Post by Green Koopa
When outputting frames like this, is there a way to put the frame
number/time in the output file name? Otherwise, it looks like I have to use
the drawtext filter to add it to the images.
Sure.

It's mentioned here:
https://www.ffmpeg.org/ffmpeg-all.html#image2-2

The output filenames are specified by a pattern, which can be used to
produce sequentially numbered series of files. The pattern may
contain the string "%d" or "%0Nd", this string specifies the position
of the characters representing a numbering in the filenames. If the
form "%0Nd" is used, the string representing the number in each
filename is 0-padded to N digits.

So
$ ffmpeg ... -f image2 "img-%03d.jpg"
counts from 001.

If also supports strftime() style patterns:

For example to generate image files from the strftime()
"%Y-%m-%d_%H-%M-%S" pattern, the following ffmpeg command can be used:
$ ffmpeg -f v4l2 -r 1 -i /dev/video0 -f image2 -strftime 1 "%Y-%m-%d_%H-%M-%S.jpg"

Note that the time stamps are current time, not frame "time stamps"
such as PTS. also note that the frame numbers are those arriving at the
muxer, disregardless of how many frames came in at the demuxer and were
added or dropped.

HTH,
Moritz
Lou
2015-01-15 17:34:24 UTC
Permalink
Post by Green Koopa
-q did set the jpeg compression level, making it consistent across frames.
(It had no affect on the png compression level.) Thanks for the tips Lou.
For PNG you can use -compression_level. Range is 0-100. Default is 100
(highest compression, IIRC).
Green Koopa
2015-01-15 20:53:53 UTC
Permalink
Post by Lou
Post by Green Koopa
-q did set the jpeg compression level, making it consistent across frames.
(It had no affect on the png compression level.) Thanks for the tips Lou.
For PNG you can use -compression_level. Range is 0-100. Default is 100
(highest compression, IIRC).
Thanks again Lou. Any tips on where I could have learned that without
bothering everyone with basic questions?
Werner Robitza
2015-01-17 16:34:36 UTC
Permalink
Post by Green Koopa
Any tips on where I could have learned that without
bothering everyone with basic questions?
It's all documented under ffmpeg -h full. The problem is that some
global options are mapped to the encoders, so they're not explicitly
listed under, say, http://ffmpeg.org/ffmpeg-all.html#png

I guess what's missing is an appropriate Wiki page for image encoding.
For video/audio encoding, we have a good amount of documentation…
Continue reading on narkive:
Loading...