FFMpeg批量转换视频文件挂起

时间:2017-06-13 21:46:45

标签: python video ffmpeg

我有一些.avi文件包含以h264编码的视频,我想更改为.mp4并根据需要更改费率。您可以在下面看到用于转换的代码。我的问题是当我尝试转换所有文件时ffmpeg会挂起,并且它挂起的文件会不时变化,我想知道为什么?代码下面是ffmpeg挂起的输出。我在Windows 10,python 2.7下运行。

import subprocess
import os

def convert(fileName):
    sourceFile = fileName
    print sourceFile.split('.')
    targetFile = fileName.split('.')[0] + ".mp4"
    subprocess.call(['ffmpeg', '-y', '-i', sourceFile, '-r',
         '30000/1001', '-b:a', '2M', '-bt', '4M', '-vcodec',
          'libx264', '-pass', '1', '-coder', '0', '-bf', '0',
           '-flags', '-loop', '-wpredp', '0', '-an', targetFile])



# Set the directory you want to start from
def convertBatch(rootDir = '.'):
    for dirName, subdirList, fileList in os.walk(rootDir):
        print('Found directory: %s' % dirName)

        for fname in fileList:
            if fname.endswith(".avi"):
                convert('%s/%s' % (dirName,fname))
                #os.remove('%s/%s' % (dirName,fname))


convertBatch("F:\\data\\mp4")
ffmpeg version 3.1.4 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, avi, from 'filename.avi':
  Metadata:
    encoder         : Lavf57.56.100
  Duration: 00:00:01.00, start: 0.000000, bitrate: 611 kb/s
    Stream #0:0: Video: h264 (Constrained Baseline) (x264 / 0x34363278), yuv420p, 1024x1024, 578 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc
Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (F:\data\mp4_1_16\11\14\512/11_14_512_16.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
[libx264 @ 00000000028e42c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 00000000028e42c0] profile Constrained Baseline, level 3.2
[libx264 @ 00000000028e42c0] 264 - core 148 r2721 72d53ab - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=1:0:0 analyse=0x1:0 me=dia subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=18 lookahead_threads=6 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 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
[mp4 @ 0000000002bd00a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, mp4, to 'filename.mp4':
  Metadata:
    encoder         : Lavf57.41.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1024x1024, q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc57.48.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help

1 个答案:

答案 0 :(得分:0)

删除ffmpeg标志-pass 1

经过反复试验,我发现问题出在ffmpeg标志-pass 1,我认为(没有研究),因为ffmpeg会将统计数据写入同一个文件。那会引起冲突吗?