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
5504 memset(trk->vos_data + trk->vos_len, 0, AV_INPUT_BUFFER_PADDING_SIZE);5504 memset(trk->vos_data + trk->vos_len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
5505 }5505 }
5506 5506
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
5507 if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&5526 if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
5508 (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {5527 (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
5509 if (!s->streams[pkt->stream_index]->nb_frames) {5528 if (!s->streams[pkt->stream_index]->nb_frames) {
@@ -5582,22 +5601,6 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 72 unmodified lines
5582 }5601 }
5583 }5602 }
5584 5603
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
5601 if (trk->entry >= trk->cluster_capacity) {5604 if (trk->entry >= trk->cluster_capacity) {
5602 unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE;5605 unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE;
5603 if (av_reallocp_array(&trk->cluster, new_capacity,5606 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