MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / decavsubInit

Function decavsubInit

libhb/decavsub.c:49–166  ·  view source on GitHub ↗

* decavsubInit *********************************************************************** * Init function for libav subtitle decoding that may be wrapped * by HB subtitle decoder **********************************************************************/

Source from the content-addressed store, hash-verified

47 * by HB subtitle decoder
48 **********************************************************************/
49hb_decavsub_context_t * decavsubInit( hb_work_object_t * w, hb_job_t * job )
50{
51 hb_decavsub_context_t * ctx = calloc( 1, sizeof( hb_decavsub_context_t ) );
52
53 if (ctx == NULL)
54 {
55 hb_error("decavsubInit: calloc ctx failed");
56 return NULL;
57 }
58 ctx->seen_forced_sub = 0;
59 ctx->last_pts = AV_NOPTS_VALUE;
60 ctx->job = job;
61 ctx->subtitle = w->subtitle;
62
63 const AVCodec * codec = avcodec_find_decoder(ctx->subtitle->codec_param);
64 if (codec == NULL)
65 {
66 hb_error("encavsubInit: avcodec_find_decoder failed");
67 goto fail;
68 }
69 AVCodecContext * context = avcodec_alloc_context3(codec);
70 if (context == NULL)
71 {
72 hb_error("decavsubInit: avcodec_alloc_context3 failed");
73 goto fail;
74 }
75
76 ctx->context = context;
77 context->codec = codec;
78 context->pkt_timebase.num = ctx->subtitle->timebase.num;
79 context->pkt_timebase.den = ctx->subtitle->timebase.den;
80
81 if (ctx->subtitle->extradata && ctx->subtitle->extradata->size)
82 {
83 context->extradata = av_malloc(ctx->subtitle->extradata->size);
84 if (context->extradata == NULL)
85 {
86 hb_error("decavsubInit: av_malloc extradata failed");
87 goto fail;
88 }
89 memcpy(context->extradata,
90 ctx->subtitle->extradata->bytes,
91 ctx->subtitle->extradata->size);
92 context->extradata_size = ctx->subtitle->extradata->size;
93 }
94
95 // Set decoder opts...
96 AVDictionary * av_opts = NULL;
97 if (ctx->subtitle->codec_param == AV_CODEC_ID_EIA_608)
98 {
99 av_dict_set( &av_opts, "data_field", "first", 0 );
100 av_dict_set( &av_opts, "real_time", "1", 0 );
101 }
102 else if (ctx->subtitle->codec_param == AV_CODEC_ID_MOV_TEXT)
103 {
104 char * width = hb_strdup_printf("%d", job->title->geometry.width);
105 char * height = hb_strdup_printf("%d", job->title->geometry.height);
106 av_dict_set( &av_opts, "width", width, 0 );

Callers 3

decsrtInitFunction · 0.85
decsubInitFunction · 0.85
decssaInitFunction · 0.85

Calls 6

hb_errorFunction · 0.85
hb_strdup_printfFunction · 0.85
hb_avcodec_openFunction · 0.85
hb_logFunction · 0.85
hb_set_extradataFunction · 0.85
hb_buffer_list_clearFunction · 0.85

Tested by

no test coverage detected