0

I have gameplay footage recorded with ShadowPlay (“GeForce Experience”) at 60 FPS, which as I understand results in variable frame rate, because the game drops frames sometimes. However, trying to use this video in Adobe Premiere results in the game audio severely falling behind the visuals, because Premiere treats it as if every frame was the same length.

I have tried HandBrake with these settings:

Quality: constant, RF 0 (lossless)
FPS: 60, constant
Detelecine: Off
Decomb: Off
Denoise: Off
Deblock: Off

But the output video is not only much smaller than the source video, but it's massively worse in terms of visual quality. Why isn't it lossless when I've set it to what it claims is lossless?

Input video info: http://pastebin.com/7Tss4brj
Output video info: http://pastebin.com/DKFEzDKk (from Mediainfo)

How can I convert a variable framerate video to a constant framerate video losslessly?

10
  • If you have mediainfo, can you post the readout for your output. Use View->Text mode.
    – Gyan
    Feb 6, 2017 at 19:25
  • Hope this helps: Input video info: pastebin.com/7Tss4brj Output video info: pastebin.com/DKFEzDKk Feb 7, 2017 at 10:56
  • Technically, not lossless as RF is recorded as 1 not 0. Still, it shouldn't be "massively worse in terms of visual quality". How are you testing playback?
    – Gyan
    Feb 7, 2017 at 11:36
  • Playing it in VLC or previewing in Premiere. It has huge compression artifacts all over the place, especially with rapid movement. Feb 7, 2017 at 11:55
  • Hm, just compared screenshots from the two videos in VLC and it seems about equal. The preview in Premiere is far worse. Let me investigate. It might be an issue with Premiere. Still, why is it RF 1 when I've set it as 0 and why is the output file so much smaller? Feb 7, 2017 at 12:10

2 Answers 2

3

To start with: your version of Handbrake is old. Version 1.0.3 came out very recently, it's got some improvements over that older version.

Second, CQ0 is not actually "lossless." It's aiming for "lossless" quality, but it's going to bump up against the data rate limitations of the H.264 Level, so while it might need, say, 100MbPS at a given point to achieve "lossless" compression, Level 4.0 might be capping it at 20MbPS or something like that. Note in the Encoding Settings readout on your export file it lists "vbv_maxrate=20000," that's where your bitrate is capped. So to get as close to lossless as possible you'd need something like Level 5.2.

So ratcheting up your H.264 level will improve quality, but Premiere may end up chugging very hard on it. H.264 is really bad for editing. It's very computationally complex, largely because it doesn't store each frame separately (called Intraframe compression) but it takes batches of frames (called a Group of Pictures, or GOP) and compresses them together, in such a way that any one frame within a GOP will depend on the surrounding frames in order to reproduce a complete image. This is called Interframe compression, and the number of frames in a GOP depends on the parameters set at encode time, and may even be variable (not typical), but you can see what those parameters in MediaInfo by noting the line that says "Format settings, GOP" ("N=30" means 30 frames per GOP), or looking at the encoding settings where it notes "keyint" (Keyframe Interval). So needing to decode all 30 frames to show you any one frame is very CPU and RAM intensive.

If you've got the storage I'd recommend considering using DNxHD, which is a "mezzanine" (editing friendly) codec that preserves quality, considered "virtually lossless," but has low CPU/RAM impact. The catch is very high bitrates. So we're talking ~130-200GB/hr at 1080p59.94. The other catch is that DNxHD has very limited supported resolutions and frame rates. There's also CineForm which is just as high a quality, but far more flexible, and both CineForm and DNxHD are natively supported by Premiere (CineForm in 2015 and later) but last I checked CineForm support in other tools, like ffmpeg, is lacking.

So are more editing-friendly solution would be to use ffmpeg to make DNxHD with a command line the following:

ffmpeg -i (input file).mp4 -c:v dnxhd -b:v 290M -c:a pcm_s16le -r 60 (output).mxf

That would make DNxHD with uncompressed audio in an MXF Op1a file. You could also whack .mov on the end there and make a Quicktime file instead just as easily. Note that -r sets the output frame rate. You could try using H.264 in ffmpeg by changing the video codec (-c:v), but you'll run into the same limitations as you would working with Handbrake, so I don't know if it's really worth it to go into that here.

4
  • CQ0 is actually lossless. If you do a SSIM compare with the source, the metric result will be 1.0 i.e. perfect fidelity. H.264 levels are meant for hardware decoders, so they can gracefully decline to decode a stream beyond their capabilities, instead of rendering a stuttering playback. But they don't constrain x264. It will complain if your resolution/bitrate exceeds an explicitly set level but proceed nonetheless.
    – Gyan
    Mar 5, 2017 at 5:03
  • To reduce decoding burden, you can always set a low GOP size and disable B-frames. I don't use Handbrake, but it's easily done with ffmpeg. DNxHD will use more bandwidth than necessary.
    – Gyan
    Mar 5, 2017 at 5:15
  • I'm not sure if h264 cq0 is lossless in terms of bit depth.. i mean.. if you go from 8 bit to 8 bit is ok.. if 10 or 12 to 8 you will have a loss unless a 16 bit version of h264 crf 0 is available.. @Mulvya do a 16 bit per component + alpha option exists ? Dec 3, 2017 at 0:35
  • Alpha is not available, and x264 does 8 and 10 bit only.
    – Gyan
    Dec 3, 2017 at 4:50
0

I record my Shadowplay content with the following settings:

  • 1440p
  • 50MBps
  • 60 FPS
  • Microphone and Desktop Audio on seperate channels

So it's not compatible with the mentioned DNxHD. The audio channels are are also in variable framerates and must be synced.

The following will re-encode the video and audio in 60 FPS CFR and will not have audio sync issues in Adobe Premier. You save it to a batch file (.bat) and then run it via the command line with the video file as the first argument.

@echo off
set inputFile=%1
set outputFile=%inputFile:.mp4=_cbr.mp4%
ffmpeg  ^
-i %inputFile% ^
-vsync 1 -async 1 ^
-map 0:v:0 ^
    -c:v libx264 ^
    -preset veryfast ^
    -x264-params "nal-hrd=cbr" ^
    -b:v 50M ^
    -framerate 60 ^
-map 0:a:0 ^
    -c:a:0 aac ^
    -b:a 384k ^
-map 0:a:1  ^
    -c:a:1 aac ^
    -b:a 384k ^
%outputFile%

When comparing individual frames, I did not notice a difference in quality between this and the original recording. You can change some of the options like the framerate to match your content, or increase the bitrate if you think there is some loss.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.