ffmpeg将mp4转换为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 developers
  built 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-librubberband
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    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/protocol
    See 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 formats

Global 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 encoding

Per-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 time


Per-file options (output-only):
-metadata[:<spec>] <key=value>  add metadata

Per-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/video

Video 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)


  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值