FLIR One Developer / Blog / Topics / android, video / How to record videos in android

How to record videos in android

Home Forums FLIR developer community General discussion How to record videos in android

Tagged: ,

This topic contains 10 replies, has 8 voices, and was last updated by Profile photo of Moti Moti 4 months, 1 week ago.

Viewing 11 posts - 1 through 11 (of 11 total)

  • Author

    Posts

  • #3868

    Profile photo of jit
    jit

    Participant

    how to record a video just like “Flir One app”,
    I can get pictures but don’t know how to record videos,
    could someone give a idea or share the code?

    #3869

    Profile photo of Tim Liew
    Tim Liew

    Moderator

    Hi Jit,

    I believe you have to do so by recording a sequence of frames in the void onFrameProcessed(RenderedImage renderedImage) callback. If you refer to the documentation: if your goal is to record a video from a sequence of frames, use android.media.MediaCodec and call mediaCodec.queueInputBuffer from this method with the frame’s pixelData byte array put in the input ByteBuffer of the mediaCodec. Hope this helps.

    Best,
    Tim

    #3964

    Profile photo of jit
    jit

    Participant

    Thank you for your great help Tim.

    #4789

    Profile photo of Francisco Javier
    Francisco Javier

    Participant

    I need to record videos like Jit, but I see mediaCodec.queueInputBuffer and I don’t understand well, Can anyone help me with a bit of code which works? I could post my code but it doesn’t work, because I don’t understand well that I need to do.

    Thanks in advance.

    #6491

    Profile photo of diraj
    diraj

    Participant

    hello,<br />
    thisis an example how to do this !<br />
    public class VideoCapture extends Activity implements OnClickListener, SurfaceHolder.Callback {<br />
    MediaRecorder recorder;<br />
    SurfaceHolder holder;<br />
    boolean recording = false;<br />
    @Override<br />
    public void onCreate(Bundle savedInstanceState) {<br />
    super.onCreate(savedInstanceState);<br />
    requestWindowFeature(Window.FEATURE_NO_TITLE);<br />
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,<br />
    WindowManager.LayoutParams.FLAG_FULLSCREEN);<br />
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);</p>
    <p> recorder = new MediaRecorder();<br />
    initRecorder();<br />
    setContentView(R.layout.main);</p>
    <p> SurfaceView cameraView = (SurfaceView) findViewById(R.id.CameraView);<br />
    holder = cameraView.getHolder();<br />
    holder.addCallback(this);<br />
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);</p>
    <p> cameraView.setClickable(true);<br />
    cameraView.setOnClickListener(this);<br />
    }</p>
    <p> private void initRecorder() {<br />
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);<br />
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);</p>
    <p> CamcorderProfile cpHigh = CamcorderProfile<br />
    .get(CamcorderProfile.QUALITY_HIGH);<br />
    recorder.setProfile(cpHigh);<br />
    recorder.setOutputFile(“/sdcard/videocapture_example.mp4”);<br />
    recorder.setMaxDuration(50000); // 50 seconds<br />
    recorder.setMaxFileSize(5000000); // Approximately 5 megabytes<br />
    }</p>
    <p> private void prepareRecorder() {<br />
    recorder.setPreviewDisplay(holder.getSurface());</p>
    <p> try {<br />
    recorder.prepare();<br />
    } catch (IllegalStateException e) {<br />
    e.printStackTrace();<br />
    finish();<br />
    } catch (IOException e) {<br />
    e.printStackTrace();<br />
    finish();<br />
    }<br />
    }</p>
    <p> public void onClick(View v) {<br />
    if (recording) {<br />
    recorder.stop();<br />
    recording = false;</p>
    <p> // Let’s initRecorder so we can record again<br />
    initRecorder();<br />
    prepareRecorder();<br />
    } else {<br />
    recording = true;<br />
    recorder.start();<br />
    }<br />
    }</p>
    <p> public void surfaceCreated(SurfaceHolder holder) {<br />
    prepareRecorder();<br />
    }</p>
    <p> public void surfaceChanged(SurfaceHolder holder, int format, int width,<br />
    int height) {<br />
    }</p>
    <p> public void surfaceDestroyed(SurfaceHolder holder) {<br />
    if (recording) {<br />
    recorder.stop();<br />
    recording = false;<br />
    }<br />
    recorder.release();<br />
    finish();<br />
    }<br />
    }this might help you r<br />
    ragards<br />
    diraj<br />
    public class VideoCapture extends Activity implements OnClickListener, SurfaceHolder.Callback {<br />
    MediaRecorder recorder;<br />
    SurfaceHolder holder;<br />
    boolean recording = false;<br />
    @Override<br />
    public void onCreate(Bundle savedInstanceState) {<br />
    super.onCreate(savedInstanceState);<br />
    requestWindowFeature(Window.FEATURE_NO_TITLE);<br />
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,<br />
    WindowManager.LayoutParams.FLAG_FULLSCREEN);<br />
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);</p>
    <p> recorder = new MediaRecorder();<br />
    initRecorder();<br />
    setContentView(R.layout.main);</p>
    <p> SurfaceView cameraView = (SurfaceView) findViewById(R.id.CameraView);<br />
    holder = cameraView.getHolder();<br />
    holder.addCallback(this);<br />
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);</p>
    <p> cameraView.setClickable(true);<br />
    cameraView.setOnClickListener(this);<br />
    }</p>
    <p> private void initRecorder() {<br />
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);<br />
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);</p>
    <p> CamcorderProfile cpHigh = CamcorderProfile<br />
    .get(CamcorderProfile.QUALITY_HIGH);<br />
    recorder.setProfile(cpHigh);<br />
    recorder.setOutputFile(“/sdcard/videocapture_example.mp4”);<br />
    recorder.setMaxDuration(50000); // 50 seconds<br />
    recorder.setMaxFileSize(5000000); // Approximately 5 megabytes<br />
    }</p>
    <p> private void prepareRecorder() {<br />
    recorder.setPreviewDisplay(holder.getSurface());</p>
    <p> try {<br />
    recorder.prepare();<br />
    } catch (IllegalStateException e) {<br />
    e.printStackTrace();<br />
    finish();<br />
    } catch (IOException e) {<br />
    e.printStackTrace();<br />
    finish();<br />
    }<br />
    }</p>
    <p> public void onClick(View v) {<br />
    if (recording) {<br />
    recorder.stop();<br />
    recording = false;</p>
    <p> // Let’s initRecorder so we can record again<br />
    initRecorder();<br />
    prepareRecorder();<br />
    } else {<br />
    recording = true;<br />
    recorder.start();<br />
    }<br />
    }</p>
    <p> public void surfaceCreated(SurfaceHolder holder) {<br />
    prepareRecorder();<br />
    }</p>
    <p> public void surfaceChanged(SurfaceHolder holder, int format, int width,<br />
    int height) {<br />
    }</p>
    <p> public void surfaceDestroyed(SurfaceHolder holder) {<br />
    if (recording) {<br />
    recorder.stop();<br />
    recording = false;<br />
    }<br />
    recorder.release();<br />
    finish();<br />
    }<br />
    }public class VideoCapture extends Activity implements OnClickListener, SurfaceHolder.Callback {<br />
    MediaRecorder recorder;<br />
    SurfaceHolder holder;<br />
    boolean recording = false;<br />
    @Override<br />
    public void onCreate(Bundle savedInstanceState) {<br />
    super.onCreate(savedInstanceState);<br />
    requestWindowFeature(Window.FEATURE_NO_TITLE);<br />
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,<br />
    WindowManager.LayoutParams.FLAG_FULLSCREEN);<br />
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);</p>
    <p> recorder = new MediaRecorder();<br />
    initRecorder();<br />
    setContentView(R.layout.main);</p>
    <p> SurfaceView cameraView = (SurfaceView) findViewById(R.id.CameraView);<br />
    holder = cameraView.getHolder();<br />
    holder.addCallback(this);<br />
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);</p>
    <p> cameraView.setClickable(true);<br />
    cameraView.setOnClickListener(this);<br />
    }</p>
    <p> private void initRecorder() {<br />
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);<br />
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);</p>
    <p> CamcorderProfile cpHigh = CamcorderProfile<br />
    .get(CamcorderProfile.QUALITY_HIGH);<br />
    recorder.setProfile(cpHigh);<br />
    recorder.setOutputFile(“/sdcard/videocapture_example.mp4”);<br />
    recorder.setMaxDuration(50000); // 50 seconds<br />
    recorder.setMaxFileSize(5000000); // Approximately 5 megabytes<br />
    }</p>
    <p> private void prepareRecorder() {<br />
    recorder.setPreviewDisplay(holder.getSurface());</p>
    <p> try {<br />
    recorder.prepare();<br />
    } catch (IllegalStateException e) {<br />
    e.printStackTrace();<br />
    finish();<br />
    } catch (IOException e) {<br />
    e.printStackTrace();<br />
    finish();<br />
    }<br />
    }</p>
    <p> public void onClick(View v) {<br />
    if (recording) {<br />
    recorder.stop();<br />
    recording = false;</p>
    <p> // Let’s initRecorder so we can record again<br />
    initRecorder();<br />
    prepareRecorder();<br />
    } else {<br />
    recording = true;<br />
    recorder.start();<br />
    }<br />
    }</p>
    <p> public void surfaceCreated(SurfaceHolder holder) {<br />
    prepareRecorder();<br />
    }</p>
    <p> public void surfaceChanged(SurfaceHolder holder, int format, int width,<br />
    int height) {<br />
    }</p>
    <p> public void surfaceDestroyed(SurfaceHolder holder) {<br />
    if (recording) {<br />
    recorder.stop();<br />
    recording = false;<br />
    }<br />
    recorder.release();<br />
    finish();<br />
    }<br />

    • This reply was modified 1 year, 5 months ago by Profile photo of diraj diraj.

    #6493

    Profile photo of Francisco Javier
    Francisco Javier

    Participant

    @diraj Thank you, I left the project what I was doing because researchs university projects sometimes do not finish and only end in a prototype. However your answer is useful if I continue with it or for other participants.

    Thanks again.

    #7183

    Profile photo of Luis
    Luis

    Participant

    Thank you for your great help Tim

    • This reply was modified 1 year, 4 months ago by Profile photo of Luis Luis.

    #8241

    Profile photo of Riddhi
    Riddhi

    Participant

    Hi. I have FLIR ONE camera.

    I want to record video using it in .seq or .csq format.

    Currently, the video is generated in .mp4

    Please help!

    Rado

    #8792

    Profile photo of Slim
    Slim

    Participant

    Hello Riddhi,

    I noticed that you are generating videos .mp4. Are you generating them through the FLIR ONE app or you are using the SDK ?
    Because I am still searching for how to generate videos with SDK, many unexplained replies.

    If anyone else knows (or can share a code snippet) how to capture a video with Flir ONE SDK, please I need your help. I am currently capturing images but not videos.

    Thank you in advance.

    Slim

    #8796

    Profile photo of Riddhi
    Riddhi

    Participant

    Hi Slim,

    Can you share your email address please?

    We can continue the discussion over there.

    Riddhi

    #9269

    Profile photo of Moti
    Moti

    Participant

    Hi Riddhi and Slim, How are you???

    I try also to generate mp4 video and I have no idea how to to it with the SDK :\

    Please help me, I have stuck with the problem for several weeks already

    I need your help. I am currently capturing images but not videos.

    My personal email is motiamar86@gmail.com

    Thanks!!

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.