Closed se7enXF closed 1 year ago
I tried it, but neither happened. How often and when does it occur?
Also, for 2., I attach the code with a try-catch in the place that seems to be the cause. Does this change behavior? FfmpegCaptureImpWinLib.zip
Thanks for your replay. Two problems occur about 5%.
For problem 2, I use your new code but problem still exist. Since this exception is not inevitable, I simulated an exception by throw new Exception
in your try block. Error can be caught and log out, but if I call FfmpegCommand.csStopFfmpeg()
function, the program is also stuck.
I think the stuck problem is that, ffmpeg_stop
function do not stop the background ffmpeg process when writeVideo
error, so ffmpeg_start
is sutck. I have two suggestions:
writeVideo
. I find the problem in google and this is most likely caused by multithreading. But I can't optimize the complex code. As it is incidental, maybe the next suggestion is more practical. ffmpeg_stop
is not really working. I guess that, if ffmpeg_stop
works, ffmpeg_start
will returns and all thread exit. I read the code in fftools_lib/ffmpeg.c but it is difficult to understand with my poor programming skills. Thanks for your replay! I don't understand the logic of running functions in the dll, so I can only turn to you for help.
I have changed the processing for the part that seems to be the cause. Will this change the behavior? FfmpegUnity_patch_lock.zip
Unfortunately, the same problem remains.
I'm sorry, but I don't have that problem in my environment. So it's hard to fix as it is. Is there any way I can reproduce the problem?
You can write a line throw new Exception("test");
at the begining in function FfmpegCaptureImpWinLib.WriteVideo.
Add two button in UI, one for StartFfmpeg() and another for StopFfmpeg().
Play unity and click StartFfmpeg(), you can see the exception. And if click StopFfmpeg(), unity editor will stuck.
It seems that ffmpeg will not start if an exception occurs at that timing. I changed it so that it doesn't stack even if it occurs, so please check it. FfmpegUnity_patch_lock2.zip
Unfortunately, it doesn't work for me. The same problem remains. Maybe WriteVideo
thread should be started until variable videoBuffers_ initialization is completed. There is still a risk of multithreading conflicts by using videoBuffers.ContainsKey()
in WriteVideo
function to determine whether it is initialized or not.
Maybe WriteVideo thread should be started until variable videoBuffers_ initialization is completed.
I changed it to look like the above. FfmpegUnity_patch_lock3.zip
I read the code in FfmpegUnity_patch_lock3.zip, and I will try it.
And I find that there is a try block in WriteAudio when using audioBuffers.ContainsKey(streamId)
. I will try it in WriteVideo.
First of all, these two mistakes are accidental. I run my program in Linux standalone build. I debug for days but not find reason.
1. FFplay segmentation fault
Once the error happens, the program crashed.
2. FfmpegCaputure writeVideo Bug
Once the error happens, if I call FfmpegCommand.StopFfmpeg() function the program and editor will stuck forever. I debug in Windows editor and found that program running is stuck at ffmpegThread.Join() at line 159 in FfmpegCommandImpWinLib.cs. In ffmpegThread, running is stuck at line 99 ffmpeg_start() function.
This error is start with
NullReferenceException: Object reference not set to an instance of an object
, following log is in the picture.