corrected timing for tudor using ffmpeg

This commit is contained in:
Anshul Maheshwari 2014-08-13 17:48:00 +05:30 committed by wforums
parent 5789a0a224
commit 47bfe6bffc
5 changed files with 58 additions and 8 deletions

View File

@ -86,11 +86,13 @@ int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context)
char*str = NULL;
#endif
int used;
LLONG ms_start, ms_end;
#ifdef ENABLE_OCR
unsigned h1,m1,s1,ms1;
unsigned h2,m2,s2,ms2;
LLONG ms_start, ms_end;
char timeline[128];
int len = 0;
#endif
x_pos = -1;
y_pos = -1;

View File

@ -613,7 +613,9 @@ int main(int argc, char *argv[])
while (switch_to_next_file(0) && !processed_enough)
{
prepare_for_new_file();
#ifdef ENABLE_FFMPEG
close_input_file();
ffmpeg_ctx = init_ffmpeg(inputfile[0]);
if(ffmpeg_ctx)
{
@ -628,20 +630,23 @@ int main(int argc, char *argv[])
{
int ret = 0;
char *bptr = buffer;
memset(bptr,0,1024);
int len = ff_get_ccframe(ffmpeg_ctx, bptr, 1024);
if(len == AVERROR(EAGAIN))
{
continue;
}
else if(len == AVERROR_EOF)
break;
else if(len == 0)
continue;
else if(len < 0 )
{
mprint("Some Error \n");
mprint("Error extracting Frame\n");
break;
}
store_hdcc(bptr,len, i,i++,&dec_sub);
store_hdcc(bptr,len, i++,fts_now,&dec_sub);
if(dec_sub.got_output)
{
encode_sub(enc_ctx, &dec_sub);
@ -657,7 +662,6 @@ int main(int argc, char *argv[])
mprint ("\rFailed to initialized ffmpeg falling back to legacy\n");
}
#endif
prepare_for_new_file();
if (auto_stream == CCX_SM_AUTODETECT)
{

View File

@ -13,6 +13,7 @@
#include <libavutil/log.h>
#include <libavutil/error.h>
#include "ccextractor.h"
struct ffmpeg_ctx
{
AVFormatContext *ifmt;
@ -20,6 +21,37 @@ struct ffmpeg_ctx
AVFrame *frame;
int stream_index;
};
/**
* call back function to be registered for avlog
*/
static void log_cb(void* ptr, int level, const char* fmt, va_list vl)
{
if (level > av_log_get_level())
return;
const char*name = NULL;
FILE *flog;
if (ccx_options.messages_target==CCX_MESSAGES_STDOUT)
flog = stdout;
else
flog = stderr;
if (level == AV_LOG_PANIC)
fprintf(flog, "[panic][%s] ", name);
else if (level == AV_LOG_FATAL)
fprintf(flog, "[fatal][%s] ", name);
else if (level == AV_LOG_ERROR)
fprintf(flog, "[error][%s] ", name);
else if (level == AV_LOG_WARNING)
fprintf(flog, "[warning][%s] ", name);
else if (level == AV_LOG_INFO)
fprintf(flog, "[info][%s] ", name);
else if (level == AV_LOG_DEBUG)
fprintf(flog, "[debug][%s] ", name);
vfprintf(flog, fmt, vl);
}
/**
* @path this path could be relative or absolute path of static file
* this path could be path of device
@ -35,6 +67,13 @@ void *init_ffmpeg(char *path)
avcodec_register_all();
av_register_all();
if(ccx_options.debug_mask & CCX_DMT_VERBOSE)
av_log_set_level(AV_LOG_INFO);
else if (ccx_options.messages_target == 0)
av_log_set_level(AV_LOG_FATAL);
av_log_set_callback(log_cb);
ctx = av_malloc(sizeof(*ctx));
if(!ctx)
{
@ -119,12 +158,17 @@ int ff_get_ccframe(void *arg,char*data,int maxlen)
{
return AVERROR(EAGAIN);
}
current_pts = av_frame_get_best_effort_timestamp(ctx->frame);
if(!pts_set)
pts_set = 1;
set_fts();
for(int i = 0;i< ctx->frame->nb_side_data;i++)
{
if(ctx->frame->side_data[i]->type == AV_FRAME_DATA_A53_CC)
{
ctx->frame->pts = av_frame_get_best_effort_timestamp(ctx->frame);
if(ctx->frame->side_data[i]->size > maxlen)
av_log(NULL,AV_LOG_ERROR,"Please consider increaing length of data\n");
av_log(NULL,AV_LOG_ERROR,"Please consider increasing length of data\n");
else
{
memcpy(data,ctx->frame->side_data[i]->data,ctx->frame->side_data[i]->size);
@ -140,5 +184,4 @@ int ff_get_ccframe(void *arg,char*data,int maxlen)
return len;
}
#endif

View File

@ -2,6 +2,7 @@
#define _FFMPEG_INTIGRATION
#ifdef ENABLE_FFMPEG
#include "libavutil/common.h"
#include "libavutil/error.h"
#endif
/**

View File

@ -204,8 +204,8 @@ int do_cb (unsigned char *cc_block, struct cc_subtitle *sub)
return 1;
// Print raw data with FTS.
dbg_print(CCX_DMT_CBRAW, "%s %d %02X:%02X:%02X", print_mstime(fts_now + fts_global),in_xds_mode,
cc_block[0], cc_block[1], cc_block[2]);
dbg_print(CCX_DMT_CBRAW, "%s %d %02X:%c%c:%02X", print_mstime(fts_now + fts_global),in_xds_mode,
cc_block[0], cc_block[1]&0x7f,cc_block[2]&0x7f, cc_block[2]);
/* In theory the writercwtdata() function could return early and not
* go through the 608/708 cases below. We do that to get accurate