How to convert mpeg2 to mp4 (h264) with NVENC ?

Hi Guys,

does anyone know how to convert a mpeg2 to mp4 (h264) with NVENC?

My setup is like this:

  • NVIDIA GTX 750 TI (Maxwell)
  • Windows 7 Pro
  • NVIDIA 335.23 Driver
  • NVENC 3.0 SDK

It’s doing fine if I pass a *.YUV Video file to the “nvEncoder_32.exe” but it isn’t working if I pass a *.mpeg file to the “nvEncoder”.

This is the Commandline that I use:

nvEncoder_32 -configFile=config.txt -outfile=output.264

Doesn’t work with Input.mpg → “inFile = input.mpg”

Commandline Verbose for not working mpg file:

External Media

Result:

External Media

But if I convert via “ffmpeg” the “input.mpg” to “input.yuv” and pass it to nvEncoder it’s working fine:

Working fine with Input.yuv → “inFile = input.yuv”
Result:

External Media

And this is my config.txt file:

///////////////////////////////////////////////////////////
// H.264 encoder parameter file
// syntax: [parameter [=] value] [[#|//] comment]
///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////
// Profile, Level

profile           = 100        // 66=Baseline, 77=Main, 100=High, 0=auto(=lowest possible profile)
level             = 40        // 10,11,12,13,20,21,22,30,31,32,40,41,42,50,51=level_idc, 0=auto(=lowest possible level)

///////////////////////////////////////////////////////////
// sequence structure

gopLength           = 25       // IDR frame distance
numBFrames          = 1        // number of B frames between I and P frames
fieldMode           = 1        // 0=prog frame, 1=field
bottomfieldFirst    = 0        // 0=top field first, 1=bottom field first
numSlices           = 1        // 0=auto, 1..PicHeightInMbs=number of slices per picture

///////////////////////////////////////////////////////////
// Input File Details
width           = 1920	// Width of Input Frame
height          = 1080      // Height of Input Frame
maxwidth        = 1920      // Max Width for resource allocation. Max resoultion  change during reconfiguration can not go beyond  MaxWidth, MaxHeight
maxheight       = 1080      // Max Width for resource allocation. Max resoultion  change during reconfiguration can not go beyond  MaxWidth, MaxHeight
inFile          = input.mpg


// Driver COde Path property
preset          = 5	    // 0=NV_ENC_PRESET_DEFAULT, 1=NV_ENC_PRESET_LOW_LATENCY_DEFAULT, 2=NV_ENC_PRESET_HP, 3=NV_ENC_PRESET_HQ, 4=NV_ENC_PRESET_BD, 5=NV_ENC_PRESET_LOW_LATENCY_HQ, 6=NV_ENC_PRESET_LOW_LATENCY_HP
interfaceType   = 2         // 0=DX9, 1=DX11, 2=CUDA, 3=DX10
syncMode        = 0         // 0=AsyncMode, 1=SyncMode

    

///////////////////////////////////////////////////////////
// bitstream characteristics (Type I HRD)

maxbitrate        = 2000000  // Peakbitrate, maximum bitrate (bits/sec), 0=use encoder defined default (level limit)
vbvBufferSize     = 2000000  // vbvBufferSize, decoder buffer size (bits), 0=use encoder defined default (level limit)
vbvInitialDelay   = 1000000  // vbvInitialDelay, initial decoder buffer fullness (bits), 0=use encoder defined default (50%)

///////////////////////////////////////////////////////////
// rate control

rcMode              = 8        // 0=fixed QP, 1=VBR, 2=CBR, 4=VBR_MINQP, 8=CBR_TWOPASS
bitrate             = 2000000  // average bit rate (bits/s) (ignored if RCMode != 1)
enableInitialRCQP   = 1
initialQPI          = 28       // If enableInitialRCQP set then It will be used as InitialQP value for I slices for RCMode !=0. constant QP value for I slices For RCMode =0.
initialQPP          = 28       // If enableInitialRCQP set then It will be used as InitialQP value for P slices for RCMode !=0. constant QP value for P slices For RCMode =0.
initialQPB          = 34       // If enableInitialRCQP set then It will be used as InitialQP value for B slices for RCMode !=0. constant QP value for B slices For RCMode =0.
frameRateNum        = 16
frameRateDen        = 0


///////////////////////////////////////////////////////////
// picture type decision

enablePtd           = 1        // 1=picture type decision will be takane by Encoder driver. 0=picture type decision will be takane by application

Can anyone help me please?! I don’t want to convert mpeg to yuv and pass it then to nvEncoder I just want to pass the mpeg file directly to the nvEncoder to generate a h264 file.

Any help would be much appreciated!

Thanks in advance!

As you’ve already discovered, the nvEncode sample-app doesn’t have a built-in MPEG-decoder – it only accepts uncompressed frame input. With some work, you can modify the nvEncode app to use the NVCUVID API to decode mpeg-2/vc-1/mpeg-4/h264 bitstreams into uncompressed YUV. Then feed the decoded output back into the NVENC block.

If you’re running on the Windows platform, NVCUVID has the added benefit of a built-in MPEG-2 transport stream/MPEG-4 program stream demuxer. (I know it works for muxed-streams with only 1 video elementary stream – I don’t know what happens if multiple videostreams are present.)

To see an example of the above concept, download the source-code for “nvenc_export”. The package contains a command-line utility “nVencode2.exe” which pretty much does exactly the above – a frankenstein creation from joining the (video decoder) NVCUVID sample with the NVENC encoder sample, resulting in a ‘proof of concept’ transcoder. Many things don’t work correctly (stereoscopic, interlaced video, 4:4:4 H264, etc.), but it should handle any main-profile video just fine.

Note, that codebase is written from the NVENC 2.0 SDK. The headerfile was updated for the 3.0 API, but main application source-code wasn’t updated to the 3.0 SDK’s version (due to significant changes already having been made to original sample-apps.)

source-code link (1.07) is here: [url]Adobe Support Community