Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Compression Techniques Problem with beginning of 2-pass encoded video

  • Problem with beginning of 2-pass encoded video

    Posted by William Lipinski on July 4, 2011 at 5:50 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: https://www.youtube.com/watch?v=PZ5v7N9g7Iw

    I’ve isolated the problem to the 2-pass aspect because single-pass encoding doesn’t cause the issue: https://www.youtube.com/watch?v=2ZLZgURPKI0 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.

    Here’s the script:

    ffmpeg -i C:ffmpegmovie%1 -bf 16 -pass 1 -vcodec libx264 -vpre libx264-%3 -b %2k -bt %2k -threads 0 -f mp4 -y NUL
    ffmpeg -i C:ffmpegmovie%1 -bf 16 -vcodec libx264 -pass 2 -acodec libfaac -ab 128k -ac 2 -bt %2k -b %2k -threads 0 -vpre libx264-%3 C:ffmpegmovie%1%4_encoded.mp4

    And the preset details for good measure (typically I use 6000 for %2, so the bitrate target is 6000k):

    coder=1
    flags=+loop
    cmp=+chroma
    partitions=+parti8x8+parti4x4+partp8x8+partb8x8
    me_method=umh
    subq=8
    me_range=16
    g=250
    keyint_min=25
    sc_threshold=40
    i_qfactor=0.71
    b_strategy=2
    qcomp=0.6
    qmin=10
    qmax=51
    qdiff=4
    bf=4
    refs=4
    directpred=3
    trellis=1
    flags2=+bpyramid+wpred+mixed_refs+dct8x8+fastpskip

    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.

    William Lipinski replied 15 years, 1 month ago 2 Members · 5 Replies
  • 5 Replies
  • Michael Rampe

    July 4, 2011 at 10:42 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.

    Michael

  • William Lipinski

    July 5, 2011 at 5:27 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.

    Regardless, problem solved. Cheers!

  • Michael Rampe

    July 6, 2011 at 9:45 pm

    [William Lipinski] “Regardless, problem solved. Cheers!”

    Maybe.

    I just replicated your problem and also got the grey frames at the start using the -crf 1 pass method I suggested.

    After some searching I found this post on the youtube support site:
    https://www.google.com/support/forum/p/youtube/thread?tid=33d1cf29da811e45&hl=en

    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;-(

    Michael

  • Michael Rampe

    July 6, 2011 at 11:37 pm

    OK. did some more digging and testing and got some solid results and answers.

    To use a football metaphor, this is a case of “it is the ball, not the player”

    Check out this post:
    https://doom10.org/index.php?topic=1343.0

    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;-)

    Michael

  • William Lipinski

    July 7, 2011 at 1:18 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:
    https://www.youtube.com/watch?v=guyr8mxu4hE
    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.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy