-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
corrupted images #9
Comments
are you manage to solve it? |
Nope |
Bro. U try adjust the quality. It reduces the probability to get corrupted
|
hi, |
i adjust this thing on rtsp-ffmpeg.js. hope it helps |
Try to use canvas instead of image object. img tag has problem updating the src element in a real time updating enviroment and with large resolution images. |
I will upload an example with canvas Image drawing that works for me with large resolution images and base64 encoding |
Hi all! I have recently uploaded and example with canvas instead of img tag that resolve the problem. You can check in server-canvas.js and index-canvas.html inside of example folder. |
HI, |
my current solution right now is reduce your ip cam video size. as lowest as possible but you can try on which settings are the best. |
Hi daniel, can you put here the code of the client side? Be sure that you are not making any conversion or codification of the image data, only take the array from the server and cast to uint8 array and convert it to blob type. You can see the javascript console output and the network messages from the navigator and check if something is going wrong |
Hi, |
So try in the drawImage method use the parameters width and height on index-canvas file. Check also the value of array data and or if the console shows any message of error. I tested this example with two ip cams with big video resolution and works well, so i think it is not a problem of resolution |
@Seikon noted thanks |
@harithFED you are welcome. If you noticed any problem please tell us. For example yesterday I discovered a problem with safari for mobile version and I am working on solve it. @plandevida Could you solve the problem? |
Hi, I also have the problem. |
Hi! Could you describe in depth how are you using the library? I think both of you have the corrupted images on client side. Manage this problem with canvas example and server canvas instead of targeting the image directly to img HTML tag. I am using the library with large resolution images and i don't have any problem in Chrome, Opera, Firefox, Edge, IE, and in android apps. Show how you are using the library, also try with png images instead of jpg |
I for one am NOT getting the corrupted images on the client side. Like I said, when I saw the issue (using the canvas demo example) then I tried to just write the frames straight to files using I get perfect images (in a sequence) if I run: |
Ok, if you are getting perfect images modifying the ffmpeg parameters maybe you need ajust these parameters by the library directly in code. BUT! I don't know that you could transform directly bytes array to image file. This is because image are not only a matrix representation of pixels, also contain information about the codification of color. For example, a value of a red pixel in RGB [255,0,0] is not the same that in gray scale [255]. This raw conversion produce chopped and decolorated images because color encoding and other reasons. Try to transform bytes array to and intermediate type like blob and then write it to disk. Node compile on C++ so maybe you have the primitive UINT8array type something like this before write to disk: Example: var buffer = Buffer.from(yourImageData); |
Here you have a method you write images directly from bytes array. function saveImage(filename, data){ |
Still getting the exact same behaviour, even after using your code. Here's the actual code I'm running for now:
And here's a snippet of the console output:
|
It seems in your code writes the image while you are getting images from the library. Maybe this causes that the function can not write the same data because write in disk is a "slow" proccess and the socket is modifiying the data object at the same time you are writting, that produces the corrupted images. Before write in disk create a copy of the data object. Do not use data = dataCopy because it only copy the reference in memory. |
Good advice, thanks! Let me give that a try. |
Nope, still doing the same thing. You can see my complete code below. I'm actually creating a new Buffer and copying it before passing it to the How do I know when the library finished sending a complete frame?
|
Ok, let me in this days test the code and maybe we can find the problem. The library receive a complete frame when on data event is fired, i think the data object should be a lock object because of the concurrency to write/read on it, but i am not sure if it occurs in a async context. Let met 3 days to check it and i will see what is happening |
Sorry, this weekend I was sick and i couldn't try the code. In this week I'll test it and I'll see you if i have the same results on images. |
Hello again @anselanza i test your code and i worked perfectly. Maybe is an issue with your cam, and you only need to adjust the parameters in your code. What version of ffmpeg are you using? Here You can see my cam configuration: power frequency power frequency: 50hz |
Got exactly same problem right here. I don't think it depends on camera, because if I edit the rtsp-ffmpeg.js file and overwrite the _args function with this :
It works. I mean, I have the whole jpg image in my directory. I know it doesn't resolve anything but I continue the investigation. |
Although my previous answer could work. The fix (in my case) was to disabled the quality option (seems not supported and making the image croppped). While disabling the quality option it works perfectly. You can test by yourself getting my fork : https://github.com/Zombitch/rtsp-ffmpeg The only thing you'll have to do is to set the quality option to false :
I'll request a pull on that. NB : FYI , I got a Hikam A7 camera. |
Hi @anselanza @plandevida @mindaugas-sasnauskas I merged the Zombitch branch to the master branch, so if you get the source code again you can test the solution for cropped images. |
Thanks @Seikon. |
Thanks, I will give it a try! |
Is the data being piped from ffmpeg's stdout? I looked through the code and it seems that when there is a data event, there is an assumption that it is a complete jpeg file. The problem with pipes is that there is no guarantee that the chunk of data is either complete, or arriving in several chunks and has to be reassembled. Lowering the quality and reducing the width x height can hide the issue if it brings the jpeg file size down to be less than the capacity of the pipe. Also, different machines and OS's have different pipe sizes. If this is the issue, the solution would be using a pipe reader that reads the chunks and looks for the beginning and ending markers for jpeg files. |
That is a very posible solution. Also I think you can change the chunk size from the admin panel of each cam if the provider has implemented it or maybe there is a way to change the chunk limit size from ffmpeg. I will take a look to pipe readers and how to control start and end characters of jpeg and png files. Thank you. |
hi, I am getting corrupted/chopped images. what might be causing this, I am trying to build home surveillance system on raspberry pi with some cheap chinese ip cameras. video on vlc doesn't seem to be flaky or anything. I tried websocket example and tried to save images do disk, most of the time I get corrupted or chopped images. so what might be the problem?
The text was updated successfully, but these errors were encountered: