Problem with beginning of 2-pass encoded video
by William Lipinski on Jul 4, 2011 at 5:50:26 am
So I'm trying to use 2-pass encoding on an uncompressed avi to produce a good-looking mp4. The presets are read correctly and everything goes fine during encoding. Then, once the video is uploaded to youtube, I find out that the first few seconds are a blocky mess, as here:
I've isolated the problem to the 2-pass aspect because single-pass encoding doesn't cause the issue:
is the same video but done in single-pass (qscale 5). The curious thing is that I've used these exact settings to make 2-pass encoded videos in the past, and those looked fine once uploaded, but now I can try over and over again without any luck. I don't see the effect when I run the files in media player classic; possibly it isn't introduced until youtube processes it, but there must be some reason why these particular videos won't process properly.
I was previously trying to use a fastfirstpass preset for the first pass, but that gave me an error so that the encode would stop at the beginning of the second pass. Ultimately I decided that the speed of the encode wasn't so big a deal for me, so I gave the first pass the same preset as the second and it ran after that.
Can anyone diagnose the cause of this problem at the beginning of the first video? I would love to switch to 2-pass, but I'm stuck on single-pass until I find out what I'm doing wrong.
Re: Problem with beginning of 2-pass encoded video by Michael Rampe on Jul 4, 2011 at 10:42:12 pm
[William Lipinski]"Can anyone diagnose the cause of this problem at the beginning of the first video? I would love to switch to 2-pass, but I'm stuck on single-pass until I find out what I'm doing wrong."
I have also experienced this. My advice would be to use 1pass encoding with -crf rate control. This is AS GOOD as a 2pass encode using -b rate control. As you are going to youtube and do not have to deliver a set bitrate, this would be your best option. In libx264, -crf ranges from 1 (best) to 51 (poorest). Do some experimentation to find the best results for your needs.
If you really are dead set on the -b rate control, try experimenting with different values for -g. This represents the GOP size and smaller values might be another solution to the youtube wierdness.
Re: Problem with beginning of 2-pass encoded video by William Lipinski on Jul 5, 2011 at 5:27:12 am
Thanks for the advice! I switched to a single-pass script and am getting good results with -crf 12. For whatever reason, my media player even seems to like these products better; with qscale, MPC would always lag on the video while audio played through at normal rate, although it was moot because it was all going into youtube anyhow.
This seems quite suspect to me but I am currently uploading a baseline profile video (no B-frames) to make sure. If it is true, it is quite a letdown from youtube;-(
Dark Shikari (aka Jason Garrett-Glaser - developer of x264) states that youtube has a broken mp4 demuxer.
I followed his suggestions and rewrapped the file to an mkv wrapper.
$ffmpeg -i badfile.mp4 -vcodec copy goodfile.mkv
This worked (no grey mess at the start) with the B-frames intact.
My other test (without B-frames) also worked but who wants to be using a baseline profile for HD video.... no one;-)
Re: Problem with beginning of 2-pass encoded video by William Lipinski on Jul 7, 2011 at 1:18:03 am
Wow, nice find. Used your exact line of code (plus an audio codec specification) to turn the original useless mp4 into this youtube-functional mkv:
Great to know that the problem wasn't some errant codec on my end. Bit strange to learn that youtube struggles with mp4, but I'm happy to have the mystery solved. Thanks again.