ljubobratovicrelja / ffmpeg-d

D port of the FFmpeg C headers
16 stars 9 forks source link

sws_scale reports null value #2

Closed zeyonaut closed 8 years ago

zeyonaut commented 8 years ago
if(rawFrame.data.ptr == null || rawFrame.linesize.ptr == null || convertedFrame.data.ptr == null || convertedFrame.linesize.ptr == null) return;
                    sws_scale(imageConversionContext, (cast(AVPicture*)rawFrame).data, (cast(AVPicture*)rawFrame).linesize, 0, cameraCodecContext.height, (cast(AVPicture *)convertedFrame).data, (cast(AVPicture *)convertedFrame).linesize);

As you can see, the code checks for any null values.

[swscaler @ 0x7f9bc10ba000] One of the input parameters to sws_scale() is NULL, please check the calling code

Why is this happening? Thanks in advance.

FFMPEG version 2.7.6

ljubobratovicrelja commented 8 years ago

Hey, I had the same issue a while ago. The message is bit confusing - it's not only if the passing pointers are null, but also if data and linesize values are valid for the format you are using. For e.g. if you want to convert AV_PIX_FMT_YUV420P to AV_PIX_FMT_RGB24, where yuv420p has 3 data planes, where it's linesize is [rowstride, rowstride/2, rowstride/2, null, null...], and the rgb24 is the single plane format, having the linesize for it's data in format [rowstride*3, null, null...]. So basically, this error you're having is probably because you didn't configure output picture the right way. Can you tell me more precisely, what are you doing with sws_scale that gives you this error message?

ljubobratovicrelja commented 8 years ago

Also, this is not really an issue of the ffmpeg-d - I think it's more like the lack of documentation and online support for ffmpeg itself that had us confused on this matter. I've opened up a gitter room for this repo, so we can discuss such topics there. And just as a hint - wherever you have the problem in the runtime, there's really a small chance that issue is in ffmpeg-d, but rather in the ffmpeg implementation. This error message, I believe, would come up as well if you called the sws_scale from c/c++ with same values.

zeyonaut commented 8 years ago

Since you identified this problem as not that of ffmpeg-d, I replied on the gitter for this repo.

By the way, what do you mean by configuring the output picture? I'm not exactly sure how you could go about doing that. Is it something to do with avpicture_fill?

Feel free to close this thread, I suppose.

ljubobratovicrelja commented 8 years ago

Hey Aaron, I found the problem. The sws_scale function interface in ffmpeg-d is not correct. Currently it is defined as:

int sws_scale(SwsContext *c, const uint8_t *  []srcSlice,
              const int []srcStride, int srcSliceY, int srcSliceH,
              const uint8_t* []dst, const int []dstStride);

But really it should be:

int sws_scale(SwsContext *c, const uint8_t **srcSlice,
              const int *srcStride, int srcSliceY, int srcSliceH,
              const uint8_t**dst, const int *dstStride);

The syntax [] defines a dynamic array, where in the C declaration of the sws_scale the [] actually is just a pointer, or better put, a pointer array. I'll go fix the problem, and mark the issue resolved as soon as I'm done. Please note there could be more cases such as this in the library. I'll search for those myself, but if you or anyone spots another declaration like this, please notify me by filing an issue, or better yet, fix the problem and make a pull request! - I'd be really grateful!

But still, it's not clear to me how the current declaration links to the swscale library at all. It would be a nice question to someone who understands the low level implementation of the dynamic arrays in D.

ljubobratovicrelja commented 8 years ago

Fixed - commit https://github.com/ljubobratovicrelja/ffmpeg-d/commit/9f5506b58a54eb51e260ccdf8b1389fba244353a