Skip to content

[WIP] Set up a Rust native version of Hardsubx context and rewrite hardsubx.c #1458

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f3b331b
Set up a Rust native version of Hardsubx context
shashwat1002 Oct 31, 2022
a3fd49c
format fixes
shashwat1002 Oct 31, 2022
0935934
clippy changes
shashwat1002 Nov 1, 2022
6e378e1
fix bugs during initialization of native hardsubx context
shashwat1002 Nov 15, 2022
dc56463
change from Option reference types to raw pointers for Hardsubx conte…
shashwat1002 Nov 15, 2022
304d1c3
add main file for hardsubx
shashwat1002 Nov 15, 2022
58f6334
add function for deinitializing hardsubx context
shashwat1002 Nov 15, 2022
3c56b24
change all hardsubx context raw pointers to use native HardsubxContext
shashwat1002 Nov 15, 2022
2d4083f
for all helper functions return string and not C character array
shashwat1002 Nov 15, 2022
2465d1e
change sub_color to a native enum
shashwat1002 Nov 15, 2022
3f78241
add a nice wrapper for levanstein distance function
shashwat1002 Nov 17, 2022
b86b053
use the ffmpeg-sys-next definition of AVPacket (and remove custom def…
shashwat1002 Nov 17, 2022
a9b491d
bring in relevant functions
shashwat1002 Nov 17, 2022
b0d3888
port hardsubx_process_frames_linear function to the decoder
shashwat1002 Nov 17, 2022
508d1a7
call the appropriate decoder function
shashwat1002 Nov 17, 2022
2c3f14d
commit Cargo Lock
shashwat1002 Nov 17, 2022
4e7d013
add function for tickertext
shashwat1002 Nov 17, 2022
17f880b
remove extern C from functions that are strictly internally rust now
shashwat1002 Nov 17, 2022
1113961
remove unused imports and fix match bug
shashwat1002 Nov 17, 2022
94b7372
remove unused imports and move a redundant match condition
shashwat1002 Nov 17, 2022
2915e9e
remove dead code
shashwat1002 Nov 17, 2022
f0f4d6f
add enum for encoding type
shashwat1002 Nov 17, 2022
1cb7606
clippy changes
shashwat1002 Nov 17, 2022
4410676
style fixes
shashwat1002 Nov 17, 2022
d44579a
finish of the main function for hardsubx
shashwat1002 Nov 17, 2022
2f14d28
hide main hardsubx function on the C side behinf ifdef macros
shashwat1002 Nov 17, 2022
d3d8ef6
add from primitive for enumerations
shashwat1002 Jan 4, 2023
5e96265
port the process_hardsubx_linear_frames_and_normal function
shashwat1002 Jan 4, 2023
d32533e
add conditional
shashwat1002 Jan 4, 2023
ceeff56
style fixes
shashwat1002 Jan 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lib_ccx/hardsubx.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>

#ifdef DISABLE_RUST
int hardsubx_process_data(struct lib_hardsubx_ctx *ctx, struct lib_ccx_ctx *ctx_normal)
{
// Get the required media attributes and initialize structures
Expand Down Expand Up @@ -119,7 +120,7 @@ int hardsubx_process_data(struct lib_hardsubx_ctx *ctx, struct lib_ccx_ctx *ctx_
avcodec_close(ctx->codec_ctx);
avformat_close_input(&ctx->format_ctx);
}

#endif
void _hardsubx_params_dump(struct ccx_s_options *options, struct lib_hardsubx_ctx *ctx)
{
// Print the relevant passed parameters onto the screen
Expand Down Expand Up @@ -317,6 +318,7 @@ void _dinit_hardsubx(struct lib_hardsubx_ctx **ctx)
freep(ctx);
}

#ifdef DISABLE_RUST
void hardsubx(struct ccx_s_options *options, struct lib_ccx_ctx *ctx_normal)
{
// This is similar to the 'main' function in ccextractor.c, but for hard subs
Expand Down Expand Up @@ -344,5 +346,5 @@ void hardsubx(struct ccx_s_options *options, struct lib_ccx_ctx *ctx_normal)
// Free all allocated memory for the data structures
_dinit_hardsubx(&ctx);
}

#endif
#endif
85 changes: 83 additions & 2 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ palette = "0.6.0"
ffmpeg-sys-next = { version = "5.0.1", optional = true, default-features = false, features = ["avcodec", "avformat", "swscale", "build"]}
tesseract-sys = { version = "0.5.12", optional = true, default-features = false}
leptonica-sys = { version = "0.4.1", optional = true, default-features = false}
num = "0.4"
num-derive = "0.3"
num-traits = "0.2"


[build-dependencies]
bindgen = "0.58.1"
Expand Down
27 changes: 27 additions & 0 deletions src/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ fn main() {
"convert_pts_to_.*",
"av_rescale_q",
"mprint",
"av_packet_unref",
"av_read_frame",
"activity_progress",
"avcodec_decode_video2",
"probe_tessdata_location",
"get_file_extension",
"init_encoder",
"dinit_encoder",
"encode_sub",
"add_cc_sub_text",
"position_sanity_check",
"process_non_multiprogram_general_loop",
"get_fts",
"segment_output_file",
"net_check_conn",
"update_encoder_list",
"general_get_more_data",
"wtv_get_more_data",
"asf_get_more_data",
"ts_get_more_data",
"ps_get_more_data",
"is_decoder_processed_enough",
"flush_cc_decode",
]);

let mut allowlist_types = vec![
Expand All @@ -24,6 +47,10 @@ fn main() {
"lib_cc_decode",
"cc_subtitle",
"ccx_output_format",
"ccx_s_options",
"lib_ccx_ctx",
"encoder_ctx",
"demuxer_data",
];

#[cfg(feature = "hardsubx_ocr")]
Expand Down
Loading