robwatkins / 4od-dl

Ruby script to download, convert and tag stuff from 4od

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some files cannot be copied to an iPad via iTunes

robwatkins opened this issue · comments

iTunes refuses to copy some files downloaded with 4od-dl to an iPad, stating that they cannot be played on the device. This happens on my iPad 2, I have not tested on any later models.

Programmes that cause this issue have AVC profile High@4.1 - this can be verified by the RTMPDump output:

INFO: Metadata:
INFO: videocodecid avc1
INFO: audiocodecid mp4a
INFO: avcprofile 100.00
INFO: avclevel 41.00

According to the iPad2 tech specs it does support this AVC level but it may be the case that 4od is incorrectly marking the video stream as a lower level and uses AVC features not supported by the iPad.

However that's just a hunch - I don't know exactly why it's not supported so I don't know what to do to fix it. I would be interested to know if any 4od-dl users have ideas on what the cause might be.

The only workaround so far is re-encoding the video using Handbrake (or similar) and copying to your iPad. I could potentially do the re-encoding as part of the ffmpeg step in 4od-dl but it will significantly slow down the process for those who don't want to copy to an iPad, so it would be via a command line switch.

@ robwatkins

Believe it or not, the iPad 2 specs at the page you consulted are totally wrong!

You will find the most reliable reference for iPad 2 specs by following this path:

Apple Support iPad Tech Specs iPad 2

There you will find that the iPad 2 supports only:

  • H.264 video up to 720p, 30 frames per second, Main Profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;
  • MPEG-4 video up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;
  • Motion JPEG (M-JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format.

So it is most likely the encoder profile and/or level (High@4.1) that is causing playback problems. You may be able to spoof the IDC and avoid the time-consuming process of re-encoding.

The user roozou at <a href=http://forum.doom9.org/showthread.php?t=152419>Doom9 compiles mux/demux -only builds of FFmpeg that allow the user to edit H.264 sequence parameter set data without having to re-encode the video stream. You can download his latest Windows binary (ffmpeg_git_31792.7z) at Sourceforge.

The command line to change the profile level to 3.1 would be as follows:
ffmpeg -i "C:\path\to\inputfile.mp4" -vcodec copy -acodec copy -scodec copy -vbsf h264_changesps=level=31 "C:\path\to\outputfile.mp4"

There is also a freeware solution called H264/AVC Level Editor for Windows users who may be averse to command-line shenanigans. I have no experience with it, but it appears to be portable and well-maintained; <a href-http://coolsoft.altervista.org/download/H264LevelEditor_1.2.0.zip>version 1.2.0 came out just a couple of days ago.

I'm gonna guess you already know about Subler.

Going the other way, you can always open up your media file in your favourite hex editor and <a href=http://www.ode2.com/?p=12>tweak a couple of bits.

You'll like this--I found a little python script that should take care of it for you:

#!/usr/bin/python

import sys
import os

if len(sys.argv) < 2:
    sys.exit("Target file not specified")

f = open(sys.argv[1],"r+b")
f.seek(0,os.SEEK_END)

marker = "avcC"+chr(1)
mlen = len(marker)

sys.stdout.write("Searching");

found = 0
while found==0:
    if(f.tell()%50000==0):
        sys.stdout.write(".")
        sys.stdout.flush()
    f.seek(-mlen-1,os.SEEK_CUR)
    s=f.read(mlen)
    if s==marker:
        found=1
    elif f.tell()==mlen:
        f.close()
        sys.exit("\nCould not find file marker")

f.seek(2,os.SEEK_CUR)
f.write(chr(0x1F))
print "\nFile successfully patched"

f.close()

I did try using H264 Level Editor/Subler but although it was able to change the AVCLevel bit it didn't make it playable on an iPad 2. I think the file must use some features of 4.1 which the iPad doesn't support.

Looks like the only option may be a re-encode