Jaffree icon indicating copy to clipboard operation
Jaffree copied to clipboard

Add User Agent Header Support

Open ssysm opened this issue 5 years ago • 7 comments

Add user agent header support for FFmpeg & FFprobe. In FFmpeg, -user_agent arg must come before -i, therefore can't use .addArguments.

ssysm avatar May 07 '20 15:05 ssysm

Hello @ssysm , I have found checked you PR and found that you probably missed how FFmpeg command line is generated. You add header property directly to FFmpeg, but you should do that for BaseInOut or BaseInput.

To make your code work without need to add extra property you should use UrlInput#addArguments instead of FFmpeg#addArguments.

kokorin avatar May 07 '20 16:05 kokorin

Hi @kokorin! Thanks for reviewing my PR request, I have looked UrlInput#addArguments and it works! I moved the add User-Agent header part to UrlInput.

ssysm avatar May 07 '20 17:05 ssysm

After 2nd commit there is no corresponding argument in FFprobe. Also it would b great to have tests that header is passed to input source. Is the same option applicable to ffmpeg output?

kokorin avatar May 07 '20 18:05 kokorin

I added the argument in FFprobe in the Input interface, but there's seems like a problem for class that is extending from SocketInput since it implemented on the Input interface. To keep constancy, I just simply return null when it tries to access the getter/setter method for userAgent (Since User-Agent is an HTTP only option). There's no output option for User-Agent since that is only a requesting only header.

On the point of testing, there's not very easy to test HTTP header related task with FFmpeg since it requires an HTTP Server with a valid media. But I do see you have an FTP Test Server setup, it would be better if you switch it to an HTTP Server.(TL;DR: Possible, but need some refactoring to test system.)

ssysm avatar May 07 '20 19:05 ssysm

FFprobe can't handle multiple inputs, so all arguments are added directly to FFprobe, not Input. Also setter on Input would contradict to FFprobe#setInput(String). I can't accept PR without tests. It's possible to test it with simple TCP socket, since we are interested only in headers which ffmpeg passes in. When ffmpeg has sent Http request it's possible to close connection. FFmpeg with fail in that case, but that would be expected and can be suppressed in tests.

Switching to HttpServer isn't very good, since HTTP uses Base64 encoding for binary data, so it would require additional time spent on encoding/decoding plus 25% overhead in size.

kokorin avatar May 08 '20 06:05 kokorin

Thanks for reviewing my code! I have added a testing HTTP server, the server will return 400 if the FFmpeg fails to set the correct User-Agent header.

ssysm avatar May 08 '20 16:05 ssysm

Interesting.. some of the CI checks is giving EOF error, I'll check again and try to reproduce the error on my end and see what's wrong.

ssysm avatar May 08 '20 16:05 ssysm