1

My text file list_of_fragments contains the list of video files to be concatenated. I assumed they have the same streams (shot from the same smartphone, with the same settings)

file barbell-home.mp4
file before.mp4
file before-otherview.mp4
file rotated.tr.mp4
file squatting-rack.mp4

I attempted to concatenate them all with: ffmpeg -loglevel warning -hide_banner -f concat -safe 0 -i list_of_fragments -c copy conc-output.mp4 Sadly, the video corresponding to the files before.mp4, before-otherview.mp4, rotated.tr.mp4, squatting-rack.mp4 was flipped upside down, i.e. rotated 180 degrees (the part corresponding to barbell-home.mp4 was not rotated). ffprobe returns (for the sake of brevity I've not included audio streams):

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'barbell-home.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2022-10-30T15:11:45.000000Z
    com.android.version: 11
  Duration: 00:00:02.05, start: 0.000000, bitrate: 21155 kb/s
  Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 20059 kb/s, SAR 1:1 DAR 16:9, 29.92 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 180
      creation_time   : 2022-10-30T15:11:45.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
    Side data:
      displaymatrix: rotation of -180.00 degrees
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'before.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2022-10-26T11:50:04.000000Z
    com.android.version: 11
  Duration: 00:00:04.22, start: 0.000000, bitrate: 21335 kb/s
  Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 20384 kb/s, SAR 1:1 DAR 16:9, 29.94 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2022-10-26T11:50:04.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'before-otherview.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2022-10-26T11:50:15.000000Z
    com.android.version: 11
  Duration: 00:00:02.47, start: 0.000000, bitrate: 21370 kb/s
  Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 20377 kb/s, SAR 1:1 DAR 16:9, 29.94 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2022-10-26T11:50:15.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'rotated.tr.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:04.85, start: 0.000000, bitrate: 25889 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 25605 kb/s, 29.92 fps, 29.92 tbr, 11488 tbn, 59.83 tbc (default)
    Metadata:
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'squatting-rack.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:01.77, start: 0.021000, bitrate: 19986 kb/s
  Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 20105 kb/s, SAR 1:1 DAR 16:9, 29.94 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]

After taking a closer look at ffprobe's output I realized:

  1. The files differ in their bitrate.
  2. Only the first file does rotate : 180 in the metadata of its video stream.

My questions:

  1. Why does only barbell-home.mp4 have rotate : 180 in the metadata of its video stream and what is the significance of it when concatenating with ffmpeg?
  2. Adding -noautorotate to the command, ffmpeg -loglevel warning -hide_banner -f concat -safe 0 -noautorotate -i list_of_fragments -c copy conc-output.mp4, does not change the output? Why so?
  3. Should I add rotate : 180 to the rest of the files or should I remove rotate : 180 from barbell-home.mp4 before proceeding to concatenate them all? If so, how might I accomplish this?
  4. How might I concatenate the files in question without flipping the video upside-down?

1 Answer 1

2

The concat demuxer amalgamates all its inputs and presents them as a single input. It takes the properties of the first input as representing the properties of the amalgam. Since the 1st input has a rotation angle, that gets carried over.

noautorotate only takes effect during encoding, not with -c copy.

Easiest way forward, at present, is to re-encode all inputs without noautorotate and then concat. Next is to re-encode only the first input. But then you have to match the encoding of the other inputs (bitrate doesn't matter).

Ultimately, during recording next time, make sure all videos are taken with the phone in identical orientation (not flipped in one recording).

1
  • Thanks. ffmpeg -i input.mp4 -c:a copy re-encoded.mp4 on each of the files solved the matter.
    – John Smith
    Nov 1, 2022 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.