Currently I am using this command to extract the images:
ffmpeg -i input.mp4 output_%03d.jpeg
But how can I improve the JPEG image quality?
Currently I am using this command to extract the images:
ffmpeg -i input.mp4 output_%03d.jpeg
But how can I improve the JPEG image quality?
-qscale:v
to control qualityUse -qscale:v
(or the alias -q:v
) as an output option.
-qmin 1
output option (because the default is -qmin 2
).ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
See the image muxer documentation for more options involving image outputs.
ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg
Use -update 1
image muxer option. Example for once per second from a live streaming input:
ffmpeg -i rtmp://input.foo -q:v 4 -r 1 -update 1 output.jpg
Output the images in a lossless format such as PNG:
mkdir stills
ffmpeg -i my-film.mp4 -vsync 0 -f image2 stills/my-film-%06d.png
Then use another program (where you can more precisely specify quality, subsampling and DCT method – e.g. GIMP) to convert the PNGs you want to JPEG.
It is possible to obtain slightly sharper images in JPEG format this way than is possible with -qmin 1 -q:v 1
and outputting as JPEG directly from ffmpeg
.
If you want to extract only the key frames (which are likely to be of higher quality post-edit) you can use something like this:
ffmpeg -skip_frame nokey -i my-film.mp4 -vsync 0 -f image2 stills/my-film-%06d.png
The -vsync 0
parameter avoids needing to specify the frame rate with -r
and means all frames in the input file are treated as, um, a frame.
mpv --osd-msg1='${estimated-frame-number} / ${estimated-frame-count}' vid1.mp4
sed -i 's/^/eq(n\\,/' frm.txt; sed -i 's/$/)\+/' frm.txt; sed -i '$ s/.$//' frm.txt; #adds eq(n\, #adds )+ at the end of each line #remove + in lastline (last digit)
then extract them as bmp or png
frms=$(cat frm.txt); ffmpeg -i vid_1.mp4 -vf "select='$frms'" -fps_mode drop "frames_%03d.bmp"
then convert to jpg - the difference is HUGE 350kb (ffmpeg jpg of best quality vs 2MB (bmp converting to jpg)!!!!
for pic in *.bmp; do convert -units PixelsPerInch -density 300 -quality 100 "$pic" "${pic//}_j.jpg"; done
(you need imagemagick's convert of course)