Tag Archive for 'ffmpeg'

Create your own iPhone ring tones

I’ve had my iPhone for a week (loving it!) and of course I want to make custom ring tones for some of my contacts. I figured out how it worked from posts like create-free-iphone-ringtones-using-itunes-in-windows but I developed my own workflow:

1. Find a source file

  • I typically start from an existing MP3 file. It might be a CD I have ripped to MP3, or a soundtrack from DVDs or other sound bites. I also have a collection of accapella samples that are a nice source.

2. Create the 15 – 30 sec tone in MP3 format

  • You don’t need a 5 min ringtone, just 15 to 30 seconds will be enough
  • I use Audacity (with the LAME MP3 encoder add-on) to load the full source MP3 file, trim out the piece I want and then add a fade-in and fade-out.

Make iPhone ringtone with Audacity

3. Export to MP3

  • I then export the file to an MP3 file of 128kbps. You don’t need better quality than that anyway. If you want, you can convert the file to mono here, or it can happen in the next step
  • Result: ringtone.mp3

4. Convert with ffmpeg to MPEG4 ringtone

  • I prefer using the command-line ffmpeg for transcoding of audio and video.
  • The simple way of doing it: ffmpeg -i ringtone.mp3 -y ringtone.m4a (.m4a stands for MPEG4 audio, ffmpeg will see this extension and use default settings for the conversion.) Afterwards you then have to change the extension to .m4r (MPEG4 ringtone).
  • The detailed one-step-only way to do this: ffmpeg.exe -i ringtone.mp3 -ac 1 -ab 128000 -f mp4 -acodec libfaac -y ringtone.m4r

5. Open file with iTunes

  • Just double-click the file, that should do it.

The lazy way:

let’s make a batch file that will automatically convert the first 30 seconds of any MP3 file into an iPhone ringtone:
SET INPUT=%1
SET NAME=%INPUT:.mp3=%
SET OUTPUT=%NAME%.m4r
echo CONVERT %INPUT% to %OUTPUT% ...
ffmpeg.exe -i %INPUT% -t 30 -ac 1 -ab 128000 -f mp4 -acodec libfaac -genre Ringtone -y %OUTPUT%

Screenshots of a DVD with ‘ffmpeg’

I’ve been playing around a lot with video conversion lately and one of the tools I use often is the Swiss armyknife for video manipulation ‘ffmpeg‘. It does format conversion (MPEG1/2/4, Quicktime, AVI …) , rescaling, recompressing, frame rate conversion … almost everything. It exists for all flavours of Linux/Unix, and also for Windows.

To give you an example: this is a script I wrote to extract screenshots of DVD files, straight from the disk.

1) the naive version
ffmpeg -i [input file] -r .05 -y [output name]%%03d.png
This does indeed extract a PNG image every 20 seconds (framerate = 0.05), but it does not take into account that the DVD image material is stored anamorphically. What you get is this:
V4Vendetta_1_720.012
Natalie Portman looks really thin, but that’s because the image dimensions (720×576 pixels – PAL standard) are for 5:4 aspect ratio, and whereas the actual image should be 16:9. So let’s make the image wider while keeping it the same height.

2) Rescale to 16:9
ffmpeg -i [input file] -r .05 -s 1024x576 -y [output name]%%03d.png
The result looks better:
V4Vendetta_1_1024.012

As you see, there are still black borders on the top and bottom. This is because a feature film is made in ‘scope’ format, with an aspect ratio of 2.39 instead of 1.78 (the decimal equivalent of 16/9). So, while the full width of the image is used, only 428 pixels of the height are actually in use. Let’s crop those black borders off.

3) Crop black borders away
ffmpeg -i [input file] -r .05 -croptop 74 -cropbottom 74 -s 1024x428 -y [output name]%%03d.png

V for Vendetta: cropped

4) old 4:3 movies
The older movies used a 4:3 aspect ratio, so when you extract them as 16:9 they look like a weight feel on them:
MammaRoma_1024
In those cases, you can use the ‘naive’ version above, which will give you:
MammaRoma_720

Here also, the actual 4:3 image is ‘letterboxed’ to the 5:4 DVD image.

Continue reading ‘Screenshots of a DVD with ‘ffmpeg’’