Software/encoding – vis
wiki:Software/encoding

Encoding Movies with MEncoder/FFmpeg

Introduction

MPlayer is available on JURECA. Please load the required modules first:

module --force purge
module use /usr/local/software/jureca/OtherStages
module load Stages/Devel-2017a

module load GCC/5.4.0
module load MPlayer

For more details on MEncoder please check here

Images => Movie:

Example 1: JPEG -> MPEG4 in AVI-container (with vcodec=mpeg4)

For details on lavopts check here

simple setup:

mencoder mf://*.jpg -mf w=1920:h=1080:fps=25:type=jpg \
-ovc lavc \
   -lavcopts vcodec=mpeg4:mbd=2:trell \
-nosound \
-o output.avi

two-pass for much better quality:

opt="vbitrate=15012060:mbd=2:keyint=132:v4mv:vqmin=3"
opt="${opt}:o=luma_elim_threshold=4:o=chroma_elim_threshold=7"
opt="${opt}:lumi_mask=0.07:dark_mask=0.10:naq:vqcomp=0.7:vqblur=0.2:mpeg_quant"

mencoder mf://\*.jpg -mf type=jpg:fps=25 \
-ovc lavc \
   -lavcopts vcodec=mpeg4:vpass=1:${opt} \
-nosound \
-o /dev/null

mencoder mf://\*.jpg -mf type=jpg:fps=25 \
-ovc lavc \
   -lavcopts vcodec=mpeg4:vpass=2:${opt} \
-nosound
-o output.avi
Example 2: PNG -> MPEG4 in AVI-container (with library x264 through FFmpeg integrated into mencoder)

For details on x264encopts check here

mencoder mf://*.png -mf w=1920:h=1080:fps=25:type=png \
-ovc x264 \
   -x264encopts \
      bitrate=900:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto \
-oac copy \
-o output.avi
Example 3: PNG -> MPEG4 (ready for QuickTime 7)

(ready for QuickTime 7 limitations - taken from here)

Pass 1:

mencoder mf://*.png -mf w=1024:h=768:fps=25:type=png \
-ovc x264 \
   -x264encopts pass=1:turbo:bitrate=900:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto \
   -vf harddup \
-oac copy \
-o output.mp4

Pass 2:

mencoder mf://*.png -mf w=1024:h=768:fps=25:type=png \
-ovc x264 \
   -x264encopts pass=2:turbo:bitrate=900:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto \
   -vf harddup \
-oac copy \
-o output.mp4
Example 4: WMV -> MPEG4 (best quality)

Shown is encoding MPEG4 movie with 5000 bit/s using best quality settings.
You can increase the quality only by increasing the bit rate and therefore the file size.

Pass 1:

mencoder input.wmv \
-ovc x264 \
   -x264encopts pass=2:bitrate=15000:bframes=3:subq=7:frameref=6:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto \
   -vf harddup \
-oac copy \
-o output.mp4

Pass 2:

mencoder input.wmv \
-ovc x264 \
   -x264encopts pass=2:bitrate=15000:bframes=3:subq=7:frameref=6:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto \
   -vf harddup \
-oac copy \
-o output.mp4

Pass 3:

mencoder input.wmv \
-ovc x264 \
   -x264encopts pass=3:bitrate=15000:bframes=3:subq=7:frameref=6:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto \
   -vf harddup \
-oac copy \
-o output.mp4

ffmpeg Examples

(https://ffmpeg.org/ffmpeg.html)
(Some very good hints: https://trac.ffmpeg.org/wiki/Slideshow)
(http://hamelot.io/visualization/using-ffmpeg-to-convert-a-set-of-images-into-a-video/)
(https://www.virag.si/2012/01/web-video-encoding-tutorial-with-ffmpeg-0-9)

Here is how to generate a mp4 movie from a number of .png images. Each image is shown 2 seconds (-framerate 1/2). The resulting movie has 25 fps (-r 25) and 4K resolution (-s 3840x2160). The quality is set to 25 (-crf 25). Lower means better quality, 15-25 is usually good. The filenames of the images are read from the filesystem in alphanumerical order (-pattern_type glob -i '*.png'). Note that glob is not available on Windows systems. If your filenames contain a consecutive numbering, you can use a pattern like "-start_number 1 -i filename_%03d.png" instead.

ffmpeg -framerate 1/2 -pattern_type glob  -i '*.png' -vcodec libx264 -crf 25 -s 3840x2160 -r 25 foo.mp4

Just some more examples:

ffmpeg -r 2 -f image2 -s 1920x1080 -i B1-gBMO%03d.png -vcodec libx264 -crf 25  -pix_fmt yuv420p foo.mp4
ffmpeg -f image2 -framerate 12 -i foo-%03d.jpeg -s 1920x1080 foo.avi
ffmpeg -i input -c:libx264 -profile:baseline -preset:ultrafast -level 1.2

any feedback welcomed - h.zilken@…, goebbert@…

Last modified 21 months ago Last modified on 03/22/18 13:44:13