I want to use Raspberry PI's system command `raspistill`to take images in a c program, the program line is: `system("raspistill -q 5 -vf -hf -o pic1.jpg -t 1 -th 0:0:0");`

However, when I run the program sometimes error occurs, 
it shows that:

> 
> mmal\_vc\_component\_enable- failed to enable component- ENOSPC
>  mmal- camera component couldn't be enabled
>  mmal- main- Failed to create camera component
>  mmal- Failed to run camera app. Please check for firmware updatesckquote
> 
> 
> 

And I have tried to add some parameters into /boot/config.txt:

> 
> gpu\_mem=128 start\_file=start\_x.elf fixup\_file=fixup\_x.dat  
> 
>  disable\_camera\_led=1 cam\_lwm=16 cam\_hwm=32 cam\_offline\_start=16
> 
> 
> 

However the error still always occurs sometimes (sometimes ok). I really want to solve this problem in order to continue my project. What should I do?
['https://Stackoverflow.com/questions/29314841', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4407689/']
This error will appear when the RPi Camera is "On" and is streaming. The component: ENOSPC cannot start unless the RPi Camera is not streaming or being used by another process.
One solution is to try to stop the Camera stream before the Snapshot and then restart it after.
This error occurs when you use I/O during camera recording operation.
I faced the same issue on using used I/O while recording.
So you can either add before recording or after not in between.