Log on
Main page Graphics Photography Audio Video Tools Web Design Documents Space & Astro Amiga Funny Surreal Gallery Links & Contact

Video related unix commands


This is a collection of various little command lines that I figured out, and that I just want to put somewhere instead of having to figure them out again, the next time I need them. I cannot guarantee they will still work in the future, as some of the tools involved may change their syntax or behavior. But they did work when I put them here.

Creating an animated gif from frames

convert -delay 20 -loop 0 frame*.png output.gif
Or straight from a camera with a bit of sharpen:
convert -delay 15 -loop 0 -resize 250x250 -sharpen 0.5 -auto-orient *.jpg output.gif

Extracting the AAC audio from an .mp4 file

ffmpeg -i input.mp4 -vn -acodec copy -y output.m4a

Remuxing several .ogm files into .mkv

find *.ogm -exec mkvmerge -o "{}.mkv" "{}" \;

Finding out what codecs are used in all your MKV files

find . -iname "*.mkv" -exec mkvinfo "{}" \; |grep -i "codec id"

Nikon D7000/D600 quicktime video to mp4 (aac audio)

Ffmpeg's syntax changes, so here are two approaches. One of them should work:
ffmpeg -i _DSC0544.MOV -vcodec copy -acodec libfaac -ab 160000 test.mp4 ffmpeg -i _DSC0544.MOV -vcodec copy -acodec aac -ab 160000 -strict -2 test.mp4

JPEG sequence to H.264 (high-def timelapse, 12 fps, no audio)

ffmpeg -r 12 -i "frame%03d.jpg" -y -an -vcodec libx264 -crf 14 -preset veryslow -s 1920x1080 output.mp4

PNG sequence and .wav to H.264 (no scaling, 12 fps, with audio)

ffmpeg -r 8 -i "frame%04d.png" -i sound.wav -y -vcodec libx264 -crf 12 -pix_fmt yuv420p -preset veryslow -acodec libfaac -ab 160000 output.mp4
Replace "veryslow" with "fast" if you're impatient.

Losslessly keep section of .mkv file

The -ss part shows where to start, and the -t part shows the duration. Ffmpeg does not seem to have a way to start at a keyframe, so you will have to try changing the start and end point until the result behaves correctly.
ffmpeg -i input.mkv -acodec copy -vcodec copy -ss 00:00:28 -t 00:01:35 output.mkv

Audio track from video file to .wav

ffmpeg -i input.mp4 -vn audio_only.wav

Convert wav into mp3

ffmpeg -i input.wav -codec:a libmp3lame -compression_level:a 1 -b:a 192000 output.mp3

Turn DTS surround audio into mp3

ffmpeg -i "input.mkv" -vcodec copy -scodec copy -acodec libmp3lame -ac 2 -ab 192000 "output.mkv"

Turn DTS surround audio into mp4

This approach assumes H.264 video and no subtitles.
ffmpeg -i "input.mkv" -vcodec copy -scodec copy -acodec libfaac -ac 2 -ab 160000 "output.mp4"

Converting MKV (h264/aac) to MP4 in FreeBSD (1st method)

mkvextract tracks source.mkv 1:video.264 2:audio.aac 3:subtitles.ass mp4box -add video.264 -add audio.aac new.mp4

Converting MKV (h264/ac3) to MP4 in FreeBSD (2nd method)

#/bin/sh # usage: makemp4 <mkv filename> <framerate, e.g. 23.976> BASENAME=`echo $1|sed s/.mkv$//` mkvextract tracks "$1" 1:video.264 2:audio.ac3 3:"$BASENAME.ass" 4:"$BASENAME-b.ass" mplayer audio.ac3 -af channels=2 -ao pcm:fast:waveheader:file=audio.wav -channels 2 -novideo 2>&1 normalize --clipping --peak audio.wav faac -q 133 audio.wav audio.aac rm "$BASENAME.mp4" mp4box "$BASENAME.mp4" -fps $2 -add video.264 rm video.264 audio.wav audio.ac3 mp4box "$BASENAME.mp4" -add audio.aac rm audio.aac

Example dcraw conversion

dcraw -T -w -g 10 10 -q 3 -m 10 "_dsc1234.dng"

Surround AAC to .wav

ffmpeg -i input.mp4 -filter_complex "channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR]" -map "[FL]" front_left.wav -map "[FR]" front_right.wav -map "[FC]" front_center.wav -map "[LFE]" lfe.wav -map "[BL]" back_left.wav -map "[BR]" back_right.wav

Splitting a video into 5 second pieces

ffmpeg -i "input.mkv" -c copy -map 0 -segment_time 5 -f segment output%03d.mkv
And putting them back together:
printf "file '%s'\n" ./*.mkv > mylist.txt ffmpeg -f concat -i mylist.txt -sn -acodec copy -vcodec copy output.mkv


Website by Joachim Michaelis