Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add FFmpeg filters #1196

Open
HunterAP23 opened this issue Oct 24, 2024 · 5 comments
Open

[FEATURE] Add FFmpeg filters #1196

HunterAP23 opened this issue Oct 24, 2024 · 5 comments
Labels
component:FFmpeg FFmpeg related issue state:Planned This issue is already scheduled to be worked on type:Enhancement New feature or request

Comments

@HunterAP23
Copy link

HunterAP23 commented Oct 24, 2024

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 k4yt3x added type:Enhancement New feature or request component:FFmpeg FFmpeg related issue state:Planned This issue is already scheduled to be worked on labels Oct 24, 2024
@k4yt3x
Copy link
Owner

k4yt3x commented Oct 24, 2024

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
Copy link

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
Copy link
Owner

k4yt3x commented Nov 19, 2024

@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
Copy link

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
Copy link
Owner

k4yt3x commented Nov 19, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:FFmpeg FFmpeg related issue state:Planned This issue is already scheduled to be worked on type:Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants