History

movenc: Fix conversion of the first frame for extradata-less H264/HEVC

Move the copying of the frame to vos_data further up in the function, so that when writing the actual frame data for the first frame, it's clear that the stream really is in annex b format, for the cases where we create extradata from the first frame. Alternatively - we could invert the checks for bitstream format. If extradata is missing, we can't pretend that the bitstream is in mp4 form, because we can't even know the NAL unit length prefix size in that case. Also avoid creating extradata for AVC intra. If the track tag is an AVC intra tag, don't copy the frame into vos_data - this matches other existing cases of how vos_data and TAG_IS_AVCI interact in other places.

Martin Storsjö committed 6 years ago

Commit 1aec1fb1 parent 1f7c8d31 file · +19 −16Browse files

Unified · Split

libavformat/movenc.c+19−16
@@ -5504,6 +5504,25 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 5503 unmodified lines
55045504 memset(trk->vos_data + trk->vos_len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
55055505 }
55065506
5507+ if ((par->codec_id == AV_CODEC_ID_DNXHD ||
5508+ par->codec_id == AV_CODEC_ID_H264 ||
5509+ par->codec_id == AV_CODEC_ID_HEVC ||
5510+ par->codec_id == AV_CODEC_ID_TRUEHD ||
5511+ par->codec_id == AV_CODEC_ID_AC3 ||
5512+ par->codec_id == AV_CODEC_ID_H264 ||
5513+ par->codec_id == AV_CODEC_ID_HEVC) && !trk->vos_len &&
5514+ !TAG_IS_AVCI(trk->tag)) {
5515+ /* copy frame to create needed atoms */
5516+ trk->vos_len = size;
5517+ trk->vos_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
5518+ if (!trk->vos_data) {
5519+ ret = AVERROR(ENOMEM);
5520+ goto err;
5521+ }
5522+ memcpy(trk->vos_data, pkt->data, size);
5523+ memset(trk->vos_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
5524+ }
5525+
55075526 if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
55085527 (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
55095528 if (!s->streams[pkt->stream_index]->nb_frames) {
@@ -5582,22 +5601,6 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 72 unmodified lines
55825601 }
55835602 }
55845603
5585− if ((par->codec_id == AV_CODEC_ID_DNXHD ||
5586− par->codec_id == AV_CODEC_ID_H264 ||
5587− par->codec_id == AV_CODEC_ID_HEVC ||
5588− par->codec_id == AV_CODEC_ID_TRUEHD ||
5589− par->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) {
5590− /* copy frame to create needed atoms */
5591− trk->vos_len = size;
5592− trk->vos_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
5593− if (!trk->vos_data) {
5594− ret = AVERROR(ENOMEM);
5595− goto err;
5596− }
5597− memcpy(trk->vos_data, pkt->data, size);
5598− memset(trk->vos_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
5599− }
5600−
56015604 if (trk->entry >= trk->cluster_capacity) {
56025605 unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE;
56035606 if (av_reallocp_array(&trk->cluster, new_capacity,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t