Camera2 API switching camera during recording

515 Views Asked by At

I'm working with Camera2 API and in my app it's important to switch the camera during recording. After each camera switch I save video fragment to disk, and after stopping the recording I merge videos into one using -f concat -safe 0 -i listPath -c copy finalPath command of FFmpeg for Android. When I open a separate video fragment, it looks correct, but when I open the merged video, videos recorded on the back camera are rotated 180 degrees. The problem is only in the merged video.

In meta-tag of videos if video recorded on back camera, then "rotate" tag has 90 degrees, otherwise 270 degrees.

As I understood when ffmpeg merges a videos it automatically rotates the video if it has different "rotate" tag in he's metatags.

How I can solve this problem?

P.S Also I tried to use MP4Parser Library for merging, but it has the same problems.
P.P.S. -noautorotate param for ffmpeg does not help me.

1

There are 1 best solutions below

0
On

Quite contrary, ffmpeg ignored the orientation of input fragments when it was merging them together. This is inevitable when you use -c copy. Your choice is to rotate video coming from one of the cameras before appending it to the result. In terms of performance, this is, unfortunately, equivalent to full transcoding.

The alternative approach would be to use MediaCodec instead of Recorder. This is more code on your side, but you can ditch ffmpeg and produce one continues movie sans postprocessing.