0

I wanted to run a PSNR check on a encoded segment but avoid extracting the segment in a lossless codec first for comparsion. I just wanted to trim the input, however it looks like this is disabled.

My command:

ffmpeg -i original.mp4 -i segment.mp4 -filter_complex "[0:v]trim=10:20,setpts=PTS-STARTPTS[0v];[1:v]setpts=PTS-STARTPTS[1v];[0v][1v]psnr" -f null -

This will run through the whole original input file and not trim the video in the filter.

If I try to trim the input with -ss and -t, only the input -ss flag is working. It will set the input correct but ignore the -t timestamp.

ffmpeg -ss 10 -i original.mp4 -t 10 -i segment.mp4 -filter_complex [0:v][1:v]psnr -f null - 

Different placement of the -t will have no effect.

I also tried to set the duration in trim while keeping the -ss input which is working.

ffmpeg -ss 10 -i original.mp4 -i segment.mp4 -filter_complex "[0:v]trim=duration=10,setpts=PTS-STARTPTS[0v];[1:v]setpts=PTS-STARTPTS[1v];[0v][1v]psnr" -f null - 

I did try this with end and end_frame but neither one worked.

The same applies if I use -lavfi instead of -filter_complex.

I did have a brief look at the sourcecode of the PSNR filter but could not find any refrences to trim or -t.

Is this function blocked or am I doing something wrong? Would there be an alternative way to doing this without encoding a lossless version of the same segment to compare?

1 Answer 1

1

The original command is almost fine. However, the order of inputs should be swapped, and if there's any audio, that should be disabled.

ffmpeg -i original.mp4 -i segment.mp4 -filter_complex "[0:v]trim=10:20,setpts=PTS-STARTPTS[0v];[1:v]setpts=PTS-STARTPTS[1v];[1v][0v]psnr" -an -f null -

Also, in the snippet below

ffmpeg -ss 10 -i original.mp4 -t 10 -i segment.mp4

if you meant to limit the duration of original.mp4, then -t 10 should be placed before -i original.mp4.

5
  • i cannot confirm this. if i switch the videos it will still run the full length of the original input. also it makes no difference if it would be working. if the two videos are switched since they are still compared to eachother and would give exactly the same result regarding the placement. also the -t flag, i stated in my original post that -t will be ignored no matter where i place it. Commented Nov 14, 2018 at 16:35
  • PSNR is not a symmetrical metric so the order of the inputs matter. Share the full log.
    – Gyan
    Commented Nov 14, 2018 at 16:40
  • please test it for yourself. since this is not related to my initial question it would be confusing to add the log about something else to the above question. i can give you the two results lines here: $ffmpeg -i $input1 -i $input2 -filter_complex "[0:v][1:v]psnr" -f null - PSNR y:45.763443 u:48.766435 v:50.143376 average:46.673590 min:45.239254 max:50.089223 $ffmpeg -i $input1 -i $input2 -filter_complex "[1:v][0:v]psnr" -f null - PSNR y:45.763443 u:48.766435 v:50.143376 average:46.673590 min:45.239254 max:50.089223 Commented Nov 14, 2018 at 16:44
  • I meant the log of your first command. I can reproduce the asymmetry of PSNR here.
    – Gyan
    Commented Nov 14, 2018 at 16:52
  • I was wrong about the -t flag and it worked being placed infront! i must have missed that in all my testing and moving things around. additionally it looks like the trim is working too but the PSNR filter will run through the whole video regardless... which confused me. thank you for pushing the right buttons and make me double and triple check. (btw, I still cannot confirm different PSNR results by switching the videos.) Commented Nov 14, 2018 at 17:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.