Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use filtering and stream copy together with ffmpeg?

Tags:

ffmpeg

ffmpeg -ss 0 -t 8  -i  input.mp4  -acodec copy -vcodec copy output.mp4

can set codec. However, to filter:

ffmpeg  -i  input.mp4  -vf  crop=100:100:0:0 output.mp4

if combined:

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.

how to set codec like time clip?

like image 877
chole Avatar asked Nov 28 '18 11:11

chole


1 Answers

Not possible to copy & filter the same stream

Getting the error Filtering and streamcopy cannot be used together means you have to avoid setting stream copy mode (for example -c:v copy, -c:a copy, -vcodec copy, -acodec copy, -c copy, etc) when filtering the same video or audio.

Filtering requires the input video to be fully decoded into raw video, then the raw video is processed by the filter(s), finally it is encoded:

 _______              ______________
|       |            |              |
| input |  demuxer   | encoded data |   decoder
| file  | ---------> | packets      | -----+
|_______|            |______________|      |
                                           v
                                       _________
                                      |         |
                                      | decoded |
                                      | frames  |
                                      |_________|
                                           |
                                           v
                                       __________
                                      |          |
                                      | filtered |
                                      | frames   |
                                      |__________|
 ________             ______________       |
|        |           |              |      |
| output | <-------- | encoded data | <----+
| file   |   muxer   | packets      |   encoder
|________|           |______________|

Stream copy mode omits decoding and encoding. It is like a copy and paste:

 _______              ______________            ________
|       |            |              |          |        |
| input |  demuxer   | encoded data |  muxer   | output |
| file  | ---------> | packets      | -------> | file   |
|_______|            |______________|          |________|

So it is not possible to filter and stream copy the same stream at the same time. However, you can stream copy unfiltered streams while filtering others. Example to filter video and stream copy audio:

ffmpeg -i input -filter_complex "[0:v]scale=iw/2:-1[v]" -map "[v]" -map 0:a -c:a copy output

See the ffmpeg documentation for more info.

like image 181
llogan Avatar answered Sep 20 '22 00:09

llogan