Capture 1: 1 aspect ratio video on Android

I am trying to develop an Android application that will record video with a resolution of 15 sec 640x640 using MediaRecorder, extract all frames using ffmpeg, apply some art filters using gpuimage, and then combine frames with video using ffmpeg.

I encountered the problem of recording video with a resolution of 640x640. (Instagram android app does this)

I tried using MediaRecorder setVideoSize (640, 640) and the output video is 640x640, but the video looks like a 640x480 video stretched vertically to make it 640x640. I assume that since 640x640 is not the resolution returned by the supported video capture resolution list of the device. Is there a way to tell the media recorder to maintain proportions when performing such a scaling to get a video that was scaled from 640x480 to 640x640 by cropping the width rather than stretching it in height?

+6
source share
1 answer

Finally, I ended up capturing at 640x480, trimming it to 480x480, splitting it into frames using ffmpeg, and then when the frames are combined back into the video using ffmpeg, it scales to 640x640.

String[] ffmpegCommand = {"/sdcard/frames/ffmpeg", "-i", "/sdcard/frames/test.3gp", "-vf", "crop=480:480:80:0,transpose=1", "-r", "30", "-an", "-qscale:v", "2", "-vsync", "1", "-threads", "4", "/sdcard/frames/image%03d.jpg"}; 

Transpose = 1 is required when the application is running in portrait mode.

Note. When capturing to display only that part of the video that will be included in the final cropped video, I added two black bars of 80 pixels over the preview screen to hide 80 pixels on both sides of the video, which is later cropped. Thus, the user gets what he sees in the preview.

+4
source

Source: https://habr.com/ru/post/959236/


All Articles