如何与ffmpeg一起使用过滤和流复制?

cho*_*ole 6 ffmpeg

ffmpeg -ss 0 -t 8  -i  input.mp4  -acodec copy -vcodec copy output.mp4
Run Code Online (Sandbox Code Playgroud)

可以设置编解码器。但是,要过滤:

ffmpeg  -i  input.mp4  -vf  crop=100:100:0:0 output.mp4
Run Code Online (Sandbox Code Playgroud)

如果合并:

Filtergraph 'crop=100:100:0:0' was defined for video output stream 0:0 but codec copy was selected.
Filtering and streamcopy cannot be used together.
Run Code Online (Sandbox Code Playgroud)

如何像时间剪辑一样设置编解码器?

llo*_*gan 17

不可能

过滤要求输入视频完全解码为原始视频,然后原始视频由过滤器处理,然后进行编码:

 _______              ______________
|       |            |              |
| input |  demuxer   | encoded data |   decoder
| file  | ---------> | packets      | -----+
|_______|            |______________|      |
                                           v
                                       _________
                                      |         |
                                      | decoded |
                                      | frames  |
                                      |_________|
                                           |
                                           v
                                       __________
                                      |          |
                                      | filtered |
                                      | frames   |
                                      |__________|
 ________             ______________       |
|        |           |              |      |
| output | <-------- | encoded data | <----+
| file   |   muxer   | packets      |   encoder
|________|           |______________|
Run Code Online (Sandbox Code Playgroud)

流复制模式省略了解码和编码:

 _______              ______________            ________
|       |            |              |          |        |
| input |  demuxer   | encoded data |  muxer   | output |
| file  | ---------> | packets      | -------> | file   |
|_______|            |______________|          |________|
Run Code Online (Sandbox Code Playgroud)

所以不可能同时过滤和流复制同一个流。但是,您可以在过滤其他流的同时流式复制未过滤的流。过滤视频和流复制音频的示例:

ffmpeg -i input -filter_complex "[0:v]scale=iw/2:-1[v]" -map "[v]" -map 0:a -c:a copy output
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅ffmpeg文档