Changing AVCodecContext.sample_aspect_ratio after the encoder was opened is by itself questionable, but if anywhere it belongs in encoding rather than filtering code.