Encoding video for the IPod

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Encoding video for the IPod

Giskard
Hi all,

I'm successfully encoding video for my PSP using libx264. Recently ;-)
my little one got an IPod Nano and of course she also wants to have
video on it.

I'm currently using:
ffmpeg -i $input -acodec libfaac -ac 1 -ar 22050 -ab 64kb -f mp4 -s
320x240 $output

This works (the low audio quality is on purpose), but it is not optimal.
I have several questions with regards to this:

1) With this command line ffmpeg uses the standard rate of 200kb for
video, right?
2) For my PSP I use libx264 with a variable bitrate with a quantiser of
28 (qmin=28, qmax=28) for encoding video. What is the equivalent
quantiser value for mp4?
3) Did anyone figure out the right command line to encode libx264 video
for the IPod?

Many thanks,
Michael

--
icq: 71772353 | skype: daneel1409 | msn: [hidden email]

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Encoding video for the IPod

Tom Bilan
>
> Hi all,
>
> I'm successfully encoding video for my PSP using libx264. Recently ;-)
> my little one got an IPod Nano and of course she also wants to have
> video on it.
>
> I'm currently using:
> ffmpeg -i $input -acodec libfaac -ac 1 -ar 22050 -ab 64kb -f mp4 -s
> 320x240 $output
>
> This works (the low audio quality is on purpose), but it is not
> optimal.
> I have several questions with regards to this:
>
> 1) With this command line ffmpeg uses the standard rate of 200kb for
> video, right?

I use my IPod for 640x480 video onto a 42" flat screen TV and 768k seems
to be a good bitrate for my uses.

> 2) For my PSP I use libx264 with a variable bitrate with a quantiser
of
> 28 (qmin=28, qmax=28) for encoding video. What is the equivalent
> quantiser value for mp4?

I use qmax of 31.  The default qmin is 2 I believe so I just let ffmpeg
control qmin.

> 3) Did anyone figure out the right command line to encode libx264
video
> for the IPod?

Here's a DOS batch file I created to encode my IPod videos.  (No
warranty etc.)

Usage:
1) Make a new directory.  Put this code notepad document and name it
ipod.bat and put it in the root of that directory.
2) Make a subdirectory called tools and put in there: ffmpeg.exe,
pthreadGC2.dll (depends on your ffmpeg.exe if you need this),
mediainfo.exe, mediainfo.dll, and nicmp4box.exe.  I have a Windows
version of grep that I put in c:\windows\system32 so if you don't have
grep already then you'll need to get one.
3) Drop any movies you want to convert in the root directory.
4) Run the ipod.bat file and when it's done check the AutoconvertIPod
subdirectory for a file you can drag into iTunes.  The original file
will be moved to AutoconvertOrig.

This batch file will keep the original aspect ratio of the movie.  If
the movie is > 640 wide then it will resize the width to 640 and the
height to the appropriate # that corresponds to the aspect ratio.  Tweak
some of the set variables if you want to experiment.

Enjoy.
-Tom

REM Created by Tom Bilan
REM No warrany given or implied.

cls
setlocal EnableDelayedExpansion
@echo off

set donedir=AutoconvertIPod
set origdir=AutoconvertOrig
set temp=Temp

set qmax=31
set NewWidth=640
set bitrate=768k
set time=-1

if not exist "%donedir%" md "%donedir%"
if not exist "%origdir%" md "%origdir%"
if not exist "%temp%" md "%temp%"


for %%i in ("*.mp4" "*.m4v" "*.mov" "*.mpg" "*.wmv" "*.avi" "*.vob") do
(

  tools\mediainfo.exe -f "%%i" > mediainfo.tmp
  for /f "tokens=3" %%k in ('grep Width mediainfo.tmp') do (set
OrigWidth=%%k)
  for /f "tokens=3" %%k in ('grep Height mediainfo.tmp') do (set
OrigHeight=%%k)
  for /f "tokens=3" %%k in ('grep FrameCount mediainfo.tmp') do (set
FrameCount=%%k)
  for /f "tokens=4" %%k in ('grep Aspect mediainfo.tmp') do (set
OrigAspect=%%k)
  for /f "tokens=4" %%k in ('grep Frame mediainfo.tmp') do (set
OrigRate=%%k)


  REM FFmpeg doesn't understand 16/9 or 4/3 so change to 16:9 or 4:3 if
needed
  if !OrigAspect!==16/9 set OrigAspect=16:9
  if !OrigAspect!==4/3 set OrigAspect=4:3

  if !OrigWidth! LEQ %NewWidth% (

    set FileName=%%~ni-!OrigWidth!x!OrigHeight!

    echo .
    echo
------------------------------------------------------------------------
-------------------------
    echo !OrigWidth! less than or equal to %NewWidth% so not resizing
frame
    echo Processing file --- %%i - !OrigWidth!x!OrigHeight! -
!FrameCount! Frames - !OrigAspect! Aspect - !OrigRate! fps
    echo Filename will be !Filename!.mp4
    echo
------------------------------------------------------------------------
-------------------------

    echo tools\ffmpeg.exe -y -i "%%~nxi" -t %time% -f mp4 -r !OrigRate!
-title "%%~ni" -vcodec libx264 -level 30 -b %bitrate% -bt %bitrate%
-qmax %qmax% -bufsize 10000k -maxrate 10000k -g 300 -coder 0 -threads
auto -acodec libfaac -ac 2 -ab 128k -vol 400 "%temp%\!Filename!.mp4-1"
    tools\ffmpeg.exe -y -i "%%~nxi" -t %time% -f mp4 -r !OrigRate!
-title "%%~ni" -vcodec libx264 -level 30 -b %bitrate% -bt %bitrate%
-qmax %qmax% -bufsize 10000k -maxrate 10000k -g 300 -coder 0 -threads
auto -acodec libfaac -ac 2 -ab 128k -vol 400 "%temp%\!Filename!.mp4-1"

  ) ELSE (

    REM Calculates new height based on aspect ratio or original and then
/16*16 to round it down to the nearest multiple of 16
    set /a NewHeight=%NewWidth%*!OrigHeight!/!OrigWidth!/16*16
    set FileName=%%~ni-%NewWidth%x!NewHeight!

    echo .
    echo
------------------------------------------------------------------------
-------------------------
    echo !OrigWidth! greater than %NewWidth% so resizing frame
    echo Processing file --- %%i - !OrigWidth!x!OrigHeight! -
!FrameCount! Frames - !OrigAspect! Aspect - !OrigRate! fps
    echo Filename will be !Filename!.mp4
    echo
------------------------------------------------------------------------
-------------------------

    echo tools\ffmpeg.exe -y -i "%%~nxi" -t %time% -f mp4 -s
%NewWidth%x!NewHeight! -r !OrigRate! -aspect !OrigAspect! -title "%%~ni"
-vcodec libx264 -level 30 -b %bitrate% -bt %bitrate% -qmax %qmax%
-bufsize 10000k -maxrate 10000k -g 300 -coder 0 -threads auto -acodec
libfaac -ac 2 -ab 128k -vol 400 "%temp%\!Filename!.mp4-1"
    tools\ffmpeg.exe -y -i "%%~nxi" -t %time% -f mp4 -s
%NewWidth%x!NewHeight! -r !OrigRate! -aspect !OrigAspect! -title "%%~ni"
-vcodec libx264 -level 30 -b %bitrate% -bt %bitrate% -qmax %qmax%
-bufsize 10000k -maxrate 10000k -g 300 -coder 0 -threads auto -acodec
libfaac -ac 2 -ab 128k -vol 400 "%temp%\!Filename!.mp4-1"
  )

  echo.
  echo.
  echo tools\NicMP4Box.exe -itags "Name=%%~ni" -add
"%temp%\!Filename!.mp4-1" "%donedir%\!Filename!.mp4"
  tools\NicMP4Box.exe -itags "Name=%%~ni" -add "%temp%\!Filename!.mp4-1"
"%donedir%\!Filename!.mp4"
  del /q %temp%\*.*
  move "%%i" %origdir%

)

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Encoding video for the IPod

Phill Clarke
In reply to this post by Giskard
On 25/12/2007, Michael Ransburg <[hidden email]> wrote:
>
>
> 3) Did anyone figure out the right command line to encode libx264 video
> for the IPod?
>
>
This page might be useful if you're a Linux user:

https://help.ubuntu.com/community/iPodVideoEncoding

Even if you are not, there's a useful FFMPEG command line for H.264 encoding
included.

Phill
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Encoding video for the IPod

Giskard
Dear Phill, all,

Phill Clarke wrote:

> On 25/12/2007, Michael Ransburg <[hidden email]> wrote:
>  
>> 3) Did anyone figure out the right command line to encode libx264 video
>> for the IPod?
>>
>>
>>    
> This page might be useful if you're a Linux user:
>
> https://help.ubuntu.com/community/iPodVideoEncoding
>
> Even if you are not, there's a useful FFMPEG command line for H.264 encoding
> included.
>  

Many thanks. In the meantime I managed to encode h.264 video which plays
on the iPod Nano, but I will also take a look at the site you reference.

This is the ffmpeg command (variable bitrate, quantiser 28) which I'm using:
ffmpeg -i input.mpeg -acodec libfaac -ac 2 -ar 44100 -ab 96kb -s 320x240
-vcodec libx264 -flags +loop -cmp +chroma -partitions
+parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0
-me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71
-maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin
28 -qmax 28 -qdiff 4 -level 30 -aspect 320:240 output.mp4

And then I'm using MP4Box to make the File iTunes compatible:
MP4Box -ipod -add "output.mp4" "output_ipod.mp4"

This works very well (I already encoded 100+ videos) and I achieve
really nice quality at low bitrates (also thanks to the variable bitrate
encoding). I hope that this will help other iPod users.

All the best,
Michael

> Phill
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>  


--
icq: 71772353 | skype: daneel1409 | msn: [hidden email]

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Encoding video for the IPod

Andy Civil
Michael Ransburg wrote:

> This works very well (I already encoded 100+ videos) and I achieve
> really nice quality at low bitrates (also thanks to the variable bitrate
> encoding). I hope that this will help other iPod users.

I think it will; could you just confirm that this is a third generation
iPod nano that you're talking about? The wikipedia page on the nano
gives the resolution of the 3rd as 320x240 which is the same as you have
in your command line, but it omits the resolution of the 2nd. I assume
it was smaller, it seems a different aspect ratio.

Also, somewhat off-topic, what do you use to get your ffmpeg output onto
your nano? Do you still have to use iTunes? Is this ffmpeg usage all
about making the video in exactly the right format so that iTunes will
accept it?

Thx.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Encoding video for the IPod

Giskard
Hi Andy,

Andy Civil wrote:

> Michael Ransburg wrote:
>
>  
>> This works very well (I already encoded 100+ videos) and I achieve
>> really nice quality at low bitrates (also thanks to the variable bitrate
>> encoding). I hope that this will help other iPod users.
>>    
>
> I think it will; could you just confirm that this is a third generation
> iPod nano that you're talking about? The wikipedia page on the nano
> gives the resolution of the 3rd as 320x240 which is the same as you have
> in your command line, but it omits the resolution of the 2nd. I assume
> it was smaller, it seems a different aspect ratio.
>  

Yes, it is 3rd generation.

> Also, somewhat off-topic, what do you use to get your ffmpeg output onto
> your nano? Do you still have to use iTunes? Is this ffmpeg usage all
> about making the video in exactly the right format so that iTunes will
> accept it?
>  

Yes, I still use iTunes. There are alternatives for Linux, but I'm
encoding the videos for my little one who is managing her iPod through
Windows and iTunes. In fact I think the MP4Box step is only needed for
iTunes to accept the video and not necessarily for the iPod to play it
(but I did not test this).

All the best,
Michael

> Thx.
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>  


--
icq: 71772353 | skype: daneel1409 | msn: [hidden email]

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user