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

Function encavsubInit

libhb/encavsub.c:71–165  ·  view source on GitHub ↗

* encavsubInit *********************************************************************** * Init function for libav subtitle encoding that may be wrapped * by HB subtitle encoder **********************************************************************/

Source from the content-addressed store, hash-verified

69 * by HB subtitle encoder
70 **********************************************************************/
71hb_encavsub_context_t * encavsubInit(hb_work_object_t *w, hb_job_t *job)
72{
73 const AVCodec *codec;
74 AVCodecContext *context;
75 hb_encavsub_context_t *ctx = calloc(1, sizeof(hb_encavsub_context_t));
76
77 if (ctx == NULL)
78 {
79 hb_error("encavsubInit: calloc ctx failed");
80 return NULL;
81 }
82 ctx->job = job;
83 ctx->subtitle = w->subtitle;
84
85 codec = avcodec_find_encoder(w->codec_param);
86 if (codec == NULL)
87 {
88 hb_error("encavsubInit: avcodec_find_encoder failed");
89 goto fail;
90 }
91 context = avcodec_alloc_context3(codec);
92 if (context == NULL)
93 {
94 hb_error("encavsubInit: avcodec_alloc_context3 failed");
95 goto fail;
96 }
97 ctx->context = context;
98 context->codec = codec;
99
100 // TEXT subtitle encoders require SSA header
101 context->subtitle_header = av_malloc(ctx->subtitle->extradata->size + 1);
102 if (context->subtitle_header == NULL)
103 {
104 hb_error("encavsubInit: av_malloc subtitle_header failed");
105 goto fail;
106 }
107 memcpy(context->subtitle_header, ctx->subtitle->extradata->bytes,
108 ctx->subtitle->extradata->size);
109 context->subtitle_header[ctx->subtitle->extradata->size] = '\0';
110 context->subtitle_header_size = ctx->subtitle->extradata->size + 1;
111 context->time_base = AV_TIME_BASE_Q;
112
113 // Set encoder opts...
114 AVDictionary *av_opts = NULL;
115 if (w->codec_param == AV_CODEC_ID_MOV_TEXT)
116 {
117 char *height = hb_strdup_printf("%d", job->height);
118 av_dict_set( &av_opts, "height", height, 0 );
119 free(height);
120 }
121 if (hb_avcodec_open(ctx->context, codec, &av_opts, 0))
122 {
123 av_dict_free( &av_opts );
124 hb_error("encavsubInit: avcodec_open failed");
125 goto fail;
126 }
127 av_dict_free( &av_opts );
128

Callers 1

InitFunction · 0.85

Calls 7

hb_errorFunction · 0.85
hb_strdup_printfFunction · 0.85
hb_avcodec_openFunction · 0.85
hb_data_closeFunction · 0.85
hb_set_extradataFunction · 0.85
realloc_enc_bufferFunction · 0.85
hb_buffer_list_clearFunction · 0.85

Tested by

no test coverage detected