@@ -95,13 +95,14 @@ public async Task TakeVideo(VideoStreamCaptureHandler handler, DateTime? timeout
9595 using ( var vidEncoder = new MMALVideoEncoder ( handler , new MMAL_RATIONAL_T ( 30 , 1 ) , timeout , split ) )
9696 using ( var renderer = new MMALVideoRenderer ( ) )
9797 {
98- vidEncoder . ConfigureOutputPort ( 0 , MMALEncoding . H264 , MMALEncoding . I420 , 10 , 25000000 ) ;
98+ this . ConfigureCameraSettings ( ) ;
99+
100+ vidEncoder . ConfigureOutputPort ( 0 , MMALEncoding . H264 , MMALEncoding . I420 , 0 , MMALVideoEncoder . MaxBitrateLevel4 ) ;
99101
100102 // Create our component pipeline.
101103 this . Camera . VideoPort . ConnectTo ( vidEncoder ) ;
102104 this . Camera . PreviewPort . ConnectTo ( renderer ) ;
103- this . ConfigureCameraSettings ( ) ;
104-
105+
105106 MMALLog . Logger . Info ( $ "Preparing to take video. Resolution: { vidEncoder . Width } x { vidEncoder . Height } . " +
106107 $ "Encoder: { vidEncoder . Outputs [ 0 ] . EncodingType . EncodingName } . Pixel Format: { vidEncoder . Outputs [ 0 ] . PixelFormat . EncodingName } .") ;
107108
@@ -131,42 +132,47 @@ public async Task TakeRawPicture(ICaptureHandler handler)
131132
132133 this . Camera . Handler = handler ;
133134
134- this . CheckPreviewComponentStatus ( ) ;
135-
136- // Enable the image encoder output port.
137- try
135+ using ( var renderer = new MMALNullSinkComponent ( ) )
138136 {
139- MMALLog . Logger . Info ( $ "Preparing to take raw picture - Resolution: { MMALCameraConfig . StillResolution . Width } x { MMALCameraConfig . StillResolution . Height } . " +
140- $ "Encoder: { MMALCameraConfig . StillEncoding . EncodingName } . Pixel Format: { MMALCameraConfig . StillSubFormat . EncodingName } ." ) ;
137+ this . ConfigureCameraSettings ( ) ;
138+ this . Camera . StillPort . SetRawCapture ( true ) ;
141139
142- // Camera warm up time
143- await Task . Delay ( 2000 ) ;
140+ this . Camera . PreviewPort . ConnectTo ( renderer ) ;
141+
142+ // Enable the image encoder output port.
143+ try
144+ {
145+ MMALLog . Logger . Info ( $ "Preparing to take raw picture - Resolution: { MMALCameraConfig . StillResolution . Width } x { MMALCameraConfig . StillResolution . Height } . " +
146+ $ "Encoder: { MMALCameraConfig . StillEncoding . EncodingName } . Pixel Format: { MMALCameraConfig . StillSubFormat . EncodingName } .") ;
144147
145- // Enable processing on the camera still port.
146- this . Camera . EnableConnections ( ) ;
148+ // Camera warm up time
149+ await Task . Delay ( 2000 ) ;
150+
151+ this . Camera . Start ( this . Camera . StillPort , new Action < MMALBufferImpl , MMALPortBase > ( this . Camera . ManagedOutputCallback ) ) ;
152+ this . Camera . StillPort . Trigger = new Nito . AsyncEx . AsyncCountdownEvent ( 1 ) ;
147153
148- this . Camera . Start ( this . Camera . StillPort , new Action < MMALBufferImpl , MMALPortBase > ( this . Camera . ManagedOutputCallback ) ) ;
149- this . Camera . StillPort . Trigger = new Nito . AsyncEx . AsyncCountdownEvent ( 1 ) ;
154+ this . StartCapture ( this . Camera . StillPort ) ;
150155
151- this . StartCapture ( this . Camera . StillPort ) ;
156+ // Wait until the process is complete.
157+ await this . Camera . StillPort . Trigger . WaitAsync ( ) ;
152158
153- // Wait until the process is complete .
154- await this . Camera . StillPort . Trigger . WaitAsync ( ) ;
159+ // Stop capturing on the camera still port .
160+ this . StopCapture ( this . Camera . StillPort ) ;
155161
156- // Stop capturing on the camera still port.
157- this . StopCapture ( this . Camera . StillPort ) ;
162+ this . Camera . Stop ( MMALCameraComponent . MMALCameraStillPort ) ;
158163
159- this . Camera . Stop ( MMALCameraComponent . MMALCameraStillPort ) ;
164+ // Close open connections and clean port pools.
165+ this . Camera . DisableConnections ( ) ;
160166
161- // Close open connections and clean port pools.
162- this . Camera . DisableConnections ( ) ;
167+ this . Camera . CleanPortPools ( ) ;
163168
164- this . Camera . CleanPortPools ( ) ;
165- }
166- finally
167- {
168- this . Camera . Handler . Dispose ( ) ;
169- }
169+ this . Camera . StillPort . SetRawCapture ( false ) ;
170+ }
171+ finally
172+ {
173+ this . Camera . Handler . Dispose ( ) ;
174+ }
175+ }
170176 }
171177
172178 /// <summary>
@@ -182,13 +188,14 @@ public async Task TakePicture(ImageStreamCaptureHandler handler, MMALEncoding en
182188 using ( var imgEncoder = new MMALImageEncoder ( handler ) )
183189 using ( var renderer = new MMALNullSinkComponent ( ) )
184190 {
191+ this . ConfigureCameraSettings ( ) ;
192+
185193 imgEncoder . ConfigureOutputPort ( 0 , encodingType , pixelFormat , 90 ) ;
186194
187195 // Create our component pipeline.
188196 this . Camera . StillPort . ConnectTo ( imgEncoder ) ;
189197 this . Camera . PreviewPort . ConnectTo ( renderer ) ;
190- this . ConfigureCameraSettings ( ) ;
191-
198+
192199 // Enable the image encoder output port.
193200 MMALLog . Logger . Info ( $ "Preparing to take picture. Resolution: { imgEncoder . Width } x { imgEncoder . Height } . " +
194201 $ "Encoder: { encodingType . EncodingName } . Pixel Format: { pixelFormat . EncodingName } .") ;
0 commit comments