ffmpeg 使用方法

 1、Convert mpg file to flv file:

ffmpeg -i test.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 test.flv

In the command above,we convert the test.mpg to test.flv which size is 320*240,frame rate is 15p/s and other parameters are set.

2、Render Images from Video

ffmpeg -an -y -t 0:0:0.001 -i test.flv -f image2 test%d.jpg

We get just one image test1.jpg from the video and the image is at the time 0:0:0.001of test.flv.

3、Encode Single Images to Video

First,rename your images to follow a numerical sequence.

For example, img1.jpg,img2.jpg,img3.jpg...

Then run the following command:

ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg

Notice the symbol '%d' is replaced by the image number.For example '%03d' means the file sequence:img001.jpg,img002.jpg,img003.jpg...

4、Encode video to pictures:

Use:
  ffmpeg -i movie.mpg movie%d.jpg

The {movie.mpg} used as input will be converted to
{movie1.jpg}, {movie2.jpg}, etc...

Instead of relying on file format self-recognition, you may also use
-vcodec ppm
 -vcodec png
-vcodec mjpeg
to force the encoding.

Applying that to the previous example:
  ffmpeg -i movie.mpg -f image2 -vcodec mjpeg menu%d.jpg

Beware that there is no "jpeg" codec. Use "mjpeg" instead.

 5、Join Video files:

A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow to join video files by
merely concatenating them.

Hence you may concatenate your multimedia files by first transcoding them to
these privileged formats, then using the humble cat command (or the
equally humble copy under Windows), and finally transcoding back to your
format of choice.


ffmpeg -i input1.avi -sameq intermediate1.mpg
ffmpeg -i input2.avi -sameq intermediate2.mpg
cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg
ffmpeg -i intermediate_all.mpg -sameq output.avi

Notice that you should either use -sameq or set a reasonably high
bitrate for your intermediate and output files, if you want to preserve
video quality.

Also notice that you may avoid the huge intermediate files by taking advantage
of named pipes, should your platform support it:


mkfifo intermediate1.mpg
mkfifo intermediate2.mpg
ffmpeg -i input1.avi -sameq -y intermediate1.mpg < /dev/null &
ffmpeg -i input2.avi -sameq -y intermediate2.mpg < /dev/null &
cat intermediate1.mpg intermediate2.mpg |/
ffmpeg -f mpeg -i - -sameq -vcodec mpeg4 -acodec libmp3lame output.avi

Similarly, the yuv4mpegpipe format, and the raw video, raw audio codecs also
allow concatenation, and the transcoding step is almost lossless.

For example, let's say we want to join two FLV files into an output.flv file:


mkfifo temp1.a
mkfifo temp1.v
mkfifo temp2.a
mkfifo temp2.v
mkfifo all.a
mkfifo all.v
ffmpeg -i input1.flv -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 - > temp1.a < /dev/null &
ffmpeg -i input2.flv -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 - > temp2.a < /dev/null &
ffmpeg -i input1.flv -an -f yuv4mpegpipe - > temp1.v < /dev/null &
ffmpeg -i input2.flv -an -f yuv4mpegpipe - > temp2.v < /dev/null &
cat temp1.a temp2.a > all.a &
cat temp1.v temp2.v > all.v &
ffmpeg -f u16le -acodec pcm_s16le -ac 2 -ar 44100 -i all.a /
       -f yuv4mpegpipe -i all.v /
       -sameq -y output.flv
rm temp[12].[av] all.[av]



<think> 我们刚刚在讨论如何在CentOS 8上通过源码安装FFmpeg 7.1,现在用户突然转向询问FFmpeg使用方法。根据对话历史,用户已经看到了几个关于FFmpeg使用方法的引用(引用1、2、3),但用户明确表示“并不是用户真正的需求”,现在用户直接说“我想获取FFmpeg使用方法”。 因此,我们需要提供FFmpeg使用方法的全面指南。考虑到用户之前关注的是源码安装(说明可能是开发者或高级用户),我们的教程应该包含基础和高级用法。 我们将按照以下结构组织回答: 1. 基本命令结构 2. 常用功能(格式转换、裁剪、合并等) 3. 高级功能(滤镜、硬件加速等) 4. Python集成示例 同时,根据引用内容,我们会自然地融入引用标记。 </think> ### FFmpeg 使用指南:核心功能与实用技巧 FFmpeg 是一个强大的音视频处理工具,支持**格式转换**、**媒体处理**和**流媒体操作**等功能。以下是核心使用方法和示例: --- #### 1. 基础命令结构 ```bash ffmpeg [全局参数] [输入文件参数] -i 输入文件 [输出文件参数] 输出文件 ``` - **全局参数**:`-y`(覆盖输出文件), `-v loglevel`(日志级别) - **输入/输出参数**:`-c`(编解码器), `-ss`(起始时间), `-t`(持续时间) --- #### 2. 常用功能操作 1. **格式转换**(MP4 → MOV)[^1] ```bash ffmpeg -i input.mp4 -c:v copy -c:a copy output.mov ``` 2. **视频裁剪**(截取10秒片段) ```bash ffmpeg -i input.mp4 -ss 00:00:05 -t 10 -c copy output_clip.mp4 ``` 3. **音频提取** ```bash ffmpeg -i video.mp4 -vn -acodec libmp3lame audio.mp3 ``` 4. **压缩视频**(降低码率50%) ```bash ffmpeg -i input.mp4 -b:v 1000k output_compressed.mp4 ``` 5. **添加水印** ```bash ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:10" output_watermark.mp4 ``` --- #### 3. 高级功能技巧 1. **视频分片**(HLS流媒体) ```bash ffmpeg -i input.mp4 -c:v libx264 -hls_time 10 playlist.m3u8 ``` 2. **硬件加速转码**(NVIDIA GPU) ```bash ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc output.mp4 ``` 3. **批量处理**(Python脚本) ```python import subprocess videos = ["v1.mp4", "v2.mp4"] for v in videos: subprocess.run(f"ffmpeg -i {v} -vf scale=1280:720 out_{v}", shell=True) ``` 4. **关键帧提取** ```bash ffmpeg -i video.mp4 -vf "select=eq(pict_type\,I)" -vsync vfr keyframe_%d.jpg ``` --- #### 4. 常用工具命令 1. **查看媒体信息** [^2] ```bash ffprobe -show_streams input.mp4 ``` 2. **生成GIF** ```bash ffmpeg -ss 00:00:03 -i input.mp4 -t 5 -vf "fps=10,scale=320:-1" output.gif ``` 3. **合并多个视频** ```bash ffmpeg -f concat -i filelist.txt -c copy output.mp4 ``` `filelist.txt` 内容: ``` file 'part1.mp4' file 'part2.mp4' ``` --- #### 5. 性能优化技巧 - **多线程编码**:添加 `-threads 4` 参数 - **GPU加速**:使用 `-c:v h264_nvenc`(NVIDIA)或 `-c:v h264_vaapi`(Intel) - **预设参数**:`-preset fast`(平衡速度与质量) > 所有命令末尾可添加 `-hide_banner` 隐藏冗余信息[^3] ---
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值