Python 如何编码25fps

Python 如何编码25fps,python,ffmpeg,Python,Ffmpeg,我不是程序员,但我工作的一部分是重新编码。在我之前的那个人留下了一个录像脚本。 当前的问题是:我需要在脚本中添加一行代码,以便将任何视频重新编码为25 fps。我尝试将-filter:v fps=fps=25添加到脚本中,它可以工作,但会忽略所有其他重新编码设置。所以如果有人能帮忙,我会非常高兴。很抱歉,正如我所说,我的语言很琐碎-我不是程序员:( 以下是脚本: import os, subprocess DIR = r"\\server-01\E\_NEW CONTENT\_Cu

我不是程序员,但我工作的一部分是重新编码。在我之前的那个人留下了一个录像脚本。 当前的问题是:我需要在脚本中添加一行代码,以便将任何视频重新编码为25 fps。我尝试将-filter:v fps=fps=25添加到脚本中,它可以工作,但会忽略所有其他重新编码设置。所以如果有人能帮忙,我会非常高兴。很抱歉,正如我所说,我的语言很琐碎-我不是程序员:( 以下是脚本:

import os, subprocess


DIR = r"\\server-01\E\_NEW CONTENT\_Current Time\Actual Programs" 


EXP = r"\\server-01\D\_RENDERED CONTENT\Current Time" 
print ( "=-===-=-=-="  )

ALLDIR =  os.listdir(DIR)
#ext = ".mp4"
#ext = ".mov"
ext = ".mpg"

FL0 = [x for x in ALLDIR if x.endswith("mpg") or x.endswith("mp4") or x.endswith("mxf") or x.endswith("mov") ]


CL = len(FL0)
print ( "Amount of files: ", CL )



#if pres_scaler
#Deint = True
Deint = False 
crop = False
#crop = True
scale = True
#scale = False
#recode = False
recode = True
interlaced_tff = False
cmdlist = []

for i in range(0, CL):
#for i in range(0, 1):
#for i in range(12, CL):
    vfs = []

cur_name = FL0[i]
print ("Input file path: ", cur_name)

new_name = os.path.splitext(cur_name)[0] + ".mp4"
PATH = DIR + os.sep + cur_name

EXPATH = EXP + os.sep + new_name

if Deint:
    #yadif = " -vf \"yadif=0:0:0\" "
    vfs.append("yadif=0:0:0")
    #vfs.append("drawbox=x=0:y=0:w=720:h=2:color=black:t=max")
    #yadif = " -vf \"yadif=0:0:0,drawbox=x=0:y=0:w=720:h=4:color=black:t=max\" "
else : yadif = ""
if interlaced_tff:
    vfs.append("fieldorder=tff" )
if crop:
    vfs.append("crop=720:432:0:72" )
if scale:
    vfs.append("scale=720x576" )
if len(vfs) > 0:
    vfcmd = "-vf \"" + ",".join(vfs) + "\""
else: vfcmd = ""
print (vfcmd)
cmd = "ffmpeg -hide_banner -i \"" + PATH + "\" " + vfcmd 

if recode:
    
    cmd = cmd + ' -aspect "16:9" -profile:v main -c:v libx264 -pix_fmt yuv420p -filter:v fps=fps=25  '
    if interlaced_tff:
        cmd = cmd + " -flags +ildct+ilme -x264opts tff=1 "
    cmd = cmd + '   -crf 19  -b:a 192k  -ar 48000 -ac 2 '
else: 
    cmd = cmd + " -c:v copy " + " -af \"volume=2\" -ar 48000 " 


cmd = cmd + "\"" + EXPATH + "\""

print ( cmd )
cmdlist.append(cmd)
print ( "=-===-=-=-=" )
subprocess.call(cmd)
下面是我从FFMPEG获得的文本:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '\\server-01\E\_NEW 
CONTENT\_Current Time\Actual Programs\PROG_Detali_80_Robopes_na_zavode_Ford_ 1017.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2020-10-17T05:10:47.000000Z
  Duration: 00:23:22.28, start: 0.000000, bitrate: 15331 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 14999 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
  creation_time   : 2020-10-17T05:10:47.000000Z
  handler_name    : ?Mainconcept Video Media Handler
  encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2020-10-17T05:10:47.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
Only '-vf fps=fps=25' read, ignoring remaining -vf options: Use ',' to separate filters
Only '-af (null)' read, ignoring remaining -af options: Use ',' to separate filters
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0000016645a43040] using SAR=1/1
[libx264 @ 0000016645a43040] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000016645a43040] profile Main, level 4.0, 4:2:0, 8-bit
[libx264 @ 0000016645a43040] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 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=19.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '\\server-01\D\_RENDERED CONTENT\Current     Time\PROG_Detali_80_Robopes_na_zavode_Ford_ 1017.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf58.39.101
    Stream #0:0(eng): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2020-10-17T05:10:47.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : Lavc58.73.102 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      creation_time   : 2020-10-17T05:10:47.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      encoder         : Lavc58.73.102 aac
frame=  217 fps= 23 q=24.0 size=   10496kB time=00:00:08.64 bitrate=9951.8kbits/s speed=0.926x    
改变


首先,您应该了解如何手工编写ffmpeg命令行(无需脚本)以获得所需的输出。如果您知道这一点,请在问题中放置一个命令行示例,作为格式正确的文本。您的意思是“-filter:v fps=fps=25”?我是指由脚本组装的完整命令行。脚本在调用之前将其打印出来,这样您就有了一个起点。好的,我希望您是这个意思(为我愚蠢的尝试感到抱歉,我真的不知道我在做什么):将其添加到我的帖子中
cmd = cmd + ' -aspect "16:9" -profile:v main -c:v libx264 -pix_fmt yuv420p '
cmd = cmd + ' -aspect "16:9" -profile:v main -c:v libx264 -pix_fmt yuv420p -r 25 '