AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 786434
Accepted
Gary U.U. Unixuser
Gary U.U. Unixuser
Asked: 2024-11-11 06:33:34 +0800 CST2024-11-11 06:33:34 +0800 CST 2024-11-11 06:33:34 +0800 CST

如何使用 ffmpeg 同时修剪开头和淡入

  • 772

使用 ffmpeg,有关于如何修剪或如何淡入的建议,但如何在一个命令中完成这两项操作?

视频应在 00:10:07 开始为黑色,并淡入 1 秒,因此在 00:10:08 时它应该完全可见。

  1. 可以同时进行修剪和淡入吗?
  2. 我可以先测试运行它吗(对于大型视频文件,这需要几个小时)。ffplay 的工作方式与 ffmpeg 略有不同。
  3. 最后是否可以做类似的事情(从 01:28:57 开始淡入淡出,持续 1 秒,然后忽略其余部分)?

谢谢您的帮助!

加里

ffmpeg
  • 1 1 个回答
  • 29 Views

1 个回答

  • Voted
  1. Best Answer
    Hermann
    2024-11-11T09:06:57+08:002024-11-11T09:06:57+08:00

    使用 ffmpeg 来实现这个功能相对简单:

    ffmpeg -i input -ss 00:10:07 -to 01:28:57 -vf "fade=in:start_time=00:10:07:duration=1,fade=out:start_time=01:28:57:duration=1" -c:a copy output
    

    将视频编码器选项添加到您的链接中。

    请注意,这将重新压缩整个视频。如果处理能力是瓶颈,您可以(理论上)单独应用淡入淡出,然后围绕主要部分进行连接。


    假设您的输入是 mp4 中的 x264,30 fps,每 10 秒出现一个 I 帧,并且 libx264 生成与输入内容合理兼容的字节流,您可以尝试以下操作:

    # fist, find the I-frames (this does not do anything, you need to look at it yourself)
    ffprobe -v error -skip_frame nokey -show_entries frame=pts_time -select_streams v -of csv=p=0 input.mp4 
    
    # for the fade-in, using the to specifier I move the end time of the segment right in front of the next I-frame (I know the I-frame's presentation time from the prior command)
    ffmpeg -i input.mp4 -ss 00:10:07 -to 00:10:9.96666666 -vf "fade=in:start_time=$((10*60+7)):duration=1" -c:v libx264 -crf 18 -c:a copy fade_in_part.mp4
    
    # for the fade-out, I use an accurate seek with the ss after the input. the to is where the fade shall end. the fade's start_time is absolute.
    ffmpeg -i input.mp4 -ss 01:28:50 -to 01:28:58 -vf "fade=out:start_time=$((1*3600+28*60+57)):duration=1" -c:v libx264 -crf 18 -c:a copy fade_out_part.mp4
    
    # for the main part, I use I-frame seeks (with ss and to before the input)
    ffmpeg -ss 00:10:10 -to 01:28:49.96666666 -i input.mp4 -c copy main_part.mp4
    
    # now put the three parts together
    ffmpeg -f concat -safe 0 -i file_list.txt -c copy output.mp4
    

    其中file_list.txt包含:

    file 'fade_in_part.mp4'
    file 'main_part.mp4'
    file 'fade_out_part.mp4'
    

    这样,您将需要编写两次主要部分,从而使 I/O 成为瓶颈。

    我认为这种方法很繁琐而且很难做到正确。

    • 1

相关问题

  • 使用 ffmpeg 从 FLAC 到 ALAC 的无损音频转换

  • 来自 PNG 帧的 H.264/MPEG-4:如何以及如何调整压缩

  • ffmpeg 命令在脚本内静默失败,但在直接运行时有效

  • 将 MKV 内的音频转换为 AC3 或 DTS,保留 6.1 声道

  • ffmpeg:普通文件名的“找不到协议”

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve