我用
call(['avconv', '-i', 'video.mp4', '-vsync', '1','-r', '1','-an','-y','%5d.jpg'])
在Python中。它有效,但它实时通过视频文件。如何加快速度,所以总共得到60张图片,视频文件的每一秒都不需要1分钟而是更少。
答案 0 :(得分:0)
以下Python代码尽可能快地提取60秒的帧,并将它们作为JPEG文件输出到当前目录中。
from subprocess import call
call([
'avconv', '-i', 'video.mp4',
'-vsync', '1',
'-r', '1',
'-an', '-y',
'-t', '60', # 60 seconds = 60 pictures
'%5d.jpg',
])
avconv version 0.8.9-6:0.8.9-0ubuntu0.13.10.1, Copyright (c) 2000-2013 the Libav developers
built on Nov 9 2013 19:09:46 with gcc 4.8.1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x14bbe00] multiple edit list entries, a/v desync might occur, patch welcome
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf53.21.1
Duration: 01:59:16.23, start: 0.000000, bitrate: 1153 kb/s
Stream #0.0(und): Video: mpeg4 (Advanced Simple Profile), yuv420p, 480x368 [PAR 1:1 DAR 30:23], 1016 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 23.98 tbc
Stream #0.1(und): Audio: aac, 48000 Hz, mono, s16, 63 kb/s
Stream #0.2(und): Audio: aac, 48000 Hz, mono, s16, 64 kb/s
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer @ 0x1670a20] w:480 h:368 pixfmt:yuv420p
[avsink @ 0x147f6a0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x14bf520] w:480 h:368 fmt:yuv420p -> w:480 h:368 fmt:yuvj420p flags:0x4
Output #0, image2, to '%5d.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf53.21.1
Stream #0.0(und): Video: mjpeg, yuvj420p, 480x368 [PAR 1:1 DAR 30:23], q=2-31, 200 kb/s, 90k tbn, 1 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 -> mjpeg)
Press ctrl-c to stop encoding
frame= 62 fps= 37 q=11.2 Lsize= -0kB time=62.00 bitrate= -0.0kbits/s dup=0 drop=1375
video:1784kB audio:0kB global headers:0kB muxing overhead -100.001204%