0

I am working on an app that needs to capture square videos just like Instagram. I used many libraries for the purpose but none helped to capture the video itself in square size. I can make the preview look like square but not the recorded video. For that I have to use FFMPEG library for cropping the video after it has been captured. But this process takes too long for 1 minute videos even with 480p video capture quality. Someone please guide me to achieve this task.

Libraries that I have used are: https://github.com/natario1/CameraView for cameraView and http://writingminds.github.io/ffmpeg-android-java/ for using ffmpeg.

Commands that I have tried for ffmpeg cropping operation are:

command = new String[]{"-y",
                "-f",
                "concat",
                "-safe",
                "0",
                "-i",
                "" + sdCardPathFile,
                "-c:v",
                "libx264",
                "-vf",
                "crop=" + getVideoResolution(),
                "-preset",
                "ultrafast",
                "-qscale",
                "0",
                "-crf",
                "28",
                "-c:a",
                "copy",
                "-flags",
                "+global_header",
                "" + joinedVideoFile.getAbsolutePath()
        };




String[] joinCommand = new String[]{
                "-y",
                "-f",
                "concat",
                "-safe",
                "0",
                "-i",
                "" + sdCardPathFile,
                "-filter:v",
                "crop=480:480",
                "-preset",
                "superfast",
                "-c:a",
                "copy",
                "" + joinedVideoFile.getAbsolutePath()
        };
Ashutosh Tiwari
  • 341
  • 2
  • 11
  • 1
    Similar question to [this](https://stackoverflow.com/questions/25285931/how-does-instagram-crop-video-in-android-app). – Maksym Bodnar Dec 13 '17 at 10:34
  • I believe you can use [this answer](https://stackoverflow.com/a/30601802/192373). – Alex Cohn Dec 13 '17 at 14:12
  • @AlexCohn Tried to explore Grafika but yet to get it done, tried changing those coordinates for rectangle but it's not making it square at all. Any guidelines or points I'm missing? – Ashutosh Tiwari Dec 15 '17 at 14:45
  • When you crop the texture, you change the video that is recorded, not the live preview. Another quirk that I can expect in your case, is that you arranged texture clipping for portrait orientation while the texture was actually landscape, or vice versa. – Alex Cohn Dec 15 '17 at 18:34
  • Tried a lot but not able to entertain a photo capture from the activity. I took out the camera object from inside of `RenderThread` and called takePicture method. @AlexCohn I really am a newbie with this `TextureView` and `SurfaceView` things and their working. – Ashutosh Tiwari Dec 18 '17 at 11:11
  • Wait a sec, are you speaking about photo capture or video? – Alex Cohn Dec 18 '17 at 11:14
  • My concern is photo and video capture both, though the thread focused on video capture. And the part where M stuck is this that I'm not being able to use the object of camera class @AlexCohn – Ashutosh Tiwari Dec 18 '17 at 14:21
  • *I'm not being able to use the object of camera class* - I am afraid this explanation is not enough. Maybe you need 1-on-1 professional help? – Alex Cohn Dec 18 '17 at 15:47

0 Answers0