How to create a high quality video file from JPGs using FFMPEG?

Questions involving a Windows version of FFmpeg.
texdrone
Posts: 14
Joined: Sun Sep 15, 2019 10:39 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by texdrone » Thu Oct 17, 2019 9:14 pm

pandy wrote:
Thu Oct 17, 2019 6:53 pm
This can be interesting for you:
https://forum.doom9.org/showthread.php?t=144271
https://forum.doom9.org/showthread.php?t=165975

I think H.264 can support 18fps - not sure how your player will deal with such video.
I can try to dig my scripts during weekend and perhaps something can be easily adapted to your needs.
Thanks!

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by pandy » Tue Oct 22, 2019 3:54 pm

Sorry for delay - this is very hectic time in my work and life - apologies

There are two scripts - first one encode losslessly video and can produce intermediate lossless file for proper encoding - I use ffv1 as it supports more video formats.

Code: Select all

@echo off
@setlocal

@ffmpeg -hide_banner -loglevel 32 -stats -y -i pic%08d.jpg -c:v ffv1 -f matroska "pic_ffv1.mkv" 
Script provided bellow encode video in a very, very compatible way - it should be playable on almost everything.
As H.264 encoding can be relatively slow process i advise You to first encode losslessly your source and if everything is fine use this intermediate file as input for bellow script.

Code: Select all

@echo off
@setlocal

@set quality=12

@SET x264opts="crf=%quality%:level=4.0:qpmin=4:vbv_maxrate=30000:vbv_bufsize=20000:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
@ffmpeg.exe -y -hide_banner -loglevel 32 -i "pic_ffv1.mkv" -c:v libx264 -preset medium -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -movflags faststart -f mp4 "pic_h264.mp4"
.

Good luck.

texdrone
Posts: 14
Joined: Sun Sep 15, 2019 10:39 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by texdrone » Tue Oct 22, 2019 4:03 pm

pandy wrote:
Tue Oct 22, 2019 3:54 pm
Sorry for delay - this is very hectic time in my work and life - apologies

There are two scripts - first one encode losslessly video and audio and can produce intermediate file for proper encoding.

Code: Select all

@echo off
@setlocal

@ffmpeg -hide_banner -loglevel 32 -stats -y -i pic%08d.jpg -c:v ffv1 -f matroska "pic_ffv1.mkv" 
Script bellow encode video in a very compatible way - it should be playable on almost everything.
As H.264 encoding can be relatively slow process i advise You to first encode losslessly your source and if everything is fine use this intermediate file as input for bellow script.

Code: Select all

@echo off
@setlocal

@set quality=12

@SET x264opts="crf=%quality%:level=4.0:qpmin=4:vbv_maxrate=30000:vbv_bufsize=20000:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
@ffmpeg.exe -y -hide_banner -loglevel 32 -i "pic_ffv1.mkv" -c:v libx264 -preset medium -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -movflags faststart -f mp4 "pic_h264.mp4"
.

Good luck.
Thanks so much! I will try this later tonight or tomorrow when I get a chance. I really appreciate your help!!

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by pandy » Tue Oct 22, 2019 4:07 pm

btw - i've mentioned audio but all related audio commands was removed - this is only to encode video.

texdrone
Posts: 14
Joined: Sun Sep 15, 2019 10:39 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by texdrone » Wed Oct 23, 2019 10:17 pm

texdrone wrote:
Tue Oct 22, 2019 4:03 pm
pandy wrote:
Tue Oct 22, 2019 3:54 pm
Sorry for delay - this is very hectic time in my work and life - apologies

There are two scripts - first one encode losslessly video and audio and can produce intermediate file for proper encoding.

Code: Select all

@echo off
@setlocal

@ffmpeg -hide_banner -loglevel 32 -stats -y -i pic%08d.jpg -c:v ffv1 -f matroska "pic_ffv1.mkv" 
I finally got time to run the first one and it looks great! There was this 'warning' at the output: [swscaler @ 0x55f34113d1a0] deprecated pixel format used, make sure you did set range correctly

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by pandy » Thu Oct 24, 2019 8:04 pm

You may try to specify color format explicitly - for example:

Code: Select all

@echo off
@setlocal

@set quality=12

@SET x264opts="crf=%quality%:level=4.0:qpmin=4:vbv_maxrate=30000:vbv_bufsize=20000:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
@ffmpeg.exe -y -hide_banner -loglevel 32 -i "pic_ffv1.mkv" -vf format=pix_fmts=yuv420p -c:v libx264 -preset medium -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -movflags faststart -f mp4 "pic_h264.mp4"
btw swscaler is one of poorer ffmpeg components - there is alternative to swscaler (have no clue how to completely disable swscaler as it can be silently, in invisible way - automatically invoked by ffmpeg filterchain) - zscale (accorodingly to many people better and faster than swscaler).
https://ffmpeg.org/ffmpeg-filters.html#zscale-1

Code: Select all

@echo off
@setlocal

@set quality=12

@SET x264opts="crf=%quality%:level=4.0:qpmin=4:vbv_maxrate=30000:vbv_bufsize=20000:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
@ffmpeg.exe -y -hide_banner -loglevel 32 -i "pic_ffv1.mkv" -vf zscale=w=iw:h=ih:f=4,format=pix_fmts=yuv420p -c:v libx264 -preset medium -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -movflags faststart -f mp4 "pic_h264.mp4"

texdrone
Posts: 14
Joined: Sun Sep 15, 2019 10:39 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by texdrone » Fri Oct 25, 2019 10:10 pm

pandy wrote:
Thu Oct 24, 2019 8:04 pm
You may try to specify color format explicitly - for example:

Code: Select all

@echo off
@setlocal

@set quality=12

@SET x264opts="crf=%quality%:level=4.0:qpmin=4:vbv_maxrate=30000:vbv_bufsize=20000:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
@ffmpeg.exe -y -hide_banner -loglevel 32 -i "pic_ffv1.mkv" -vf zscale=w=iw:h=ih:f=4,format=pix_fmts=yuv420p -c:v libx264 -preset medium -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -movflags faststart -f mp4 "pic_h264.mp4"
I just now tried running the 2nd script... had only used the 1st one so far. The 2nd script gives me this error:
[libx264 @ 0x55f16f99f7c0] height not divisible by 2 (1204x885)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by pandy » Sat Oct 26, 2019 6:09 pm

texdrone wrote:
Fri Oct 25, 2019 10:10 pm
I just now tried running the 2nd script... had only used the 1st one so far. The 2nd script gives me this error:
[libx264 @ 0x55f16f99f7c0] height not divisible by 2 (1204x885)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Almost every modern video codec expect MOD 2 for x,y - this one should work:

Code: Select all

@echo off
@setlocal

@set quality=12

@SET x264opts="crf=%quality%:level=4.0:qpmin=4:vbv_maxrate=30000:vbv_bufsize=20000:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
@ffmpeg.exe -y -hide_banner -loglevel 32 -i "pic_ffv1.mkv" -vf zscale=w=iw:h=-2:f=4,format=pix_fmts=yuv420p -c:v libx264 -preset medium -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -movflags faststart -f mp4 "pic_h264.mp4"
[/quote]

texdrone
Posts: 14
Joined: Sun Sep 15, 2019 10:39 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by texdrone » Sat Oct 26, 2019 7:48 pm

pandy wrote:
Sat Oct 26, 2019 6:09 pm

Almost every modern video codec expect MOD 2 for x,y - this one should work:
I am getting this error.

[AVFilterGraph @ 0x5646bff9c380] No such filter: 'zscale'
Error reinitializing filters!


Clearly I do not have zscale installed. After I download the zscale package from github, does it need to be extracted into specific directory before I run the autogen.sh file? After I run the autogen.sh to I then need to 'rebuild' ffmpeg? Thanks again. I searched for a 'how to add zscale to ffmpeg on linux...' but did not find a clear cut set of instructions.

I really appreciate you helping me with this! The first script alone is super helpful. :D

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: How to create a high quality video file from JPGs using FFMPEG?

Post by pandy » Sun Oct 27, 2019 7:34 pm

I think your ffmpeg is outdated - zscale is present in ffmpeg since quite long time - have no macos thus can't help but seem Zeranoe precompile binariers for 64 bit macos too. his builds should support zsale.

Anyway using rescale is not best idea (had this impression afterwhile) - perhaps better is to use pad.

Code: Select all

@echo off
@setlocal

@set quality=12

@SET x264opts="crf=%quality%:level=4.0:qpmin=4:vbv_maxrate=30000:vbv_bufsize=20000:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
@ffmpeg.exe -y -hide_banner -loglevel 32 -i "pic_ffv1.mkv" -vf pad=iw:-2,format=pix_fmts=yuv420p -c:v libx264 -preset medium -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -movflags faststart -f mp4 "pic_h264.mp4"

Post Reply
'