【问题标题】:Speeding up video to image conversion加快视频到图像的转换
【发布时间】:2014-10-09 17:34:30
【问题描述】:

我用

call(['avconv', '-i', 'video.mp4', '-vsync', '1','-r', '1','-an','-y','%5d.jpg'])

在 Python 中。它可以工作,但它会实时浏览视频文件。如何加快速度,总共得到 60 张图片,视频文件的每一秒不需要 1 分钟而是更少。

【问题讨论】:

  • 它不会实时通过它...它会尽可能快地运行。将大量文件写入磁盘非常耗时。
  • 为什么是python标签?你只是在调用一个外部应用程序。
  • 无论你想要多少张图片,所有的视频都必须解码才能做到这一点。它被称为时间压缩
  • @crs 是对的。应删除 Python 标记。所有的 python 代码都完成了......你只想改变你的 ffmpeg 命令行。 BTW ffmpeg 应该优于 avconv
  • @TimoTheobald 不,这只是 Ubuntu 上的 avconv。由于一些内部冲突,他们显示此消息。 Avconv 是一个功能少得多的分支。 ffmpeg.org

标签: ffmpeg avconv


【解决方案1】:

以下 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%

【讨论】:

  • 在这里,这个解决方案确实需要同样的时间。
猜你喜欢
  • 2016-09-04
  • 2012-10-09
  • 1970-01-01
  • 1970-01-01
  • 2016-12-22
  • 1970-01-01
  • 1970-01-01
  • 2017-02-26
相关资源
最近更新 更多