Image Files
Resize Images to a maximum resolution
convert "YourOldPicture.jpg" -resize 1600x1600 "YourNewPicture.jpg"
Create a Black-and-white picture and compress it
djpeg "YourOldPicture.jpg" | ppmtopgm | cjpeg -qual 70 >"YourNewPicture.jpg"
Rename Pictures
rename -n ’s/\.jpg$/\.JPG/’ *.jpg
Audio Files
flac2mp3
ffmpeg -i file.flac -ab 320k -ac 2 file.mp3
Normalize Audio
mp3gain -a *.mp3
Merge mp3 audio files into one
mp3wrap merged.mp3 one.mp3 two.mp3
Fade in/out audio filter
details see here: https://ffmpeg.org/ffmpeg-filters.html#afade
Fade in first 15 seconds of audio
ffmpeg [...] -afade=t=in:ss=0:d=15 [...]
Fade out last 25 seconds of a 900 seconds audio
ffmpeg [...] -afade=t=out:ss=875:d=25 [...]
You can also try sox
The next command will:
- trim out from Position 45 sec. the next 30 seconds (0:45.0 30) and
- fade the first 5 seconds (0:5) and the last 5 seconds (0 0:5) and
- convert from wav to mp3
sox infile.wav outfile.mp3 trim 0:45.0 30 fade h 0:5 0 0:5
Cut / crop audio
You can also try sox (see above) which strips, fades in and out in one command.
To strip the 1st 30 sec. of an audio file using ffmpeg do
ffmpeg -ss 30 -acodec copy -i inputfile.mp3 outputfile.mp3
To get the first 30 seconds only do:
ffmpeg -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3
wav2mp3
Convert all *.wav-files in a folder to mp3-files and move mp3’s to ‘mp3’ sub-folder
for i in *.wav; do
lame "$i" "${i%wav}mp3";
mkdir -p mp3;
mv "${i%wav}mp3" mp3/;
done
mp32wav
mpg123 -w output.wav input.mp3
mp32ogg
mpg123 -w - ./FILE.mp3 | oggenc -q 3.00 -o ./FILE.ogg -
Video Files
Focus is ffmpeg and mencoder
Anyway, you might want to install some codecs first
sudo apt-get install libavcodec-extra-52 libavdevice-extra-52 \
libavformat-extra-52 libavutil-extra-50 \
libpostproc-extra-51 libswscale-extra-0 \
libavcodec-unstripped-52 ubuntu-restricted-extras
DVD2mp4
If you have a DVD or DVD.iso file create a single .VOB file first
In case of an ISO file use: -dvd-device /path/to/dvdfile.iso
mplayer dvd://n -v -dumpstream -dumpfile /var/tmp/dvd.vob
If ‘dvd://n’ does select the wrong track identify the longest track first and replace ‘n’ by the track number
$ lsdvd |grep Longest
Longest track: 01
Now convert .vob to mp4
cat /var/tmp/dvd.vob | \
ffmpeg -i - -codec:a copy -codec:v libx264 /var/tmp/dvd.mp4
Remove audio stream
ffmpeg -i input_file.mp4 -vcodec copy -an output_file.mp4
Replace or add audio stream
1st of all identify the different streams
$ ffmpeg -i video-with-audio.avi -i audio.mp3
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-with-audio.avi':
Duration: 00:01:13.29, start: 0.000000, bitrate: 17022 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 1920x1080, 90k tbr, 90k tbn, 180k tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16
Input #1, mp3, from 'audio.mp3':
Duration: 00:00:46.52, start: 0.000000, bitrate: 192 kb/s
Stream #1.0: Audio: mp3, 44100 Hz, stereo, s16, 192 kb/s
At least one output file must be specified
As you can see in the output above we have
- Stream 0.0 video-stream (within the avi file)
- Stream 0.1 audio-stream (within the avi file)
- Stream 1.0 audio-stream (within the mp3 file)
Now you can map the streams together as you like.
What I want to have is the video stream (0.0) and the audio stream from the mp3 file (1.0)
ffmpeg -i video-with-audio.avi -i audio.mp3 -map 0.0 -map 1.0 \
-acodec copy -vcodec copy output.avi
Merge multiple videos
cat One.mpg Two.mpg Three.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy "Merged.mpg"
xvid2divx
As xvid and divx both use DX50 codec you don’t need to re-encode just relable the file
cfourcc -u DX50 -d DX50 "$file"
*2flv
ffmpeg -i ~/any.supported.format.eg.mp4 -b 4000000 -r 25 \
-s 800x600 ~/output-file.flv
If you want to use it for web streaming you should add some pseudo streaming meta data to it
This will actually inject the meta data into the file
flvtool2 -Up output-file.flv
swf2*
Requires package: pyvnc2swf
$ vnc2swf-edit -o output.flv input.swf
$ ffmpeg -i input.flv output.avi
mp42audio
$ mplayer source.mp4 -ao pcm:file=final.wav
$ lame -b 128 -q 2 final.wav final.mp3
mkv2avi
mencoder "Original.mkv" -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=6000 \
-oac mp3lame -lameopts vbr=3 -o "New.avi"
mkv2mp4
ffmpeg -i INPUT_FILE -f mp4 -r 23.976 -vcodec libx264 -s 1280x720 \
-b 3000kb -aspect 16:9 -flags +loop -cmp +chroma -deblockalpha 0 \
-deblockbeta 0 -maxrate 3500k -bufsize 4M -bt 256k -refs 1 \
-bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 \
-partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 \
-keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 \
-sc_threshold 40 -i_qfactor 0.71 -acodec libfaac -ab 384kb -ar 48000 \
-ac 2 OUTPUT.MP4
ts2avi
mencoder SOURCE.ts -oac mp3lame -lameopts abr:br=128 -ovc lavc \
-lavcopts vcodec=mpeg4:vhq:v4mv:vqmin=2:aspect=16/9:vbitrate=1267 \
-vf pp=de,crop=0:0:0:0,scale=704:400 -ffourcc DX50 -o DESTINATION.avi