0

I have a video:

Resolution: 1920*1080

PAR: 65536/65536

Rotation: 90°

In Fast 1080p30 preset, The default value for Anamorphic option is Automatic and Modules 2.

What I'm curious about is the output width. The height stays in 1080 as it should. But how/why the width changes to 1080 (1080*1080) and output video is not stretched ?

What is ffmpeg command or formula for calculating it?


Download_Input - 9 MB

Download_Output - 2 MB

Input:

General
Complete name               : C:\Users\PN\Desktop\input.mp4
Format                      : MPEG-4
Format profile              : Base Media / Version 2
Codec ID                    : mp42 (isom/mp42)
File size                   : 9.82 MiB
Duration                    : 4 s 305 ms
Overall bit rate mode       : Variable
Overall bit rate            : 19.1 Mb/s
Encoded date                : UTC 2018-12-13 07:28:30
Tagged date                 : UTC 2018-12-13 07:28:30
com.android.version         : 7.0

Video
ID                          : 1
Format                      : AVC
Format/Info                 : Advanced Video Codec
Format profile              : Baseline@L4
Format settings             : 1 Ref Frames
Format settings, CABAC      : No
Format settings, ReFrames   : 1 frame
Format settings, GOP        : M=1, N=31
Codec ID                    : avc1
Codec ID/Info               : Advanced Video Coding
Duration                    : 4 s 305 ms
Source duration             : 4 s 314 ms
Bit rate mode               : Variable
Bit rate                    : 17.4 Mb/s
Maximum bit rate            : 17.0 Mb/s
Width                       : 1 920 pixels
Height                      : 1 080 pixels
Display aspect ratio        : 16:9
Rotation                    : 90°
Frame rate mode             : Variable
Frame rate                  : 30.134 FPS
Minimum frame rate          : 24.311 FPS
Maximum frame rate          : 39.630 FPS
Original frame rate         : 30.000 FPS
Color space                 : YUV
Chroma subsampling          : 4:2:0
Bit depth                   : 8 bits
Scan type                   : Progressive
Bits/(Pixel*Frame)          : 0.279
Stream size                 : 8.95 MiB (91%)
Source stream size          : 8.95 MiB (91%)
Title                       : VideoHandle
Language                    : English
Encoded date                : UTC 2018-12-13 07:28:30
Tagged date                 : UTC 2018-12-13 07:28:30
mdhd_Duration               : 4305

Audio
ID                          : 2
Format                      : AAC
Format/Info                 : Advanced Audio Codec
Format profile              : LC
Codec ID                    : mp4a-40-2
Duration                    : 4 s 224 ms
Bit rate mode               : Constant
Bit rate                    : 192 kb/s
Channel(s)                  : 2 channels
Channel positions           : Front: L R
Sampling rate               : 48.0 kHz
Frame rate                  : 46.875 FPS (1024 SPF)
Compression mode            : Lossy
Stream size                 : 99.3 KiB (1%)
Title                       : SoundHandle
Language                    : English
Encoded date                : UTC 2018-12-13 07:28:30
Tagged date                 : UTC 2018-12-13 07:28:30

Output:

General
Complete name               : C:\Users\PN\Desktop\output.mp4
Format                      : MPEG-4
Format profile              : Base Media / Version 2
Codec ID                    : mp42 (isom/iso2/avc1/mp41)
File size                   : 2.40 MiB
Duration                    : 4 s 334 ms
Overall bit rate mode       : Variable
Overall bit rate            : 4 640 kb/s
Encoded date                : UTC 2018-12-16 02:45:36
Tagged date                 : UTC 2018-12-16 02:45:36
Writing application         : HandBrake 1.1.2 2018090500

Video
ID                          : 1
Format                      : AVC
Format/Info                 : Advanced Video Codec
Format profile              : Main@L4
Format settings             : CABAC / 4 Ref Frames
Format settings, CABAC      : Yes
Format settings, ReFrames   : 4 frames
Codec ID                    : avc1
Codec ID/Info               : Advanced Video Coding
Duration                    : 4 s 334 ms
Bit rate                    : 4 467 kb/s
Width                       : 1 080 pixels
Height                      : 1 080 pixels
Display aspect ratio        : 0.563
Frame rate mode             : Constant
Frame rate                  : 30.000 FPS
Color space                 : YUV
Chroma subsampling          : 4:2:0
Bit depth                   : 8 bits
Scan type                   : Progressive
Bits/(Pixel*Frame)          : 0.128
Stream size                 : 2.31 MiB (96%)
Writing library             : x264 core 155 r2901 7d0ff22
Encoding settings           : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=300 / keyint_min=30 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=crf / mbtree=1 / crf=22.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=20000 / vbv_bufsize=25000 / crf_max=0.0 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Encoded date                : UTC 2018-12-16 02:45:36
Tagged date                 : UTC 2018-12-16 02:45:36
Color range                 : Limited
Color primaries             : BT.709
Transfer characteristics    : BT.709
Matrix coefficients         : BT.709

Audio
ID                          : 2
Format                      : AAC
Format/Info                 : Advanced Audio Codec
Format profile              : LC
Codec ID                    : mp4a-40-2
Duration                    : 4 s 246 ms
Bit rate mode               : Variable
Bit rate                    : 167 kb/s
Channel(s)                  : 2 channels
Channel positions           : Front: L R
Sampling rate               : 48.0 kHz
Frame rate                  : 46.875 FPS (1024 SPF)
Compression mode            : Lossy
Stream size                 : 86.7 KiB (4%)
Title                       : Stereo / Stereo
Language                    : English
Default                     : Yes
Alternate group             : 1
Encoded date                : UTC 2018-12-16 02:45:36
Tagged date                 : UTC 2018-12-16 02:45:36
  • What does Handbrake have to do with ffmpeg? The question is unclear. – harrymc Dec 15 '18 at 18:18
  • 1
    Handbrake uses ffmpeg under the hood. – Gyan Dec 15 '18 at 19:10
  • To the OP, share the mediainfo readout for the input and output files. – Gyan Dec 15 '18 at 19:10
  • @Gyan Sure. Added to the question – Mehran Dec 16 '18 at 3:06
1

But how/why the width changes to 1080 (1080*1080)

The original video is 1920⨉1080, but it's actually rotated by 90° (portrait mode), so Handbrake rotates it back, which means that the height suddenly becomes 1920. For a 1080p preset, Handbrake will subsequently scale the image back to 1080 height.

and output video is not stretched ?

Because Handbrake set the display aspect ratio (DAR) to 0.563, as visible in your output. This is what anamorphic scaling does.

What is ffmpeg command or formula for calculating it?

1920⨉0.563 ~= 1080, so the horizontal value is "squeezed" to fit into 1080, then stretched while playing. You can also calculate the DAR as 9/16.

If you want to reproduce this kind of output with ffmpeg, you simply need to use the scale and setdar filters, e.g.

-vf scale=1080:1080,setdar=9:16

However, it is not clear from your question as to whether you really want or need this. I'd recommend just encoding the video with a DAR of 1. Optionally, you may want to rotate your videos back to landscape first, and reset the rotation flag with:

-metadata:s:v:0 rotate=0
  • Thank's for your response. I'm using ffmpeg to compress media in an android app. Curently I'm using this for 1080p preset: "-vf scale=-2:1080". Until I saw Handbrake is doing it in another way. I thought maybe I can do this better. – Mehran Dec 17 '18 at 15:10
  • I check the height not being smaller than 1080. if it is. then I use source height "-vf scale=-2:srcHeight" – Mehran Dec 17 '18 at 15:17
  • No, what you are doing in Android is correct. – slhck Dec 17 '18 at 17:10
  • -metadata:s:v:0 rotate=0 considering I'm using dynamic media source isn't it cleaner to let ffmpeg handle rotation by itself? – Mehran Dec 18 '18 at 6:05
  • It depends on your use case. If you want to keep the rotation flag (e.g., if you know that your player supports it), then there's no need to reset it. – slhck Dec 18 '18 at 8:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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