leonp
leonp

Reputation: 497

Rotate 90 and concatenate videos with ffmpeg

I have several videos made in landscape and portrait modes. I want to concatenate them into one movie.

For this I rotated portrait videos with:

ffmpeg -i in.mp4 -vf transpose=1 out.mp4    

Built the list of files to concatenate and concatenated all of them with:

ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4    

The result is unplayable. All players hang/crash at the first switch from landscape to rotated portrait fragment.

What do I do wrong?

In reply to LordNeckbeard request:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2017-07-20T12:50:32.000000Z
  Duration: 00:00:30.36, start: 0.000000, bitrate: 20202 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 20005 kb/s, SAR 1:1 DAR 16:9, 29.45 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2017-07-20T12:50:32.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 156 kb/s (default)
    Metadata:
      creation_time   : 2017-07-20T12:50:32.000000Z
      handler_name    : SoundHandle

Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2017-07-24T13:57:42.000000Z
  Duration: 00:00:31.94, start: 0.000000, bitrate: 20171 kb/s
    Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 19997 kb/s, SAR 1:1 DAR 16:9, 29.43 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 90
      creation_time   : 2017-07-24T13:57:42.000000Z
      handler_name    : VideoHandle
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 156 kb/s (default)
    Metadata:
      creation_time   : 2017-07-24T13:57:42.000000Z
      handler_name    : SoundHandle

At least one output file must be specified```

Upvotes: 1

Views: 3269

Answers (1)

leonp
leonp

Reputation: 497

The final algorithm which gives me the result for file $f is:

  1. Remove the metadata rotation field with:

    ffmpeg -i $f -c copy -metadata:s:v:0 rotate=0 md_$f
    
  2. Rotate the Videos:

    ffmpeg -i md_$f -vf transpose=1 rt_$f.mp4
    
  3. Convert to TS:

    ffmpeg -i rt_$f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
    
  4. Concatenate all ts files with:

    ffmpeg -i "concat:f1.ts|f2.ts|f3.ts" -c copy -bsf:a aac_adtstoasc output.mp4
    

Upvotes: 1

Related Questions