Skip to content

Instantly share code, notes, and snippets.

@hlev
Last active May 31, 2021 04:26
Show Gist options
  • Save hlev/ce79a82e02e4e504fc823d2c594e2350 to your computer and use it in GitHub Desktop.
Save hlev/ce79a82e02e4e504fc823d2c594e2350 to your computer and use it in GitHub Desktop.
Transcoding and scaling native h264 portrait video with ffmpeg

Original

https://vimeo.com/166500954

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vertical.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2016-05-20 00:41:40
  Duration: 00:02:00.06, start: 0.000000, bitrate: 4055 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1080x1920 [SAR 1:1 DAR 9:16], 3797 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-05-20 00:41:40
      handler_name    : L-SMASH Video Handler
      encoder         : AVC Coding

Simple resizing with transcoding

ffmpeg -i vertical.mp4 -c:v libx264 -vf "scale=720:-1" -c:a copy vertical720p.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vertical720p.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:02:00.06, start: 0.000000, bitrate: 1627 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280 [SAR 1:1 DAR 9:16], 1366 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

tbn is different
level=31
color_range=N/A
color_space=unknown
color_transfer=unknown
color_primaries=unknown

-s hd720

ffmpeg -i vertical.mp4 -s hd720 -c:v libx264 -c:a copy vertical.mp4

output video has landscape aspect ratio with enveloping

Copying color profile, timebase

ffmpeg -i vertical.mp4 -video_track_timescale 25 -c:v libx264 -x264opts colorprim=bt709:transfer=bt709:colormatrix=bt709:fullrange=off -vf "scale=720:-1" -profile:v high -level 4.0 -c:a copy vertical720.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vertical720p.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:02:00.06, start: 0.000000, bitrate: 1627 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x1280 [SAR 1:1 DAR 9:16], 1366 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

identical details
ffmpeg -i in.mp4 -c:v libx264 -vf "scale=1280:-1" -profile:v baseline -level:v 3.2 -c:a copy out.mp4
ffmpeg -loop 1 -r 30 -i imremovie.jpg -c:v libx264 -t 10 -vf hue=s=0,boxblur=lr=1.2,noise=c0s=7:allf=t,format=yuv420p imreout.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment