如何将FFmpeg命令转换为FFmpeg-Python代码?

问题描述 投票:0回答:2

我有这个命令行代码:

ffmpeg -hide_banner -hwaccel_device auto -hwaccel auto -thread_queue_size 2048 -f dshow -rtbufsize 2048M -pixel_format bgr24 -i video="screen-capture-recorder"  -thread_queue_size 2048 -f dshow -rtbufsize 2048M -channel_layout stereo -i audio="CABLE Output (VB-Audio Virtual Cable)" -filter_complex "[0:v]crop=1920:1040:0:0,scale=in_range=full:out_range=full:eval=init:interl=false:flags=bitexact+accurate_rnd+full_chroma_int,fps=fps=30.000,pp=fa[v1];[1:a]volume=volume=1.2[a1]" -map "[v1]" -map "[a1]" -c:a copy -c:v libx264 -preset ultrafast -tune film  -crf 17 -r 30 -force_key_frames expr:gte(t,n_forced*1) -sc_threshold 0 -pix_fmt yuvj422p -max_muxing_queue_size 2048 -copyts -start_at_zero -y -t 5 "Y:\test\ output_1".mkv

错误:过滤器图表描述中的流说明符“:a”...不匹配任何流。

我想将其转换为Python中的ffmpeg-python代码。

但是我该怎么做呢?

这就是我到目前为止所做的:

video_ = ffmpeg.input('video=screen-capture-recorder',
                     thread_queue_size=2048,
                     rtbufsize='2048M',
                     pixel_format='bgr24',
                     framerate=30,
                     f='dshow'
                     )

audio_ = ffmpeg.input('audio=virtual-audio-capturer',
                     thread_queue_size=2048,
                     rtbufsize='2048M',
                     channel_layout='stereo',
                     f='dshow'
                     )
print(' '.join(  
      ffmpeg
      .filter(video_,'fps', fps=30.000)
      .filter(video_,'crop', 1920,1040,0,0)
      .filter(video_,'pp','fa')
      .filter(video_,'scale', in_range='full', out_range ='full', eval='init', interl='false', flags='bitexact+accurate_rnd+full_chroma_int')
      .filter(audio_,'volume',volume=1.2)

      .output('Y:\\test\\output_1.mkv', acodec='copy', vcodec="libx264", preset='ultrafast',
              tune='film', crf=17, r=30, force_key_frames='expr:gte(t,n_forced*1)',
              sc_threshold=0, pix_fmt='yuv420p', max_muxing_queue_size=2048,
              start_at_zero=None, t=15)
      
      .global_args('-hide_banner')
      .global_args('-hwaccel_device', 'auto')
      .global_args('-hwaccel', 'auto')
      .global_args('-report')
      .overwrite_output()
      .compile()
))

谢谢。

ffmpeg ffmpeg-python
2个回答
0
投票

解决方案:

import ffmpeg

# fileOut = "FilePathOutput"
# time_ = "second" and 0 => for an unknown time 

# FFmpeg record=================
def videoFFmpeg(self,fileOut,time_,framerateVideo):
    
            
    video_ = ffmpeg.input('video=screen-capture-recorder',
                          thread_queue_size=2048,
                          rtbufsize='2048M',
                          pixel_format='bgr24',
                          framerate=framerateVideo,
                          f='dshow'                              
                          )

    audio_ = ffmpeg.input('audio=Микрофон (2- Xonar U7 MKII)',
                          thread_queue_size=2048,
                          rtbufsize='2048M',
                          channel_layout='stereo',
                          f='dshow'
                          )
    v2 = ffmpeg.filter(video_, 'scale',in_range='full',out_range='full',eval='init',interl='false',flags='bitexact+accurate_rnd+full_chroma_int').filter('fps', fps=framerateVideo).filter('pp', 'fa').filter('crop', 1920,1040,0,0)

    if time_==0:
        out = ffmpeg.output(v2, audio_, fileOut, acodec='copy', vcodec="libx264", preset='ultrafast',                      
                            tune='film', crf=17, r=framerateVideo, force_key_frames='expr:gte(t,n_forced*1)',
                            sc_threshold=0, pix_fmt='yuv420p', max_muxing_queue_size=2048,
                            start_at_zero=None)
    else:
        out = ffmpeg.output(v2, audio_, fileOut, acodec='copy', vcodec="libx264", preset='ultrafast',                      
                            tune='film', crf=17, r=framerateVideo, force_key_frames='expr:gte(t,n_forced*1)',
                            sc_threshold=0, pix_fmt='yuv420p', max_muxing_queue_size=2048,
                            start_at_zero=None, t=time_)
                                                                                                                                                                                                          
    
    out = out.global_args('-hide_banner')
    out = out.global_args('-hwaccel_device', 'auto')
    out = out.global_args('-hwaccel', 'auto')
    # out = out.global_args('-report')
    out = out.overwrite_output()

    self.process = out.run_async(pipe_stdin=True)
    
# Quit  FFmpeg ==================
def QuitFFmpeg(self):
    # print(1)
    self.process.communicate(str.encode("q"))

    time.sleep(3) 
    self.process.terminate()
    return 'Exit'

0
投票

谢谢,如何将 -b:v 10.1M 标志合并到捆绑包中?

问候。

© www.soinside.com 2019 - 2024. All rights reserved.