"NV_ENC_ERR_INVALID_VERSION" error while using nvenc encoder - encode

I am using the cuda nvenc encoder to encode an YUV frame. I want to stream the encoded h264 data using RTSP streaming. I need the SPSPPS buffer to do RTSP stream. I am using "nvEncGetSequenceParams" to get the spspps buffer. I have called this function after calling the "nvEncInitializeEncoder" function as expected. I am getting the "NV_ENC_ERR_INVALID_VERSION" error which means I am passing wrong struct to this function. but I have checked multiple times the struct I have passed is correct. I think this can be driver version problem. I have Quadro k5000 GPU. I have tried this on driver version 331.82 and 337.88. Following is the code I am using.
NVENCSTATUS CNvEncoderH264::GetSPSPPSBUffer(char *SPSPPSBuffer)
{
NVENCSTATUS nvSta = NV_ENC_SUCCESS;
uint32_t size = 0;
//m_spspps is of type NV_ENC_SEQUENCE_PARAM_PAYLOAD
m_spspps.inBufferSize = 512;
m_spspps.outSPSPPSPayloadSize = &size;
SET_VER(m_spspps, NV_ENC_INITIALIZE_PARAMS);
m_spspps.spsppsBuffer = SPSPPSBuffer;
nvSta = m_pEncodeAPI->nvEncGetSequenceParams(m_hEncoder,&m_spspps);
return nvSta;
}

You are setting the wrong version macro to the SPS/PPS structure. I don't have my NVIDIA code by hand, so I'll try to Google the right macro but rule of the thumb is that each structure has a specific version macro (ans you are using NV_ENC_INITIALIZE_PARAMS for the SPS/PPS structure which is definitely not right. I assume the type of m_spspps is NV_ENC_SEQUENCE_PARAM_PAYLOAD. So you should initialize it like this:
m_spspps.version = NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;

Related

msvc trying to compile cv::Matx<float,3,1> as a 4-element vector

Using MSVC 2017, OpenCV 3.4. Code
typedef Vec3f localcolor;
inline double lensqd(const localcolor & c) {
return c.ddot(c);
}
Get
error C2338: Matx should have at least 4 elements. channels >= 4
note: while compiling class template member function 'cv::Matx<float,3,1>::Matx(_Tp,_Tp,_Tp,_Tp)'
when compiling the ddot function.
The compiler is trying to instantiate a 3-element vector with 4 initializers. I can't see anything in the OCV source code that would make this happen.
So do I file a bug report with MS?
And how do you suggest I get a working build? The code is this way because I sometimes want
typedef Vec4f localcolor;
which BTW compiles without error.
Could you show the ddot function ?
I recently had the same error by attempting to initialize a Vec3f with 4 elements.

puts(NULL) - why doesn't WP+RTE complain?

Consider this small C file:
#include <stdio.h>
void f(void) {
puts(NULL);
}
I'm running the WP and RTE plugins of Frama-C like this:
frama-c-gui puts.c -wp -rte -wp-rte
I would expect this code to generate a proof obligation of valid_read_string(NULL); or similar, which would be obviously unprovable. However, to my surprise, no such thing happens. Is this a deficiency in the ACSL specification of the standard library?
Basically yes. You can see in the version of stdio.h that is bundled with Frama-C that the specification for puts is
/*# assigns *stream \from s[..]; */
extern int fputs(const char * restrict s,
FILE * restrict stream);
i.e. the bare minimum, an assigns clause (plus a from clause for Eva). Preconditions on s and stream. Adding a precondition on s would be easy; things are more complex for stream since you need a model for the various objects of type FILE.

PCL 1.8.1 crash on cloud delete after StatisticalOutliersRemoval

I have an application which is build using several DLL files.
I'm trying to perform PCL's statistical outliers removal using the following code:
PointCloudWithRGBNormalsPtr pclCloud(new PointCloudWithRGBNormals());
ConvertPointCloudToPCL(in_out_cloud /*my own structure which includes xyz, rgb, nx ny nz*/, *pclCloud);
pcl::StatisticalOutlierRemoval<PointXYZRGBNormal> sor;
sor.setInputCloud(pclCloud);
sor.setMeanK(10);
sor.setStddevMulThresh(1.0);
sor.filter(*pclCloud);
ConvertPointCloudToPCL:
static void ConvertPointCloudToPCL(const std::vector<Cloud3DrgbN> &in, PointCloudWithRGBNormals &output)
{
for (auto it = in.begin(); it != in.end(); it++)
{
const Cloud3DrgbN &p3d = *it;;
PointXYZRGBNormal p;
p.x = p3d.x;
p.y = p3d.y;
p.z = p3d.z;
p.normal_x = p3d.nX;
p.normal_y = p3d.nY;
p.normal_z = p3d.nZ;
p.r = p3d.r;
p.g = p3d.g;
p.b = p3d.b;
output.push_back(p);
}
}
For some reason, if I call this function from 1 of my dlls it works as it should. However, there's 1 dll that if I call it from it, when pclCloud goes out of scope, I'm getting an exception from Eigen's Memory.h file at the handmade_aligned_free function
I'm using Windows 10 64-bit, pcl 1.8.1 and Eigen 3.3 (tried 3.3.4, same thing)
Update:
After further digging, I've found that EIGEN_MALLOC_ALREADY_ALIGNED was set to 0 because I'm using AVX2 in my "problematic" DLL. I'm still not sure though why using Eigen's "handmade" aligned malloc/free causes this crash.
There seems to be a known issue (see this) with Eigen, PCL & AVX
Well I found the problem and how to solve it.
It seems that the DLLs that comes with the "All in 1 installer" for windows weren't compiled with AVX/AVX2 support.
When linking these libraries with my own DLLs, the ones that compiled using the AVX, this mismatch caused Eigen to use the different types of allocations and freeing of memory causing the crash.
I compiled PCL from source using AVX2 and linked these library and everything works.
It's worth mentioning that the DLL that worked before now has issues since it doesn't have AVX and PCL now do.

F# interactive Marshal.SizeOf with Mono throws “assertion” error

I am trying to read a GIF file header into a structure with F#, using Mono 5.8 on Mac OSX. The following code sample works fine in Visual Studio 2017 on Windows 10; however, when I try to run it in Visual Studio for Mac, I get the following error in F# interactive:
* Assertion at class-accessors.c:138, condition `mono_class_has_static_metadata (klass)' not met
The code I am using is below. The structure is probably incorrect since I just threw it together quickly for the question, but
open System
open System.IO
open System.Runtime.InteropServices
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type GifHeader = {
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
signature: string
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
version: string
logicalWidth: int16
logicalHeight: int16
}
When I invoke Marshal.SizeOf(typeof<GifHeader>) in Visual Studio for Mac's FSI, I get the error mentioned above.
I noticed that when I am reading into a structure like:
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type SomeOtherHeader = {
field1: uint16
field2: int32
field3: int16
field4: float
}
i.e. with no MarshalAs UnmanagedType specification, the error is not thrown.
Does anyone know what this error means? I haven't seen any other instances of this particular error on Google or other SE posts, and it is especially puzzling since it doesn't occur on Windows/.NET Framework 4.7. Not having the interactive window to test code is a massive hindrance for learning, and quite frustrating since I don't think it's possible to use an alternative (non-Mono) FSI.
This was an issue intrinsic to the current Mono release. Per the Mono team, this has been fixed as of Mono 5.14.

openCV 3.0, openCL and meanShiftFiltering

Based on the changes in openCV 3.0 and openCL, I can not seem to get pyrMeanShiftFiltering to work using openCL. I know that ocl::meanShiftFiltering was supported in openCV 2.4.10. The two functions below take the same amount of time to execute.
How can I even check which functions in openCV 3.0 are supported under openCL? Any suggestions?
#include <opencv2/core/ocl.hpp> //attempting to use openCL
using namespace cv;
using namespace ocl;
void meanShiftOCL()
{
setUseOpenCL(true)
UMat in, out;
imread("./images/img.png").copyTo(in);
pyrMeanShiftFiltering(in, out, 40, 20, 3);
}
//not using openCL
void meanShift()
{
Mat in, out;
imread("./images/img.png").copyTo(in);
pyrMeanShiftFiltering(in, out, 40, 20, 3);
}
I'm not sure that there is simple way to determine it with given OpenCV binaries, but you can recompile OpenCV yourself with additional define (can be specified in cmake):
CV_OPENCL_RUN_VERBOSE
With this define every function for which OpenCL implementation is available will print to console (stdout) the following message:
<function name>: OpenCL implementation is running
Regarded to your question - currently pyrMeanShiftFiltering doesn't have OpenCL implementation, as I know.

Resources