2017-06-13 25 views
0

我有一些.avi文件包含編碼在h264中的視頻,我想更改爲.mp4並在需要時更改費率。你可以看到下面用於轉換的代碼。我的問題是,當我嘗試轉換所有文件時,ffmpeg會掛起,並且它掛起的文件不時發生更改,我不知道爲什麼?代碼下面是ffmpeg掛起的輸出。我在Windows 10,Python 2.7下運行。FFMpeg批量轉換視頻文件掛起

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 
+0

我有時想知道爲什麼,但是這個問題看起來很模糊。你能否可靠地重現錯誤?如果沒有,我會說這是電腦侏儒,肆虐他們的魔法,但也看到:https://superuser.com/questions/250155/ffmpeg-hangs-when-creating-a-video – jmunsch

+0

是的,我已經嘗試了很多次,使用不同數量的文件。當文件數量很少時,每件事情都很好,當文件數量很大時它會掛起。一般來說,我認爲資源不應該是一個問題,因爲我的文件相對較小(只是我有很多)。我會去驗證資源使用情況。感謝回覆。 –

回答

0

刪除ffmpeg的標誌-pass 1

試驗和錯誤之後,我發現這個問題是在FFmpeg標誌-pass 1,我覺得(沒做研究),這是因爲ffmpeg的會將統計數據寫入同一個文件。那會導致衝突?