当前位置: 首页 > news >正文

ffmpeg将mp4转换为swf

文章目录

    • ffmpeg安装、配置
        • java运行报错 Cannot run program "ffmpeg"
    • ffmpeg命令
        • mp4转为swf示例
      • ### ffmpeg -i input.mkv -b:v 600 -c:v libx264 -vf scale=1920:1080 -crf 10 -ar 48000 -r 24 output.swf
        • mkv转为swf示例
    • 其他
      • 文档
      • 命令参数简介

需要将mp4转换为swf,网上有很多软件,不是收费,就是功能不全,要不就是分辨率比例不满足要求。突然想到实在不行就自己开发个,谁让自己是程序员呢。

ffmpeg安装、配置

不是只写程序就行,需要先安装ffpmeg。

下载地址:
https://www.gyan.dev/ffmpeg/builds/#release-builds # 下载zip包就行

然后配置环境变量,在path中添加即可。
ffmpeg.exe所在的目录就是要添加到path中的路径。如:
D:\Program Files\ffmpeg\ffmpeg-7.0.1-essentials_build\bin

打开cmd,输入ffmpeg -h 命令试下是否可以了。

注:git bash命令行最好也添加下。

java运行报错 Cannot run program “ffmpeg”

Cannot run program “ffmpeg -i d:\swf\input.mp4 -vcodec libx264 -f flv d:\swf\output.swf”: CreateProcess error=2, 系统找不到指定的文件

解决方案:
1、ffmpeg已安装,且环境变量已配置。
2、git bash的安装路径下,也添加bin下的3个exe。

但还是报错,这就怪了。

ffmpeg命令

初衷原本是想用java开发的,后来发现直接用命令就可以,那应该比java更方便。

这里特别强调下,ffmpeg是个非常强大的命令,里面知识特别多,如果连扩展也算上,如:ffmpeg-all,ffplay。那么知识就更多了,要花太多的时间
想要用好这个命令,对视频音频各种编码还需要有一定认知,一般人都不太懂这个。
所以,我们会用几个常用命令,能实现简单转换就够了。

命令模板:

usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

ffmpeg -version # 查看版本
ffmpeg -h # 帮助

以下表格内三种写法是等价的:

音频视频字幕
-codec:a-codec:v-codec:s
-c:a-c:v-c:s
-acodec-vcodec-scodec

①、主要命令选项
-f fmt (input/output) :指定输入或者输出文件格式(封装格式,视频容器)。常规可省略,而使用依据扩展名(文件的前几百 K 的内容,智能分析)的自动指定,但一些选项需要强制明确设定。
-i filename(input) :指定输入文件。
-y(global):默认自动覆盖输出文件,而不再询问确认。
-n( global):不覆盖输出文件,如果输出文件已经存在则立即退出。
-t duration( input/output):限制输入/输出的时间。如果是在 -i 前面,就是限定从输入中读取多少时间的数据;如果是用于限定输出文件,则表示写入多少时间数据后就停止。duration 可以是以秒为单位的数值或者 hh:mm:ss.xxx 格式的时间值。注意 -to 和 -t 是互斥的,-t 有更高优先级。
-to position (output) :只写入 position 时间后就停止,position 可以是以秒为单位的数值或者 hh:mm:ss.xxx 格式的时间值。注意 -to 和 -t 是互斥的,-t 有更高优先级。
-ss position (input/output):当在 -i 前,表示定位输入文件到 position 指定的位置。注意可能一些格式是不支持精确定位的,所以 ffmpeg 可能是定位到最接近 position(在之前)的可定位点。position 可以是以秒为单位的数值或者 hh:mm:ss.xxx 格式的时间值。
-codec[:stream_specifier] codec (input/output,per-stream) :为特定的文件选择编/解码模式,对于输出文件就是编码器, 对于输入或者某个流就是解码器。选项参数中 codec 是编解码器的名字,或者是 copy(仅对输出文件)则意味着流数据直接复制而不再编码。
使用下面命令可以检测 ffmepg 所支持的所有编码器的格式

ffmpeg -encoders # 查看所支持的所有编码器的格式,内容太多,不列出了,还是那句话ffmpeg是个比较专业的东西

mp4转为swf示例
ffmpeg -i input.mp4 -vcodec copy -f flv output.swf
参数说明:
-i input.mp4 指定输入文件。
-vcodec copy 表示复制视频编解码器数据。
-f flv 指定输出格式为FLV,因为SWF通常通过FLV容器格式传输视频。

### ffmpeg -i input.mkv -b:v 600 -c:v libx264 -vf scale=1920:1080 -crf 10 -ar 48000 -r 24 output.swf

报错:
SWF muxer only supports VP6, FLV, Flash Screen Video, P
NG and MJPEG

mkv转为swf示例
ffmpeg -i input.mkv -c:v flashvideo -c:a flashaudio -f flash output.swf
在这个命令中:
-i input.mkv 指定输入文件。
-c:v flashvideo 指定视频编码器为flashvideo,这是SWF格式支持的视频编码器之一。
-c:a flashaudio 指定音频编码器为flashaudio,这是SWF格式支持的音频编码器之一。
-f flash 指定输出格式为SWF。
output.swf 是输出文件的名称。请注意,确保你的FFmpeg版本支持你想要使用的编码器。如果你的版本不支持这些编码器,你可能需要使用其他编码器或者升级你的FFmpeg。

其他

文档

官网文档:
https://ffmpeg.org/ffmpeg.html

这个是文档详细描述页:
https://ffmpeg.org/documentation.html

比较不错的文章:
FFmpeg常用命令行讲解及实战一

命令参数简介

ffmpeg -h返回的内容:

ffmpeg -h
返回:
ffmpeg version 7.0.1-essentials_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developersbuilt with gcc 13.2.0 (Rev5, Built by MSYS2 project)configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberbandlibavutil      59.  8.100 / 59.  8.100libavcodec     61.  3.100 / 61.  3.100libavformat    61.  1.100 / 61.  1.100libavdevice    61.  1.100 / 61.  1.100libavfilter    10.  1.100 / 10.  1.100libswscale      8.  1.100 /  8.  1.100libswresample   5.  1.100 /  5.  1.100libpostproc    58.  1.100 / 58.  1.100
Universal media converter
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...Getting help:-h      -- print basic options-h long -- print more options-h full -- print all options (including all format and codec specific options, very long)-h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocolSee man ffmpeg for detailed description of the options.Per-stream options can be followed by :<stream_spec> to apply that option to specific streams only. <stream_spec> can be a stream index, or v/a/s for video/audio/subtitle (see manual for full syntax).Print help / information / capabilities:
-L                  show license
-h <topic>          show help
-version            show version
-muxers             show available muxers
-demuxers           show available demuxers
-devices            show available devices
-decoders           show available decoders
-encoders           show available encoders
-filters            show available filters
-pix_fmts           show available pixel formats
-layouts            show standard channel layouts
-sample_fmts        show available audio sample formatsGlobal options (affect whole program instead of just one file):
-v <loglevel>       set logging level
-y                  overwrite output files
-n                  never overwrite output files
-stats              print progress report during encodingPer-file options (input and output):
-f <fmt>            force container format (auto-detected otherwise)
-t <duration>       stop transcoding after specified duration
-to <time_stop>     stop transcoding after specified time is reached
-ss <time_off>      start transcoding at specified timePer-file options (output-only):
-metadata[:<spec>] <key=value>  add metadataPer-stream options:
-c[:<stream_spec>] <codec>  select encoder/decoder ('copy' to copy stream without reencoding)
-filter[:<stream_spec>] <filter_graph>  apply specified filters to audio/videoVideo options:
-r[:<stream_spec>] <rate>  override input framerate/convert to given output framerate (Hz value, fraction or abbreviation)
-aspect[:<stream_spec>] <aspect>  set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-vn                 disable video
-vcodec <codec>     alias for -c:v (select encoder/decoder for video streams)
-vf <filter_graph>  alias for -filter:v (apply filters to video streams)
-b <bitrate>        video bitrate (please use -b:v)Audio options:
-aq <quality>       set audio quality (codec-specific)
-ar[:<stream_spec>] <rate>  set audio sampling rate (in Hz)
-ac[:<stream_spec>] <channels>  set number of audio channels
-an                 disable audio
-acodec <codec>     alias for -c:a (select encoder/decoder for audio streams)
-ab <bitrate>       alias for -b:a (select bitrate for audio streams)
-af <filter_graph>  alias for -filter:a (apply filters to audio streams)Subtitle options:
-sn                 disable subtitle
-scodec <codec>     alias for -c:s (select encoder/decoder for subtitle streams)
http://www.lryc.cn/news/384937.html

相关文章:

  • 论文学习 --- RL Regret-based Defense in Adversarial Reinforcement Learning
  • 【Linux小命令】一文讲清ldd命令及使用场景
  • 自费5K,测评安德迈、小米、希喂三款宠物空气净化器谁才是高性价比之王
  • 1373. 二叉搜索子树的最大键值和
  • 基于java + Springboot 的二手物品交易平台实现
  • Shopee本土店选品有什么技巧?EasyBoss ERP为你整理了6个高效选品的方法!
  • 3D在线展览馆的独特魅力,技术如何重塑展览业的未来?
  • 基于SpringBoot的藏区特产销售平台
  • hudi系列-schema evolution(一)
  • Redis-实战篇-缓存雪崩
  • 线性代数|机器学习-P18快速下降奇异值
  • 本地离线模型搭建指南-中文大语言模型底座选择依据
  • 【代码随想录】【算法训练营】【第51天】 [115]不同的子序列 [583]两个字符串的删除操作 [72]编辑距离
  • 24下半年软考集合!30s打破信息差!
  • 如何在Xcode中设置库路径
  • 小程序的基本使用
  • [保姆级教程]uniapp设置字体引入字体格式
  • 【Webpack】前端工程化之Webpack与模块化开发
  • 【Android】记录在自己的AMD处理器无法使用Android studio 虚拟机处理过程
  • LearnOpenGL - Android OpenGL ES 3.0 使用 FBO 进行离屏渲染
  • 人工智能虚拟仿真系统,解决算法难、编程难、应用场景难三大难题
  • CTE(公共表表达式)和视图在查询时的性能影响
  • 新能源行业必会基础知识-----电力市场概论笔记-----绪论
  • 003 SpringBoot操作ElasticSearch7.x
  • npm install报错Maximum call stack size exceeded
  • 第1章 基础知识
  • python脚本 限制 外部访问 linux服务器端口
  • Redis-哨兵模式-主机宕机-推选新主机的过程
  • 游戏工厂:AI(AIGC/ChatGPT)与流程式游戏开发
  • 每日一练 - OSPF 组播地址