Skip to content

Instantly share code, notes, and snippets.

@rcombs

rcombs/stdin Secret

Created March 13, 2018 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcombs/a3b1a9f879a7a40b230eb8676bda660f to your computer and use it in GitHub Desktop.
Save rcombs/a3b1a9f879a7a40b230eb8676bda660f to your computer and use it in GitHub Desktop.
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index be0028a29f..257697e05a 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -371,11 +371,11 @@ struct eac3_info {
};
#if CONFIG_AC3_PARSER
-static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
+static int parse_eac3(MOVMuxContext *mov, const AVPacket *pkt, MOVTrack *track, int *num_blocks)
{
AC3HeaderInfo *hdr = NULL;
struct eac3_info *info;
- int num_blocks, ret;
+ int ret = 1;
if (!track->eac3_priv && !(track->eac3_priv = av_mallocz(sizeof(*info))))
return AVERROR(ENOMEM);
@@ -392,7 +392,8 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
}
info->data_rate = FFMAX(info->data_rate, hdr->bit_rate / 1000);
- num_blocks = hdr->num_blocks;
+ if (num_blocks)
+ *num_blocks = hdr->num_blocks;
if (!info->ec3_done) {
/* AC-3 substream must be the first one */
@@ -418,7 +419,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
} else if (hdr->substreamid < info->num_ind_sub ||
hdr->substreamid == 0 && info->substream[0].bsid) {
info->ec3_done = 1;
- goto concatenate;
+ goto end;
}
}
@@ -468,44 +469,53 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
}
}
-concatenate:
+end:
+ av_free(hdr);
+
+ return ret;
+}
+
+static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
+{
+ int num_blocks;
+ struct eac3_info *info;
+ int ret = parse_eac3(mov, pkt, track, &num_blocks);
+ if (ret <= 0)
+ return ret;
+
+ info = track->eac3_priv;
+
if (!info->num_blocks && num_blocks == 6) {
- ret = pkt->size;
- goto end;
+ return pkt->size;
}
else if (info->num_blocks + num_blocks > 6) {
- ret = AVERROR_INVALIDDATA;
- goto end;
+ return AVERROR_INVALIDDATA;
}
if (!info->num_blocks) {
ret = av_packet_ref(&info->pkt, pkt);
if (!ret)
info->num_blocks = num_blocks;
- goto end;
+ return ret;
} else {
if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0)
- goto end;
+ return ret;
memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, pkt->size);
info->num_blocks += num_blocks;
info->pkt.duration += pkt->duration;
if ((ret = av_copy_packet_side_data(&info->pkt, pkt)) < 0)
- goto end;
+ return ret;
if (info->num_blocks != 6)
- goto end;
+ return ret;
av_packet_unref(pkt);
ret = av_packet_ref(pkt, &info->pkt);
if (ret < 0)
- goto end;
+ return ret;
av_packet_unref(&info->pkt);
info->num_blocks = 0;
}
- ret = pkt->size;
-
-end:
- av_free(hdr);
- return ret;
+ return pkt->size;
}
#endif
@@ -6581,12 +6591,28 @@ static int mov_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
{
int ret = 1;
AVStream *st = s->streams[pkt->stream_index];
+ MOVMuxContext *mov = s->priv_data;
+ MOVTrack *trk = &mov->tracks[pkt->stream_index];
if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
} else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL);
+ } else if ((st->codecpar->codec_id == AV_CODEC_ID_DNXHD ||
+ st->codecpar->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) {
+ /* copy frame to create needed atoms */
+ trk->vos_len = pkt->size;
+ trk->vos_data = av_malloc(pkt->size);
+ if (!trk->vos_data)
+ return AVERROR(ENOMEM);
+ memcpy(trk->vos_data, pkt->data, pkt->size);
+#if CONFIG_AC3_PARSER
+ } else if (st->codecpar->codec_id == AV_CODEC_ID_EAC3) {
+ ret = parse_eac3(mov, pkt, trk, NULL);
+ if (ret < 0)
+ ret = 0;
+#endif
}
return ret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment