# First few seconds of pyTivo-pushed H.264 MP4's are severely pixelated



## Spenner (Mar 28, 2006)

The first few seconds of H.264 MP4's that I push using pyTivo play severely pixelated, then clears after about 7 seconds and is fine.

Screenshots attached.

I tried several files, all with the same result. They play fine on VLC on my PC.

I'm using YAMB (mkvextract/mp4box).
The source is MKV with H.264 video, and AC3 640K audio. I convert the AC3 to 448K and remux to MP4, so it should meet Tivo's requirements for pushing H.264.

Here's ffmpeg's report on the source MKV:
Seems stream 0 codec frame rate differs from container frame rate: 47.95 (5994/125) -> 23.98 (24000/1001)
Input #0, matroska, from 'test.mkv':
Duration: 00:01:05.32, start: 0.000000, bitrate: N/A
Stream #0.0(eng): Video: h264, yuv420p, 1280x720, PAR 1:1 DAR 16:9, 23.98 tbr, 1k tbn, 47.95 tbc
Stream #0.1(eng): Audio: ac3, 48000 Hz, 6 channels, s16
Stream #0.2(eng): Subtitle: 0x0000

This is the workflow:
C:\test>mkvextract tracks test.mkv 1:test.h264 2:test.ac3
Extracting track 1 with the CodecID 'V_MPEG4/ISO/AVC' to the file 'test.h264'. Container format: AVC/h.264 elementary stream
Extracting track 2 with the CodecID 'A_AC3' to the file 'test.ac3'. Container format: Dolby Digital (AC3)
Progress: 100%

C:\test>eac3to test.ac3 test.448k.ac3 -448 -libav
AC3, 5.1 channels, 0:01:05, 640kbps, 48khz
Decoding with libav/ffmpeg...
Remapping channels...
Encoding AC3 <448kbps> with libAften...
Creating file "test.448k.ac3"...
eac3to processing took 2 seconds.
Done.

C:\test>mp4box -add test.h264 -fps 23.98 -add test.448k.ac3 testmp4.mp4
AVC-H264 import - frame size 1280 x 720 at 23.980 FPS
Import results: 1566 samples - Slices: 9 I 602 P 955 B - 0 SEI - 9 IDR
AC3 import - sample rate 48000 - 6 channels
Saving testmp4.mp4: 0.500 secs Interleaving

Anyone seen this? Any other parameters I should be using in the workflow? I'd love it if I could send someone my test.mp4 (45MB) to try pushing on their tivo and see if it works.

Thanks.


----------



## wmcbrine (Aug 2, 2003)

On my S3, I often see a grey screen for the first few seconds of an MP4, unless I rewind. This isn't limited to pyTivo pushes -- I see it on Web Videos (TiVoCasts). Tekzilla doesn't do it, though.


----------



## Rdian06 (Apr 12, 2008)

I think this has been mentioned in the past and people settled on it's some issue with the Tivo's h264 decoder chip. They couldn't seem to figure out what about the mp4 was triggering it.


----------



## moyekj (Jan 24, 2006)

Yes it's normal with S3 & THD H.264 decoders. I'm sure txporter will chime in as he did a lot of investigation on it and never came up with a solution.
NOTE: VC-1 encodes in ASF (WMV) container do not suffer from same problem, so it's probably MP4 container related issue.


----------



## txporter (Sep 18, 2006)

Yes, it does appear to be related to the decoding on the Tivo side. I tried everything that I could think of and was unable to fix the start-up pixelation with x264 encoded files. Like moyekj said, VC-1 video is clean from that standpoint...but encoding to VC-1 is a PITA, you are forced to stereo (which is actually fine for me) and encoding times are MUCH longer. If you are interested to try VC-1, you can download Microsoft Expression Encoder and use the instructions from Streambaby video compatibility. If you are interested in burning in subs (which is the main reason I transcode/re-encode), I found that having a .srt file with the same name (in the same folder) as the one you input to MEE will result in burned in subs.


----------



## txporter (Sep 18, 2006)

wmcbrine said:


> On my S3, I often see a grey screen for the first few seconds of an MP4, unless I rewind. This isn't limited to pyTivo pushes -- I see it on Web Videos (TiVoCasts). Tekzilla doesn't do it, though.


This was reported on the Handbrake forums as being an issue with a player not supporting MP4 edit lists and could be solved by disabling b-frames. I haven't ever seen a grey screen on my TivoHDs though, so maybe the differences in decoders between S3/HD is coming into play.


----------



## txporter (Sep 18, 2006)

Just an update on the VC-1 encoding side of things, for those of you who are interested. I have been vacillating between H.264, MPEG2, and now VC-1 encoding for a while now. I like to push my DVDs up to my tivo for viewing and my wife likes subtitles, so I have been hardsubbing the videos. I started with x264 encoding because I could get very good quality videos at ~2kbps (SD) and there were a lot of programs out there that could do the encoding. The space savings was great. I was, however, highly annoyed at the playback issues on my TivoHD. The garbled opening scene and "shimmering" picture were annoying to me. Enough that I decided to move away from x264 encoding.

My next choice of encoding was simply to go with MPEG2 encoding with hardsubs. I learned to use Avisynth and HCenc. I can get excellent quality SD video at 3.5-4kbps with absolutely no playback issues. The fact that I need to run at roughly 2X the bitrate though is still a bit annoying to me (I am close to filling my 1.5TB drive on my Tonidoplug). So I decided to take a look back at VC-1 encoding.

I attempted to use VC-1 encoding before moving to HCenc. At that point, I didn't know avisynth and there were very, very few GUI based encoders that would encode with VC-1. Couple that with how picky Tivos are with VC-1 encoding, and I quickly lost interest. Now that I have been playing around with HCenc/avisynth for a few months, I decided to give Zambelli's WMCMD.vbs script a look. It accepts avisynth input like HCenc.

I began to do testing on various encoding parameters. I quickly found that I could get comparable quality VC-1 encoding to my MPEG2 encodings at about the same bitrates as x264 (~2kbps). All of my testing was done using SSIM measurements with avisynth. I began flipping through the settings, beginning mainly with the presets (default, good, better, best). I was surprised to find how little difference they made on final quality. Possibly this is due to my pre-processing in avisynth...but I don't think so.


```
Preset	Bitrate	SSIM	x264 SSIM	Encoding Cost
default	2032	74.3	0.9635	        1
good	1963	74.76	0.9643	        1.32
better	1948	74.78	0.9643	        1.75
best	1954	74.89	0.9645	        3.32
```
So basically, for a 4-6% space savings, I need to spend 32% to 232% longer to encode the video. I think I am ok with default. I also played around with the other settings (loop filter, adaptive dead zone, differential quantization, complexity, etc etc). Turning off the loop filter resulted in better picture quality for the same bitrate. Turning on adaptive dead zone resulted in similar picture quality with greatly reduced bitrate. Differential quantization did very little.

I ended up with encoding parameters that looked like this:

```
cscript "Path\To\wmcmd.vbs" -input video.avs -v_mode 2 -v_codec WVC1 -v_qp 3.5 -v_adz 1 -v_keydist 5 -v_loopfilter 0 -a_codec WMASTD -a_input video.ac3 -a_setting 128_48_2 -log video.txt -output video.wmv
```
I am using a 1-pass VBR "quality" based encode at a quantization of 3.5. That results in ~2kbps video on the test clips I have used (this is dependent on how much processing is done in avisynth). You need to force WMASTD for the audio codec because that's what Tivo wants. I demux video/audio because it is easier to deal with only video in avisynth.

I began pushing some of the clips to my Tivo to test them out. The playback on these clips was AWFUL. The video was a bunch of jerks and jumps and stops. It turns out that Tivo doesn't like 23.976fps VC-1, but only 29.97fps (at least for SD resolutions). I had been removing the 3:2 pulldown in avisynth...but now I should not.

My current avs file looks like this:

```
setmtmode(2)
loadplugin("Path\To\DGDecode.dll")
LoadPlugin("Path\To\Fluxsmooth.dll")
LoadPlugin("Path\To\Undot.dll")
LoadPlugin("Path\To\MaskTools.dll")
LoadPlugin("Path\To\WarpSharp.dll")
LoadPlugin("Path\To\mt_masktools-25.dll")
LoadPlugin("Path\To\RemoveGrain.dll")
LoadPlugin("Path\To\Repair.dll")
Import("Path\To\LSFmod.v1.9.avs")
LoadPlugin("Path\To\MT.dll")
loadplugin("Path\To\VSFilter.dll")

MPEG2Source("Path\To\video.d2v",cpu=3)

Undot().FluxsmoothT(3)
MT("""LSFmod()""",threads=4,splitvertical=true)

# use VobSub for .idx/.sub subtitles, use TextSub for .srt/.smi/etc
#VobSub("Path\To\video.d2v.idx")
TextSub("Path\To\video.d2v.srt")
```
The avisynth script can be simplified depending on what you want to do, and WMCMD.vbs will actually take a few other video formats as inputs (.wmv, .asf, .avi and .mpg). On my Q6600 machine that I use for encoding, I can encode in ~70% realtime (~21 fps). That is roughly 2/3rds the speed that I was encoding with HCenc for 40-50% space savings. That can be sped up a bit with a simpler avs script or converting directly from .mpg, but it is still a slow encoder compared to what you can see with ffmpeg or x264.

Now, with the same pre-processing that I was doing with HCenc (join VOB in VRD to single mpg, run DGIndex to create .d2v file, extract captions/subtitles, and extract ac3 track), I can batch process a bunch of videos to VC-1 video that my TivoHD seems to be happy with. I still have more testing to do, but the garbled opening scene is gone and seeking seems to be better than x264 encodes (not quite as good as MPEG2 though). I will report back with more observations as I watch shows and notice things. I am hoping that I have now found a possible solution for optimizing video size with viewing pleasure.


----------



## dlfl (Jul 6, 2006)

txporter said:


> Just an update on the VC-1 encoding side of things, for those of you who are interested. ..........


Thanks for a good summary. Can you elaborate on the "shimmering" effect you mentioned? I searched this forum for posts by you with "shimmering" in them and found none.

I have used process flows in the past similar to yours (dgindex, AviSynth, Zambelli script etc.) but I think I could settle for a few bad initial seconds if I could just use a VideoReDo-encoded .mp4 file. However I am wondering about this shimmering effect. I haven't done enough viewing with VRD encodings and streambaby to notice this effect.

Interesting to note that apparently the Zambelli script hasn't changed since 2007. Also, I never had good results when I tried to input .mpg files directly into the Zambelli script. It presumably was a codec problem, but I tried a lot of things and never got it to work. What version of AviSynth are you using?


----------



## Spenner (Mar 28, 2006)

I should have posted earlier... I did solve problem with MP4's pixelating/green for the first few seconds of playback. When muxing, I put the AC3 stream first, then the H264 video stream, and it plays fine right from the start.


```
mp4creator -create=Audio.ac3 -optimize -use64bits Output.mp4
mp4creator -create=Video.h264 -rate=23.976 -timescale=23976 -optimize Output.mp4
```


----------



## txporter (Sep 18, 2006)

dlfl said:


> Thanks for a good summary. Can you elaborate on the "shimmering" effect you mentioned? I searched this forum for posts by you with "shimmering" in them and found none.
> 
> I have used process flows in the past similar to yours (dgindex, AviSynth, Zambelli script etc.) but I think I could settle for a few bad initial seconds if I could just use a VideoReDo-encoded .mp4 file. However I am wondering about this shimmering effect. I haven't done enough viewing with VRD encodings and streambaby to notice this effect.
> 
> Interesting to note that apparently the Zambelli script hasn't changed since 2007. Also, I never had good results when I tried to input .mpg files directly into the Zambelli script. It presumably was a codec problem, but I tried a lot of things and never got it to work. What version of AviSynth are you using?


The shimmering effect is difficult for describe well...so I call it shimmering. I am probably not consistent with what I call it. I might have said strobing or something like that. It is really noticeable because I burn-in my subs (stationary image for a relatively long period of time). Basically, what happens is that the image seems to be shift up and down very quickly. It is an oddly intermittent problem. If I pause the video and then play again (sometimes I will need to do this multiple times), I can get the video to play smoothly. It doesn't necessarily need to be a pause, but any trick play. And any additional trick play can make it start again. Maybe I am just too OCD, but it annoyed the hell out of me. My wife didn't seem to notice or care.

Yes, the zambelli script isn't being updated. Windows Media Encoder development either went away or was merged into Windows Expression Encoder. I decided to use his code rather than Expression because I like to be able to batch encode. From what I can tell, the options aren't really very different in Expression versus what was possible in WME. I suppose they may have sped up the encoding process. /shrug

I am using avisynth 2.5.8 MT (I believe). I have never really experimented with different versions. My beginnings with avisynth were really from XVID4PSP, and I believe that is the version of avisynth it uses. I just point to all of its included plugins.


----------



## txporter (Sep 18, 2006)

Spenner said:


> I should have posted earlier... I did solve problem with MP4's pixelating/green for the first few seconds of playback. When muxing, I put the AC3 stream first, then the H264 video stream, and it plays fine right from the start.
> 
> 
> ```
> ...


Very interesting! What do you use to create the h264 elementary stream? So you are basically first creating a .mp4 file with only audio and then adding the video to it in the second operation?


----------



## txporter (Sep 18, 2006)

dlfl said:


> Thanks for a good summary. Can you elaborate on the "shimmering" effect you mentioned? I searched this forum for posts by you with "shimmering" in them and found none.


I hadn't thought on this for a while since I had decided to move away from x264 encoding. I am 99% sure that this is the same thing that can be seen if you take progressive video and view it in vdub with a simple script: Src,AssumeTFF().SeparateFields(). The separated fields from each frame match because they are progressive, but they move up and down just a very few lines from each other. I just don't know why it happens. I was always using Handbrake before for my encoding. I might try to just send avs into x264 and see what I get.


----------



## Spenner (Mar 28, 2006)

txporter said:


> Very interesting! What do you use to create the h264 elementary stream? So you are basically first creating a .mp4 file with only audio and then adding the video to it in the second operation?


I'm using eac3to, but you could use mkvextract also. Since Tivo audio must be AC3 with a max 448kb/s, I use eac3to because it can convert DTS and/or downsample higher-bitrate AC3 in one step with the extract, otherwise you'd need to do a separate step after mkvextract.


```
eac3to souce.mkv 1: Video.h264 2: Audio.ac3 [-448 will convert DTS or downsample AC3 greater than 448kb/s]
mp4creator -create=Audio.ac3 -optimize -use64bits Output.mp4
mp4creator -create=Video.h264 -rate=23.976 -timescale=23976 -optimize Output.mp4
```


----------



## txporter (Sep 18, 2006)

Ok. So you aren't actually encoding these videos yourself? I can use eac3to to demux some of my old encodes to see if it fixes the pixelation though. I might be going back to x264 after all.  Thanks for the post. Just need to verify that I can fix the "shimmering".


----------



## moyekj (Jan 24, 2006)

Just for grins you may want to try a newer version of ffmpeg and the following sample encoding profile (assuming mpeg2 with AC3 as source video):
http://www.tivocommunity.com/tivo-vb/showthread.php?p=7753263#post7753263

Perhaps it's coincidence but I noticed that on my S3s the resulting mp4 files following a pyTivo push play right away with no video blackout for the first few seconds. That was the case for short clips of 1080i, 720p and 480i resolutions. Don't know if that's because newer ffmpeg or change in recipe or some combination of the two.
Of course this is for original S3 model - behavior could be different for THD models as we have discovered the decoders are very different between those models.


----------



## txporter (Sep 18, 2006)

I will try to find some time to play around with this on my tivo this weekend. Can't really do it from here. I would love to find a way to get back to x264 encoding! I did a sample pass through x264 with my avs file as input. Easy peasy. Wish I would have learned avisynth earlier.


----------



## txporter (Sep 18, 2006)

I messed around with this a bit this weekend. I verified that Spenner's mp4creator formula works fine for eliminating the issue with the opening scene (on TivoHD). I still get the odd display on the hardsubs. I experimented a bit with that as well this weekend. If I pause a show and just step through the video, I can see subtitles that look great, and others that appear to have some jaggy lines or something in them. If I start playing on one of the messed up subtitles, all subtitles going forward look like that. If I pause and then advance to a scene with good looking subs, then they look good until I do some sort of trick play. I couldn't find any pattern to the good/bad subs (like frames re-created from telecined frames or anything like that).

I also played around a bit with ffmpeg. I really hate ffmpeg.  The syntax is bothersome since there are almost no defaults. At any rate, I created a video only mp4 which I believe ended up being baseline profile. When I pushed that, the subtitles problem appeared to go away (and opening scene was fine also). I am not sure whether it was the fact that it was baseline profile or did not contain audio. Still experimenting. Hopefully I can find the answer and use x264 for encoding rather than ffmpeg .

Also, I pushed up a few of the VC-1 encoded shows that I _thought_ I had found a working solution. They played like crap. 23.976fps progressive would stop and start very nastily like I mentioned above. 29.97fps pulldown material didn't display right on the telecined frames. I think that I am going to drop any work with VC-1 and focus on finding a solution with x264. I feel like I am close.


----------



## txporter (Sep 18, 2006)

Ok, I think I need to put h.264 encodings away again. This tearing/shimmering of the image appears to be a decode issue on the TivoHD/Series3. Also, even though I have always correlated hard-coded subs with this issue in my mind, it occurs even without them. It is just more difficult to pick up (easier to see with a static image). At any rate, I have adjusted just about every setting in x264 and still see the problem. I have verified that it does not exist on my computer and that the videos when transcoded to MPEG2 with ffmpeg play fine. Unless Tivo can do something on the software side of things, I think this will continue to exist. Does anyone know if it is possible for Tivo to adjust the decode of H.264 files with software, or is this solely a function of the hardware decoder?


----------



## moyekj (Jan 24, 2006)

txporter, I'm curious to see if original S3 units also have this tearing/shimmering decoding issue as I haven't noticed it, but then again I don't have hard subs in my clips. If you can make a short clip available that illustrates the problem perhaps I can give it a look see.


----------



## txporter (Sep 18, 2006)

Here is a link to download some test clips:
http://txporter.tonidoid.com:10001/app/websharepro/share/MP4%20testclips/

The first one is a 2min hardsubs sample of a Rescue Me episode. The second one is the same episode but with the same subtitle hardcoded basically from the beginning of the episode clip to the end (for some reason I never thought to do this before!). You should be able to use that one to step through the frames and see exactly how often or when the picture starts to change.

update: I added another test clip that I encoded with HCenc (MPEG2) instead of x264.


----------



## txporter (Sep 18, 2006)

@moyekj- Have you ever tried pushing a mp4 with softsubs? I have little experience with softsubing, but I am wondering if possibly Tivo might recognize them (not likely)?


----------



## moyekj (Jan 24, 2006)

txporter said:


> Here is a link to download some test clips:
> http://txporter.tonidoid.com:10001/app/websharepro/share/MP4%20testclips/
> 
> The first one is a 2min hardsubs sample of a Rescue Me episode. The second one is the same episode but with the same subtitle hardcoded basically from the beginning of the episode clip to the end (for some reason I never thought to do this before!). You should be able to use that one to step through the frames and see exactly how often or when the picture starts to change.
> ...


These mp4 files do not play back smoothly compared to the mpg version that's for sure. I also tried generating my own mp4 from test_clip-hcenc.mpg and it also turned out just as bad. However, from my own mpg sources I don't see that issue. For example take a look at this one:
http://tivostream.googlecode.com/files/oshort.mp4
For me it plays back nice and smooth which is easy to see from smooth scrolling text at bottom. Plays just as nice as source mpg clip.

If you have the original/unmodified TiVo source for the above test clip (i.e. direct from TiVo and just cut down to 2 minutes without any further processing) I'd be interested in getting hold of it to see if it suffers the same problem when encoding.


----------



## txporter (Sep 18, 2006)

moyekj said:


> These mp4 files do not play back smoothly compared to the mpg version that's for sure. I also tried generating my own mp4 from test_clip-hcenc.mpg and it also turned out just as bad. However, from my own mpg sources I don't see that issue. For example take a look at this one:
> http://tivostream.googlecode.com/files/oshort.mp4
> For me it plays back nice and smooth which is easy to see from smooth scrolling text at bottom. Plays just as nice as source mpg clip.
> 
> If you have the original/unmodified TiVo source for the above test clip (i.e. direct from TiVo and just cut down to 2 minutes without any further processing) I'd be interested in getting hold of it to see if it suffers the same problem when encoding.


I added the source file to the same link as above. It is DVD source rather than Tivo. Is your clip from a SD recording or resize from HD? I notice that you left it as 29.97fps. When I look at the clip in vdub, it looks like it is actually interlaced content (i.e. when separating fields it doesn't show the normal aabbccdd pattern that you see with progressive content, but rather looks like abcedfg where each field is unique...which is indicative of interlaced). So maybe this is re-sized 1080i content? Maybe the Tivo needs to see 29.97fps for H.264 content?

update: I added a clip that I did not IVTC back to progressive, but encoded it with telecined frames. It is 29.97fps. Playback looks ok on computer, but the interlacing is obvious on the telecined frames. I am not at home, so haven't had a chance to try on tivo. If you try it, let me know if it plays back ok or not.


----------



## moyekj (Jan 24, 2006)

txporter said:


> I added the source file to the same link as above. It is DVD source rather than Tivo. Is your clip from a SD recording or resize from HD? I notice that you left it as 29.97fps. When I look at the clip in vdub, it looks like it is actually interlaced content (i.e. when separating fields it doesn't show the normal aabbccdd pattern that you see with progressive content, but rather looks like abcedfg where each field is unique...which is indicative of interlaced). So maybe this is re-sized 1080i content? Maybe the Tivo needs to see 29.97fps for H.264 content?


 It's 480i source directly from TiVo recording of an SD channel. 720p (59.94fps) & 1080i (29.97fps) sources from TiVo with same encoding profile are also fine for me as well. My encoding profile uses same frame rate as source. I noticed your mp4 clips are 23.976fps but your source mpg is 29.97fps. Why change frame rate during encode?
I'll have to try a 23.976fps DVD source to see what happens but I do suspect that TiVo probably does better with 29.97fps or 59.94fps for H.264 decoding.

I'm not home now so can't try your 29.97fps mp4 clip until tonight.


----------



## txporter (Sep 18, 2006)

moyekj said:


> It's 480i source directly from TiVo recording of an SD channel. 720p (59.94fps) & 1080i (29.97fps) sources from TiVo with same encoding profile are also fine for me as well. My encoding profile uses same frame rate as source. I noticed your mp4 clips are 23.976fps but your source mpg is 29.97fps. Why change frame rate during encode?
> I'll have to try a 23.976fps DVD source to see what happens but I do suspect that TiVo probably does better with 29.97fps or 59.94fps for H.264 decoding.
> 
> I'm not home now so can't try your 29.97fps mp4 clip until tonight.


I remove the pulldown because it is easier to deal with for encoding (all progressive frames rather than 3 progressive and 2 telecined). If it displays fine though at 29.97 fps with telecined frames and fixes the playback issues...great. Will have to give it a whirl.

As far as your source, it is interesting. It's been a while since I have dealt with re-encoding/transcoding SD Tivo material, but I thought most everything that was 480i was NSTC film footage pulldown to 29.97fps. Apparently not.


----------



## txporter (Sep 18, 2006)

I added a couple of clips (23.976fps and 29.97fps) with softsubs now as well. They are muxed with mp4box rather than mp4creator since creator doesn't handle subtitles. Not sure if the opening scene will be garbled or not.


----------



## moyekj (Jan 24, 2006)

txporter said:


> I remove the pulldown because it is easier to deal with for encoding (all progressive frames rather than 3 progressive and 2 telecined). If it displays fine though at 29.97 fps with telecined frames and fixes the playback issues...great. Will have to give it a whirl.
> 
> As far as your source, it is interesting. It's been a while since I have dealt with re-encoding/transcoding SD Tivo material, but I thought most everything that was 480i was NSTC film footage pulldown to 29.97fps. Apparently not.


 Just tried the 29.97fps mp4 clip you generated and that certainly played back a lot more smoothly than the previous ones. I do have some DVD rips with 23.976fps which I will encode using my ffmpeg recipe and keep same frame rate to see how it goes. Will report back on that later.

UPDATE: Created mp4 from a progressive 2:3 pulldown 23.976fps DVD rip. ffmpeg actually converted that to progressive 59.94fps mp4 and that played back fine on TiVo. I guess I can try explicitly to specify preserve 23.976fps but I think it's becoming obvious here that TiVo likes 29.97fps or 59.94fps.


----------



## txporter (Sep 18, 2006)

Yes, it does appear to be framerate driven. The 29.97fps clips show no issue with the subtitle shimmering/flickering that I describe earlier. Actually, they do show issues when pausing and stepping through frames, but it does not ever show in the fullspeed play back. At least I know now how to fix it. The problem with the 29.97fps telecined mp4, is that the actual video playback is ugly. The tivo doesn't seem to handle the telecined frames well. I will have to see what can be done to improve this playback. I have tried encoding the video with x264 interlaced method (called MBAFF), but the tivo does not appear to actually look for field order flags on h.264 content. I will need to look at motion compensation filters with avisynth, I guess.

I also tried various methods of muxing the files to see if that made a difference in playback. No change in how the subtitles (still images) displayed. 23.976fps showed the problem, 29.97fps did not. I uploaded the clips with softsubs, and they did not display.

At least I know now that mp4box can be used to mux the files as well as mp4creator and eliminate the garbled opening scene. mp4box allows the muxing to happen in one command line instead of multiple like mp4creator. Not much of a difference really though, but you can create mp4s with softsubs as well (if you want to play them on something besides Tivo).


----------



## moyekj (Jan 24, 2006)

From progressive 2:3 pulldown 23.976fps DVD rip I mentioned in previous post I forced ffmpeg to keep 23.976fps just to see result - it was fine and playback was smooth. So I can't generalize that 23.976fps mp4 is no good for TiVo.

The difference is that my DVD rip showed these specs (from Mediainfo):

```
Width                            : 720 pixels
Height                           : 480 pixels
Display aspect ratio             : 16:9
Frame rate                       : 23.976 fps
Standard                         : Component
Resolution                       : 8 bits
Colorimetry                      : 4:2:0
Scan type                        : Progressive
Scan order                       : 2:3 Pulldown
```
Your Rescue.Me.S2E07-clip.mpg specs:

```
Width                            : 720 pixels
Height                           : 480 pixels
Display aspect ratio             : 16:9
Frame rate                       : 29.970 fps
Standard                         : NTSC
Resolution                       : 8 bits
Colorimetry                      : 4:2:0
Scan type                        : Interlaced
Scan order                       : Top Field First
```
The differences are perhaps because my DVD originated from film and yours from TV show?


----------



## txporter (Sep 18, 2006)

Hmm, ok. What was your ffmpeg encode string? ffmpeg just uses x264, so this is weird...


----------



## moyekj (Jan 24, 2006)

txporter said:


> Hmm, ok. What was your ffmpeg encode string? ffmpeg just uses x264, so this is weird...


What I used was below. I normally do not have -r 23.976 and let ffmpeg decide frame rate, which for my DVD source results in progressive 59.94fps without that option.
From your DVD source using the profile below with -r 23.976 results in same bad playback as your 23.976fps mp4 files, however if you encode without forcing that frame rate then it comes out fine (and 29.97fps frame rate).

```
FFMPEG -y -i INPUT -threads CPU_CORES -acodec copy -vcodec libx264 -flags +loop -coder ac -level 41 -b 3000k -refs 3 -bf 3 -me_method umh -subq 9 -me_range 16 -qmin 10 -qmax 50 -qscale 1 -sameq -g 24 -r 23.976 -f mp4 OUTPUT
```
Obviously adjust FFMPEG, INPUT, CPU_CORES and OUTPUT accordingly.

i.e. So far the above recipe without the -r 23.976 option has seemed to work pretty well for any SD mpeg2 source (with AC3 audio).

EDIT: This is using ffmpeg SVN-r21085 if that matters (which you can find in the kmttg win32 tools zip file).


----------



## txporter (Sep 18, 2006)

moyekj said:


> From progressive 2:3 pulldown 23.976fps DVD rip I mentioned in previous post I forced ffmpeg to keep 23.976fps just to see result - it was fine and playback was smooth. So I can't generalize that 23.976fps mp4 is no good for TiVo.
> 
> The difference is that my DVD rip showed these specs (from Mediainfo):
> 
> ...


I didn't catch your question at the bottom before. As far as DVD rips go, I haven't found there to be a difference in whether the DVD is 100% FILM (2:3 pulldown as yours) or whether it is mixed content (both 2:3 pulldown + interlaced fields on opening credits/scenecuts/wherever). In either case, I can force them back to 23.976fps and they both show the same issue with subtitles.

I have uploaded another sample to the download link (test_clip-29.97yadif.mp4). This is the same clip encoded progressive with the telecined frames de-interlaced with Yadif. It seems to look pretty good on my computer.


----------



## txporter (Sep 18, 2006)

Ok, some updates.

I converted a 100% FILM source (23.976fps with 2:3 pulldown) rather than mixed content like the Rescue Me clip. Same issue at 23.976fps with subtitle shimmering.

I tried changing the framerate of 23.976fps source material to 24, 25, and 29.97fps. 24fps still shows shimmering subtitles. 25fps does not and neither does 29.97fps. Converting to 25fps requires duplication of 1 frame/second (+1 more every 1001 frames), while converting to 29.97fps requires duplication of 6 frames/second. Some may pick up on jerky motion with the duplicated frames. I believe this is the same thing that ffmpeg does (duplicating frames to reach desired framerate). From a filesize standpoint, 25fps will be a bit smaller than 29.97fps since there are fewer frames per second.

I pushed the mp4 with pulldown up to the Tivo. The tivo does not respect the flags and it plays out of sync with the audio. This is currently not a solution.

I encoded a 1080i and a 720p clip and hardcoded the subtitles. As moyekj indicated above, they both play back with no subtitles issues at 29.97fps and 59.94fps, respectively.

So there appears to be a problem with framerates around 24 fps. For the time being, I will likely try to encode at 25fps for SD material and source framerate for 1080i/720p material.

Kevin, you may want to consider using crf with ffmpeg instead of forcing a bitrate and using --interlaced (that is for x264, not sure what the ffmpeg flag is) for 1080i material. The final encoding size with the interlace flag set is about 10% smaller than without it. The playback seems comparable with/without the flag though, so it might just be easier to keep the same profile for both 1080i and 720p. I haven't settled on a crf yet, but I think it will likely be around 21 for HD material (I use ~19 for SD).

For 1080i, 19 crf was 8250 kbps for a 2min clip, 21 crf was 6250 kbps.

For 720p, 19 crf was 7900 kbps for a 2min clip, 21 crf was 5600 kbps.

To me, the quality of crf 21 was just as good as 19. I will stick with that for now (and I can at least achieve some space savings with 720p then). I could probably safely go to a higher crf and still not sacrifice too much quality.


----------



## txporter (Sep 18, 2006)

I watched a couple of episodes at 25 fps and the jerky video was a bit too annoying. I decided to make a clip at 2x framerate (47.952fps) to verify that it was a minimum framerate issue not some multiple of 23.976 issue. Double framerate film material plays back fine as well. I also found that I could drop my bitrate quite a bit and be happy with the video quality. So doubling the framerate and moving to crf 21 leaves me with a mp4 that is still smaller than a comparable MPEG2 file with nice playback. I have sent a PM to TivoJerry about the film framerate playback issues and he was going to file a bug report for me. 

Also, just realised today that 720p material can be encoded at 29.97fps by just dropping all of the duplicated frames with decent final results. That cuts the file size down a lot. Anyhow, I think I have found some encoding settings that I am happy with finally for h.264. Thanks everyone for all your ideas and help. Hopefully, tivo can find a software solution for 23.976fps playback that will allow a bit more space sizings.


----------



## txporter (Sep 18, 2006)

txporter said:


> Also, just realised today that 720p material can be encoded at 29.97fps by just dropping all of the duplicated frames with decent final results.


This is not precisely correct. 720p material (House, Lie to Me, other 720p episodic shows) are really 24p film material that is pulled down to 29.97fps and then the rate is doubled. To me, that really doesn't seem like true 720p since you only have 4 unique frames for every 10 shown. :down:

At any rate, I took a 720p clip last night and rebuilt the original 23.976fps stream. As expected, the size savings is huge (even if just kept as MPEG2) but surprisingly, a 1280x720 23.976fps h.264 with hardsubs plays back totally fine on my TivoHD! No subtitle shimmer that I can see. This problem is just SO odd. There is apparently some resolution component to the playback as well?? I guess I will need to experiment a bit with some resizings to see if I can get SD material to play back at 23.976fps without shimmering.

TivoJerry has submitted the bug report for me now and I have included this thread in the info. Hopefully the folks there at Tivo can diagnose the problem in the decode software.


----------



## txporter (Sep 18, 2006)

txporter said:


> At any rate, I took a 720p clip last night and rebuilt the original 23.976fps stream. As expected, the size savings is huge (even if just kept as MPEG2) but surprisingly, a 1280x720 23.976fps h.264 with hardsubs plays back totally fine on my TivoHD! No subtitle shimmer that I can see. This problem is just SO odd. There is apparently some resolution component to the playback as well?? I guess I will need to experiment a bit with some resizings to see if I can get SD material to play back at 23.976fps without shimmering.
> 
> TivoJerry has submitted the bug report for me now and I have included this thread in the info. Hopefully the folks there at Tivo can diagnose the problem in the decode software.


This statement was a little hasty. I encoded some SD version at various resolutions and forcing various SARs, but they all still showed subtitle shimmer at 23.976fps. This forced me to take a closer look at the 720p encode at 23.976fps and it does shimmer, just not as noticeably (at least not visible when supine in bed!). So I am back to having an issue with displaying h.264 at certain framerates. I suppose that is better at having some combination of frame size/frame rate. Hopefully the folks at Tivo can come through for me.


----------



## orangeboy (Apr 19, 2004)

Once again resurrecting "old" thread with a question: How do you guys deal with mpeg2 > h264 washout?

I found this image as an example:









I've got several old videos that I'd like to transcode into mp4, but the results are similar to what the image depicts. I'm using ffmpeg to do the transcoding.


----------



## txporter (Sep 18, 2006)

orangeboy said:


> Once again resurrecting "old" thread with a question: How do you guys deal with mpeg2 > h264 washout?
> 
> I found this image as an example:
> 
> ...


Are you converting from HD to SD resolutions? It looks like it might be what happens if you do not convert from BT.709 --> BT.601. I don't use ffmpeg for conversion, but there is a filter for avisynth that I use when doing HD to SD resolution changes called Colormatrix. It attempts to keep color consistency between those colorspaces. The standardized format for HD video is BT.709. The standard for SD is BT.601. Frankly, a lot of this particular subject is way above my head, but I have read a few threads and asked some questions about it on videohelp.com and doom9.org. I don't think you can adjust colors with ffmpeg without use of avisynth (avs files).


----------



## orangeboy (Apr 19, 2004)

txporter said:


> Are you converting from HD to SD resolutions? It looks like it might be what happens if you do not convert from BT.709 --> BT.601. I don't use ffmpeg for conversion, but there is a filter for avisynth that I use when doing HD to SD resolution changes called Colormatrix. It attempts to keep color consistency between those colorspaces. The standardized format for HD video is BT.709. The standard for SD is BT.601. Frankly, a lot of this particular subject is way above my head, but I have read a few threads and asked some questions about it on videohelp.com and doom9.org. I don't think you can adjust colors with ffmpeg without use of avisynth (avs files).


Thanks - I'll look into avisynth. For the most part though, I'm converting old SD dvd rips, some converted into VCD format. And they are OLD (1970's), so _any_ degradation I'm trying to avoid like the plague (and I know there's a cost with any transcode).


----------



## txporter (Sep 18, 2006)

orangeboy said:


> Thanks - I'll look into avisynth. For the most part though, I'm converting old SD dvd rips, some converted into VCD format. And they are OLD (1970's), so _any_ degradation I'm trying to avoid like the plague (and I know there's a cost with any transcode).


I'd suggest posting on videohelp.com (maybe in the Video Conversion forum) about it. There are a few folks that frequent it that will likely be able to pinpoint your issue very quickly. If you do go down the path of learning to use avisynth, there are a lot of things that you can do with your video (removing grain and banding, color manipulation, cropping, resizing, de-interlacing, sharpening, etc etc).


----------



## txporter (Sep 18, 2006)

Update on the shimmering subtitle issue: TivoJerry wrote me today that there is still no movement on my bug report for 23.976fps H.264 on TivoHD. He doesn't expect anything to happen quickly on it or possibly at all. However, he did confirm that this is not an issue on Premiere. At least that's something.


----------



## LoREvanescence (Jun 19, 2007)

wmcbrine said:


> On my S3, I often see a grey screen for the first few seconds of an MP4, unless I rewind. This isn't limited to pyTivo pushes -- I see it on Web Videos (TiVoCasts). Tekzilla doesn't do it, though.


Oh my S3 I see the same thing, only with the black screen. But Rarely, maybe once in 20 plays. It will only doe it on SD h.264 and when it does it it is only once, and I can play a bunch of additional h.264 videos with out ever seeing the problem.

I am also seeing another odd problem, but it's happened on a couple mpeg2 videos as well, but seeing it more on h.264. Every once in awhile when I start playback of a video, the screen will go black. There is no video or audio playing. This condition may last from 1 to 3 minutes. Hitting any button on the tivo remote does nothing but flash the remote led. No sound effects, hitting tivo does not bring you home. The first couple times i saw this I thought the tivo frooze and I was going to have to pull the power. But The video will then all the sudden just start to play 1 to 3 minutes later with out any pixilation and everything is fine. Any buttons you hit during the black screen period are ignored, so if you hit tivo home it's not going to bounce you home once the video starts playing, the video just plays as normal.


----------



## txporter (Sep 18, 2006)

I tried watching some shows that I have encoded with x264 at 23.976fps today (with hardcoded subs) on my TivoHD. I am not seeing the subtitle shimmering issue that I reported in this thread any more. I have written TivoJerry to see if Tivo has actually made some changes to fix this on their end, but I have gotten confirmation yet. At any rate, it appears to have been fixed.


----------

