I just finished installing ffmpeg
on debian wheezy using these instructions - http://trac.ffmpeg.org/wiki/UbuntuCompilationGuide. Now I want to encode a video to play on my iPod classic. The video has the following info:
$ mediainfo in.mp4
General
Complete name : in.mp4
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42
File size : 1.21 GiB
Duration : 55mn 10s
Overall bit rate mode : Variable
Overall bit rate : 3 130 Kbps
Encoded date : UTC 2010-08-25 23:38:59
Tagged date : UTC 2010-08-25 23:38:59
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.2
Format settings, CABAC : Yes
Format settings, ReFrames : 2 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 55mn 10s
Bit rate mode : Variable
Bit rate : 3 000 Kbps
Maximum bit rate : 5 000 Kbps
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 fps
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.109
Stream size : 1.16 GiB (96%)
Language : English
Encoded date : UTC 2010-07-21 13:28:49
Tagged date : UTC 2010-07-21 13:28:49
Color primaries : BT.709-5, BT.1361, IEC 61966-2-4, SMPTE RP177
Transfer characteristics : BT.709-5, BT.1361
Matrix coefficients : BT.709-5, BT.1361, IEC 61966-2-4 709, SMPTE RP177
Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : LC
Codec ID : 40
Duration : 55mn 10s
Bit rate mode : Variable
Bit rate : 125 Kbps
Maximum bit rate : 270 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 44.1 KHz
Compression mode : Lossy
Stream size : 49.4 MiB (4%)
Language : English
Encoded date : UTC 2010-07-21 13:28:49
Tagged date : UTC 2010-07-21 13:28:49
mdhd_Duration : 3310353
I have already tried just copying the video to the IPod with banshee
but the video just shows a black screen. Which is the best format to play the video on the Ipod? What ffmpeg parameters should I use? I would like to maximize resolution while minimizing file size.
You will probably have to re-encode because the iPod Classic can handle up to 640x480 according to the specs you provided, but your video is 1280x720. Video can be H.264, Baseline Profile, Level 3.0:
ffmpeg -i in.mp4 -vcodec libx264 -crf 23 -preset fast -profile:v baseline \
-level 3 -refs 6 -vf "scale=640:-1,pad=iw:480:0:(oh-ih)/2,format=yuv420p" \
-acodec copy output.mp4
Control quality with -crf
and encoding speed with -preset
. See the FFmpeg and x264 Encoding Guide for more info on those options.
-level
currently does not set -refs
for this encoder, so set it manually. There is a pending patch to resolve this so it should be fixed soon.
The scale
video filter will scale the output to 640x360 in this case. The -1
value maintains the original 16:9 aspect ratio in the height dimension, while the 640
value sets the new width.
The pad
video filter specifies the new maximum width and height of the video, plus the side-padding and top-padding in pixels. This is necessary to letterbox the original 16:9 video into the 4:3 aspect ratio required by the iPod classic. If this is not done then the iPod will expand the video to fit the screen height and will crop off the sides of the video during playback. To calculate the necessary values for for this parameter, consider that:
1280*x = 640 # x is the resize factor in the width dimension
x = 640/1280 = 0.5 # now we know x
720*x + 2*p = 480 # scaling the original video height by x, then adding
# equal padding p above and below the video must give the new desired
# video height of 480. solve for p
360 + 2*p = 480
p = 60
The format
video filter will ensure that the output uses a compatible chroma subsampling scheme. ffmpeg
attempts to avoid or minimize chroma subsampling by default when using libx264, but non-FFmpeg based players and devices do not support anything other than yuv420p, so including this will ensure compatibility. This is the same as using -pix_fmt yuv420p
that you may see in other examples, but using format
allows you to be specific as to where it will be applied in relation to other filters (not that it really matters too much in this case).
Since the audio is probably fine as is it can be stream copied (re-muxed) instead of re-encoded.