onlydarksets

Just another WordPress.com weblog

Convert Sage recordings to iPhone

Posted by onlydarksets on September 19, 2008

I have posted an updated method.  I STRONGLY SUGGEST YOU USE IT INSTEAD!  I leave the below for posterity…

 

NOTE: mencoder is not cutting commercials properly on my system.  Everything else is working fine.  I’ll post an update when I get it working.

Here is how I’m converting SageTV recordings to iPhone-compatible (and Touch/iPod-compatible) MP4 videos.  This will also work for the Zune!

At a high level, the steps (and applications used) are:

  1. DVRMSToolbox: monitor the recordings directories, identify which shows to process, grab the metadata that is later written to the MP4, and control program flow
  2. comskip or ShowAnalyzer: Scan for commercials
  3. mencoder: Cut commercials
  4. ffmpeg: Convert to MP4 (note: I had problems with the latest Windows build of ffmpeg, but the one from babgvant.com worked fine)
    1. Option 2 is to use mencoder to cut out commercials and convert to MP4 in single pass, and then use NicMP4Box to fix the MP4 container to make it iPod-compatible
  5. AtomicParsley: Write metadata to identify as TV Shows (plus any other info we have)

I am assuming basic familiarity with DTb, so I’ll talk about how to setup the Profile to process a Sage recording, but I am not addressing installing DTb or setting up the processing condition.

More after the break…

DTb: Setup the Profiles

Note you will need to create one profile for SD and one for HD.  The only difference will be profile indicated in the the call to mencoder/ffmpeg (step 6).

  1. Throttle to prevent unlimited workers from running
  2. Set a timeout (trust me – the first time mencoder hangs and you don’t have “Lost” waiting for you in the morning like you were expecting, you’ll be glad)
  3. Update OutputFile context to allow for MP4 extension:
    FIND IN OutputFile: ^((.*\\)(.*)\.(.*))\z
    REPLACE IN OutputFile: $2$3.mp4
  4. Create a new context to specify the Sage commercial file location:
    FIND IN InputFile: ^((.*\\)(.*)\.(.*))\z
    REPLACE IN SageEDLFile: $2$3.edl
  5. Find commercials
  6. Option 1 – ffmpeg
    Note: this process is tried and true, but you suffer a performance hit since mencoder has to rewrite the entire file to cut the commercials. 

    1. Cut commercials with mencoder
      mencoder “%InputFile%” -edl “%SageEDLFile%” -oac copy -ovc copy -of mpeg -o “%OutputFile%.mpg”
    2. Convert with ffmpeg
      Profile: X264 with AAC
  7. Option 2 – mencoder
    Note: mencoder does not have the best implementation of the mp4 container, and I have had problems getting the conversion to work properly.  However, if you can get it to work, the overall process is faster) 

    1. Cut and convert with mencoder
      mencoder “%InputFile%” -edl “%SageEDLFile%” -profile x264IPod-SD -o “%OutputFile%.tmp.mp4”
    2. Remux MP4 with NicMP4Box
      NicMP4Box -add “%OutputFile%.TMP.mp4” “%OutputFile%”
  8. Add basic metadata to MP4:
    AtomicParsley “%OutputFile%” –genre “TV Shows” –stik “TV Show” –TVNetwork %channelName% –TVShowName “%Title%” –TVEpisode “%episode%” –description “%description%” –category=”%category%”
  9. Rename the output file to something meaningful:
    CONTEXT: OutputFile
    PATTERN: %Title% – %originalAirDate% – %episode%

Setup the Profiles

I use two profiles, one for HD sources and one for SD.  I resize to 640×480 or 640×360, since that’s the max resolution the iPhone can handle (Zune can handle 720×480).

A couple of other notes:

  • You must use H.264 or MPEG-4 with AAC audio – the iPhone supports nothing else.
  • You can mess with the bitrates (bitrate=x), but keep in mind the bitrate maximums (vbv_maxrate=x) that the iPhone supports (currently 1500).
  • The maximum IDC is currently 30 (level_idc=30)
  • Cabac is not supported (nocabac)

Option 1: ffmpeg

Here’s the ffmpeg profile that’s working for me right now (note the “-ac 2” parameter for the audio encoding – this was the only way I could get the sound to play on the iPhone):

<profile>
<name>MPEG-4 with AAC HD</name>
<description>MPEG-4 with AAC HD (iPhone-compatible Archive)</description>
<extension>mp4</extension>
<video>-vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2</video>
<audio>-acodec libfaac -ac 2 -ab 128000</audio>
</profile>

Here are some other command lines that I’ve found, mostly from here, in case you want to tinker:

  • ffmpeg -y -benchmark -threads 2 -i “input.dvr-ms” -async 1 -deinterlace -s qvga -vcodec libx264 -b 384000 -bufsize 384 -coder 0 -level 13 -acodec libfaac “output.mp4”
  • 4:3 and 16:9:
    • ffmpeg -y -benchmark -threads 2 -i “%CutDvrmsFile%” -async 1 -deinterlace -croptop 0 -cropbottom 4 -cropleft 8 -cropright 6 -s 704:480 -vcodec libx264 -b 832k -maxrate 960k -bufsize 384k -coder 1 -level 13  -flags +loop -cmp +chroma -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -flags2 +wpred+mixed_refs+8x8dct+brdo -me umh -trellis 2 -bidir_refine 1 -refs 3 -b_strategy 1 -directpred 2 -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -aspect 4:3 -acodec libfaac -ab 128k “%OutputFile%”
    • ffmpeg -y -benchmark -threads 2 -i “%CutDvrmsFile%” -async 1 -deinterlace -croptop 56 -cropbottom 60 -cropleft 8 -cropright 6 -s 704:368 -vcodec libx264 -b 832k -maxrate 960k -bufsize 384k -coder 1 -level 13  -flags +loop -cmp +chroma -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -flags2 +wpred+mixed_refs+8x8dct+brdo -me umh -trellis 2 -bidir_refine 1 -refs 3 -b_strategy 1 -directpred 2 -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -aspect 16:9 -acodec libfaac -ab 128k “%OutputFile%”
  • ffmpeg -i input -acodec libfaac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 640×360 -title X output.mp4
    (from http://ffmpeg.mplayerhq.hu/faq.html#SEC25)

Option 2: mencoder

[x264IPod-SD]
profile-desc=”H.264/AAC MP4 SD for iPhone –After this, use NicMP4Box to remux–”
lavdopts=threads=2
vf=pp=md,scale=640:-10,harddup
ovc=x264=yes
x264encopts=turbo=1:bitrate=768:vbv_maxrate=1500:vbv_bufsize=244:nocabac:level_idc=30:threads=2
oac=faac=yes
faacopts=br=128:object=2:mpeg=4:raw=yes
of=lavf=yes
lavfopts=format=mp4
#DtbExtension=mp4
#dtbhres=”-vf pp=md,scale={0}:-10,harddup”

[x264IPod-HD]
profile-desc=”H.264/AAC MP4 SD for iPhone –After this, use NicMP4Box to remux–”
lavdopts=threads=2
vf=pp=md,scale=640:-10,harddup
ovc=x264=yes
x264encopts=turbo=1:bitrate=1200:vbv_maxrate=1500:vbv_bufsize=244:nocabac:level_idc=30:threads=2
oac=faac=yes
faacopts=br=128:object=2:mpeg=4:raw=yes
of=lavf=yes
lavfopts=format=mp4
#DtbExtension=mp4
#dtbhres=”-vf pp=md,scale={0}:-10,harddup”

Resources:

Related posts:

14 Responses to “Convert Sage recordings to iPhone”

  1. Rob B said

    If you can live with commercials it can be done in one easy step, complete with iTunes integration.

    f you want to muck about with Mencoder you can also get it to work by tweaking the watch dirs.

    Best of all (Drum roll please!) It’s bloody well free…🙂

    http://www.ipodifier.com/

    No I’m not affilliated with the dev, apart from having helped beta test it, and I’m not affilliated with Frey apart from having wrestled with SageTv since version 2POINTpain.

    V6 is a thing of beauty

    Enjoy

  2. Thanks for the suggestion! I did look into this, along with the in-built conversion tools in SageMC. For me, I prefer a little more control over the process, and, of course, I want the commercials gone (I’m not quite there yet, but I’m still working on it!). iPodifier is a great suggestion for those who don’t want to muck around with it, though.

  3. […] Convert for iPhone using mencoder/ffmpeg 13 06 2008 UPDATE: Check my newer post for detailed instructions. […]

  4. raskar said

    Great conf !
    I’ts works for me when I add the video into iTunes and synchronise. But when I enter directly my video url through safari, Safari can’t play it.
    Do you know why ?

  5. What do you mean “enter directly…through safari”? Does it play in Quicktime (I assume so, if iTunes can handle it)? Are you trying to stream it?

  6. […] discovered that you can add such meta data to MP4 files. I found this valuable information on this web blog site. The author explains how you can use a freeware application called Atomic Parsley to add such meta […]

  7. […] by onlydarksets on January 2, 2009 I posted a method for converting SageTV files to iPod/iPhone compliant files a while back, but a number of the files weren’t converting properly.  I also had problems […]

  8. iPhone 5…

    […]Convert Sage recordings to iPhone « onlydarksets[…]…

  9. LASIK malaysia…

    […]Convert Sage recordings to iPhone « onlydarksets[…]…

  10. MALT Lymphoma Symptoms…

    […]Convert Sage recordings to iPhone « onlydarksets[…]…

  11. animation said

    I’ve learn several good stuff here. Certainly value bookmarking for revisiting. I wonder how a lot attempt you place to make this type of wonderful informative website.

  12. Paulina said

    It’s appropriate time to make some plans for the longer term and it’s time to be happy.
    I have learn this submit and if I may I wish to suggest you some
    attention-grabbing things or tips. Perhaps you can write next
    articles regarding this article. I want to learn even more issues about it!

  13. Hi there, this weekend is good in favor of me, as
    this point in time i am reading this fantastic educational article here at my house.

  14. Amazing things here. I’m very happy to look your article.
    Thanks a lot and I’m looking forward to touch you. Will you kindly dop me a mail?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: