This is an old revision of the document!


Multimedia encoding

Images

convert

size operations

  • resize: scale image
    convert in.png -resize 640x480 out.png
  • crop: crop image
    convert in.png -crop 640x480+10+10 out.png
  • extent: add margins or crops
    convert in.png -gravity center -extent 1420x1420       out.png
    convert in.png                 -extent 1420x1420-10-10 out.png

Annotate an image with text

Simple text:

convert in.png \
  -pointsize 20 -fill red -draw 'text 10,30 "My text" ' \
  out.png

Text with shadow:

convert in.png \
  -gravity SouthEast \
  -stroke '#000C' -strokewidth 2 -annotate 0 "My text" \
  -stroke none    -fill white    -annotate 0 "My text" \
  out.png

Append images

convert in1.png in2.png +append out.png # horizontally
convert in1.png in2.png -append out.png # vertically

More complex:

convert im1.png -resize 640x480 ppm:- \
	| convert im2.png - +append ppm:- \
		| convert im3.png - -append final.png

Formats

  • EPS to RGB:
    convert -density 600x600 -flatten -depth 8 -colorspace RGB file.eps ppm:- | convert - file.png

Exif

exiftool

  • restore exif Orientation tag: if you have photos captured with a device that sets the orientation tag, but you used a viewer that doesn't use this tag, and rotated the image with a software that doesn't update this tag, then the image is inconsistent and is not well displayed in exif-aware viewers. To reset the orientation tag, you can use the following command:
    exiftool -overwrite_original -Orientation="Horizontal (normal)" <file>

Video

mencoder

(comes with mplayer).

http://gentoo-wiki.com/HOWTO_Mencoder_Introduction_Guide

General syntax:

mencoder \
  <input data> \
  <input options> \
  <output options> \
  <output data>

Input data and options

  • Video files
    mencoder \
      <input_file_1> <input_file_2> ... \
      <input options> \
      <output options> \
      <output data>
  • Image files
    mencoder \
      "mf://img.o.*.PNG" \
      -mf fps=25 \
      <output options> \
      <output data>
  • Image files from stdin (only works with jpg images, but you can use convert to pipe to mencoder)
    mencoder \
      - \
      -demuxer lavf -lavfdopts format=mjpeg \
      <output options> \
      <output data>
  • Video filters:
    • -vf yadif=0 : deinterlace
    • -vf scale=640:480 : scale video
    • -vf crop=w:h:x:y : crop video
    • -vf “crop=640:360:0:60,scale=1280:720” : multiple video filters
    • -vf pp=? : post processing subfilters

Output data and options

Specify the video codec with -ovc option, and audio codec with -oac option. copy is possible with both.

  • xvid
    mencoder \
      <input data> \
      <input options> \
      -ovc xvid -xvidencopts bitrate=800:quant_type=mpeg:gmc:chroma_opt:vhq=4:bvhq=1:trellis \
      -o <output_file>

    xvid encode options:

    • bitrate=<value>: constant bitrate, in kbs
    • fixed_quant=<1-31>: constant quantization (quality), lower is better
    • trellis : speeds up encoding
  • h264
    mencoder \
      <input data> \
      <input options> \
      -ovc x264 -x264encopts bitrate=800 \
      -o <output_file>

    x264 encode options:

    • bitrate=<value>: constant bitrate, in kbs
    • crf=<1.0-50.0>: constant quality, lower is better
  • WebM
    mencoder \
      <input data> \
      <input options> \
      -ovc lavc -ffourcc VP80 -of lavf -lavfopts format=webm -lavcopts vcodec=libvpx:vqscale=22.0 \
      -o <output_file>

    lavc options:

    • vbitrate=<value>: constant bitrate, in kbs
    • vqscale=<1.0-31.0>: constant quantization (quality), lower is better
  • mp3
    mencoder \
      <input data> \
      <input options> \
      -oac mp3lame -lameopts abr:br=128 \
      -o <output_file>

Other operations

  • cut the file (here from 10'00“ to 10'30”):
    mencoder -ss 10:00 -endpos 30 -ovc copy -oac copy movie.avi -o submovie.avi

ffmpeg

  • -c:v libx264 or libxvid for video codec
  • -c:a pcm_s16le or libmp3lame for video codec
  • -b:v 800k or -b:a 128k for video or audio bitrate
  • -q:v 20 or -q:a 90 for video or audio quality (-crf 20 for x264)
  • append side by side two videos:
    ffmpeg -i in_left.avi -vf "pad=1280:480 [left]; movie=in_right.avi [right]; [left][right] overlay=640:0" -c:v libx264 -b:v 800k out.avi
  • encode video from images sequence:
    ffmpeg -r 50 -i 01/all/image_1_%07d.pgm -r 50 -c:v libx264 -b:v 800k video_01.avi
  • cut clip (ss is start time, t is duration):
    ffmpeg -i in.avi -ss 00:00:23 -t 00:00:19 out.avi
  • render subtitles (requires to be compiled with libass):
    ffmpeg -i in.avi -vf subtitles=in.srt out.avi

AviDemux

A GUI easier to use, like VirtualDub for Windows.

PhotoFilmStrip

Kdenlive

Tried Openshot and Cinelerra but seem crappy, Kdenlive seems to have better design.

  • Transitions : works between two video tracks that overlap (eg dissolve).
  • Audio track volume : add effect “Audio Correction / Volume (keyframable)”, then double click to add modification points.

Audio

mp3

lame

To encode from wav to mp3 in “speech” quality :

lame -V2 --vbr-new -q0 --lowpass 10 -s 22.05 -b32 file.wav file.mp3

ogg

(using vorbis-tools package)

oggenc

To encode from wav to ogg in “speech” quality :

oggenc -b 32 --downmix --resample 22050 file.wav -o file.ogg

Converting from ogg to ogg in “speech” quality :

oggdec -b 16 -R file.ogg -o - | oggenc -r -B 16 -C 1 -b 32 --resample 22050 - -o file_recomp.ogg

sox

play, record, process

  • Cut: (start position / length)
    sox in_file.wav out_file.wav trim 2:37:32 4:00
  • Reencode:
    sox in_file.type1 out_file.type2
    sox in_file.type1 -t type2 - | oggenc ...

ffmpeg

  • extract sound track from video:
    ffmpeg -i video.avi sound.mp3
software/video.1419699839.txt.gz · Last modified: 2014/12/27 17:03 by cyril
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0