mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-09-23 15:24:41 +00:00
Python bindings with extraction of CE608 grid and writing to a SRT output. (#768)
* added python_extract to encoders_srt and the captions are being extracted in needed format. Search for an alternative to asprintf * Checking if the alternative to asprintf generate proper srts * CC captions accessible via python script * Removing python caption code from __wrap_write function * removing old cc_to_python functions * Removing python_subs structure and all the changes done for that struct * Removing filename functions from ccextractor.* * Renaming make_message to time_wrapper * Applying to python_extract codebase: SSA format * Added python_extract_time_based and done validation for ssa * pplying python_extract_time_based: Done validation for srt and webvtt * led attempt for SAMI support of python_extract. Code is commented * Appluing python_extract_time_based: validate support for SMPTETT * Added python_extract_transcript and made changes for time printing. * added show_extracted_captions_wtih_timings function * Added show_extracted_captions_with_timings to python script for testing purpose. * refactored extractors to api directory. commented out show captions in main() * build and build library working for the extractors. * made caption generator work with a 0.1 time sleep. Start refactoring * added asprintf for windows. * file being written in the running directory * Auto -deletion of python temporary file * Python captions printing status set to proper. * termination of tail successful * Writing successful for the sample * Generating unalternating output * adding api_support.py * Adding bld_flags in build_api * Added to build_library * Auto deletion of temporary file on SIGINT * Discussing Seg fault with Izaron * working for python and linux with samples. testing -out=pythonapi with stream * Done adding bitmap support * added -out=pythonapi support for bitmap * Setting the messages_target to 0 for output = pythonapi * Added wrapper for setting -out=pythonapi. Checking if -stdout value can be used in python. * adding the cc_to_stdout=1 value for -out=pythonapi. Thus generation of output file has been avoided. May be needed to change in future. * added extractor for g608 grid. removed sami extractor. need to work on overlap of -out=pythonapi and -out=g608 * Removed overlap of -out=pythonapi by adding -pythonapi and signal_python_api global variable. * added support for seperate c608 grid catching. Need to test the output via python. * added support for seperate printing of text font and color in CE608. Need to make sure that the function is inbuilt. * ADDED ce608 GRID SUPPORT FROM PYTHON need to discuss whether to keep the print_cc_grid function specific to the module or make it user accessible. Mostly it would be better to make it user accessible. * made changes in the call_from_python_api function such that only api_options is needed to be passed. An if statement before the call to g608_extractor has also been added. Waiting for Carlos to comment on the output generated till this stage. * added a signal_python_api check before calling every write function. Thus basic writing output can be avoided. * Commented all calls to python_extract_time_based. making changes to python_extract_g608 to be called only from the point when a g608 caption is detected. * Added pass_cc_buffer_to_python in encoders_common.c temporarily redefined get_*_encoded from static to normal included the above functions in encoders_common.h * Added if-else statement for switch in encode_sub function. This is done mainly for making sure no output is generated in the api call. * Added ccx_encoders_python.c Defined pass_cc_buffer_to_python in ccx_encoders_python.c added if else statement in encode_sub's switch to make sure that the output is not generated in case of -pythonapi call * Removed __wrap_write from the entire code base. It's declaration and definition are only present in CCExtractor.* * Commented out the /dev/null part in ccx_encoders_common.c. Proceeding further on checking for file generation. * Added output_filename in array global variable and is generated in init_write function. included ccextractor.h in output.c to access global variable signal_python_api for avoiding output generation in init_write and invalid free in dinit_write. * Modified the definition of init_write function for accessing signal_python_api. * Deleted the commented part of /dev/null in ccx_encoders_common.c. * Added target_message=0 in -pythonapi param parsing in param.c to avoid the API from printing to STDOUT. Deleted the commented part of -out=pythonapi. Thinking of adding a different param for silencing the output when the call is made from python api. * Removed __wrap_write from ccextractor.c and ccextractor.h. * Added ccx_to_python_g608 and modified api_support.py file. added documentation in ccextractor.c. * added the generate srt script. However, some random characters are coming in first line. Need to talk about this. * Added SRT generator for python. Using string to remove the garbage value. Add code for srt counter and also the start_time and end_time conversion. * removed the trash characters and added code to print the timings. However, the last blank frame also results in a print. Need to take care of this. * rectified the mistake of writing only timings and not captions. now next step is to just make the timings print properly * some minor changes before diving into extracting srt_counter from the made codebase * Added extraction of srt_counter in python_extract via fflush srt_counter-value. Need to modify the processing in python. * Added the entire method to extract captions and generate srt files. Next, step would be a to define a concise function for writing the srt * Processing into a srt working properly. Next step is to add the information of font into the caption text. * the data is getting generated for proper SRT counters. * A turning point to the appraoch. Added END OF FRAME line for printing the data for every particular srt_counter. Proceeding further with the generation of srt by data manipulation. * some minor bugs but the output srt is being generated correctly. However, The font and colour encoding needs to be done. * Taken care of random characters. Need to discuss this with Carlos. Moving further to font/color processing. * Taken care of random characters. Need to discuss this with Carlos. Moving further to font/color processing. * Added fflush and cleaned up the python code of srt generation * Added <i> tag for italics. Proceeding further with other types. * Added the code to check for underline. However, need to check how CCExtractor generates srt when both italics and underline are present. For now a new line is added if both are present. * Shifting for making changes in th i/O work. * Stable ouput for samples with italics is being generated. * Added the PYTHONAPI macro definition and testing for its existence in the set_python_api function. * build script for linux is working correctly. Build_library is showing error of invalid def of set_pythonapi. Moreover, extractor has some memory seg fault. * Added mod to set a MACRO as my_python_api to set the callback function. Till now all calls to the reporter are commented. Working on getting the reporter to print the lines. * Changes have been implemented to bring reporter in working state. For now a constant string is passed from extractor. Need to make the proper parsing possible. * Changed the code in extractor such that entire grid is returned to the callback function. Need to provide this grid to the write function and also cleanup the codebase. * Writing the outputted srt in a file called "temp.srt". Need to modify init_write to push filename that is to be created in python using callback. * Added code to get start and end time simultaneously. entire SRT is getting generated. * removed ccx_python_encoders.c * Compiling and executing on Windows * Moved definitions get_line_encoded, get_color_encoded, get_font_encoded from ccx_encoders_g608.c to ccx_encoders_common.c. Also, deleted the static definition of get_font_encoded from ccx_encoders_webvtt.c * added a write statement in write_cc_bitmap_as_srt * Rectified transfer of get_line_encoded, get_color_encoded and get_font_encoded from ccx_decoders_common.c to ccx_encoders_common.c.
This commit is contained in:
committed by
Carlos Fernandez Sanz
parent
773ddf8bc2
commit
21eaa3de04
50
api/api_support.py
Normal file
50
api/api_support.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import ccextractor as cc
|
||||
import ccx_to_python_g608 as g608
|
||||
import python_srt_generator as srt_generator
|
||||
##
|
||||
#help_string to be included in the documentation
|
||||
#it is the help string for telling what kind of output the user wants to STDOUT
|
||||
#the redirection of output to STDOUT can be changed easily to whatsoever usage the user wants to put in.
|
||||
##
|
||||
help_string = """
|
||||
Case is the value that would give the desired output.
|
||||
case = 0 --> print start_time,end_time,text,color,font
|
||||
case = 1 --> print start_time,end_time,text
|
||||
case = 2 --> print start_time,end_time,color
|
||||
case = 3 --> print start_time,end_time,font
|
||||
case = 4 --> print start_time,end_time,text,color
|
||||
case = 5 --> print start_time,end_time,text,font
|
||||
case = 6 --> print start_time,end_time,color,font
|
||||
"""
|
||||
text,font,color = [],[],[]
|
||||
filename = " "
|
||||
srt_counter = " "
|
||||
def generate_output_srt(line):
|
||||
global text,font,color
|
||||
global filename, srt_counter
|
||||
if "filename:" in line:
|
||||
filename = str(str(line.split(":")[1]).split("\n")[0])
|
||||
#check for an alternative to wipe the output file in python
|
||||
fh = srt_generator.generate_file_handle(filename,'w')
|
||||
fh.write("")
|
||||
srt_generator.delete_file_handle(fh)
|
||||
elif "srt_counter-" in line:
|
||||
srt_counter = str(line.split("-")[1])
|
||||
fh = srt_generator.generate_file_handle(filename,'a')
|
||||
fh.write(srt_counter)
|
||||
srt_generator.delete_file_handle(fh)
|
||||
elif "start_time" in line:
|
||||
fh = srt_generator.generate_file_handle(filename,'a')
|
||||
srt_generator.generate_output_srt_time(fh, line)
|
||||
srt_generator.delete_file_handle(fh)
|
||||
elif "***END OF FRAME***" in line:
|
||||
data = g608.return_g608_grid(0,text,color,font)
|
||||
fh = srt_generator.generate_file_handle(filename,'a')
|
||||
srt_generator.generate_output_srt(fh, data)
|
||||
srt_generator.delete_file_handle(fh)
|
||||
text,font,color = [],[],[]
|
||||
else:
|
||||
g608.g608_grid_former(line,text,color,font)
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,65 @@
|
||||
###
|
||||
#MANDATORY UPDATES IN EVERY PYTHON SCRIPT
|
||||
###
|
||||
import ccextractor as cc
|
||||
import os
|
||||
import time
|
||||
import api_support
|
||||
from multiprocessing import Queue,Process,Event
|
||||
import sys
|
||||
s = cc.api_init_options()
|
||||
cc.check_configuration_file(s)
|
||||
for i in sys.argv[1:]:
|
||||
cc.api_add_param(s,str(i))
|
||||
#cc.setstdout(s)
|
||||
compile_ret = cc.compile_params(s,len(sys.argv[1:]));
|
||||
start_ret = cc.api_start(s);
|
||||
import time
|
||||
|
||||
def templer():
|
||||
s = cc.api_init_options()
|
||||
cc.check_configuration_file(s)
|
||||
for i in sys.argv[1:]:
|
||||
cc.api_add_param(s,str(i))
|
||||
#very mandatory for keeping a track of pythonapi call. Always must be set.
|
||||
cc.my_pythonapi(s, callback)
|
||||
|
||||
compile_ret = cc.compile_params(s,len(sys.argv[1:]));
|
||||
|
||||
#very mandatory for keeping a track of pythonapi call. Always must be called so that the program knows that the call is from pythonapi.
|
||||
cc.call_from_python_api(s)
|
||||
|
||||
start_ret = cc.api_start(s);
|
||||
|
||||
def callback(line):
|
||||
api_support.generate_output_srt(line)
|
||||
if __name__=="__main__":
|
||||
templer()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#for item in cc.captions_timings_list:
|
||||
# print item(0),item(1)
|
||||
# print item(2)
|
||||
#cc.cvar.array.has_api_start_exited=1
|
||||
#print "\n"
|
||||
#print "The extracted captions with respective timings are as follows:"
|
||||
###one line functions to directly check the extracted captions that would be otherwise accessible in python.
|
||||
###just uncomment the next line.
|
||||
#cc.show_extracted_captions_with_timings()
|
||||
|
||||
###THE FOLLOWING LOOP LETS USER USE THE EXTRACTED CAPTIONS ALONG WITH THEIR TIMINGS.
|
||||
#for i in xrange(cc.cc_to_python_get_number_of_subs()):
|
||||
# caption = cc.cc_to_python_get_modified_sub(i)
|
||||
# print caption.srt_counter
|
||||
# print "start time = {}\t end time = {}".format(caption.start_time,caption.end_time)
|
||||
# for j in xrange(cc.cc_to_python_get_modified_sub_buffer_size(i)):
|
||||
# print cc.cc_to_python_get_modified_sub_buffer(i,j)
|
||||
|
||||
"""
|
||||
#print cc.cc_to_python_get_subs_number_of_lines()
|
||||
#printing python_subs.subs
|
||||
#for item in xrange(cc.cc_to_python_get_subs_number_of_lines()):
|
||||
# print cc.cc_to_python_get_sub(item)
|
||||
|
||||
#os.system('clear')
|
||||
"""
|
||||
|
||||
@@ -11,11 +11,12 @@ SRC_HASH="$(find ../src/lib_hash/ -name '*.c')"
|
||||
SRC_PROTOBUF="$(find ../src/protobuf-c/ -name '*.c')"
|
||||
SRC_UTF8PROC="../src/utf8proc/utf8proc.c"
|
||||
API_WRAPPERS="$(find ../api/wrappers/ -name '*.c')"
|
||||
BLD_SOURCES="../src/ccextractor.c ccextractor_wrap.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC $API_WRAPPERS"
|
||||
API_EXTRACTORS="$(find ../api/extractors/ -name '*.c')"
|
||||
BLD_SOURCES="../src/ccextractor.c ccextractor_wrap.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC $API_WRAPPERS $API_EXTRACTORS"
|
||||
|
||||
../linux/pre-build.sh
|
||||
|
||||
out=$((LC_ALL=C gcc -fPIC -c $BLD_INCLUDE $BLD_SOURCES) 2>&1)
|
||||
out=$((LC_ALL=C gcc -fPIC -c -DPYTHONAPI $BLD_FLAGS $BLD_INCLUDE $BLD_SOURCES $BLD_LINKER) 2>&1)
|
||||
#out=$((LC_ALL=C gcc -fPIC -c -Wl,-wrap,write $BLD_INCLUDE $BLD_SOURCES) 2>&1)
|
||||
res=$?
|
||||
if [[ $out == *"gcc: command not found"* ]]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
BLD_LINKER="-lm -zmuldefs -l tesseract -l lept -l python2.7"
|
||||
WRAPPER_FLAGS="-Wl,-wrap,write"
|
||||
|
||||
out=$((swig -python ccextractor.i && ./build_api && gcc -shared $(find -name '*.o') -o _ccextractor.so ) 2>&1)
|
||||
out=$((swig -python ccextractor.i && ./build_api && gcc -shared $(find -name '*.o') -o _ccextractor.so $BLD_LINKER) 2>&1)
|
||||
#out=$((swig -python ccextractor.i && ./build_api && gcc -shared $WRAPPER_FLAGS $(find -name '*.o') -o _ccextractor.so ) 2>&1)
|
||||
res=$?
|
||||
if [[ $out == *"gcc: command not found"* ]]
|
||||
|
||||
@@ -9,6 +9,69 @@
|
||||
#include "../src/lib_ccx/ccx_share.h"
|
||||
#include "../src/ccextractor.h"
|
||||
#include "../api/wrappers/wrapper.h"
|
||||
%}
|
||||
void my_pythonapi(struct ccx_s_options *api_options, PyObject* func);
|
||||
%pythoncode %{
|
||||
def g608_grid_former(line,text,color,font):
|
||||
if "text[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
text.append(line)
|
||||
if "color[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
color.append(line)
|
||||
if "font[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
font.append(line)
|
||||
|
||||
def print_g608_grid(case,text,color,font):
|
||||
help_string = """
|
||||
Case is the value that would give the desired output.
|
||||
case = 0 --> print start_time,end_time,text,color,font
|
||||
case = 1 --> print start_time,end_time,text
|
||||
case = 2 --> print start_time,end_time,color
|
||||
case = 3 --> print start_time,end_time,font
|
||||
case = 4 --> print start_time,end_time,text,color
|
||||
case = 5 --> print start_time,end_time,text,font
|
||||
case = 6 --> print start_time,end_time,color,font
|
||||
"""
|
||||
if case==0:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
|
||||
elif case==1:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
elif case==2:
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
elif case==3:
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
elif case==4:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
elif case==5:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
elif case==6:
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
else:
|
||||
print help_string
|
||||
|
||||
%}
|
||||
%include "../src/lib_ccx/ccx_common_common.h"
|
||||
%include "../src/ccextractor.h"
|
||||
|
||||
@@ -95,6 +95,72 @@ except __builtin__.Exception:
|
||||
pass
|
||||
_newclass = 0
|
||||
|
||||
|
||||
def my_pythonapi(api_options, func):
|
||||
return _ccextractor.my_pythonapi(api_options, func)
|
||||
my_pythonapi = _ccextractor.my_pythonapi
|
||||
|
||||
def g608_grid_former(line,text,color,font):
|
||||
if "text[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
text.append(line)
|
||||
if "color[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
color.append(line)
|
||||
if "font[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
font.append(line)
|
||||
|
||||
def print_g608_grid(case,text,color,font):
|
||||
help_string = """
|
||||
Case is the value that would give the desired output.
|
||||
case = 0 --> print start_time,end_time,text,color,font
|
||||
case = 1 --> print start_time,end_time,text
|
||||
case = 2 --> print start_time,end_time,color
|
||||
case = 3 --> print start_time,end_time,font
|
||||
case = 4 --> print start_time,end_time,text,color
|
||||
case = 5 --> print start_time,end_time,text,font
|
||||
case = 6 --> print start_time,end_time,color,font
|
||||
"""
|
||||
if case==0:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
|
||||
elif case==1:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
elif case==2:
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
elif case==3:
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
elif case==4:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
elif case==5:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
elif case==6:
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
else:
|
||||
print help_string
|
||||
|
||||
|
||||
EXIT_OK = _ccextractor.EXIT_OK
|
||||
EXIT_NO_INPUT_FILES = _ccextractor.EXIT_NO_INPUT_FILES
|
||||
EXIT_TOO_MANY_INPUT_FILES = _ccextractor.EXIT_TOO_MANY_INPUT_FILES
|
||||
@@ -145,49 +211,111 @@ debug_608_to_ASC = _ccextractor.debug_608_to_ASC
|
||||
def add_cc_sub_text(sub, str, start_time, end_time, info, mode, arg7):
|
||||
return _ccextractor.add_cc_sub_text(sub, str, start_time, end_time, info, mode, arg7)
|
||||
add_cc_sub_text = _ccextractor.add_cc_sub_text
|
||||
class cc_to_python_subs(_object):
|
||||
class python_subs_modified(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, cc_to_python_subs, name, value)
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, python_subs_modified, name, value)
|
||||
__swig_getmethods__ = {}
|
||||
__getattr__ = lambda self, name: _swig_getattr(self, cc_to_python_subs, name)
|
||||
__getattr__ = lambda self, name: _swig_getattr(self, python_subs_modified, name)
|
||||
__repr__ = _swig_repr
|
||||
__swig_setmethods__["inputfile"] = _ccextractor.cc_to_python_subs_inputfile_set
|
||||
__swig_getmethods__["inputfile"] = _ccextractor.cc_to_python_subs_inputfile_get
|
||||
__swig_setmethods__["buffer_count"] = _ccextractor.python_subs_modified_buffer_count_set
|
||||
__swig_getmethods__["buffer_count"] = _ccextractor.python_subs_modified_buffer_count_get
|
||||
if _newclass:
|
||||
inputfile = _swig_property(_ccextractor.cc_to_python_subs_inputfile_get, _ccextractor.cc_to_python_subs_inputfile_set)
|
||||
__swig_setmethods__["num_input_files"] = _ccextractor.cc_to_python_subs_num_input_files_set
|
||||
__swig_getmethods__["num_input_files"] = _ccextractor.cc_to_python_subs_num_input_files_get
|
||||
buffer_count = _swig_property(_ccextractor.python_subs_modified_buffer_count_get, _ccextractor.python_subs_modified_buffer_count_set)
|
||||
__swig_setmethods__["srt_counter"] = _ccextractor.python_subs_modified_srt_counter_set
|
||||
__swig_getmethods__["srt_counter"] = _ccextractor.python_subs_modified_srt_counter_get
|
||||
if _newclass:
|
||||
num_input_files = _swig_property(_ccextractor.cc_to_python_subs_num_input_files_get, _ccextractor.cc_to_python_subs_num_input_files_set)
|
||||
__swig_setmethods__["basefilename"] = _ccextractor.cc_to_python_subs_basefilename_set
|
||||
__swig_getmethods__["basefilename"] = _ccextractor.cc_to_python_subs_basefilename_get
|
||||
srt_counter = _swig_property(_ccextractor.python_subs_modified_srt_counter_get, _ccextractor.python_subs_modified_srt_counter_set)
|
||||
__swig_setmethods__["start_time"] = _ccextractor.python_subs_modified_start_time_set
|
||||
__swig_getmethods__["start_time"] = _ccextractor.python_subs_modified_start_time_get
|
||||
if _newclass:
|
||||
basefilename = _swig_property(_ccextractor.cc_to_python_subs_basefilename_get, _ccextractor.cc_to_python_subs_basefilename_set)
|
||||
__swig_setmethods__["extension"] = _ccextractor.cc_to_python_subs_extension_set
|
||||
__swig_getmethods__["extension"] = _ccextractor.cc_to_python_subs_extension_get
|
||||
start_time = _swig_property(_ccextractor.python_subs_modified_start_time_get, _ccextractor.python_subs_modified_start_time_set)
|
||||
__swig_setmethods__["end_time"] = _ccextractor.python_subs_modified_end_time_set
|
||||
__swig_getmethods__["end_time"] = _ccextractor.python_subs_modified_end_time_get
|
||||
if _newclass:
|
||||
extension = _swig_property(_ccextractor.cc_to_python_subs_extension_get, _ccextractor.cc_to_python_subs_extension_set)
|
||||
__swig_setmethods__["subs"] = _ccextractor.cc_to_python_subs_subs_set
|
||||
__swig_getmethods__["subs"] = _ccextractor.cc_to_python_subs_subs_get
|
||||
end_time = _swig_property(_ccextractor.python_subs_modified_end_time_get, _ccextractor.python_subs_modified_end_time_set)
|
||||
__swig_setmethods__["buffer"] = _ccextractor.python_subs_modified_buffer_set
|
||||
__swig_getmethods__["buffer"] = _ccextractor.python_subs_modified_buffer_get
|
||||
if _newclass:
|
||||
subs = _swig_property(_ccextractor.cc_to_python_subs_subs_get, _ccextractor.cc_to_python_subs_subs_set)
|
||||
__swig_setmethods__["number_of_lines"] = _ccextractor.cc_to_python_subs_number_of_lines_set
|
||||
__swig_getmethods__["number_of_lines"] = _ccextractor.cc_to_python_subs_number_of_lines_get
|
||||
buffer = _swig_property(_ccextractor.python_subs_modified_buffer_get, _ccextractor.python_subs_modified_buffer_set)
|
||||
__swig_setmethods__["g608_grid_color_count"] = _ccextractor.python_subs_modified_g608_grid_color_count_set
|
||||
__swig_getmethods__["g608_grid_color_count"] = _ccextractor.python_subs_modified_g608_grid_color_count_get
|
||||
if _newclass:
|
||||
number_of_lines = _swig_property(_ccextractor.cc_to_python_subs_number_of_lines_get, _ccextractor.cc_to_python_subs_number_of_lines_set)
|
||||
g608_grid_color_count = _swig_property(_ccextractor.python_subs_modified_g608_grid_color_count_get, _ccextractor.python_subs_modified_g608_grid_color_count_set)
|
||||
__swig_setmethods__["g608_grid_color"] = _ccextractor.python_subs_modified_g608_grid_color_set
|
||||
__swig_getmethods__["g608_grid_color"] = _ccextractor.python_subs_modified_g608_grid_color_get
|
||||
if _newclass:
|
||||
g608_grid_color = _swig_property(_ccextractor.python_subs_modified_g608_grid_color_get, _ccextractor.python_subs_modified_g608_grid_color_set)
|
||||
__swig_setmethods__["g608_grid_font_count"] = _ccextractor.python_subs_modified_g608_grid_font_count_set
|
||||
__swig_getmethods__["g608_grid_font_count"] = _ccextractor.python_subs_modified_g608_grid_font_count_get
|
||||
if _newclass:
|
||||
g608_grid_font_count = _swig_property(_ccextractor.python_subs_modified_g608_grid_font_count_get, _ccextractor.python_subs_modified_g608_grid_font_count_set)
|
||||
__swig_setmethods__["g608_grid_font"] = _ccextractor.python_subs_modified_g608_grid_font_set
|
||||
__swig_getmethods__["g608_grid_font"] = _ccextractor.python_subs_modified_g608_grid_font_get
|
||||
if _newclass:
|
||||
g608_grid_font = _swig_property(_ccextractor.python_subs_modified_g608_grid_font_get, _ccextractor.python_subs_modified_g608_grid_font_set)
|
||||
|
||||
def __init__(self):
|
||||
this = _ccextractor.new_cc_to_python_subs()
|
||||
this = _ccextractor.new_python_subs_modified()
|
||||
try:
|
||||
self.this.append(this)
|
||||
except __builtin__.Exception:
|
||||
self.this = this
|
||||
__swig_destroy__ = _ccextractor.delete_cc_to_python_subs
|
||||
__swig_destroy__ = _ccextractor.delete_python_subs_modified
|
||||
__del__ = lambda self: None
|
||||
cc_to_python_subs_swigregister = _ccextractor.cc_to_python_subs_swigregister
|
||||
cc_to_python_subs_swigregister(cc_to_python_subs)
|
||||
python_subs_modified_swigregister = _ccextractor.python_subs_modified_swigregister
|
||||
python_subs_modified_swigregister(python_subs_modified)
|
||||
cvar = _ccextractor.cvar
|
||||
|
||||
class python_subs_array(_object):
|
||||
__swig_setmethods__ = {}
|
||||
__setattr__ = lambda self, name, value: _swig_setattr(self, python_subs_array, name, value)
|
||||
__swig_getmethods__ = {}
|
||||
__getattr__ = lambda self, name: _swig_getattr(self, python_subs_array, name)
|
||||
__repr__ = _swig_repr
|
||||
__swig_setmethods__["temporary_file"] = _ccextractor.python_subs_array_temporary_file_set
|
||||
__swig_getmethods__["temporary_file"] = _ccextractor.python_subs_array_temporary_file_get
|
||||
if _newclass:
|
||||
temporary_file = _swig_property(_ccextractor.python_subs_array_temporary_file_get, _ccextractor.python_subs_array_temporary_file_set)
|
||||
__swig_setmethods__["fp"] = _ccextractor.python_subs_array_fp_set
|
||||
__swig_getmethods__["fp"] = _ccextractor.python_subs_array_fp_get
|
||||
if _newclass:
|
||||
fp = _swig_property(_ccextractor.python_subs_array_fp_get, _ccextractor.python_subs_array_fp_set)
|
||||
__swig_setmethods__["output_filename"] = _ccextractor.python_subs_array_output_filename_set
|
||||
__swig_getmethods__["output_filename"] = _ccextractor.python_subs_array_output_filename_get
|
||||
if _newclass:
|
||||
output_filename = _swig_property(_ccextractor.python_subs_array_output_filename_get, _ccextractor.python_subs_array_output_filename_set)
|
||||
__swig_setmethods__["has_api_start_exited"] = _ccextractor.python_subs_array_has_api_start_exited_set
|
||||
__swig_getmethods__["has_api_start_exited"] = _ccextractor.python_subs_array_has_api_start_exited_get
|
||||
if _newclass:
|
||||
has_api_start_exited = _swig_property(_ccextractor.python_subs_array_has_api_start_exited_get, _ccextractor.python_subs_array_has_api_start_exited_set)
|
||||
__swig_setmethods__["old_sub_count"] = _ccextractor.python_subs_array_old_sub_count_set
|
||||
__swig_getmethods__["old_sub_count"] = _ccextractor.python_subs_array_old_sub_count_get
|
||||
if _newclass:
|
||||
old_sub_count = _swig_property(_ccextractor.python_subs_array_old_sub_count_get, _ccextractor.python_subs_array_old_sub_count_set)
|
||||
__swig_setmethods__["sub_count"] = _ccextractor.python_subs_array_sub_count_set
|
||||
__swig_getmethods__["sub_count"] = _ccextractor.python_subs_array_sub_count_get
|
||||
if _newclass:
|
||||
sub_count = _swig_property(_ccextractor.python_subs_array_sub_count_get, _ccextractor.python_subs_array_sub_count_set)
|
||||
__swig_setmethods__["subs"] = _ccextractor.python_subs_array_subs_set
|
||||
__swig_getmethods__["subs"] = _ccextractor.python_subs_array_subs_get
|
||||
if _newclass:
|
||||
subs = _swig_property(_ccextractor.python_subs_array_subs_get, _ccextractor.python_subs_array_subs_set)
|
||||
__swig_setmethods__["is_transcript"] = _ccextractor.python_subs_array_is_transcript_set
|
||||
__swig_getmethods__["is_transcript"] = _ccextractor.python_subs_array_is_transcript_get
|
||||
if _newclass:
|
||||
is_transcript = _swig_property(_ccextractor.python_subs_array_is_transcript_get, _ccextractor.python_subs_array_is_transcript_set)
|
||||
|
||||
def __init__(self):
|
||||
this = _ccextractor.new_python_subs_array()
|
||||
try:
|
||||
self.this.append(this)
|
||||
except __builtin__.Exception:
|
||||
self.this = this
|
||||
__swig_destroy__ = _ccextractor.delete_python_subs_array
|
||||
__del__ = lambda self: None
|
||||
python_subs_array_swigregister = _ccextractor.python_subs_array_swigregister
|
||||
python_subs_array_swigregister(python_subs_array)
|
||||
|
||||
|
||||
def api_init_options():
|
||||
return _ccextractor.api_init_options()
|
||||
@@ -229,21 +357,49 @@ def print_end_msg():
|
||||
return _ccextractor.print_end_msg()
|
||||
print_end_msg = _ccextractor.print_end_msg
|
||||
|
||||
def show_extracted_captions_with_timings():
|
||||
return _ccextractor.show_extracted_captions_with_timings()
|
||||
show_extracted_captions_with_timings = _ccextractor.show_extracted_captions_with_timings
|
||||
|
||||
def main(argc, argv):
|
||||
return _ccextractor.main(argc, argv)
|
||||
main = _ccextractor.main
|
||||
|
||||
def cc_to_python_get_subs_number_of_lines():
|
||||
return _ccextractor.cc_to_python_get_subs_number_of_lines()
|
||||
cc_to_python_get_subs_number_of_lines = _ccextractor.cc_to_python_get_subs_number_of_lines
|
||||
def cc_to_python_get_old_count():
|
||||
return _ccextractor.cc_to_python_get_old_count()
|
||||
cc_to_python_get_old_count = _ccextractor.cc_to_python_get_old_count
|
||||
|
||||
def cc_to_python_get_sub(i):
|
||||
return _ccextractor.cc_to_python_get_sub(i)
|
||||
cc_to_python_get_sub = _ccextractor.cc_to_python_get_sub
|
||||
def cc_to_python_set_old_count():
|
||||
return _ccextractor.cc_to_python_set_old_count()
|
||||
cc_to_python_set_old_count = _ccextractor.cc_to_python_set_old_count
|
||||
|
||||
def __wrap_write(file_handle, buffer, nbyte):
|
||||
return _ccextractor.__wrap_write(file_handle, buffer, nbyte)
|
||||
__wrap_write = _ccextractor.__wrap_write
|
||||
def cc_to_python_get_number_of_subs():
|
||||
return _ccextractor.cc_to_python_get_number_of_subs()
|
||||
cc_to_python_get_number_of_subs = _ccextractor.cc_to_python_get_number_of_subs
|
||||
|
||||
def cc_to_python_get_modified_sub(i):
|
||||
return _ccextractor.cc_to_python_get_modified_sub(i)
|
||||
cc_to_python_get_modified_sub = _ccextractor.cc_to_python_get_modified_sub
|
||||
|
||||
def cc_to_python_get_modified_sub_buffer_size(i):
|
||||
return _ccextractor.cc_to_python_get_modified_sub_buffer_size(i)
|
||||
cc_to_python_get_modified_sub_buffer_size = _ccextractor.cc_to_python_get_modified_sub_buffer_size
|
||||
|
||||
def cc_to_python_get_modified_sub_buffer(i, j):
|
||||
return _ccextractor.cc_to_python_get_modified_sub_buffer(i, j)
|
||||
cc_to_python_get_modified_sub_buffer = _ccextractor.cc_to_python_get_modified_sub_buffer
|
||||
|
||||
def cc_to_python_get_output_filename():
|
||||
return _ccextractor.cc_to_python_get_output_filename()
|
||||
cc_to_python_get_output_filename = _ccextractor.cc_to_python_get_output_filename
|
||||
|
||||
def call_from_python_api(api_options):
|
||||
return _ccextractor.call_from_python_api(api_options)
|
||||
call_from_python_api = _ccextractor.call_from_python_api
|
||||
|
||||
def set_pythonapi(api_options):
|
||||
return _ccextractor.set_pythonapi(api_options)
|
||||
set_pythonapi = _ccextractor.set_pythonapi
|
||||
|
||||
def setautoprogram(api_options):
|
||||
return _ccextractor.setautoprogram(api_options)
|
||||
@@ -252,6 +408,14 @@ setautoprogram = _ccextractor.setautoprogram
|
||||
def setstdout(api_options):
|
||||
return _ccextractor.setstdout(api_options)
|
||||
setstdout = _ccextractor.setstdout
|
||||
|
||||
def setpesheader(api_options):
|
||||
return _ccextractor.setpesheader(api_options)
|
||||
setpesheader = _ccextractor.setpesheader
|
||||
|
||||
def setdebugdvbsub(api_options):
|
||||
return _ccextractor.setdebugdvbsub(api_options)
|
||||
setdebugdvbsub = _ccextractor.setdebugdvbsub
|
||||
# This file is compatible with both classic and new-style classes.
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
61
api/ccx_to_python_g608.py
Normal file
61
api/ccx_to_python_g608.py
Normal file
@@ -0,0 +1,61 @@
|
||||
def g608_grid_former(line,text,color,font):
|
||||
if "text[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
text.append(line)
|
||||
if "color[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
color.append(line)
|
||||
if "font[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
font.append(line)
|
||||
|
||||
def return_g608_grid(case,text,color,font):
|
||||
ret_val = {'text':" ",'color':" ",'font':" "}
|
||||
help_string = """
|
||||
Case is the value that would give the desired output.
|
||||
case = 0 --> print start_time,end_time,text,color,font
|
||||
case = 1 --> print start_time,end_time,text
|
||||
case = 2 --> print start_time,end_time,color
|
||||
case = 3 --> print start_time,end_time,font
|
||||
case = 4 --> print start_time,end_time,text,color
|
||||
case = 5 --> print start_time,end_time,text,font
|
||||
case = 6 --> print start_time,end_time,color,font
|
||||
"""
|
||||
if case==0:
|
||||
if text:
|
||||
ret_val['text']=text
|
||||
if color:
|
||||
ret_val['color']=color
|
||||
if font:
|
||||
ret_val['font']=font
|
||||
|
||||
elif case==1:
|
||||
if text:
|
||||
ret_val['text']=text
|
||||
elif case==2:
|
||||
if color:
|
||||
ret_val['color']=color
|
||||
elif case==3:
|
||||
if font:
|
||||
ret_val['font']=font
|
||||
elif case==4:
|
||||
if text:
|
||||
ret_val['text']=text
|
||||
if color:
|
||||
ret_val['color']=color
|
||||
elif case==5:
|
||||
if text:
|
||||
ret_val['text']=text
|
||||
if font:
|
||||
ret_val['font']=font
|
||||
elif case==6:
|
||||
if color:
|
||||
ret_val['color']=color
|
||||
if font:
|
||||
ret_val['font']=font
|
||||
else:
|
||||
print help_string
|
||||
return ret_val
|
||||
171
api/extractors/extractor.c
Normal file
171
api/extractors/extractor.c
Normal file
@@ -0,0 +1,171 @@
|
||||
#include "extractor.h"
|
||||
|
||||
/*WRITE wrapper for extracting \
|
||||
* start_time,
|
||||
* end_time,
|
||||
* captions
|
||||
*/
|
||||
void python_extract(int srt_counter, unsigned h1, unsigned m1, unsigned s1, unsigned ms1, unsigned h2, unsigned m2, unsigned s2, unsigned ms2, char* buffer){
|
||||
//check if the srt_counter value already exists
|
||||
int i;
|
||||
for(i=0;i<array.sub_count;i++){
|
||||
if (srt_counter==array.subs[i].srt_counter){
|
||||
array.subs[i].buffer_count++;
|
||||
array.subs[i].buffer = realloc(array.subs[i].buffer,sizeof(char*)*array.subs[i].buffer_count);
|
||||
array.subs[i].buffer[array.subs[i].buffer_count-1] = malloc(sizeof(char)*strlen(buffer));
|
||||
strcpy (array.subs[i].buffer[array.subs[i].buffer_count-1], buffer);
|
||||
//array.update_status =1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
array.sub_count++;
|
||||
array.subs = realloc(array.subs,sizeof(struct python_subs_modified)*array.sub_count);
|
||||
array.subs[array.sub_count-1].srt_counter= srt_counter;
|
||||
|
||||
array.subs[array.sub_count-1].start_time = time_wrapper("%02u:%02u:%02u,%03u",h1,m1,s1,ms1);
|
||||
array.subs[array.sub_count-1].end_time = time_wrapper("%02u:%02u:%02u,%03u",h2,m2,s2,ms2);
|
||||
|
||||
array.subs[array.sub_count-1].buffer_count=1;
|
||||
array.subs[array.sub_count-1].buffer = malloc(sizeof(char*)*array.subs[array.sub_count-1].buffer_count);
|
||||
array.subs[array.sub_count-1].buffer[array.subs[array.sub_count-1].buffer_count-1] = malloc(sizeof(char)*strlen(buffer));
|
||||
strcpy(array.subs[array.sub_count-1].buffer[array.subs[array.sub_count-1].buffer_count-1], buffer);
|
||||
//array.update_status =1;
|
||||
}
|
||||
|
||||
|
||||
void python_extract_g608_grid(unsigned h1, unsigned m1, unsigned s1, unsigned ms1, unsigned h2, unsigned m2, unsigned s2, unsigned ms2, char* buffer, int identifier, int srt_counter){
|
||||
/*
|
||||
* identifier = 0 ---> adding start and end time
|
||||
* identifier = 1 ---> subtitle
|
||||
* identifier = 2 ---> color
|
||||
* identifier = 3 ---> font
|
||||
*/
|
||||
//check if the caption with same start and end time already exists
|
||||
int i;
|
||||
char* output;
|
||||
char* start_time = time_wrapper("%02u:%02u:%02u,%03u",h1,m1,s1,ms1);
|
||||
char* end_time = time_wrapper("%02u:%02u:%02u,%03u",h2,m2,s2,ms2);
|
||||
for(i=0;i<array.sub_count;i++){
|
||||
if ((strcmp(start_time,array.subs[i].start_time)==0)&&(strcmp(end_time,array.subs[i].end_time)==0)){
|
||||
if (identifier==1){
|
||||
// adding the subtitle to the buffer of the array
|
||||
array.subs[i].buffer = realloc(array.subs[i].buffer,sizeof(char*)*array.subs[i].buffer_count);
|
||||
array.subs[i].buffer[array.subs[i].buffer_count-1] = malloc(sizeof(char)*strlen(buffer));
|
||||
strcpy (array.subs[i].buffer[array.subs[i].buffer_count-1], buffer);
|
||||
#if defined(PYTHONAPI)
|
||||
asprintf(&output,"text[%d]:%s\n",srt_counter,buffer);
|
||||
run(array.reporter,output);
|
||||
#endif
|
||||
|
||||
//fprintf(array.fp,"text[%d]:%s\n",srt_counter,buffer);
|
||||
//fflush(array.fp);
|
||||
array.subs[i].buffer_count++;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
if(identifier==2){
|
||||
// forming the g608_grid_color
|
||||
array.subs[i].g608_grid_color = realloc(array.subs[i].g608_grid_color,sizeof(char*)*array.subs[i].g608_grid_color_count);
|
||||
array.subs[i].g608_grid_color[array.subs[i].g608_grid_color_count-1] = malloc(sizeof(char)*strlen(buffer));
|
||||
strcpy (array.subs[i].g608_grid_color[array.subs[i].g608_grid_color_count-1], buffer);
|
||||
#if defined(PYTHONAPI)
|
||||
asprintf(&output,"color[%d]:%s\n",srt_counter,buffer);
|
||||
run(array.reporter,output);
|
||||
#endif
|
||||
|
||||
//fprintf(array.fp,"color[%d]:%s\n",srt_counter,buffer);
|
||||
//fflush(array.fp);
|
||||
array.subs[i].g608_grid_color_count++;
|
||||
return;
|
||||
}
|
||||
else if(identifier==3){
|
||||
// forming the g608_grid
|
||||
array.subs[i].g608_grid_font = realloc(array.subs[i].g608_grid_font,sizeof(char*)*array.subs[i].g608_grid_font_count);
|
||||
array.subs[i].g608_grid_font[array.subs[i].g608_grid_font_count-1] = malloc(sizeof(char)*strlen(buffer));
|
||||
strcpy (array.subs[i].g608_grid_font[array.subs[i].g608_grid_font_count-1], buffer);
|
||||
#if defined(PYTHONAPI)
|
||||
asprintf(&output,"font[%d]:%s\n",srt_counter,buffer);
|
||||
run(array.reporter,output);
|
||||
#endif
|
||||
//fprintf(array.fp,"font[%d]:%s\n",srt_counter,buffer);
|
||||
//fflush(array.fp);
|
||||
array.subs[i].g608_grid_font_count++;
|
||||
return;
|
||||
}
|
||||
else if(identifier==4){
|
||||
// writing end of frame
|
||||
#if defined(PYTHONAPI)
|
||||
asprintf(&output,"***END OF FRAME***\n",srt_counter,buffer);
|
||||
run(array.reporter,output);
|
||||
#endif
|
||||
//fprintf(array.fp,"***END OF FRAME***\n",srt_counter,buffer);
|
||||
//fflush(array.fp);
|
||||
array.subs[i].g608_grid_font_count++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if the start time and end time do not match then
|
||||
// we are just initializing a new element in the array and
|
||||
// initiating its buffer count and grid count
|
||||
array.sub_count++;
|
||||
array.subs = realloc(array.subs,sizeof(struct python_subs_modified)*array.sub_count);
|
||||
|
||||
array.subs[array.sub_count-1].start_time = start_time;
|
||||
array.subs[array.sub_count-1].end_time = end_time;
|
||||
#if defined(PYTHONAPI)
|
||||
asprintf(&output,"srt_counter-%d\n",srt_counter);
|
||||
run(array.reporter,output);
|
||||
asprintf(&output,"start_time-%s\t end_time-%s\n",start_time,end_time);
|
||||
run(array.reporter,output);
|
||||
#endif
|
||||
//fprintf(array.fp,"srt_counter-%s\t",start_time);
|
||||
//fprintf(array.fp,"start_time-%s\t",start_time);
|
||||
//fprintf(array.fp,"end_time-%s\n",end_time);
|
||||
array.subs[array.sub_count-1].buffer_count=1;
|
||||
array.subs[array.sub_count-1].buffer=NULL;
|
||||
|
||||
array.subs[array.sub_count-1].g608_grid_color_count=1;
|
||||
array.subs[array.sub_count-1].g608_grid_font_count=1;
|
||||
array.subs[array.sub_count-1].g608_grid_color=NULL;
|
||||
array.subs[array.sub_count-1].g608_grid_font=NULL;
|
||||
}
|
||||
|
||||
|
||||
void python_extract_time_based(unsigned h1, unsigned m1, unsigned s1, unsigned ms1, unsigned h2, unsigned m2, unsigned s2, unsigned ms2, char* buffer){
|
||||
//check if the caption with same start and end time already exists
|
||||
int i;
|
||||
char* start_time = time_wrapper("%02u:%02u:%02u,%03u",h1,m1,s1,ms1);
|
||||
char* end_time = time_wrapper("%02u:%02u:%02u,%03u",h2,m2,s2,ms2);
|
||||
for(i=0;i<array.sub_count;i++){
|
||||
if ((strcmp(start_time,array.subs[i].start_time)==0)&&(strcmp(end_time,array.subs[i].end_time)==0)){
|
||||
fprintf(array.fp,"%s\n",buffer);
|
||||
fflush(array.fp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
array.sub_count++;
|
||||
array.subs = realloc(array.subs,sizeof(struct python_subs_modified)*array.sub_count);
|
||||
|
||||
array.subs[array.sub_count-1].start_time = start_time;
|
||||
array.subs[array.sub_count-1].end_time = end_time;
|
||||
|
||||
//array.subs[array.sub_count-1].buffer_count=1;
|
||||
//array.subs[array.sub_count-1].buffer = malloc(sizeof(char*)*array.subs[array.sub_count-1].buffer_count);
|
||||
//array.subs[array.sub_count-1].buffer[array.subs[array.sub_count-1].buffer_count-1] = malloc(sizeof(char)*strlen(buffer));
|
||||
//strcpy(array.subs[array.sub_count-1].buffer[array.subs[array.sub_count-1].buffer_count-1], buffer);
|
||||
|
||||
fprintf(array.fp,"start_time:%s\t",start_time);
|
||||
fprintf(array.fp,"end_time:%s\n",end_time);
|
||||
fprintf(array.fp,"%s\n",buffer);
|
||||
fflush(array.fp);
|
||||
}
|
||||
|
||||
void python_extract_transcript(char* buffer){
|
||||
//check if the caption with same start and end time already exists
|
||||
python_extract_time_based(0,0,0,0,0,0,0,0,buffer);
|
||||
array.is_transcript=1;
|
||||
}
|
||||
|
||||
11
api/extractors/extractor.h
Normal file
11
api/extractors/extractor.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "ccextractor.h"
|
||||
|
||||
void python_extract(int srt_counter, unsigned h1, unsigned m1, unsigned s1, unsigned ms1, unsigned h2, unsigned m2, unsigned s2, unsigned ms2, char* buffer);
|
||||
void python_extract_time_based(unsigned h1, unsigned m1, unsigned s1, unsigned ms1, unsigned h2, unsigned m2, unsigned s2, unsigned ms2, char* buffer);
|
||||
void python_extract_transcript(char* buffer);
|
||||
void python_extract_g608_grid(unsigned h1, unsigned m1, unsigned s1, unsigned ms1, unsigned h2, unsigned m2, unsigned s2, unsigned ms2, char* buffer, int identifier, int srt_counter);
|
||||
|
||||
|
||||
|
||||
78
api/python_srt_generator.py
Normal file
78
api/python_srt_generator.py
Normal file
@@ -0,0 +1,78 @@
|
||||
import ccextractor as cc
|
||||
import re
|
||||
|
||||
def generate_file_handle(filename, mode):
|
||||
fh = open(filename,mode)
|
||||
# print "Creating output file: ", fh.name
|
||||
return fh
|
||||
|
||||
def delete_file_handle(fh):
|
||||
fh.close()
|
||||
##
|
||||
# data would be a dictionary containg the following keys:
|
||||
# text, color, font
|
||||
##
|
||||
def generate_output_srt_time( fh, data):
|
||||
data = data.split("-")
|
||||
end_time = str(data[-1].split("\n")[0])
|
||||
start_time = str(data[1].split("\t")[0])
|
||||
fh.write(start_time)
|
||||
fh.write(" --> ")
|
||||
fh.write(end_time)
|
||||
fh.write("\n")
|
||||
fh.flush()
|
||||
|
||||
"""
|
||||
#Handling underline
|
||||
buff = ""
|
||||
underline_flag = 0
|
||||
for i,font_type in enumerate(font_line):
|
||||
if font_type == 'U' and not underline_flag:
|
||||
buff = buff + '<u> '
|
||||
underline_flag = 1
|
||||
underline=1
|
||||
elif font_type =="R" and underline_flag:
|
||||
buff = buff + '</u>'
|
||||
underline_flag = 0
|
||||
continue;
|
||||
buff += letter[i]
|
||||
#adding a new line after buff has seen underline
|
||||
#need to cross check with CCExtractor output as to how they are doing
|
||||
if underline:
|
||||
buff+= "\n"
|
||||
else:
|
||||
buff=""
|
||||
"""
|
||||
def comparing_text_font_grids(text, font):
|
||||
temp = []
|
||||
|
||||
for letter,font_line in zip(text,font):
|
||||
if " " not in letter:
|
||||
buff=""
|
||||
underline,italics = 0,0
|
||||
#Handling italics
|
||||
italics_flag = 0
|
||||
for i,font_type in enumerate(font_line):
|
||||
if font_type == 'I' and not italics_flag:
|
||||
buff = buff + '<i>'
|
||||
italics_flag = 1
|
||||
elif font_type =="R" and italics_flag:
|
||||
buff = buff + '</i>'
|
||||
italics_flag = 0
|
||||
buff += letter[i]
|
||||
temp.append(buff)
|
||||
return (temp,font)
|
||||
|
||||
|
||||
def generate_output_srt( fh, d):
|
||||
temp = []
|
||||
d['text'],d['font']= comparing_text_font_grids(d['text'],d['font'])
|
||||
for item in d['text']:
|
||||
if " " not in item:
|
||||
o = re.sub(r'[\x00-\x1e]',r'',item)
|
||||
o = re.sub(r'\x1f[!@#$%^&*()]*', r'', o)
|
||||
temp.append(o)
|
||||
fh.write(o)
|
||||
fh.write("\n")
|
||||
fh.flush()
|
||||
fh.write("\n")
|
||||
@@ -1,5 +1,26 @@
|
||||
#include "wrapper.h"
|
||||
#include "ccextractor.h"
|
||||
|
||||
/*
|
||||
output=pythonapi wrapper
|
||||
*/
|
||||
|
||||
//void set_pythonapi_via_python(struct ccx_s_options *api_options, PyObject * func){
|
||||
// printf("Inside set pythonapi\n");
|
||||
// array.reporter = func;
|
||||
// api_add_param(api_options,"-pythonapi");
|
||||
//}
|
||||
|
||||
void set_pythonapi(struct ccx_s_options *api_options){
|
||||
api_add_param(api_options,"-pythonapi");
|
||||
}
|
||||
#if defined(PYTHONAPI)
|
||||
void set_pythonapi_via_python(struct ccx_s_options *api_options, PyObject * func){
|
||||
//setting the user specified callback function as a array element which would be global in C
|
||||
array.reporter = func;
|
||||
api_add_param(api_options,"-pythonapi");
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
autoprogram wrapper
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include "ccextractor.h"
|
||||
|
||||
#if defined(PYTHONAPI)
|
||||
//void set_pythonapi_via_python(struct ccx_s_options *api_options);
|
||||
void set_pythonapi_via_python(struct ccx_s_options *api_options, PyObject * func);
|
||||
#define my_pythonapi(args, func) set_pythonapi_via_python(args, func)
|
||||
#else
|
||||
#define my_pythonapi(args, func) set_pythonapi(args)
|
||||
#endif
|
||||
void set_pythonapi(struct ccx_s_options *api_options);
|
||||
void setautoprogram(struct ccx_s_options *api_options);
|
||||
void setstdout(struct ccx_s_options *api_options);
|
||||
void setpesheader(struct ccx_s_options *api_options);
|
||||
void setdebugdbvsub(struct ccx_s_options *api_options);
|
||||
void setdebugdvbsub(struct ccx_s_options *api_options);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
find /vagrant/First\ phase\ evaluation/ -name '*.ts' -exec sh -c '
|
||||
find /vagrant/Second\ phase\ evaluation/ -name '*.ts' -exec sh -c '
|
||||
for file do
|
||||
python ../../api/api_testing.py $file
|
||||
python ../../api/api_testing.py $file -quiet
|
||||
done
|
||||
' sh {} +
|
||||
|
||||
@@ -10,12 +10,14 @@ SRC_GPAC="$(find ../src/gpacmp4/ -name '*.c')"
|
||||
SRC_HASH="$(find ../src/lib_hash/ -name '*.c')"
|
||||
SRC_PROTOBUF="$(find ../src/protobuf-c/ -name '*.c')"
|
||||
SRC_UTF8PROC="../src/utf8proc/utf8proc.c"
|
||||
BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC"
|
||||
API_WRAPPERS="$(find ../api/wrappers/ -name '*.c')"
|
||||
API_EXTRACTORS="$(find ../api/extractors/ -name '*.c')"
|
||||
BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC $API_WRAPPERS $API_EXTRACTORS"
|
||||
BLD_LINKER="-lm -zmuldefs -l tesseract -l lept"
|
||||
|
||||
./pre-build.sh
|
||||
|
||||
out=$((LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER)2>&1)
|
||||
out=$((LC_ALL=C gcc -g $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER)2>&1)
|
||||
#out=$((LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE $WRAPPER_FLAGS -o ccextractor $BLD_SOURCES $BLD_LINKER)2>&1)
|
||||
res=$?
|
||||
if [[ $out == *"gcc: command not found"* ]]
|
||||
|
||||
@@ -27,7 +27,8 @@ void sigterm_handler(int sig)
|
||||
|
||||
void sigint_handler(int sig)
|
||||
{
|
||||
if (ccx_options.print_file_reports)
|
||||
remove(array.temporary_file);
|
||||
if (ccx_options.print_file_reports)
|
||||
print_file_report(signal_ctx);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
@@ -376,7 +377,6 @@ int api_start(struct ccx_s_options api_options){
|
||||
if(is_decoder_processed_enough(ctx) == CCX_TRUE)
|
||||
break;
|
||||
} // file loop
|
||||
python_subs.extension = ctx->extension;
|
||||
close_input_file(ctx);
|
||||
free((void *) ctx->extension);
|
||||
|
||||
@@ -409,7 +409,6 @@ int api_start(struct ccx_s_options api_options){
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
#endif
|
||||
python_subs.basefilename = ctx->basefilename;
|
||||
dinit_libraries(&ctx);
|
||||
|
||||
if (!ret)
|
||||
@@ -423,10 +422,14 @@ int api_start(struct ccx_s_options api_options){
|
||||
mprint("code in the MythTV's branch. Please report results to the address above. If\n");
|
||||
mprint("something is broken it will be fixed. Thanks\n");
|
||||
}
|
||||
return ret ? EXIT_OK : EXIT_NO_CAPTIONS;
|
||||
remove(array.temporary_file);
|
||||
fclose(array.fp);
|
||||
return ret ? EXIT_OK : EXIT_NO_CAPTIONS;
|
||||
}
|
||||
|
||||
struct ccx_s_options* api_init_options(){
|
||||
array.temporary_file = "test.txt";
|
||||
array.fp = fopen("test.txt", "a");
|
||||
init_options(&ccx_options);
|
||||
return &ccx_options;
|
||||
}
|
||||
@@ -436,30 +439,33 @@ void check_configuration_file(struct ccx_s_options api_options){
|
||||
}
|
||||
|
||||
int compile_params(struct ccx_s_options *api_options,int argc){
|
||||
api_options->python_params = realloc(api_options->python_params, (api_options->python_param_count+1) * sizeof *api_options->python_params);
|
||||
//adding the parameter ./ccextractor to the list of python_params for further parsing
|
||||
api_options->python_params = realloc(api_options->python_params, (api_options->python_param_count+1) * sizeof *api_options->python_params);
|
||||
api_options->python_params[api_options->python_param_count] = malloc(strlen("./ccextractor")+1);
|
||||
strcpy(api_options->python_params[api_options->python_param_count], "./ccextractor");
|
||||
api_options->python_param_count++;
|
||||
|
||||
char* temp = api_options->python_params[api_options->python_param_count-1];
|
||||
int i;
|
||||
for (i = api_options->python_param_count-1; i > 0; i--)
|
||||
api_options->python_params[i] = api_options->python_params[i-1];
|
||||
api_options->python_params[0] = temp;
|
||||
int ret = parse_parameters (api_options, api_options->python_param_count, api_options->python_params);
|
||||
if (ret == EXIT_NO_INPUT_FILES)
|
||||
{
|
||||
|
||||
int ret = parse_parameters (api_options, api_options->python_param_count, api_options->python_params);
|
||||
if (ret == EXIT_NO_INPUT_FILES)
|
||||
{
|
||||
print_usage ();
|
||||
fatal (EXIT_NO_INPUT_FILES, "(This help screen was shown because there were no input files)\n");
|
||||
}
|
||||
else if (ret == EXIT_WITH_HELP)
|
||||
{
|
||||
}
|
||||
else if (ret == EXIT_WITH_HELP)
|
||||
{
|
||||
return EXIT_OK;
|
||||
}
|
||||
else if (ret != EXIT_OK)
|
||||
{
|
||||
}
|
||||
else if (ret != EXIT_OK)
|
||||
{
|
||||
exit(ret);
|
||||
}
|
||||
return EXIT_OK;
|
||||
}
|
||||
return EXIT_OK;
|
||||
}
|
||||
|
||||
void api_add_param(struct ccx_s_options* api_options,char* arg){
|
||||
@@ -469,59 +475,175 @@ void api_add_param(struct ccx_s_options* api_options,char* arg){
|
||||
api_options->python_param_count++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function to print the i-th param submitted by the user.
|
||||
* Helpful for debugging
|
||||
*/
|
||||
char * api_param(struct ccx_s_options* api_options, int count){
|
||||
return api_options->python_params[count];
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function to get the total number of params provided by the user.
|
||||
* Helpful for debugging
|
||||
*/
|
||||
int api_param_count(struct ccx_s_options* api_options){
|
||||
return api_options->python_param_count;
|
||||
}
|
||||
|
||||
/*subs functions*/
|
||||
int cc_to_python_get_subs_number_of_lines(){
|
||||
return python_subs.number_of_lines;
|
||||
}
|
||||
char* cc_to_python_get_sub(int i){
|
||||
return python_subs.subs[i];
|
||||
int cc_to_python_get_old_count(){
|
||||
return array.old_sub_count;
|
||||
}
|
||||
|
||||
void cc_to_python_set_old_count(){
|
||||
array.old_sub_count=array.sub_count;
|
||||
}
|
||||
|
||||
/*filename functions*/
|
||||
int cc_to_python_get_number_of_subs(){
|
||||
return array.sub_count;
|
||||
}
|
||||
|
||||
struct python_subs_modified cc_to_python_get_modified_sub(int i){
|
||||
return array.subs[i];
|
||||
}
|
||||
|
||||
int cc_to_python_get_modified_sub_buffer_size(int i){
|
||||
return array.subs[i].buffer_count;
|
||||
}
|
||||
char* cc_to_python_get_modified_sub_buffer(int i, int j){
|
||||
return array.subs[i].buffer[j];
|
||||
}
|
||||
|
||||
char* cc_to_python_get_output_filename(){
|
||||
return array.output_filename;
|
||||
}
|
||||
/*
|
||||
char* cc_to_python_get_basefilename(){
|
||||
return python_subs.basefilename;
|
||||
* asprintf alternative
|
||||
* Defined only in case of windows users.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
int vasprintf(char **strp, const char *fmt, va_list ap) {
|
||||
//_vscprintf tells you how big the buffer needs to be
|
||||
int len = _vscprintf(fmt, ap);
|
||||
if (len == -1) {
|
||||
return -1;
|
||||
}
|
||||
size_t size = (size_t)len + 1;
|
||||
char *str = malloc(size);
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
// _vsprintf_s is the "secure" version of vsprintf
|
||||
int r = vsprintf_s(str, len + 1, fmt, ap);
|
||||
if (r == -1) {
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
*strp = str;
|
||||
return r;
|
||||
}
|
||||
|
||||
int asprintf(char **strp, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int r = vasprintf(strp, fmt, ap);
|
||||
va_end(ap);
|
||||
return r;
|
||||
}
|
||||
char* cc_to_python_get_extension(){
|
||||
return python_subs.extension;
|
||||
#endif
|
||||
char* time_wrapper(char* fmt, unsigned h, unsigned m, unsigned s, unsigned ms){
|
||||
char * time;
|
||||
asprintf(&time,fmt, h, m, s, ms);
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* char* time_wrapper(char* fmt, unsigned h, unsigned m, unsigned s, unsigned ms){
|
||||
int buf_len = 12;
|
||||
char *x = malloc( 10* sizeof(char));
|
||||
int size = snprintf(x, 13, fmt, h, m, s, ms);
|
||||
if(size >= buf_len) {
|
||||
x = realloc(x,(size) * sizeof(char));
|
||||
snprintf(x, 13, fmt, h, m, s, ms);
|
||||
}
|
||||
printf("\n%02u:%02u:%02u,%02u\t%s\n",h,m,s,ms,x);
|
||||
return x;
|
||||
}
|
||||
*/
|
||||
|
||||
//int __real_write(int file_handle, char* buffer, int nbyte);
|
||||
int __wrap_write(int file_handle, char* buffer, int nbyte)
|
||||
{
|
||||
python_subs.number_of_lines++;
|
||||
|
||||
if (python_subs.number_of_lines==1)
|
||||
python_subs.subs = malloc(python_subs.number_of_lines*sizeof(char*));
|
||||
else
|
||||
python_subs.subs = realloc(python_subs.subs,python_subs.number_of_lines*sizeof(char*));
|
||||
|
||||
python_subs.subs[python_subs.number_of_lines-1] = malloc((strlen(buffer)+1)*sizeof(char));
|
||||
strcpy(python_subs.subs[python_subs.number_of_lines-1],buffer);
|
||||
return write(file_handle,buffer,nbyte);
|
||||
// return __real_write(file_handle,buffer,nbyte);
|
||||
//char* time_wrapper(const char *fmt, ...)
|
||||
//{
|
||||
// int n;
|
||||
// int size = 1000; // Guess we need no more than 100 bytes */
|
||||
// char *p, *np;
|
||||
// va_list ap;
|
||||
// if ((p = malloc(size)) == NULL)
|
||||
// return NULL;
|
||||
// while (1) {
|
||||
// /* Try to print in the allocated space */
|
||||
// va_start(ap, fmt);
|
||||
// n = vsnprintf(p, size, fmt, ap);
|
||||
// va_end(ap);
|
||||
// /* Check error code */
|
||||
// if (n < 0)
|
||||
// return NULL;
|
||||
// /* If that worked, return the string */
|
||||
// if (n < size)
|
||||
// return p;
|
||||
// /* Else try again with more space */
|
||||
// size = n + 1; /* Precisely what is needed */
|
||||
// if ((np = realloc (p, size)) == NULL) {
|
||||
// free(p);
|
||||
// return NULL;
|
||||
// }
|
||||
// else {
|
||||
// p = np;
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
void show_extracted_captions_with_timings(){
|
||||
int i;
|
||||
for(i=0;i<array.sub_count;i++){
|
||||
if (!array.is_transcript)
|
||||
mprint("start_time = %s\tend_time = %s\n",array.subs[i].start_time,array.subs[i].end_time);
|
||||
int j=0;
|
||||
while(j<array.subs[i].buffer_count){
|
||||
mprint("%s\n",array.subs[i].buffer[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void call_from_python_api(struct ccx_s_options *api_options){
|
||||
int indicator = api_options->signal_python_api;
|
||||
if (indicator)
|
||||
signal_python_api=1;
|
||||
else
|
||||
signal_python_api=0;
|
||||
}
|
||||
|
||||
#if defined(PYTHONAPI)
|
||||
void run(PyObject * reporter, char * line) {
|
||||
const char * s = line;
|
||||
assert ( PyFunction_Check(reporter) );
|
||||
PyObject* args = PyTuple_Pack(1, PyString_FromString(s));
|
||||
PyObject_CallObject((PyObject*)reporter, args);
|
||||
}
|
||||
#endif
|
||||
int main(int argc, char* argv[]){
|
||||
int i;
|
||||
struct ccx_s_options* api_options = api_init_options();
|
||||
check_configuration_file(*api_options);
|
||||
for(i = 1; i < argc; i++)
|
||||
api_add_param(api_options,argv[i]);
|
||||
|
||||
int compile_ret = compile_params(api_options,argc);
|
||||
int start_ret = api_start(*api_options);
|
||||
|
||||
return start_ret;
|
||||
int i;
|
||||
struct ccx_s_options* api_options = api_init_options();
|
||||
check_configuration_file(*api_options);
|
||||
for(i = 1; i < argc; i++)
|
||||
api_add_param(api_options,argv[i]);
|
||||
|
||||
int compile_ret = compile_params(api_options,argc);
|
||||
call_from_python_api(api_options);
|
||||
//mprint("signal_python_api = %d\n", signal_python_api);
|
||||
int start_ret = api_start(*api_options);
|
||||
|
||||
//uncomment the next line to check the extracted captions along with timings
|
||||
// show_extracted_captions_with_timings();
|
||||
return start_ret;
|
||||
}
|
||||
|
||||
@@ -22,18 +22,44 @@ CURLcode res;
|
||||
#define LEPT_MSG_SEVERITY L_SEVERITY_NONE
|
||||
#endif
|
||||
|
||||
struct cc_to_python_subs{
|
||||
char **inputfile; // List of files to process
|
||||
int num_input_files; // How many input files
|
||||
char* basefilename;
|
||||
char* extension;
|
||||
char** subs;
|
||||
int number_of_lines;
|
||||
#if defined(PYTHONAPI)
|
||||
#include "Python.h"
|
||||
#include "funcobject.h"
|
||||
#endif
|
||||
|
||||
struct python_subs_modified{
|
||||
int buffer_count;
|
||||
int srt_counter;
|
||||
char *start_time;
|
||||
char* end_time;
|
||||
char** buffer;
|
||||
|
||||
//g608 specific elements
|
||||
int g608_grid_color_count;
|
||||
char** g608_grid_color;
|
||||
int g608_grid_font_count;
|
||||
char** g608_grid_font;
|
||||
};
|
||||
|
||||
struct python_subs_array{
|
||||
#if defined(PYTHONAPI)
|
||||
PyObject* reporter;
|
||||
#endif
|
||||
char* temporary_file;
|
||||
FILE *fp;
|
||||
char* output_filename;
|
||||
int has_api_start_exited;
|
||||
int old_sub_count;
|
||||
int sub_count;
|
||||
struct python_subs_modified* subs;
|
||||
int is_transcript;
|
||||
};
|
||||
|
||||
|
||||
struct ccx_s_options ccx_options;
|
||||
struct lib_ccx_ctx *signal_ctx;
|
||||
struct cc_to_python_subs python_subs;
|
||||
struct python_subs_array array;
|
||||
int signal_python_api; // 1 symbolises that python wrapper made the call.
|
||||
//volatile int terminate_asap = 0;
|
||||
|
||||
struct ccx_s_options* api_init_options();
|
||||
@@ -47,14 +73,20 @@ char * api_param(struct ccx_s_options* api_options, int count);
|
||||
void sigterm_handler(int sig);
|
||||
void sigint_handler(int sig);
|
||||
void print_end_msg(void);
|
||||
|
||||
void show_extracted_captions_with_timings();
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
int cc_to_python_get_subs_number_of_lines();
|
||||
char* cc_to_python_get_sub(int i);
|
||||
int cc_to_python_get_old_count();
|
||||
void cc_to_python_set_old_count();
|
||||
int cc_to_python_get_number_of_subs();
|
||||
struct python_subs_modified cc_to_python_get_modified_sub(int i);
|
||||
int cc_to_python_get_modified_sub_buffer_size(int i);
|
||||
char* cc_to_python_get_modified_sub_buffer(int i, int j);
|
||||
char* cc_to_python_get_output_filename();
|
||||
|
||||
//char* cc_to_python_get_basefilename();
|
||||
//char* cc_to_python_get_extension();
|
||||
|
||||
//int __real_write(int file_handle, char* buffer, int nbyte);
|
||||
int __wrap_write(int file_handle, char* buffer, int nbyte);
|
||||
void call_from_python_api(struct ccx_s_options *api_options);
|
||||
#if defined(PYTHONAPI)
|
||||
void run(PyObject * reporter, char * line);
|
||||
#endif
|
||||
#endif //CCEXTRACTOR_H
|
||||
|
||||
@@ -197,6 +197,7 @@ struct ccx_s_options // Options from user parameters
|
||||
#endif
|
||||
char** python_params; // An array of strings to store the params supplied in the python processing
|
||||
int python_param_count; // Count of the total number of params passed via python bindings
|
||||
int signal_python_api; // 1 symbolises that python wrapper made the call.
|
||||
};
|
||||
|
||||
extern struct ccx_s_options ccx_options;
|
||||
|
||||
@@ -185,13 +185,13 @@ void _dtvcc_write_row(ccx_dtvcc_writer_ctx *writer, ccx_dtvcc_service_decoder *d
|
||||
ccx_common_logging.log_ftn("[CEA-708] _dtvcc_write_row: "
|
||||
"conversion failed: %s\n", strerror(errno));
|
||||
|
||||
__wrap_write(fd, encoded_buf_start, encoded_buf - encoded_buf_start);
|
||||
write(fd, encoded_buf_start, encoded_buf - encoded_buf_start);
|
||||
|
||||
free(encoded_buf_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
__wrap_write(fd, buf, buf_len);
|
||||
write(fd, buf, buf_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,18 +215,18 @@ void ccx_dtvcc_write_srt(ccx_dtvcc_writer_ctx *writer, ccx_dtvcc_service_decoder
|
||||
"%02u:%02u:%02u,%03u", buf + strlen(buf));
|
||||
sprintf(buf + strlen(buf),"%s", (char *) encoder->encoded_crlf);
|
||||
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
|
||||
for (int i = 0; i < CCX_DTVCC_SCREENGRID_ROWS; i++)
|
||||
{
|
||||
if (!_dtvcc_is_row_empty(tv, i))
|
||||
{
|
||||
_dtvcc_write_row(writer, decoder, i, encoder, 1);
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
encoder->encoded_crlf, encoder->encoded_crlf_length);
|
||||
}
|
||||
}
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
encoder->encoded_crlf, encoder->encoded_crlf_length);
|
||||
}
|
||||
|
||||
@@ -284,10 +284,10 @@ void ccx_dtvcc_write_transcript(ccx_dtvcc_writer_ctx *writer, ccx_dtvcc_service_
|
||||
sprintf(buf + strlen(buf), "POP|"); //TODO caption mode(pop, rollup, etc.)
|
||||
|
||||
if (strlen(buf))
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
|
||||
_dtvcc_write_row(writer, decoder, i, encoder, 0);
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
encoder->encoded_crlf, encoder->encoded_crlf_length);
|
||||
}
|
||||
}
|
||||
@@ -315,15 +315,15 @@ void _dtvcc_write_sami_header(dtvcc_tv_screen *tv, struct encoder_ctx *encoder)
|
||||
buf_len += sprintf(buf + buf_len, "</head>%s%s", encoder->encoded_crlf, encoder->encoded_crlf);
|
||||
buf_len += sprintf(buf + buf_len, "<body>%s", encoder->encoded_crlf);
|
||||
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, buf_len);
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, buf_len);
|
||||
}
|
||||
|
||||
void _dtvcc_write_sami_footer(dtvcc_tv_screen *tv, struct encoder_ctx *encoder)
|
||||
{
|
||||
char *buf = (char *) encoder->buffer;
|
||||
sprintf(buf, "</body></sami>");
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
encoder->encoded_crlf, encoder->encoded_crlf_length);
|
||||
}
|
||||
|
||||
@@ -345,16 +345,16 @@ void ccx_dtvcc_write_sami(ccx_dtvcc_writer_ctx *writer, ccx_dtvcc_service_decode
|
||||
sprintf(buf, "<sync start=%llu><p class=\"unknowncc\">%s",
|
||||
(unsigned long long) tv->time_ms_show + encoder->subs_delay,
|
||||
encoder->encoded_crlf);
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
|
||||
for (int i = 0; i < CCX_DTVCC_SCREENGRID_ROWS; i++)
|
||||
{
|
||||
if (!_dtvcc_is_row_empty(tv, i))
|
||||
{
|
||||
_dtvcc_write_row(writer, decoder, i, encoder, 1);
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
encoder->encoded_br, encoder->encoded_br_length);
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd,
|
||||
encoder->encoded_crlf, encoder->encoded_crlf_length);
|
||||
}
|
||||
}
|
||||
@@ -362,7 +362,7 @@ void ccx_dtvcc_write_sami(ccx_dtvcc_writer_ctx *writer, ccx_dtvcc_service_decode
|
||||
sprintf(buf, "<sync start=%llu><p class=\"unknowncc\"> </p></sync>%s%s",
|
||||
(unsigned long long) tv->time_ms_hide + encoder->subs_delay,
|
||||
encoder->encoded_crlf, encoder->encoded_crlf);
|
||||
__wrap_write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
write(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
|
||||
}
|
||||
|
||||
void _ccx_dtvcc_write(ccx_dtvcc_writer_ctx *writer, ccx_dtvcc_service_decoder *decoder, struct encoder_ctx *encoder)
|
||||
@@ -480,7 +480,7 @@ void ccx_dtvcc_writer_output(ccx_dtvcc_writer_ctx *writer, ccx_dtvcc_service_dec
|
||||
CCX_COMMON_EXIT_FILE_CREATION_FAILED, "[CEA-708] Failed to open a file\n");
|
||||
}
|
||||
if (!encoder->no_bom)
|
||||
__wrap_write(writer->fd, UTF8_BOM, sizeof(UTF8_BOM));
|
||||
write(writer->fd, UTF8_BOM, sizeof(UTF8_BOM));
|
||||
}
|
||||
|
||||
_ccx_dtvcc_write(writer, decoder, encoder);
|
||||
|
||||
@@ -558,4 +558,4 @@ void free_subtitle(struct cc_subtitle* sub)
|
||||
|
||||
freep(&sub->data);
|
||||
freep(&sub);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "ccx_decoders_708_output.h"
|
||||
#include "ccx_encoders_xds.h"
|
||||
#include "ccx_encoders_helpers.h"
|
||||
|
||||
#include "../ccextractor.h"
|
||||
#ifdef ENABLE_SHARING
|
||||
#include "ccx_share.h"
|
||||
#endif //ENABLE_SHARING
|
||||
@@ -353,7 +353,7 @@ int write_subtitle_file_footer(struct encoder_ctx *ctx,struct ccx_s_write *out)
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line (ctx, ctx->buffer,(unsigned char *) str);
|
||||
ret = __wrap_write(out->fh, ctx->buffer, used);
|
||||
ret = write(out->fh, ctx->buffer, used);
|
||||
if (ret != used)
|
||||
{
|
||||
mprint("WARNING: loss of data\n");
|
||||
@@ -366,7 +366,7 @@ int write_subtitle_file_footer(struct encoder_ctx *ctx,struct ccx_s_write *out)
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line (ctx, ctx->buffer,(unsigned char *) str);
|
||||
ret = __wrap_write (out->fh, ctx->buffer, used);
|
||||
ret = write (out->fh, ctx->buffer, used);
|
||||
if (ret != used)
|
||||
{
|
||||
mprint("WARNING: loss of data\n");
|
||||
@@ -382,7 +382,7 @@ int write_subtitle_file_footer(struct encoder_ctx *ctx,struct ccx_s_write *out)
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line (ctx, ctx->buffer,(unsigned char *) str);
|
||||
ret = __wrap_write (out->fh, ctx->buffer, used);
|
||||
ret = write (out->fh, ctx->buffer, used);
|
||||
if (ret != used)
|
||||
{
|
||||
mprint("WARNING: loss of data\n");
|
||||
@@ -401,7 +401,7 @@ static int write_bom(struct encoder_ctx *ctx, struct ccx_s_write *out)
|
||||
int ret = 0;
|
||||
if (!ctx->no_bom){
|
||||
if (ctx->encoding == CCX_ENC_UTF_8){ // Write BOM
|
||||
ret = __wrap_write(out->fh, UTF8_BOM, sizeof(UTF8_BOM));
|
||||
ret = write(out->fh, UTF8_BOM, sizeof(UTF8_BOM));
|
||||
if ( ret < sizeof(UTF8_BOM)) {
|
||||
mprint("WARNING: Unable tp write UTF BOM\n");
|
||||
return -1;
|
||||
@@ -409,7 +409,7 @@ static int write_bom(struct encoder_ctx *ctx, struct ccx_s_write *out)
|
||||
|
||||
}
|
||||
if (ctx->encoding == CCX_ENC_UNICODE){ // Write BOM
|
||||
ret = __wrap_write(out->fh, LITTLE_ENDIAN_BOM, sizeof(LITTLE_ENDIAN_BOM));
|
||||
ret = write(out->fh, LITTLE_ENDIAN_BOM, sizeof(LITTLE_ENDIAN_BOM));
|
||||
if ( ret < sizeof(LITTLE_ENDIAN_BOM)) {
|
||||
mprint("WARNING: Unable to write LITTLE_ENDIAN_BOM \n");
|
||||
return -1;
|
||||
@@ -437,7 +437,7 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
|
||||
return -1;
|
||||
REQUEST_BUFFER_CAPACITY(ctx,strlen (ssa_header)*3);
|
||||
used = encode_line (ctx, ctx->buffer,(unsigned char *) ssa_header);
|
||||
ret = __wrap_write (out->fh, ctx->buffer, used);
|
||||
ret = write (out->fh, ctx->buffer, used);
|
||||
if(ret < used)
|
||||
{
|
||||
mprint("WARNING: Unable to write complete Buffer \n");
|
||||
@@ -463,7 +463,7 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
|
||||
{
|
||||
used = encode_line (ctx, ctx->buffer,(unsigned char *) webvtt_header[i]);
|
||||
}
|
||||
ret = __wrap_write (out->fh, ctx->buffer,used);
|
||||
ret = write (out->fh, ctx->buffer,used);
|
||||
if(ret < used)
|
||||
{
|
||||
mprint("WARNING: Unable to write complete Buffer \n");
|
||||
@@ -478,7 +478,7 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
|
||||
return -1;
|
||||
REQUEST_BUFFER_CAPACITY(ctx,strlen (sami_header)*3);
|
||||
used = encode_line (ctx, ctx->buffer,(unsigned char *) sami_header);
|
||||
ret = __wrap_write (out->fh, ctx->buffer, used);
|
||||
ret = write (out->fh, ctx->buffer, used);
|
||||
if(ret < used)
|
||||
{
|
||||
mprint("WARNING: Unable to write complete Buffer \n");
|
||||
@@ -492,7 +492,7 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
|
||||
return -1;
|
||||
REQUEST_BUFFER_CAPACITY(ctx,strlen (smptett_header)*3);
|
||||
used=encode_line (ctx, ctx->buffer,(unsigned char *) smptett_header);
|
||||
ret = __wrap_write(out->fh, ctx->buffer, used);
|
||||
ret = write(out->fh, ctx->buffer, used);
|
||||
if(ret < used)
|
||||
{
|
||||
mprint("WARNING: Unable to write complete Buffer \n");
|
||||
@@ -506,7 +506,7 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
|
||||
net_send_header(rcwt_header, sizeof(rcwt_header));
|
||||
else
|
||||
{
|
||||
ret = __wrap_write(out->fh, rcwt_header, sizeof(rcwt_header));
|
||||
ret = write(out->fh, rcwt_header, sizeof(rcwt_header));
|
||||
if(ret < 0)
|
||||
{
|
||||
mprint("Unable to write rcwt header\n");
|
||||
@@ -516,7 +516,7 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
|
||||
|
||||
break;
|
||||
case CCX_OF_RAW:
|
||||
ret = __wrap_write(out->fh,BROADCAST_HEADER, sizeof(BROADCAST_HEADER));
|
||||
ret = write(out->fh,BROADCAST_HEADER, sizeof(BROADCAST_HEADER));
|
||||
if(ret < sizeof(BROADCAST_HEADER))
|
||||
{
|
||||
mprint("Unable to write Raw header\n");
|
||||
@@ -539,7 +539,7 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
|
||||
return -1;
|
||||
REQUEST_BUFFER_CAPACITY(ctx,strlen (simple_xml_header)*3);
|
||||
used=encode_line (ctx, ctx->buffer,(unsigned char *) simple_xml_header);
|
||||
ret = __wrap_write(out->fh, ctx->buffer, used);
|
||||
ret = write(out->fh, ctx->buffer, used);
|
||||
if(ret < used)
|
||||
{
|
||||
mprint("WARNING: Unable to write complete Buffer \n");
|
||||
@@ -574,7 +574,7 @@ int write_cc_subtitle_as_simplexml(struct cc_subtitle *sub, struct encoder_ctx *
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ret = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if(ret < context->encoded_crlf_length)
|
||||
{
|
||||
mprint("Warning:Loss of data\n");
|
||||
@@ -610,14 +610,14 @@ void write_cc_line_as_simplexml(struct eia608_screen *data, struct encoder_ctx *
|
||||
length = get_str_basic (context->subline, data->characters[line_number],
|
||||
context->trim_subs, CCX_ENC_ASCII, context->encoding, CCX_DECODER_608_SCREEN_WIDTH);
|
||||
|
||||
ret = __wrap_write(context->out->fh, cap, strlen(cap));
|
||||
ret = __wrap_write(context->out->fh, context->subline, length);
|
||||
ret = write(context->out->fh, cap, strlen(cap));
|
||||
ret = write(context->out->fh, context->subline, length);
|
||||
if(ret < length)
|
||||
{
|
||||
mprint("Warning:Loss of data\n");
|
||||
}
|
||||
ret = __wrap_write(context->out->fh, cap1, strlen(cap1));
|
||||
ret = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
ret = write(context->out->fh, cap1, strlen(cap1));
|
||||
ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
|
||||
}
|
||||
|
||||
@@ -781,7 +781,6 @@ static int init_output_ctx(struct encoder_ctx *ctx, struct encoder_cfg *cfg)
|
||||
char *basefilename = NULL; // Input filename without the extension
|
||||
char *extension = NULL; // Input filename without the extension
|
||||
|
||||
|
||||
#define check_ret(filename) if (ret != EXIT_OK) \
|
||||
{ \
|
||||
fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED,"Failed to open output file: %s\nDetails : %s\n", filename, strerror(errno)); \
|
||||
@@ -826,9 +825,8 @@ static int init_output_ctx(struct encoder_ctx *ctx, struct encoder_cfg *cfg)
|
||||
}
|
||||
else if (cfg->write_format != CCX_OF_NULL)
|
||||
{
|
||||
basefilename = get_basename(ctx->first_input_file);
|
||||
extension = get_file_extension(cfg->write_format);
|
||||
|
||||
basefilename = get_basename(ctx->first_input_file);
|
||||
extension = get_file_extension(cfg->write_format);
|
||||
if (basefilename == NULL)
|
||||
{
|
||||
basefilename = get_basename("untitled");
|
||||
@@ -1054,7 +1052,7 @@ void set_encoder_rcwt_fileformat(struct encoder_ctx *ctx, short int format)
|
||||
|
||||
static int write_newline(struct encoder_ctx *ctx, int lang)
|
||||
{
|
||||
return __wrap_write(ctx->out[lang].fh, ctx->encoded_crlf, ctx->encoded_crlf_length);
|
||||
return write(ctx->out[lang].fh, ctx->encoded_crlf, ctx->encoded_crlf_length);
|
||||
}
|
||||
|
||||
struct ccx_s_write *get_output_ctx(struct encoder_ctx *ctx, int lan)
|
||||
@@ -1111,7 +1109,7 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
|
||||
xds_write_transcript_line_prefix(context, out, data->start_time, data->end_time, data->cur_xds_packet_class);
|
||||
if (data->xds_len > 0)
|
||||
{
|
||||
ret = __wrap_write(out->fh, data->xds_str, data->xds_len);
|
||||
ret = write(out->fh, data->xds_str, data->xds_len);
|
||||
if (ret < data->xds_len)
|
||||
{
|
||||
mprint("WARNING:Loss of data\n");
|
||||
@@ -1131,8 +1129,12 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
|
||||
data->end_time += utc_refvalue * 1000;
|
||||
}
|
||||
|
||||
switch (context->write_format)
|
||||
{
|
||||
//making a call to python_encoder so that if the call is from the api, no output is generated.
|
||||
if (signal_python_api)
|
||||
wrote_something = pass_cc_buffer_to_python(data, context);
|
||||
else {
|
||||
switch (context->write_format)
|
||||
{
|
||||
case CCX_OF_SRT:
|
||||
if (!context->startcredits_displayed && context->start_credits_text != NULL)
|
||||
try_to_add_start_credits(context, data->start_time);
|
||||
@@ -1182,7 +1184,8 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wrote_something)
|
||||
context->last_displayed_subs_ms = data->end_time;
|
||||
|
||||
@@ -1200,7 +1203,7 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
|
||||
try_to_add_start_credits(context, sub->start_time);
|
||||
wrote_something = write_cc_bitmap_as_srt(sub, context);
|
||||
break;
|
||||
case CCX_OF_SSA:
|
||||
case CCX_OF_SSA:
|
||||
if (!context->startcredits_displayed && context->start_credits_text != NULL)
|
||||
try_to_add_start_credits(context, sub->start_time);
|
||||
wrote_something = write_cc_bitmap_as_ssa(sub, context);
|
||||
@@ -1245,7 +1248,7 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
|
||||
net_send_header(sub->data, sub->nb_data);
|
||||
else
|
||||
{
|
||||
ret = __wrap_write(context->out->fh, sub->data, sub->nb_data);
|
||||
ret = write(context->out->fh, sub->data, sub->nb_data);
|
||||
if (ret < sub->nb_data) {
|
||||
mprint("WARNING: Loss of data\n");
|
||||
}
|
||||
@@ -1351,3 +1354,63 @@ void write_cc_buffer_to_gui(struct eia608_screen *data, struct encoder_ctx *cont
|
||||
}
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
unsigned int get_line_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
unsigned char *orig = buffer; // Keep for debugging
|
||||
unsigned char *line = data->characters[line_num];
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
int bytes = 0;
|
||||
switch (ctx->encoding)
|
||||
{
|
||||
case CCX_ENC_UTF_8:
|
||||
bytes = get_char_in_utf_8(buffer, line[i]);
|
||||
break;
|
||||
case CCX_ENC_LATIN_1:
|
||||
get_char_in_latin_1(buffer, line[i]);
|
||||
bytes = 1;
|
||||
break;
|
||||
case CCX_ENC_UNICODE:
|
||||
get_char_in_unicode(buffer, line[i]);
|
||||
bytes = 2;
|
||||
case CCX_ENC_ASCII:
|
||||
*buffer = line[i];
|
||||
bytes = 1;
|
||||
break;
|
||||
}
|
||||
buffer += bytes;
|
||||
}
|
||||
return (unsigned int)(buffer - orig); // Return length
|
||||
}
|
||||
unsigned int get_color_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
unsigned char *orig = buffer; // Keep for debugging
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if (data->colors[line_num][i] < 10)
|
||||
*buffer++ = data->colors[line_num][i] + '0';
|
||||
else
|
||||
*buffer++ = 'E';
|
||||
}
|
||||
*buffer = 0;
|
||||
return (unsigned)(buffer - orig); // Return length
|
||||
}
|
||||
unsigned int get_font_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
unsigned char *orig = buffer; // Keep for debugging
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if(data->fonts[line_num][i] == FONT_REGULAR)
|
||||
*buffer++ = 'R';
|
||||
else if(data->fonts[line_num][i] == FONT_UNDERLINED_ITALICS)
|
||||
*buffer++ = 'B';
|
||||
else if(data->fonts[line_num][i] == FONT_UNDERLINED)
|
||||
*buffer++ = 'U';
|
||||
else if(data->fonts[line_num][i] == FONT_ITALICS)
|
||||
*buffer++ = 'I';
|
||||
else
|
||||
*buffer++ = 'E';
|
||||
}
|
||||
return (unsigned)(buffer - orig); // Return length
|
||||
}
|
||||
|
||||
@@ -214,4 +214,10 @@ int reset_output_ctx(struct encoder_ctx *ctx, struct encoder_cfg *cfg);
|
||||
void find_limit_characters(unsigned char *line, int *first_non_blank, int *last_non_blank, int max_len);
|
||||
int get_str_basic(unsigned char *out_buffer, unsigned char *in_buffer, int trim_subs,
|
||||
enum ccx_encoding_type in_enc, enum ccx_encoding_type out_enc, int max_len);
|
||||
|
||||
|
||||
unsigned int get_line_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data);
|
||||
unsigned int get_color_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data);
|
||||
unsigned int get_font_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data);
|
||||
int pass_cc_buffer_to_python(struct eia608_screen *data, struct encoder_ctx *context);
|
||||
#endif
|
||||
|
||||
@@ -1,66 +1,8 @@
|
||||
#include "lib_ccx.h"
|
||||
#include "../ccextractor.h"
|
||||
#include "ccx_encoders_common.h"
|
||||
#include "ccx_encoders_helpers.h"
|
||||
|
||||
static unsigned int get_line_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
unsigned char *orig = buffer; // Keep for debugging
|
||||
unsigned char *line = data->characters[line_num];
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
int bytes = 0;
|
||||
switch (ctx->encoding)
|
||||
{
|
||||
case CCX_ENC_UTF_8:
|
||||
bytes = get_char_in_utf_8(buffer, line[i]);
|
||||
break;
|
||||
case CCX_ENC_LATIN_1:
|
||||
get_char_in_latin_1(buffer, line[i]);
|
||||
bytes = 1;
|
||||
break;
|
||||
case CCX_ENC_UNICODE:
|
||||
get_char_in_unicode(buffer, line[i]);
|
||||
bytes = 2;
|
||||
case CCX_ENC_ASCII:
|
||||
*buffer = line[i];
|
||||
bytes = 1;
|
||||
break;
|
||||
}
|
||||
buffer += bytes;
|
||||
}
|
||||
return (unsigned int)(buffer - orig); // Return length
|
||||
}
|
||||
static unsigned int get_color_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
unsigned char *orig = buffer; // Keep for debugging
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if (data->colors[line_num][i] < 10)
|
||||
*buffer++ = data->colors[line_num][i] + '0';
|
||||
else
|
||||
*buffer++ = 'E';
|
||||
}
|
||||
*buffer = 0;
|
||||
return (unsigned)(buffer - orig); // Return length
|
||||
}
|
||||
static unsigned int get_font_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
unsigned char *orig = buffer; // Keep for debugging
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if(data->fonts[line_num][i] == FONT_REGULAR)
|
||||
*buffer++ = 'R';
|
||||
else if(data->fonts[line_num][i] == FONT_UNDERLINED_ITALICS)
|
||||
*buffer++ = 'B';
|
||||
else if(data->fonts[line_num][i] == FONT_UNDERLINED)
|
||||
*buffer++ = 'U';
|
||||
else if(data->fonts[line_num][i] == FONT_ITALICS)
|
||||
*buffer++ = 'I';
|
||||
else
|
||||
*buffer++ = 'E';
|
||||
}
|
||||
return (unsigned)(buffer - orig); // Return length
|
||||
}
|
||||
int write_cc_buffer_as_g608(struct eia608_screen *data, struct encoder_ctx *context)
|
||||
{
|
||||
int used;
|
||||
@@ -82,28 +24,42 @@ int write_cc_buffer_as_g608(struct eia608_screen *data, struct encoder_ctx *cont
|
||||
context->srt_counter++;
|
||||
sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
if (!signal_python_api)
|
||||
write(context->out->fh, context->buffer, used);
|
||||
sprintf (timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u%s",
|
||||
h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
|
||||
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
|
||||
if (!signal_python_api)
|
||||
write (context->out->fh, context->buffer, used);
|
||||
if (signal_python_api)
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->buffer,0);
|
||||
for (int i=0;i<15;i++)
|
||||
{
|
||||
int length = get_line_encoded (context, context->subline, i, data);
|
||||
__wrap_write(context->out->fh, context->subline, length);
|
||||
if (!signal_python_api)
|
||||
write(context->out->fh, context->subline, length);
|
||||
if (signal_python_api)
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline,1);
|
||||
|
||||
length = get_color_encoded (context, context->subline, i, data);
|
||||
__wrap_write(context->out->fh, context->subline, length);
|
||||
if (!signal_python_api)
|
||||
write(context->out->fh, context->subline, length);
|
||||
if (signal_python_api)
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline,2);
|
||||
|
||||
length = get_font_encoded (context, context->subline, i, data);
|
||||
__wrap_write(context->out->fh, context->subline, length);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if (!signal_python_api)
|
||||
write(context->out->fh, context->subline, length);
|
||||
if (signal_python_api)
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline,3);
|
||||
if (!signal_python_api)
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
wrote_something=1;
|
||||
}
|
||||
|
||||
__wrap_write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if (!signal_python_api)
|
||||
write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
return wrote_something;
|
||||
}
|
||||
|
||||
47
src/lib_ccx/ccx_encoders_python.c
Normal file
47
src/lib_ccx/ccx_encoders_python.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "lib_ccx.h"
|
||||
#include "../ccextractor.h"
|
||||
#include "ccx_encoders_common.h"
|
||||
#include "ccx_encoders_helpers.h"
|
||||
|
||||
int pass_cc_buffer_to_python(struct eia608_screen *data, struct encoder_ctx *context)
|
||||
{
|
||||
int used;
|
||||
unsigned h1,m1,s1,ms1;
|
||||
unsigned h2,m2,s2,ms2;
|
||||
LLONG ms_start, ms_end;
|
||||
int wrote_something = 0;
|
||||
ms_start = data->start_time;
|
||||
|
||||
ms_start+=context->subs_delay;
|
||||
if (ms_start<0) // Drop screens that because of subs_delay start too early
|
||||
return 0;
|
||||
|
||||
ms_end = data->end_time;
|
||||
|
||||
millis_to_time (ms_start,&h1,&m1,&s1,&ms1);
|
||||
millis_to_time (ms_end-1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line.
|
||||
char timeline[128];
|
||||
context->srt_counter++;
|
||||
sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
sprintf (timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u%s",
|
||||
h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
|
||||
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->buffer,0,context->srt_counter);
|
||||
for (int i=0;i<15;i++)
|
||||
{
|
||||
int length = get_line_encoded (context, context->subline, i, data);
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline,1,context->srt_counter);
|
||||
|
||||
length = get_color_encoded (context, context->subline, i, data);
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline,2,context->srt_counter);
|
||||
|
||||
length = get_font_encoded (context, context->subline, i, data);
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline,3,context->srt_counter);
|
||||
wrote_something=1;
|
||||
}
|
||||
python_extract_g608_grid(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline,4,context->srt_counter);
|
||||
return wrote_something;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ int write_stringz_as_sami(char *string, struct encoder_ctx *context, LLONG ms_st
|
||||
}
|
||||
|
||||
used = encode_line(context, context->buffer, (unsigned char *) str);
|
||||
ret = __wrap_write (context->out->fh, context->buffer, used);
|
||||
ret = write (context->out->fh, context->buffer, used);
|
||||
if(ret != used)
|
||||
{
|
||||
return ret;
|
||||
@@ -74,15 +74,15 @@ int write_stringz_as_sami(char *string, struct encoder_ctx *context, LLONG ms_st
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n",context->subline);
|
||||
}
|
||||
ret = __wrap_write(context->out->fh, el, u);
|
||||
ret = write(context->out->fh, el, u);
|
||||
if(ret != u)
|
||||
goto end;
|
||||
|
||||
ret = __wrap_write(context->out->fh, context->encoded_br, context->encoded_br_length);
|
||||
ret = write(context->out->fh, context->encoded_br, context->encoded_br_length);
|
||||
if(ret != context->encoded_br_length)
|
||||
goto end;
|
||||
|
||||
ret = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if(ret != context->encoded_crlf_length)
|
||||
goto end;
|
||||
|
||||
@@ -95,7 +95,7 @@ int write_stringz_as_sami(char *string, struct encoder_ctx *context, LLONG ms_st
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line (context, context->buffer,(unsigned char *) str);
|
||||
ret = __wrap_write(context->out->fh, context->buffer, used);
|
||||
ret = write(context->out->fh, context->buffer, used);
|
||||
if(ret != used)
|
||||
goto end;
|
||||
sprintf ((char *) str,
|
||||
@@ -105,7 +105,7 @@ int write_stringz_as_sami(char *string, struct encoder_ctx *context, LLONG ms_st
|
||||
{
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
ret = __wrap_write(context->out->fh, context->buffer, used);
|
||||
ret = write(context->out->fh, context->buffer, used);
|
||||
if(ret != used)
|
||||
goto end;
|
||||
|
||||
@@ -139,7 +139,7 @@ int write_cc_bitmap_as_sami(struct cc_subtitle *sub, struct encoder_ctx *context
|
||||
sprintf(buf,
|
||||
"<SYNC start=%llu><P class=\"UNKNOWNCC\">\r\n"
|
||||
, (unsigned long long)ms_start);
|
||||
__wrap_write(context->out->fh, buf, strlen(buf));
|
||||
write(context->out->fh, buf, strlen(buf));
|
||||
for (int i = sub->nb_data - 1; i >= 0; i--)
|
||||
{
|
||||
if (rect[i].ocr_text && *(rect[i].ocr_text))
|
||||
@@ -149,22 +149,22 @@ int write_cc_bitmap_as_sami(struct cc_subtitle *sub, struct encoder_ctx *context
|
||||
token = strtok(rect[i].ocr_text, "\r\n");
|
||||
sprintf(buf, "%s", token);
|
||||
token = strtok(NULL, "\r\n");
|
||||
__wrap_write(context->out->fh, buf, strlen(buf));
|
||||
write(context->out->fh, buf, strlen(buf));
|
||||
if (i != 0)
|
||||
__wrap_write(context->out->fh, context->encoded_br, context->encoded_br_length);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->encoded_br, context->encoded_br_length);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
sprintf(buf, "</P></SYNC>\r\n");
|
||||
__wrap_write(context->out->fh, buf, strlen(buf));
|
||||
write(context->out->fh, buf, strlen(buf));
|
||||
}
|
||||
else //we write an empty subtitle to clear the old one
|
||||
{
|
||||
sprintf(buf,
|
||||
"<SYNC start=%llu><P class=\"UNKNOWNCC\"> </P></SYNC>\r\n\r\n"
|
||||
, (unsigned long long)ms_start);
|
||||
__wrap_write(context->out->fh, buf, strlen(buf));
|
||||
write(context->out->fh, buf, strlen(buf));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -221,7 +221,8 @@ int write_cc_buffer_as_sami(struct eia608_screen *data, struct encoder_ctx *cont
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer,(unsigned char *) str);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
//python_extract_sami(startms,endms,context->buffer);
|
||||
for (int i=0;i<15;i++)
|
||||
{
|
||||
if (data->row_used[i])
|
||||
@@ -232,11 +233,12 @@ int write_cc_buffer_as_sami(struct eia608_screen *data, struct encoder_ctx *cont
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n",context->subline);
|
||||
}
|
||||
__wrap_write (context->out->fh, context->subline, length);
|
||||
write (context->out->fh, context->subline, length);
|
||||
//python_extract_sami(startms,endms,context->buffer);
|
||||
wrote_something = 1;
|
||||
if (i!=14)
|
||||
__wrap_write (context->out->fh, context->encoded_br, context->encoded_br_length);
|
||||
__wrap_write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write (context->out->fh, context->encoded_br, context->encoded_br_length);
|
||||
write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
}
|
||||
}
|
||||
sprintf ((char *) str,"</P></SYNC>\r\n");
|
||||
@@ -245,7 +247,7 @@ int write_cc_buffer_as_sami(struct eia608_screen *data, struct encoder_ctx *cont
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer,(unsigned char *) str);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
sprintf ((char *) str,
|
||||
"<SYNC start=%llu><P class=\"UNKNOWNCC\"> </P></SYNC>\r\n\r\n",
|
||||
(unsigned long long)endms);
|
||||
@@ -254,6 +256,6 @@ int write_cc_buffer_as_sami(struct eia608_screen *data, struct encoder_ctx *cont
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer,(unsigned char *) str);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
return wrote_something;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "utility.h"
|
||||
#include "ccx_encoders_helpers.h"
|
||||
|
||||
|
||||
void write_stringz_as_smptett(char *string, struct encoder_ctx *context, LLONG ms_start, LLONG ms_end)
|
||||
{
|
||||
int used;
|
||||
@@ -55,7 +54,7 @@ void write_stringz_as_smptett(char *string, struct encoder_ctx *context, LLONG m
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer, (unsigned char *) str);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
// Scan for \n in the string and replace it with a 0
|
||||
while (pos_r < len)
|
||||
{
|
||||
@@ -82,10 +81,10 @@ void write_stringz_as_smptett(char *string, struct encoder_ctx *context, LLONG m
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n", context->subline);
|
||||
}
|
||||
__wrap_write(context->out->fh, el, u);
|
||||
write(context->out->fh, el, u);
|
||||
//write (wb->fh, encoded_br, encoded_br_length);
|
||||
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
begin += strlen ((const char *) begin)+1;
|
||||
}
|
||||
|
||||
@@ -95,14 +94,14 @@ void write_stringz_as_smptett(char *string, struct encoder_ctx *context, LLONG m
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer, (unsigned char *) str);
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
sprintf ((char *) str, "<p begin=\"%02u:%02u:%02u.%03u\">\n\n", h2, m2, s2, ms2);
|
||||
if (context->encoding != CCX_ENC_UNICODE)
|
||||
{
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer, (unsigned char *) str);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
sprintf ((char *) str, "</p>\n");
|
||||
free(el);
|
||||
free(unescaped);
|
||||
@@ -141,12 +140,13 @@ int write_cc_bitmap_as_smptett(struct cc_subtitle *sub, struct encoder_ctx *cont
|
||||
millis_to_time(ms_start, &h1, &m1, &s1, &ms1);
|
||||
millis_to_time(ms_end - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line.
|
||||
sprintf((char *)context->buffer, "<p begin=\"%02u:%02u:%02u.%03u\" end=\"%02u:%02u:%02u.%03u\">\n", h1, m1, s1, ms1, h2, m2, s2, ms2);
|
||||
__wrap_write(context->out->fh, buf, strlen(buf));
|
||||
write(context->out->fh, buf, strlen(buf));
|
||||
len = strlen(rect[i].ocr_text);
|
||||
__wrap_write(context->out->fh, rect[i].ocr_text, len);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
//python_extract_time_based (h1,m1,s1,ms1,h2,m2,s2,ms2,rect[i].ocr_text);
|
||||
write(context->out->fh, rect[i].ocr_text, len);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
sprintf(buf, "</p>\n");
|
||||
__wrap_write(context->out->fh, buf, strlen(buf));
|
||||
write(context->out->fh, buf, strlen(buf));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -256,8 +256,8 @@ int write_cc_buffer_as_smptett(struct eia608_screen *data, struct encoder_ctx *c
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer,(unsigned char *) str);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
|
||||
write (context->out->fh, context->buffer, used);
|
||||
//python_extract_time_based(h1,m1,s1,ms1,h2,m2,s2,ms2,"");
|
||||
// Trimming subs because the position is defined by "tts:origin"
|
||||
int old_trim_subs = context->trim_subs;
|
||||
context->trim_subs=1;
|
||||
@@ -426,10 +426,11 @@ int write_cc_buffer_as_smptett(struct eia608_screen *data, struct encoder_ctx *c
|
||||
}
|
||||
|
||||
|
||||
__wrap_write(context->out->fh, final, strlen(final));
|
||||
write(context->out->fh, final, strlen(final));
|
||||
//python_extract_time_based(h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline);
|
||||
|
||||
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
context->trim_subs=old_trim_subs;
|
||||
|
||||
sprintf ((char *) str," <style tts:backgroundColor=\"#000000FF\" tts:fontSize=\"18px\"/></span>\n </p>\n");
|
||||
@@ -438,7 +439,7 @@ int write_cc_buffer_as_smptett(struct eia608_screen *data, struct encoder_ctx *c
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str);
|
||||
}
|
||||
used = encode_line(context, context->buffer,(unsigned char *) str);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
|
||||
if (context->encoding!=CCX_ENC_UNICODE)
|
||||
{
|
||||
|
||||
@@ -23,14 +23,14 @@ int write_stringz_as_srt(char *string, struct encoder_ctx *context, LLONG ms_sta
|
||||
context->srt_counter++;
|
||||
sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
sprintf (timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u%s",
|
||||
h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
dbg_print(CCX_DMT_DECODER_608, "\n- - - SRT caption - - -\n");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s",timeline);
|
||||
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
int len=strlen (string);
|
||||
unsigned char *unescaped= (unsigned char *) malloc (len+1);
|
||||
unsigned char *el = (unsigned char *) malloc (len*3+1); // Be generous
|
||||
@@ -64,14 +64,14 @@ int write_stringz_as_srt(char *string, struct encoder_ctx *context, LLONG ms_sta
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n",context->subline);
|
||||
}
|
||||
__wrap_write(context->out->fh, el, u);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, el, u);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
begin+= strlen ((const char *) begin)+1;
|
||||
}
|
||||
|
||||
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
|
||||
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
free(el);
|
||||
free(unescaped);
|
||||
|
||||
@@ -111,14 +111,14 @@ int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context)
|
||||
context->srt_counter++;
|
||||
sprintf(timeline, "%u\r\n", context->srt_counter);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
sprintf (timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u\r\n",
|
||||
h1,m1,s1,ms1, h2,m2,s2,ms2);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
len = strlen(str);
|
||||
__wrap_write (context->out->fh, str, len);
|
||||
__wrap_write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write (context->out->fh, str, len);
|
||||
write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
}
|
||||
freep(&str);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
context->srt_counter++;
|
||||
sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
|
||||
sprintf (timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u%s",
|
||||
h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf);
|
||||
@@ -205,7 +205,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
dbg_print(CCX_DMT_DECODER_608, "\n- - - SRT caption ( %d) - - -\n", context->srt_counter);
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s",timeline);
|
||||
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
for (int i=0;i<15;i++)
|
||||
{
|
||||
if (data->row_used[i])
|
||||
@@ -265,7 +265,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
do_dash=0;
|
||||
|
||||
if (do_dash)
|
||||
__wrap_write(context->out->fh, "- ", 2);
|
||||
write(context->out->fh, "- ", 2);
|
||||
prev_line_start=first;
|
||||
prev_line_end=last;
|
||||
prev_line_center1=center1;
|
||||
@@ -278,8 +278,9 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n",context->subline);
|
||||
}
|
||||
__wrap_write(context->out->fh, context->subline, length);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->subline, length);
|
||||
//python_extract_time_based (h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
wrote_something=1;
|
||||
// fprintf (wb->fh,context->encoded_crlf);
|
||||
}
|
||||
@@ -287,7 +288,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
|
||||
|
||||
// fprintf (wb->fh, context->encoded_crlf);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
//printf("$ = %s\n",context->encoded_crlf);
|
||||
return wrote_something;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ int write_stringz_as_ssa(char *string, struct encoder_ctx *context, LLONG ms_sta
|
||||
dbg_print(CCX_DMT_DECODER_608, "\n- - - ASS/SSA caption - - -\n");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s",timeline);
|
||||
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
//python_extract (context->srt_counter,h1,m1,s1,ms1,h2,m2,s2,ms2,context->buffer);
|
||||
int len=strlen (string);
|
||||
unsigned char *unescaped= (unsigned char *) malloc (len+1);
|
||||
unsigned char *el = (unsigned char *) malloc (len*3+1); // Be generous
|
||||
@@ -58,14 +59,16 @@ int write_stringz_as_ssa(char *string, struct encoder_ctx *context, LLONG ms_sta
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n",context->subline);
|
||||
}
|
||||
__wrap_write(context->out->fh, el, u);
|
||||
__wrap_write(context->out->fh, "\\N", 2);
|
||||
write(context->out->fh, el, u);
|
||||
//python_extract (context->srt_counter,h1,m1,s1,ms1,h2,m2,s2,ms2,el);
|
||||
write(context->out->fh, "\\N", 2);
|
||||
//python_extract (context->srt_counter,h1,m1,s1,ms1,h2,m2,s2,ms2,"\\N");
|
||||
begin+= strlen ((const char *) begin)+1;
|
||||
}
|
||||
|
||||
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
|
||||
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
free(el);
|
||||
free(unescaped);
|
||||
|
||||
@@ -117,9 +120,10 @@ int write_cc_bitmap_as_ssa(struct cc_subtitle *sub, struct encoder_ctx *context)
|
||||
sprintf (timeline, "Dialogue: 0,%02u:%02u:%02u.%01u,%02u:%02u:%02u.%02u,Default,,0000,0000,0000,,",
|
||||
h1,m1,s1,ms1/10, h2,m2,s2,ms2/10);
|
||||
used = encode_line(context, context->buffer,(unsigned char *) timeline);
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
__wrap_write (context->out->fh, str, len);
|
||||
__wrap_write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write (context->out->fh, context->buffer, used);
|
||||
//python_extract_time_based (h1,m1,s1,ms1,h2,m2,s2,ms2,str);
|
||||
write (context->out->fh, str, len);
|
||||
write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
}
|
||||
freep(&str);
|
||||
}
|
||||
@@ -200,8 +204,7 @@ int write_cc_buffer_as_ssa(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
dbg_print(CCX_DMT_DECODER_608, "\n- - - ASS/SSA caption - - -\n");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s",timeline);
|
||||
|
||||
__wrap_write (context->out->fh, context->buffer, used);
|
||||
|
||||
write (context->out->fh, context->buffer, used);
|
||||
int line_count = 0;
|
||||
for (int i=0;i<15;i++)
|
||||
{
|
||||
@@ -262,7 +265,7 @@ int write_cc_buffer_as_ssa(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
do_dash=0;
|
||||
|
||||
if (do_dash)
|
||||
__wrap_write(context->out->fh, "- ", 2);
|
||||
write(context->out->fh, "- ", 2);
|
||||
prev_line_start=first;
|
||||
prev_line_end=last;
|
||||
prev_line_center1=center1;
|
||||
@@ -276,8 +279,12 @@ int write_cc_buffer_as_ssa(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n",context->subline);
|
||||
}
|
||||
if (line_count)
|
||||
__wrap_write(context->out->fh, "\\N", 2);
|
||||
__wrap_write(context->out->fh, context->subline, length);
|
||||
{
|
||||
write(context->out->fh, "\\N", 2);
|
||||
//python_extract_time_based (h1,m1,s1,ms1,h2,m2,s2,ms2,"\\N");
|
||||
}
|
||||
write(context->out->fh, context->subline, length);
|
||||
//python_extract_time_based (h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline);
|
||||
line_count++;
|
||||
wrote_something=1;
|
||||
}
|
||||
@@ -285,6 +292,6 @@ int write_cc_buffer_as_ssa(struct eia608_screen *data, struct encoder_ctx *conte
|
||||
|
||||
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
|
||||
|
||||
__wrap_write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
return wrote_something;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ int write_cc_bitmap_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *c
|
||||
}
|
||||
}
|
||||
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -211,13 +211,13 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx
|
||||
else
|
||||
fdprintf(context->out->fh, "%s|", sub->mode);
|
||||
}
|
||||
ret = __wrap_write(context->out->fh, context->subline, length);
|
||||
ret = write(context->out->fh, context->subline, length);
|
||||
if (ret < length)
|
||||
{
|
||||
mprint("Warning:Loss of data\n");
|
||||
}
|
||||
|
||||
ret = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if (ret < context->encoded_crlf_length)
|
||||
{
|
||||
mprint("Warning:Loss of data\n");
|
||||
@@ -333,13 +333,14 @@ void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx
|
||||
fdprintf(context->out->fh, "%s|", mode);
|
||||
}
|
||||
|
||||
ret = __wrap_write(context->out->fh, context->subline, length);
|
||||
ret = write(context->out->fh, context->subline, length);
|
||||
python_extract_transcript(context->subline);
|
||||
if (ret < length)
|
||||
{
|
||||
mprint("Warning:Loss of data\n");
|
||||
}
|
||||
|
||||
ret = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if (ret < context->encoded_crlf_length)
|
||||
{
|
||||
mprint("Warning:Loss of data\n");
|
||||
|
||||
@@ -137,7 +137,7 @@ int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_
|
||||
dbg_print(CCX_DMT_DECODER_608, "\n- - - WEBVTT caption - - -\n");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s", timeline);
|
||||
|
||||
written = __wrap_write(context->out->fh, context->buffer, used);
|
||||
written = write(context->out->fh, context->buffer, used);
|
||||
if (written != used)
|
||||
return -1;
|
||||
int len = strlen(string);
|
||||
@@ -173,14 +173,14 @@ int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_
|
||||
dbg_print(CCX_DMT_DECODER_608, "\r");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s\n", context->subline);
|
||||
}
|
||||
written = __wrap_write(context->out->fh, el, u);
|
||||
written = write(context->out->fh, el, u);
|
||||
if (written != u)
|
||||
{
|
||||
free(el);
|
||||
free(unescaped);
|
||||
return -1;
|
||||
}
|
||||
written = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
written = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if (written != context->encoded_crlf_length)
|
||||
{
|
||||
free(el);
|
||||
@@ -191,7 +191,7 @@ int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_
|
||||
|
||||
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
|
||||
|
||||
written = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
written = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
free(el);
|
||||
free(unescaped);
|
||||
if (written != context->encoded_crlf_length)
|
||||
@@ -224,21 +224,21 @@ int write_webvtt_header(struct encoder_ctx *context)
|
||||
|
||||
char* outline_css_file = (char*)malloc((strlen(css_file_name) + strlen(webvtt_outline_css)) * sizeof(char));
|
||||
sprintf(outline_css_file, webvtt_outline_css, css_file_name);
|
||||
__wrap_write (context->out->fh, outline_css_file, strlen(outline_css_file));
|
||||
write (context->out->fh, outline_css_file, strlen(outline_css_file));
|
||||
} else {
|
||||
__wrap_write(context->out->fh, webvtt_inline_css, strlen(webvtt_inline_css));
|
||||
write(context->out->fh, webvtt_inline_css, strlen(webvtt_inline_css));
|
||||
if(ccx_options.enc_cfg.line_terminator_lf == 1) // If -lf parameter is set.
|
||||
{
|
||||
__wrap_write(context->out->fh, "\n", 1);
|
||||
write(context->out->fh, "\n", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
__wrap_write(context->out->fh,"\r\n",2);
|
||||
write(context->out->fh,"\r\n",2);
|
||||
}
|
||||
}
|
||||
|
||||
__wrap_write(context->out->fh, "##\n", 3);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
write(context->out->fh, "##\n", 3);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
|
||||
if (context->timing->sync_pts2fts_set)
|
||||
{
|
||||
@@ -250,7 +250,7 @@ int write_webvtt_header(struct encoder_ctx *context)
|
||||
context->timing->sync_pts2fts_pts,
|
||||
h1, m1, s1, ms1);
|
||||
used = encode_line(context, context->buffer, (unsigned char *)header_string);
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
|
||||
}
|
||||
|
||||
@@ -294,10 +294,11 @@ int write_cc_bitmap_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *conte
|
||||
sprintf(timeline, "%02u:%02u:%02u.%03u --> %02u:%02u:%02u.%03u%s",
|
||||
h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf);
|
||||
used = encode_line(context, context->buffer, (unsigned char *)timeline);
|
||||
__wrap_write(context->out->fh, context->buffer, used);
|
||||
write(context->out->fh, context->buffer, used);
|
||||
len = strlen(str);
|
||||
__wrap_write(context->out->fh, str, len);
|
||||
__wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
//python_extract_time_based (h1,m1,s1,ms1,h2,m2,s2,ms2,str);
|
||||
write(context->out->fh, str, len);
|
||||
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
}
|
||||
freep(&str);
|
||||
}
|
||||
@@ -340,36 +341,6 @@ int write_cc_subtitle_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *con
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: move this repeating function from ccx_encoders_g608.c to the files ccx_encoders_helpers.(c|h)
|
||||
int get_line_encoded(struct encoder_ctx *ctx, unsigned char *buffer, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
unsigned char *orig = buffer;
|
||||
unsigned char *line = data->characters[line_num];
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
int bytes = 0;
|
||||
switch (ctx->encoding)
|
||||
{
|
||||
case CCX_ENC_UTF_8:
|
||||
bytes = get_char_in_utf_8(buffer, line[i]);
|
||||
break;
|
||||
case CCX_ENC_LATIN_1:
|
||||
get_char_in_latin_1(buffer, line[i]);
|
||||
bytes = 1;
|
||||
break;
|
||||
case CCX_ENC_UNICODE:
|
||||
get_char_in_unicode(buffer, line[i]);
|
||||
bytes = 2;
|
||||
case CCX_ENC_ASCII:
|
||||
*buffer = line[i];
|
||||
bytes = 1;
|
||||
break;
|
||||
}
|
||||
buffer += bytes;
|
||||
}
|
||||
return (unsigned int)(buffer - orig); // Return length
|
||||
}
|
||||
|
||||
void get_color_events(int *color_events, int line_num, struct eia608_screen *data)
|
||||
{
|
||||
int first, last;
|
||||
@@ -471,12 +442,12 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
||||
|
||||
dbg_print(CCX_DMT_DECODER_608, "\n- - - WEBVTT caption - - -\n");
|
||||
dbg_print(CCX_DMT_DECODER_608, "%s", timeline);
|
||||
|
||||
written = __wrap_write(context->out->fh, context->buffer, used);
|
||||
written = write(context->out->fh, context->buffer, used);
|
||||
if (written != used)
|
||||
return -1;
|
||||
|
||||
int length = get_line_encoded(context, context->subline, i, data);
|
||||
//python_extract_time_based (h1,m1,s1,ms1,h2,m2,s2,ms2,context->subline);
|
||||
|
||||
if (context->encoding != CCX_ENC_UNICODE)
|
||||
{
|
||||
@@ -507,23 +478,23 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
||||
if (open_font != FONT_REGULAR)
|
||||
{
|
||||
if (open_font & FONT_ITALICS)
|
||||
__wrap_write(context->out->fh, strdup("<i>"), 3);
|
||||
write(context->out->fh, strdup("<i>"), 3);
|
||||
if (open_font & FONT_UNDERLINED)
|
||||
__wrap_write(context->out->fh, strdup("<u>"), 3);
|
||||
write(context->out->fh, strdup("<u>"), 3);
|
||||
}
|
||||
|
||||
// opening events for colors
|
||||
int open_color = color_events[j] & 0xFF; // Last 16 bytes
|
||||
if (open_color != COL_WHITE)
|
||||
{
|
||||
__wrap_write(context->out->fh, strdup("<c."), 3);
|
||||
__wrap_write(context->out->fh, color_text[open_color][0], strlen(color_text[open_color][0]));
|
||||
__wrap_write(context->out->fh, ">", 1);
|
||||
write(context->out->fh, strdup("<c."), 3);
|
||||
write(context->out->fh, color_text[open_color][0], strlen(color_text[open_color][0]));
|
||||
write(context->out->fh, ">", 1);
|
||||
}
|
||||
}
|
||||
|
||||
// write current text symbol
|
||||
__wrap_write(context->out->fh, &(context->subline[j]), 1);
|
||||
write(context->out->fh, &(context->subline[j]), 1);
|
||||
|
||||
if (ccx_options.use_webvtt_styling)
|
||||
{
|
||||
@@ -531,7 +502,7 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
||||
int close_color = color_events[j] >> 16; // First 16 bytes
|
||||
if (close_color != COL_WHITE)
|
||||
{
|
||||
__wrap_write(context->out->fh, strdup("</c>"), 4);
|
||||
write(context->out->fh, strdup("</c>"), 4);
|
||||
}
|
||||
|
||||
// closing events for fonts
|
||||
@@ -539,9 +510,9 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
||||
if (close_font != FONT_REGULAR)
|
||||
{
|
||||
if (close_font & FONT_ITALICS)
|
||||
__wrap_write(context->out->fh, strdup("</i>"), 4);
|
||||
write(context->out->fh, strdup("</i>"), 4);
|
||||
if (close_font & FONT_UNDERLINED)
|
||||
__wrap_write(context->out->fh, strdup("</u>"), 4);
|
||||
write(context->out->fh, strdup("</u>"), 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -552,12 +523,12 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
||||
free(font_events);
|
||||
}
|
||||
|
||||
written = __wrap_write(context->out->fh,
|
||||
written = write(context->out->fh,
|
||||
context->encoded_crlf, context->encoded_crlf_length);
|
||||
if (written != context->encoded_crlf_length)
|
||||
return -1;
|
||||
|
||||
written = __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
written = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||
if (written != context->encoded_crlf_length)
|
||||
return -1;
|
||||
|
||||
|
||||
@@ -862,7 +862,7 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra
|
||||
free(filename);
|
||||
|
||||
if (track->header != NULL)
|
||||
__wrap_write(desc, track->header, strlen(track->header));
|
||||
write(desc, track->header, strlen(track->header));
|
||||
|
||||
for (int i = 0; i < track->sentence_count; i++)
|
||||
{
|
||||
@@ -871,26 +871,26 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra
|
||||
|
||||
if(track->codec_id == MATROSKA_TRACK_SUBTITLE_CODEC_ID_WEBVTT)
|
||||
{
|
||||
__wrap_write(desc, "\n\n", 2);
|
||||
write(desc, "\n\n", 2);
|
||||
|
||||
struct block_addition* blockaddition = sentence->blockaddition;
|
||||
|
||||
// writing comment
|
||||
if (blockaddition!=NULL) {
|
||||
if (blockaddition->comment != NULL) {
|
||||
__wrap_write(desc, sentence->blockaddition->comment, sentence->blockaddition->comment_size);
|
||||
__wrap_write(desc, "\n", 1);
|
||||
write(desc, sentence->blockaddition->comment, sentence->blockaddition->comment_size);
|
||||
write(desc, "\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
// writing cue identifier
|
||||
if (blockaddition != NULL) {
|
||||
if (blockaddition->cue_identifier != NULL) {
|
||||
__wrap_write(desc, blockaddition->cue_identifier, blockaddition->cue_identifier_size);
|
||||
__wrap_write(desc, "\n", 1);
|
||||
write(desc, blockaddition->cue_identifier, blockaddition->cue_identifier_size);
|
||||
write(desc, "\n", 1);
|
||||
}
|
||||
else if (blockaddition->comment != NULL) {
|
||||
__wrap_write(desc, "\n", 1);
|
||||
write(desc, "\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,23 +903,23 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra
|
||||
char *timestamp_end = malloc(sizeof(char) * 80);
|
||||
timestamp_to_vtttime(time_end, timestamp_end);
|
||||
|
||||
__wrap_write(desc, timestamp_start, strlen(timestamp_start));
|
||||
__wrap_write(desc, " --> ", 5);
|
||||
__wrap_write(desc, timestamp_end, strlen(timestamp_start));
|
||||
write(desc, timestamp_start, strlen(timestamp_start));
|
||||
write(desc, " --> ", 5);
|
||||
write(desc, timestamp_end, strlen(timestamp_start));
|
||||
|
||||
// writing cue settings list
|
||||
if (blockaddition != NULL) {
|
||||
if (blockaddition->cue_settings_list != NULL) {
|
||||
__wrap_write(desc, " ", 1);
|
||||
__wrap_write(desc, blockaddition->cue_settings_list, blockaddition->cue_settings_list_size);
|
||||
write(desc, " ", 1);
|
||||
write(desc, blockaddition->cue_settings_list, blockaddition->cue_settings_list_size);
|
||||
}
|
||||
}
|
||||
__wrap_write(desc, "\n", 1);
|
||||
write(desc, "\n", 1);
|
||||
|
||||
int size = 0;
|
||||
while (*(sentence->text + size) == '\n' || *(sentence->text + size) == '\r')
|
||||
size++;
|
||||
__wrap_write(desc, sentence->text + size, sentence->text_size - size);
|
||||
write(desc, sentence->text + size, sentence->text_size - size);
|
||||
|
||||
free(timestamp_start);
|
||||
free(timestamp_end);
|
||||
@@ -936,17 +936,17 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra
|
||||
char *timestamp_end = malloc(sizeof(char) * 80);
|
||||
timestamp_to_srttime(time_end, timestamp_end);
|
||||
|
||||
__wrap_write(desc, number, strlen(number));
|
||||
__wrap_write(desc, "\n", 1);
|
||||
__wrap_write(desc, timestamp_start, strlen(timestamp_start));
|
||||
__wrap_write(desc, " --> ", 5);
|
||||
__wrap_write(desc, timestamp_end, strlen(timestamp_start));
|
||||
__wrap_write(desc, "\n", 1);
|
||||
write(desc, number, strlen(number));
|
||||
write(desc, "\n", 1);
|
||||
write(desc, timestamp_start, strlen(timestamp_start));
|
||||
write(desc, " --> ", 5);
|
||||
write(desc, timestamp_end, strlen(timestamp_start));
|
||||
write(desc, "\n", 1);
|
||||
int size=0;
|
||||
while (*(sentence->text+size)=='\n' || *(sentence->text+size)=='\r' )
|
||||
size++;
|
||||
__wrap_write(desc, sentence->text+size, sentence->text_size-size);
|
||||
__wrap_write(desc, "\n\n", 2);
|
||||
write(desc, sentence->text+size, sentence->text_size-size);
|
||||
write(desc, "\n\n", 2);
|
||||
|
||||
free(timestamp_start);
|
||||
free(timestamp_end);
|
||||
@@ -959,16 +959,16 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra
|
||||
time_end = MIN(time_end, track->sentences[i + 1]->time_start - 1);
|
||||
char *timestamp_end = generate_timestamp_ass_ssa(time_end);
|
||||
|
||||
__wrap_write(desc, "Dialogue: Marked=0,", strlen("Dialogue: Marked=0,"));
|
||||
__wrap_write(desc, timestamp_start, strlen(timestamp_start));
|
||||
__wrap_write(desc, ",", 1);
|
||||
__wrap_write(desc, timestamp_end, strlen(timestamp_start));
|
||||
__wrap_write(desc, ",", 1);
|
||||
write(desc, "Dialogue: Marked=0,", strlen("Dialogue: Marked=0,"));
|
||||
write(desc, timestamp_start, strlen(timestamp_start));
|
||||
write(desc, ",", 1);
|
||||
write(desc, timestamp_end, strlen(timestamp_start));
|
||||
write(desc, ",", 1);
|
||||
char* text = ass_ssa_sentence_erase_read_order(sentence->text);
|
||||
while((text[0]=='\\') && (text[1]=='n' || text[1]=='N'))
|
||||
text+=2;
|
||||
__wrap_write(desc, text, strlen(text));
|
||||
__wrap_write(desc, "\n", 1);
|
||||
write(desc, text, strlen(text));
|
||||
write(desc, "\n", 1);
|
||||
|
||||
free(timestamp_start);
|
||||
free(timestamp_end);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "lib_ccx.h"
|
||||
#include "../ccextractor.h"
|
||||
#include "ccx_common_option.h"
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
@@ -8,12 +9,14 @@
|
||||
|
||||
void dinit_write(struct ccx_s_write *wb)
|
||||
{
|
||||
if (wb->fh > 0)
|
||||
close(wb->fh);
|
||||
freep(&wb->filename);
|
||||
if (wb->with_semaphore && wb->semaphore_filename)
|
||||
unlink(wb->semaphore_filename);
|
||||
freep(&wb->semaphore_filename);
|
||||
if(!signal_python_api){
|
||||
if (wb->fh > 0)
|
||||
close(wb->fh);
|
||||
freep(&wb->filename);
|
||||
if (wb->with_semaphore && wb->semaphore_filename)
|
||||
unlink(wb->semaphore_filename);
|
||||
freep(&wb->semaphore_filename);
|
||||
}
|
||||
}
|
||||
|
||||
int temporarily_close_output(struct ccx_s_write *wb)
|
||||
@@ -47,13 +50,24 @@ int temporarily_open_output(struct ccx_s_write *wb)
|
||||
|
||||
int init_write (struct ccx_s_write *wb, char *filename, int with_semaphore)
|
||||
{
|
||||
if (signal_python_api){
|
||||
char* output;
|
||||
//writing to memory which would be then tailed by python.
|
||||
asprintf(&output,"filename:%s\n",filename);
|
||||
#if defined(PYTHONAPI)
|
||||
run(array.reporter, output);
|
||||
#endif
|
||||
return EXIT_OK;
|
||||
}
|
||||
memset(wb, 0, sizeof(struct ccx_s_write));
|
||||
wb->fh=-1;
|
||||
wb->temporarily_closed = 0;
|
||||
wb->filename = filename;
|
||||
|
||||
wb->with_semaphore = with_semaphore;
|
||||
wb->append_mode = ccx_options.enc_cfg.append_mode;
|
||||
mprint ("Creating %s\n", filename);
|
||||
if (!signal_python_api)
|
||||
mprint ("Creating %s\n", filename);
|
||||
if(!(wb->append_mode))
|
||||
wb->fh = open (filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE);
|
||||
else
|
||||
|
||||
@@ -1137,6 +1137,13 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[])
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//adding the support for -pythonapi param to indicate that python wrappers have been used
|
||||
if (strcmp(argv[i], "-pythonapi")==0)
|
||||
{
|
||||
opt->signal_python_api =1;
|
||||
opt->messages_target=0;
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_HARDSUBX
|
||||
// Parse -hardsubx and related parameters
|
||||
|
||||
@@ -533,6 +533,8 @@ char *get_file_extension(enum ccx_output_format write_format)
|
||||
return strdup(".xml");
|
||||
case CCX_OF_G608:
|
||||
return strdup(".g608");
|
||||
//case CCX_OF_PYTHON_API:
|
||||
// return strdup("");
|
||||
case CCX_OF_NULL:
|
||||
return NULL;
|
||||
case CCX_OF_CURL:
|
||||
@@ -579,7 +581,6 @@ char *create_outfilename(const char *basename, const char *suffix, const char *e
|
||||
strcat(ptr, suffix);
|
||||
if(extension)
|
||||
strcat(ptr, extension);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Express 2013 for Windows Desktop
|
||||
VisualStudioVersion = 12.0.40629.0
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ccextractor", "ccextractor.vcxproj", "{0F0063C4-BCBC-4379-A6D5-84A5669C940A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(Performance) = preSolution
|
||||
HasPerformanceSessions = true
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\api\extractors\extractor.h" />
|
||||
<ClInclude Include="..\api\wrappers\wrapper.h" />
|
||||
<ClInclude Include="..\src\gpacmp4\gpac\avparse.h" />
|
||||
<ClInclude Include="..\src\gpacmp4\gpac\base_coding.h" />
|
||||
<ClInclude Include="..\src\gpacmp4\gpac\bitstream.h" />
|
||||
@@ -126,6 +128,8 @@
|
||||
<ClInclude Include="..\src\win_spec_incld\stdint.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\api\extractors\extractor.c" />
|
||||
<ClCompile Include="..\api\wrappers\wrapper.c" />
|
||||
<ClCompile Include="..\src\ccextractor.c" />
|
||||
<ClCompile Include="..\src\gpacmp4\avc_ext.c" />
|
||||
<ClCompile Include="..\src\gpacmp4\avilib.c" />
|
||||
@@ -212,6 +216,7 @@
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_curl.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_g608.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_helpers.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_python.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_sami.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_smptett.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_splitbysentence.c" />
|
||||
|
||||
@@ -357,6 +357,12 @@
|
||||
<ClInclude Include="..\src\lib_ccx\lib_ccx.h">
|
||||
<Filter>Header Files\lib_ccx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\api\extractors\extractor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\api\wrappers\wrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\ccextractor.c">
|
||||
@@ -809,6 +815,15 @@
|
||||
<ClCompile Include="..\src\lib_ccx\matroska.c">
|
||||
<Filter>Source Files\lib_ccx</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\api\extractors\extractor.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\api\wrappers\wrapper.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_python.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\src\lib_ccx\ccx_sub_entry_message.proto">
|
||||
|
||||
Reference in New Issue
Block a user