st = av_mallocz(sizeof(AVStream));
memcpy(st, ic->streams[i], sizeof(AVStream));
st->codec = avcodec_alloc_context();
+ if (!st->codec) {
+ print_error(filename, AVERROR(ENOMEM));
+ av_exit(1);
+ }
memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext));
s->streams[i] = st;
int64_t pts)
{
static uint8_t *subtitle_out = NULL;
- int subtitle_out_max_size = 65536;
+ int subtitle_out_max_size = 1024 * 1024;
int subtitle_out_size, nb, i;
AVCodecContext *enc;
AVPacket pkt;
for(i = 0; i < nb; i++) {
sub->pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q);
+ // start_display_time is required to be 0
+ sub->pts += av_rescale_q(sub->start_display_time, (AVRational){1, 1000}, AV_TIME_BASE_Q);
+ sub->end_display_time -= sub->start_display_time;
+ sub->start_display_time = 0;
subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
subtitle_out_max_size, sub);
+ if (subtitle_out_size < 0) {
+ fprintf(stderr, "Subtitle encoding failed\n");
+ av_exit(1);
+ }
av_init_packet(&pkt);
pkt.stream_index = ost->index;
pkt.data = subtitle_out;
pkt.size = subtitle_out_size;
- pkt.pts = av_rescale_q(pts, ist->st->time_base, ost->st->time_base);
+ pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base);
if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) {
/* XXX: the pts correction is handled here. Maybe handling
it in the codec would be better */
AVSubtitle subtitle, *subtitle_to_free;
int got_subtitle;
AVPacket avpkt;
+ int bps = av_get_bits_per_sample_format(ist->st->codec->sample_fmt)>>3;
if(ist->next_pts == AV_NOPTS_VALUE)
ist->next_pts= ist->pts;
handle_eof:
ist->pts= ist->next_pts;
- if(avpkt.size && avpkt.size != pkt->size && verbose>0)
+ if(avpkt.size && avpkt.size != pkt->size &&
+ !(ist->st->codec->codec->capabilities & CODEC_CAP_SUBFRAMES) && verbose>0)
fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
/* decode the packet if needed */
continue;
}
data_buf = (uint8_t *)samples;
- ist->next_pts += ((int64_t)AV_TIME_BASE/2 * data_size) /
+ ist->next_pts += ((int64_t)AV_TIME_BASE/bps * data_size) /
(ist->st->codec->sample_rate * ist->st->codec->channels);
break;}
case CODEC_TYPE_VIDEO:
/* get default parameters from command line */
ic = avformat_alloc_context();
+ if (!ic) {
+ print_error(filename, AVERROR(ENOMEM));
+ av_exit(1);
+ }
memset(ap, 0, sizeof(*ap));
ap->prealloced_context = 1;
filename = "pipe:";
oc = avformat_alloc_context();
+ if (!oc) {
+ print_error(filename, AVERROR(ENOMEM));
+ av_exit(1);
+ }
if (!file_oformat) {
file_oformat = guess_format(NULL, filename, NULL);