k4yt3x / video2x

A machine learning-based lossless video super resolution framework. Est. Hack the Valley II, 2018.
https://video2x.org
GNU Affero General Public License v3.0
10.9k stars 1.02k forks source link

[FEATURE] Add FFmpeg filters #1196

Open HunterAP23 opened 1 month ago

HunterAP23 commented 1 month ago

FFmpeg contains many filters that users may want to apply to their upscaled videos. Providing some method of letting users enter in their complex filters & options would be beneficial.

Alternatively some basic filters (sharpening, deinterlacing, etc) could be available as dropdowns / CLI arguments directly, but that may be a lot of work to add individual filters & options.

Some good ideas for filters to support: Deinterlacing

Enforcing framerate

Denoising / Grain removal

Sharpening

Smoothing

Remove shaking

These are just suggestions that some users might find interesting to utilize

k4yt3x commented 1 month ago

Yeah it's definitely a nice-to-have. Let me think about if this should be implemented within Video2X. Unlike our past implementations with Python, where we can just allow the user to add custom string to the -vf argument, if we need to add filters in 6.0.0, we'll need to create filter graphs in C++, so it's probably going to add too much complexity.

At the same time, I'd like to keep the new version focus on the core functionalities. Since I'm the only maintainer, the more features I add the more bugs there will be. It's probably wiser for me to spend the limited time available on features like adding interpolation and such.

ShortyCM commented 6 days ago

Giving the option to enter your own command line should be super simple. I don't want to encode to something lossy. I want to do lossless encoding so I can process it afterwards. Letting me enter my own ffmpeg command line would allow that very easily. Then I could set x265 to lossless output and do whatever I want with that video afterwards. Even if that's just encoding it again to a certain target.

k4yt3x commented 6 days ago

@ShortyCM Here's the thing, you're saying "easy" probably because you assume I'm just calling FFmpeg as a command, but I'm using its C libraries for better performance. To pass it a codec, for example, I can't just pass it the string -c:v libx264. Instead, I'll have to do:

// In CLI
encoder_config->codec = AV_CODEC_ID_H264;

// In the encoder
const AVCodec *encoder = avcodec_find_encoder(encoder_config->codec);

Then, some options may be a field in the AVCodecContext, like bitrate:

// In CLI
encoder_config->bit_rate = 2000000;

// In the encoder
enc_ctx_->bit_rate = encoder_config->bit_rate;

... and some options need to be set with av_opt_set:

// In CLI
encoder_config->crf = 17.0f;

// In the encoder
std::string crf_str = std::to_string(encoder_config->crf);
av_opt_set(enc_ctx_->priv_data, "crf", crf_str.c_str(), 0);

If you would like to rewrite it to make it easy, by all means; if you want lossless right now, perhaps try ffv1; if you want lossless H265, that's something I can potentially add down the road, but it's not going to be "super simple."

ShortyCM commented 6 days ago

Something like this...

// Set the CRF and preset for any codecs that support it
std::string crf_str = std::to_string(encoder_config->crf);
av_opt_set(enc_ctx_->priv_data, "crf", crf_str.c_str(), 0);
av_opt_set(enc_ctx_->priv_data, "preset", encoder_config->preset, 0);

// Set x265-specific options for lossless encoding
av_opt_set(enc_ctx_->priv_data, "x265-params", "lossless=1:scenecut=40:open-gop=0", 0);
k4yt3x commented 6 days ago

Since I can't hardcode or introduce just x265-params. Maybe we can implement some kind of a parser or use multitoken to accept custom AVOption values. I'll look into this.

At the same time, I feel like this is a separate feature. Could you please open another issue?