簡體   English   中英

我無法將 ffmpeg 命令轉換為 ffmpeg-python

[英]I have trouble converted ffmpeg command to ffmpeg-python

我正在嘗試使用以下 ffmpeg 命令從 HDR 轉換為 SDR,該命令有效

ffmpeg -i input.mov -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx264 -crf 0 -preset ultrafast -tune fastdecode output.mp4

但是,我無法將其轉換為 ffmpeg-python 格式。 你能指導我如何處理分號、等號和奇怪的 = = 案例嗎?

ffmpeg.input("input.mov", r=fps).filter('zscale', t='linear:npl').filter('format', 'gbrpf32le') ...

轉換非常簡單:

ffmpeg.input('input.mov')\
    .video.filter('zscale', t='linear', npl=100)\
    .filter('format', pix_fmts='gbrpf32le')\
    .filter('zscale', p='bt709')\
    .filter('tonemap', tonemap='hable', desat=0)\
    .filter('zscale', t='bt709', m='bt709', r='tv')\
    .filter('format', pix_fmts='yuv420p')\
    .output('output.mp4', vcodec='libx264', crf=0, preset='ultrafast', tune='fastdecode')\
    .run()

  • ffmpeg.input ffmpeg.input(...)的 Arguments 以輸入文件名開頭,后跟輸入 arguments。
  • .video后跟.filter(...).filter(...).filter(...)應用視頻過濾器鏈。
  • filter(...)以過濾器名稱開頭,后跟過濾器參數 arguments。
    語法是 <param_name0>=param_value0, <param_name1>=param_value1...
  • output(...) 以 output 文件名開頭,后跟 output arguments。

唯一需要注意的是format過濾器。
format過濾器的參數名稱是pix_fmts (我們通常跳過它)。
獲取參數名稱的一種方法是使用 FFmpeg 幫助(在命令行中):

ffmpeg -h filter=format

Output:

Filter format
  Convert the input video to one of the specified pixel formats.
    Inputs:
       #0: default (video)
    Outputs:
       #0: default (video)
(no)format AVOptions:
   pix_fmts          <string>     ..FV....... A '|'-separated list of pixel formats

在這里我們可以看到參數名稱是pix_fmts


使用 ffmpeg-python 時,建議添加.overwrite_output() (相當於-y參數)。

對於測試,建議添加.global_args('-report')以創建日志文件(完成測試后刪除.global_args('-report') )。

ffmpeg.input('input.mov')\
    .video.filter('zscale', t='linear', npl=100)\
    .filter('format', pix_fmts='gbrpf32le')\
    .filter('zscale', p='bt709')\
    .filter('tonemap', tonemap='hable', desat=0)\
    .filter('zscale', t='bt709', m='bt709', r='tv')\
    .filter('format', pix_fmts='yuv420p')\
    .output('output.mp4', vcodec='libx264', crf=0, preset='ultrafast', tune='fastdecode')\
    .global_args('-report').overwrite_output().run()

日志向我們展示了實際的 FFmpeg 命令:

ffmpeg -i input.mov -filter_complex "[0:v]zscale=npl=100:t=linear[s0];[s0]format=pix_fmts=gbrpf32le[s1];[s1]zscale=p=bt709[s2];[s2]tonemap=desat=0:tonemap=hable[s3];[s3]zscale=m=bt709:r=tv:t=bt709[s4];[s4]format=pix_fmts=yuv420p[s5]" -map "[s5]" -crf 0 -preset ultrafast -tune fastdecode -vcodec libx264 output.mp4 -report -y

如您所見,ffmpeg-python 使用-filter_complex而不是-vf ,並使用臨時命名為[s0][s1][s2] ...
結果等同於您的原始命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM