python - 使用 ffmpeg 调整大小后文件损坏

标签 python python-3.x video ffmpeg instagram

我正在制作一个将视频发送到 Instagram 的机器人。然而 instagram 只允许 1:1 宽高比视频 ,所以我试图在python(ffmpy模块)中使用ffmpeg来调整视频(.mp4)文件的大小。

这是我正在使用的 ffmpeg 代码-analyzeduration 20M -probesize 20M -y -i FILE.MP4 -vf "scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:white NEW_FILE.MP4
但是,这会损坏文件吗?调整大小之前的文件大小为 1.815305 MB,但在 ffmpeg 作业之后为 0.058714 MB。那么给了什么?

(我也尝试使用 -aspect 1:1 但这也会损坏文件)

Ffmpy 似乎工作正常,因为有时如果文件超过 20 MB,我会运行它来减小文件大小 -y -i FILE.MP4 -vcodec libx264 -crf 24 NEW_FILE.MP4这很好用。

如果需要,这是完整的日志:

Oct 23 07:32:03 test-instabot app/worker.1: MP4 SIZE BEFORE ASPECT RESIZE IS: 1.815305 MB 
Oct 23 07:32:03 test-instabot app/worker.1: ffmpeg version 4.0.2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers 
Oct 23 07:32:03 test-instabot app/worker.1:   built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 
Oct 23 07:32:03 test-instabot app/worker.1:   configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg 
Oct 23 07:32:03 test-instabot app/worker.1:   libavutil      56. 14.100 / 56. 14.100 
Oct 23 07:32:03 test-instabot app/worker.1:   libavcodec     58. 18.100 / 58. 18.100 
Oct 23 07:32:03 test-instabot app/worker.1:   libavformat    58. 12.100 / 58. 12.100 
Oct 23 07:32:03 test-instabot app/worker.1:   libavdevice    58.  3.100 / 58.  3.100 
Oct 23 07:32:03 test-instabot app/worker.1:   libavfilter     7. 16.100 /  7. 16.100 
Oct 23 07:32:03 test-instabot app/worker.1:   libswscale      5.  1.100 /  5.  1.100 
Oct 23 07:32:03 test-instabot app/worker.1:   libswresample   3.  1.100 /  3.  1.100 
Oct 23 07:32:03 test-instabot app/worker.1:   libpostproc    55.  1.100 / 55.  1.100 
Oct 23 07:32:03 test-instabot app/worker.1: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './media/t4nYbas.mp4': 
Oct 23 07:32:03 test-instabot app/worker.1:   Metadata: 
Oct 23 07:32:03 test-instabot app/worker.1:     major_brand     : isom 
Oct 23 07:32:03 test-instabot app/worker.1:     minor_version   : 512 
Oct 23 07:32:03 test-instabot app/worker.1:     compatible_brands: isomiso2avc1mp41 
Oct 23 07:32:03 test-instabot app/worker.1:     encoder         : Lavf58.12.100 
Oct 23 07:32:03 test-instabot app/worker.1:   Duration: 00:00:06.04, start: 0.000000, bitrate: 2404 kb/s 
Oct 23 07:32:03 test-instabot app/worker.1:     Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 480x854, 2402 kb/s, 29.98 fps, 29.98 tbr, 19184 tbn, 59.95 tbc (default) 
Oct 23 07:32:03 test-instabot app/worker.1:     Metadata: 
Oct 23 07:32:03 test-instabot app/worker.1:       handler_name    : VideoHandler 
Oct 23 07:32:03 test-instabot app/worker.1: Stream mapping: 
Oct 23 07:32:03 test-instabot app/worker.1:   Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) 
Oct 23 07:32:03 test-instabot app/worker.1: Press [q] to stop, [?] for help 
Oct 23 07:32:03 test-instabot app/worker.1: [swscaler @ 0x6882200] Warning: data is not aligned! This can lead to a speed loss 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] profile High, level 3.2 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_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 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 
Oct 23 07:32:03 test-instabot app/worker.1: Output #0, mp4, to './media/t4nYbas.mp4': 
Oct 23 07:32:03 test-instabot app/worker.1:   Metadata: 
Oct 23 07:32:03 test-instabot app/worker.1:     major_brand     : isom 
Oct 23 07:32:03 test-instabot app/worker.1:     minor_version   : 512 
Oct 23 07:32:03 test-instabot app/worker.1:     compatible_brands: isomiso2avc1mp41 
Oct 23 07:32:03 test-instabot app/worker.1:     encoder         : Lavf58.12.100 
Oct 23 07:32:03 test-instabot app/worker.1:     Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1080x1080, q=-1--1, 29.98 fps, 19184 tbn, 29.98 tbc (default) 
Oct 23 07:32:03 test-instabot app/worker.1:     Metadata: 
Oct 23 07:32:03 test-instabot app/worker.1:       handler_name    : VideoHandler 
Oct 23 07:32:03 test-instabot app/worker.1:       encoder         : Lavc58.18.100 libx264 
Oct 23 07:32:03 test-instabot app/worker.1:     Side data: 
Oct 23 07:32:03 test-instabot app/worker.1:       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 
Oct 23 07:32:03 test-instabot app/worker.1: frame=    1 fps=0.0 q=29.0 Lsize=      57kB time=00:00:00.00 bitrate=9032923.1kbits/s speed=7.89e-05x     
Oct 23 07:32:03 test-instabot app/worker.1: video:57kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.383109% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] frame I:1     Avg QP:29.91  size: 57223 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] mb I  I16..4: 12.6% 74.9% 12.5% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] 8x8 transform intra:74.9% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] coded y,uvDC,uvAC intra: 52.6% 24.4% 1.0% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] i16 v,h,dc,p: 94%  0%  5%  1% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 10% 28%  4%  6%  5%  7%  5%  7% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 17% 15%  7%  9%  7%  9%  7%  9% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] i8c dc,h,v,p: 78%  9% 12%  2% 
Oct 23 07:32:03 test-instabot app/worker.1: [libx264 @ 0x66c99c0] kb/s:13722.08 
Oct 23 07:32:03 test-instabot app/worker.1: MP4 SIZE AFTER ASPECT RESIZE IS: 0.058714 MB

最佳答案

您的命令模板显示 -i FILE.MP4NEW_FILE.MP4但在您的实际命令中,输入是 ./media/t4nYbas.mp4和输出是一样的,./media/t4nYbas.mp4 . FFmpeg 无法就地编辑文件。输出文件必须不同。

关于python - 使用 ffmpeg 调整大小后文件损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52951931/

相关文章:

ios - Flutter video_player 从头开始​​重新启动视频

java - 如何在Java中连接/合并两个视频到一个新的视频文件中?

python - 使用异步结果调用 cuda() 导致 SyntaxError

python - pytorch前向检查输入尺寸错误

python - 如何查找元素的xpath、类名 python selenium

python - 从 python 中的列表中删除所有整数

c++ - Python 3.2 PyRun_SimpleString - 它在哪里?

flash - 什么是具有Flash和html5支持的优秀视频+声音播放器?

python - 打印()到上一行?

python - Matplotlib 极坐标图未绘制在应有的位置