flutter_ffmpeg concat demuxer | front camera videos are upside-down or corrupted

403 views Asked by At

I am currently recording multiple mp4 clips (using Flutter's camera package) and then using ffmpeg concat demuxer to create a single video:

await _flutterFFmpeg.execute('-f concat -safe 0 -i ${txtFile.path} -c copy ${outputClipPath.path}');

This works correctly with any video from the rear camera. When I also concat videos from the front camera, these are upside-down as it seems that ffmpeg does not detect their metadata rotation.

Currently, I have manged to detect if a video is front camera or rear camera in this way:

final FlutterFFprobe flutterFFprobe = FlutterFFprobe();
MediaInformation mediaInformation = await flutterFFprobe.getMediaInformation(this.path);

Map<dynamic, dynamic> mp = mediaInformation.getAllProperties();

int rotation = mp['streams'][0]['side_data_list'][0]['rotation'];
if (rotation == 90) {
  // Video is upside down and from front-camera
}

The question is, do I need to rotate the video myself prior to concat it? If yes, what is the best way to do that with flutter_ffmpeg?

I managed to rotate the video with the following command:

await _flutterFFmpeg.execute('-noautorotate -i ${this.path} -metadata:s:v rotate="0" -vf "transpose=2" ${outputClipPath.path}');

But if I do that then the concat result is corrupted. How do I preserve the encoding and stream after rotation?

Thank you.

1

There are 1 answers

0
ibrahim Eltayfe On

try to re-encode all the videos with the same codec like this:

-y -i ${videoFile.path} -c:a aac -c:v h264 ${destinationPath}

then you can contact the clips like this:

-y -f concat -i $videosPathsTextFilePath -c:a aac -c:v copy $fullVideoOutPath

I hope this works for you.