1

I wanted to know if we can feed the output of an encode operation to a "filter_complex" with a command like:

ffmpeg -i input.mp4 -c:v libx264 -s:v 1920x1080 -b:v 10000k "[encoder-output-1]" \
-c:v libx264 -s:v 1280x720 -b:v 5000k "[encoder-output-2]" \
-c:v libx264 -s:v 640x360 -b:v 2000k "[encoder-output-3]" \
-filter_complex "[encoder-output-1][0:v]psnr" -f null - \
-filter_complex "[encoder-output-2][0:v]psnr" -f null -\
-filter_complex "[encoder-output-3][0:v]psnr" -f null - 

If we can do something like this, how should one name the output pad of the encoder, so that one can reference/map it in the filter_complex If not, please let me know what is the easiest way to achieve something like this.

Note:

  1. I would be using third party encoders that don't have the capability to calculate PSNR scores internally. Thus, I would like to compute the PSNR within an FFmpeg filter.
nsp
  • 87
  • 8

1 Answers1

0

Filters need decoded frames, so the encoded output can't be used directly. You can pipe it to another ffmpeg process.

ffmpeg -i input.mp4 -map 0:v -map 0:v -map 0:v
       -c:v libx264 -b:v:0 10000k -b:v:1 5000k -b:v:2 2000k -f nut - | 
 ffmpeg -i input.mp4 -f nut -i -
        -filter_complex "[1:v:0][0:v]psnr;[1:v:1][0:v]psnr;[1:v:2][0:v]psnr" -f null -

To avoid decoding the video twice, use

ffmpeg -i input.mp4 -map 0:v -map 0:v -map 0:v -map 0:v
       -c:v libx264 -c:v:3 rawvideo -b:v:0 10000k -b:v:1 5000k -b:v:2 2000k -f nut - | 
 ffmpeg -f nut -i -
        -filter_complex "[1:v:0][1:v:3]psnr;[1:v:1][1:v:3]psnr;[1:v:2][1:v:3]psnr" -f null -
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks for the inputs. I am trying to avoid decoding the input twice, as it is a very high bitrate input content. Thus, I was trying to avoid using pipes for the same. Is there any way to introduce a decoder after an encoder in the first pipeline? – nsp Aug 18 '17 at 08:25
  • Great! This should work. I needed a small clarification. If the third party encoder that i am using doesnt support multi-bitrate mode like x264, i will need to have multiple instances of that encoder. In this case, should i use named pipes for piping the output? – nsp Aug 18 '17 at 08:49
  • Can you give an example? The multi-bitrate mode is a feature of ffmpeg, not the encoder. ffmpeg creates contexts for each mapped stream and invokes encoders for them. – Gyan Aug 18 '17 at 08:53
  • Didnt know that the multi bitrate mode was a feature of FFmpeg. My use-case potentially might involve multiple streams, each with different resolutions – nsp Aug 18 '17 at 11:51
  • In this case, I would have multiple x264 instances for each of these resolutions. I think a solution to this problem would be to use multiple named pipes, as suggested in [link](https://stackoverflow.com/questions/37548606/redirect-ffmpegs-output-to-multiple-named-pipes-on-windows). I wanted to know if there is a better method to pass multiple outputs to the next ffmpeg instance. – nsp Aug 18 '17 at 12:12