Navigation

Tricks avconv/ffmpeg, SOX, ImageMagick

http://wiki.ubuntu.cz/triky_s_imagemagick_a_ffmpeg

Convert video to images:

avconv -i video.mov -sameq output/%09d.png
avconv -i video.mov -same_quant output/%09d.png

Create video / timelapse: 5frames/s, best quality -qscale 1

ffmpeg -r 5 -qscale 1 -i input/%09d.jpg output.avi

Rename/sort images for avconv/ffmpeg input criteria:

x=1;
rm sorted/*
for f in notsorted/*.jpg; do
  cp $f sorted/`printf %09d $x`.jpg;
  let "x+=1";
done

Change video speed:

# Slow down / slower video
avconv -i input.avi -r 25 -filter:v "setpts=(30/1)*PTS" -qscale 1 out.avi

# Accelerate / faster video
avconv -i input.avi -r 25 -filter:v "setpts=(1/30)*PTS" -qscale 1 out.avi

# Adjust multiple files
 for f in *.mp4; do avconv -i $f -r 25 -filter:v "setpts=(1/30)*PTS" out/$f; done

Change video and audio speed:

for f in *.MOV; do
  avconv -i $f -map 0:0 "${f/.MOV}"_video.avi;
  avconv -i $f -map 0:1 "${f/.MOV}"_audio.wav;
  sox "${f/.MOV}"_audio.wav "${f/.MOV}"_audio_speed.wav speed 4;
  sox "${f/.MOV}"_audio.wav "${f/.MOV}"_audio_tempo.wav tempo 4;
  avconv -i "${f/.MOV}"_video.avi -r 25 -filter:v "setpts=0.25*PTS" "${f/.MOV}"_video_speed.avi;
  avconv -i "${f/.MOV}"_video_speed.avi -i "${f/.MOV}"_audio_speed.wav "${f/.MOV}"_video_audiospeed.avi;
  avconv -i "${f/.MOV}"_video_speed.avi -i "${f/.MOV}"_audio_tempo.wav "${f/.MOV}"_video_audiotempo.avi;
done

 

Rotate video (180):

avconv -i input.avi -vf transpose=1,transpose=1 rotated.avi

Change video framerate:

avconv -i input.avi -r 125 out.avi;

Analyze pictures (detect storm/lightning)

mkdir storm
#ffmpeg -i storm.MOV -sameq storm/%09d.png
avconv -i storm.MOV - same_quant storm/%09d.png

for f in  storm/*.png; do
  #cp $f serazeno/`printf %08d $x`.jpg;
  printf '# '$f' ' >> analoutput.txt
  convert $f -resize 1x1  txt:- | grep -v '^$\|^\s*\#' >> analoutput.txt
done

#grep -v '^$\|^\s*\#' temp 

Merge video and audio file/track

avconv -i video.avi -i audio.wav -c copy merged.avi

# Audio delay 00:00:22.0
avconv -i output.avi -itsoffset 00:00:22.0 -c:v libx264 -i rec27.mp3 -c:a ac3 outputfile.mp4

Create video from photos:

avconv -r 10 -start_number 8 -i sorted/%09d.jpg -b:v 1000k output.mp4

...