简体   繁体   English

ffmpeg奇怪的x264编码行为

[英]ffmpeg weird x264 encoding behavior

I have a captured a 720x480 video with a display aspect ratio of 16:9 which I want to crop, resize and pad, but just the x264 encoding command is giving me a headache. 我捕获了一个显示纵横比为16:9的720x480视频,我想要对其进行裁剪,调整大小和填充,但是x264编码命令让我头疼。

( Screenshot of input.m2v ) Here is my command: input.m2v的屏幕快照 )这是我的命令:

ffmpeg -ss 1861 -i input.m2v -c:v libx264 -profile:v main -preset:v medium -level 3.1 -x264opts crf=21.228 -t 60 -y -f mp4 output.mp4

And here is the ffmpeg output: 这是ffmpeg的输出:

( Screen shot of output.mp4 ) output.mp4的屏幕截图

Input #0, mpegvideo, from 'input.m2v':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mpeg2video (Main), yuv420p(tv), 720x480 [SAR 32:27 DAR 1
6:9], max. 6605 kb/s, 31.02 fps, 59.94 tbr, 1200k tbn, 59.94 tbc
[libx264 @ 02ba84c0] using SAR=32/27
[libx264 @ 02ba84c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 02ba84c0] profile Main, level 3.1
[libx264 @ 02ba84c0] 264 - core 144 r2525 40bb568 - H.264/MPEG-4 AVC codec - Cop
yleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
lock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
e_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chro
ma_qp_offset=-2 threads=12 lookahead_threads=2 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=2 keyint=250 keyint_min=25 scene
cut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=21.2 qcomp=0.60 qpmin
=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf56.19.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 720x48
0 [SAR 32:27 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc56.21.102 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))

The output size is 720x480, displayed as 853x480, as expected. 如预期的那样,输出大小为720x480,显示为853x480。 But it looks like the frame has been vertically scaled by a factor of 1.18 and then cropped to a height of 480, so that I am losing the top and bottom of the frame. 但是看起来框架已经垂直缩放了1.18倍,然后裁剪到480的高度,这样我就失去了框架的顶部和底部。 In fact, the behavior is equivalent to: 实际上,该行为等效于:

-vf "scale=720:569,crop=720:480:0:0"

Although I assume the aspect ratio plays a part here (I think the 1.18 factor is really (16/9)/(720/480)) I am surprised that ffmpeg would do that out of the blue. 尽管我认为宽高比在这里起着一定的作用(我认为1.18因子的确是(16/9)/(720/480)),但我感到惊讶的是ffmpeg会突如其来地做到这一点。 May be someone more knowledgeable than me could explain it? 可能是一个比我更能解释的知识的人吗?

Based on the screenshots, there's no error here. 根据屏幕截图,这里没有错误。

Your source is 720x480 with DAR 16:9 but Potplayer is keeping its video window at 720x480 while obeying the M2V's aspect ratio, which is to say, some of the letterbox padding in the first video is added by Potplayer and is not in the video stream. 您的信号源是DAR 16:9的720x480,但是Potplayer遵循M2V的宽高比时将其视频窗口保持在720x480,也就是说,第一个视频中的某些信箱填充是由Potplayer添加的,不在视频流中。 In the output, the horizontal canvas is appropriately expanded to 853 pixels. 在输出中,水平画布适当地扩展到853像素。 No scaling has occurred. 没有发生缩放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM