Convert

Aus SchnallIchNet
Wechseln zu: Navigation, Suche

Source: VIA and extended by me... ;-)

Converting Files with Linux September 21st, 2011 No Comments

The following tipps work under a linux terminal:


Image Files

If you want to change image files via terminal, ImageMagick is a good choice.


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

  • Convert flac to mp3 audiofile:
    ffmpeg -i file.flac -ab 320k -ac 2 file.mp3


Normalize Audio

Give all mp3 songs the same sound level (it’s called Audio normalization)

mp3gain -a *.mp3


Merge mp3 audio files to one

mp3wrap merged.mp3 one.mp3 two.mp3


fade in/out 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 [...]

or try sox:

this 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

try sox (see above) which strips, fades in and out in one command.
to strip the 1st 30 sec. of an audio file

ffmpeg -ss 30 -acodec copy -i inputfile.mp3 outputfile.mp3

to only get the 1st 30 sec. of an audio file

ffmpeg -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3


wav2mp3

  • Convert all *.wav-files in one folder two *.mp3-files and remove the *.wav-files:
    for i in *.wav;do lame "$i" "${i%wav}mp3"; rm "$i"; done
  • Convert all *.wav-files in one folder two *.mp3-files and move mp3's to mp3-folder:
    for i in *.wav;do lame "$i" "${i%wav}mp3"; mkdir -p mp3; mv "${i%wav}mp3" mp3/; done


mp32wav

convert mp3 to wav

mpg123 -w output.wav input.mp3


mp32ogg

convert mp3 to ogg

mpg123 -w - ./FILE.mp3 | oggenc -q 3.00 -o ./FILE.ogg -


Video Files

For quite a lot purposes is the command line tool FFmpeg with its lots of options a good choice. For others might MEncoder be better. You might also 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


DVD to mp4

If you have a DVD or DVD.iso file create a single .VOB file

mplayer dvd://n -v -dumpstream -dumpfile /var/tmp/dvd.vob

If 'dvd://n' detects the wrong stream locate longest stream and replace 'n' by stream number

$ lsdvd |grep Longest 
Longest track: 01

If it's an ISO file replace 'dvd://n' by: -dvd-device /path/to/dvdfile.iso

Now convert .vob to mp4:

cat /var/tmp/dvd.vob | ffmpeg -i - -codec:a copy -codec:v libx264 /var/tmp/dvd.mp4


strip audio from video

ffmpeg -i input_file.mp4 -vcodec copy -an output_file.mp4


replace/add audio in/to a video

1st of all get the 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

now you can see:

  • stream 0.0 video-stream in the avi
  • stream 0.1 audio-stream in the avi
  • stream 1.0 audio-stream (the mp3 file)

now, to get the video with the mp3-file as audio, do:

ffmpeg -i video-with-audio.avi -i audio.mp3 -map 0.0 -map 1.0 -acodec copy -vcodec copy output.avi

here you tell ffmpeg to map streams 0.0 and 1.0 into the new output.avi


Merge many video files to one

cat One.mpg Two.mpg Three.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy "Merged.mpg"


avi2mpg

ffmpeg -i "Original.avi" "New.mpg"


flv2mpeg

  • Convert FLV to MPG file:
    ffmpeg -i video.flv video.mpg
  • Convert MPG to FLV file:
    ffmpeg -i video.mpg video.flv

this works for avi, too!


flv2avi

  • Convert FLV to AVI file:
    ffmpeg -i video.flv -ar 22050 -b 2048k video.avi
  • Convert AVI to FLV file:
    ffmpeg -i video.avi video.flv


avi2avi

-)

xvid2divx

relabel file from XviD to DivX 5
needs no recoding just re-label it as DivX

cfourcc -u DX50 -d DX50 "$file"

flv2mp3

  • Convert FLV to mp3 audio file:
    ffmpeg -i video.flv -ab 192k output.mp3


*2flv

to convert some format to flv
for webstreaming there is some more work to do, which i will describe here...

flv streaming in apache:

  • get the apache module: HERE
  • compile with apxs2 (debian) btw. apxs (RH-related distros)
    apxs2 -i -c ./mod_flvx.c
  • load into apache2:
cat /etc/apache2/mods-available/flvx.load

# flv-streaming plugin
# source: http://people.apache.org/%7Epquerna/modules/mod_flvx.c
# build:  apxs -c -i ./mod_flvx.c

LoadModule flvx_module /usr/lib/apache2/modules/mod_flvx.so
AddHandler flv-stream .flv
  • enable module:
    a2enmod flvx
  • restart apache
  • create flv:
    ffmpeg -i ~/any.supported.format.eg.mp4 -b 4000000 -r 25 -s 800x600 ~/output-file.flv
    • perhaps try around with b-frames: -b_qfactor 4.0 - see man ffmpeg
  • Add pseudostreaming meta data to the file:
    flvtool2 -Up output-file.flv
    • if you want to preserve a file WITHOUT meta data for webstreaming create a backup
      flvtool2 will inject metadata into actual file!


swf2avi

requires package: pyvnc2swf

vnc2swf-edit -o output.flv input.swf
ffmpeg -i input.flv output.avi


mov2avi

ffmpeg -i movie.mov -acodec copy -vcodec copy movie.avi


mp42mpg

ffmpeg -i "Original.mp4" -target ntsc-vcd "New.mpg"


mp42avi

ffmpeg -i filename.mp4 -vcodec mpeg4 -acodec ac3 -ar 48000 -ab 192k output.avi

or

-acodec libmp3lame


mp42mp3

mp42wav

extracts audio from an mp4 video file

mplayer source.mp4 -ao pcm:file=tmp.wav
lame -b 128 -q 2 tmp.wav final.mp3


mod2avi

?


vcd2avi

mencoder vcd://2 -o "New.avi" -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2000

dvd2avi

to do this you will have to run the following command-tripple:

  1. get the black border dimensions to cut them off
  2. run pass 1 with mencoder to create the 'divx2pass.log', which is needed by pass 2 run
  3. run pass 2

1)

play TRACK 1 (dvd://1), chapter 3

mplayer dvd://1 [-dvd-device /path/to/dir or /dev/cdrom] -chapter 3 -vf cropdetect
...
[CROP] Crop area: X: 0..719  Y: 70..505  (-vf crop=720:432:0:72).0
...

2) do the 1st pass with mencoder
set -vf crop= to the value mplayer puts out to console
while running the 1st command

mencoder dvd://1 [-dvd-device /path/to/dir or /dev/cdrom] \
-vf crop=720:432:0:72,scale=704:304 -ovc xvid \
-xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=1 \
-oac copy -o /dev/null
  • scale=704:304 ==> nice for 16:9
    if you change that, be sure the values both are dividable by 16!!
  • if you dont want to use CD (700MB) to backup that film try using a bitrate ob 1200 or 1400 instead of 658
    • a bitrate of 1600 creates a 2GB file out of 4.6GB-DVD and has acceptable quality...

3)

2nd pass run...
be sure the divx2pass.log file is in CWD where you start mencoder...

mencoder dvd://1 dvd://1 [-dvd-device /path/to/dir or /dev/cdrom] \
-vf crop=720:416:0:80,scale=704:304 -ovc xvid \
-xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=2 \
-alang de -oac mp3lame -lameopts br=96:cbr:vol=6 -o FILM.avi

ogv2avi

mencoder "Original.ogv" -ovc xvid -oac mp3lame -xvidencopts pass=1 -o "New.avi"

wmv2mpg

aspect=16/9 should eventually be changed to 4/3 or other aspects

mencoder -of avi -ofps 25 \
 -oac mp3lame -lameopts cbr:br=112:aq=3:mode=0:vol=0 \
 -vf hqdn3d,softskip,harddup \
 -ovc xvid \
 -xvidencopts bitrate=501:max_key_interval=37:aspect=16/9:turbo:nochroma_me:notrellis:max_bframes=0:vhq=0 \
 Original.wmv \
 -o New.avi

mkv2avi

mencoder "Original.mkv" -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=6000 -oac mp3lame -lameopts vbr=3 -o "New.avi"

or use ffmpeg

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

Siehe auch

  1. Ffmpeg