History

avformat/movenc: add support for syncframes concatenation for E-AC-3.

E-AC-3 samples should contain 6 audio blocks, so concatenate syncframes in order to achieve this.

Benoit Fouet committed 12 years ago

Commit f87134c1 parent 4da71111 file · +37 −6Browse files

Unified · Split

libavformat/movenc.c+37−6
@@ -295,7 +295,9 @@ static int mov_write_ac3_tag(AVIOContext *pb, MOVTrack *track) · 294 unmodified lines
295295 }
296296
297297 struct eac3_info {
298+ AVPacket pkt;
298299 uint8_t ec3_done;
300+ uint8_t num_blocks;
299301
300302 /* Layout of the EC3SpecificBox */
301303 /* maximum bitrate */
@@ -412,11 +414,34 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) · 110 unmodified lines
412414 }
413415 }
414416
415−/* TODO: concatenate syncframes to have 6 blocks per entry */
416417 concatenate:
417− if (num_blocks != 6) {
418− avpriv_request_sample(track->enc, "%d block(s) in syncframe", num_blocks);
419− return AVERROR_PATCHWELCOME;
418+ if (!info->num_blocks && num_blocks == 6)
419+ return pkt->size;
420+ else if (info->num_blocks + num_blocks > 6)
421+ return AVERROR_INVALIDDATA;
422+
423+ if (!info->num_blocks) {
424+ int ret;
425+ if ((ret = av_copy_packet(&info->pkt, pkt)) < 0)
426+ return ret;
427+ info->num_blocks = num_blocks;
428+ return 0;
429+ } else {
430+ int ret;
431+ if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0)
432+ return ret;
433+ memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, pkt->size);
434+ info->num_blocks += num_blocks;
435+ info->pkt.duration += pkt->duration;
436+ if ((ret = av_copy_packet_side_data(&info->pkt, pkt)) < 0)
437+ return ret;
438+ if (info->num_blocks != 6)
439+ return 0;
440+ av_free_packet(pkt);
441+ if ((ret = av_copy_packet(pkt, &info->pkt)) < 0)
442+ return ret;
443+ av_free_packet(&info->pkt);
444+ info->num_blocks = 0;
420445 }
421446
422447 return pkt->size;
@@ -436,8 +461,8 @@ static int mov_write_eac3_tag(AVIOContext *pb, MOVTrack *track) · 13 unmodified lines
436461 size = 2 + 4 * (info->num_ind_sub + 1);
437462 buf = av_malloc(size);
438463 if (!buf) {
439− av_freep(&track->eac3_priv);
440− return AVERROR(ENOMEM);
464+ size = AVERROR(ENOMEM);
465+ goto end;
441466 }
442467
443468 init_put_bits(&pbc, buf, size);
@@ -467,6 +492,9 @@ static int mov_write_eac3_tag(AVIOContext *pb, MOVTrack *track) · 23 unmodified lines
467492 avio_write(pb, buf, size);
468493
469494 av_free(buf);
495+
496+end:
497+ av_free_packet(&info->pkt);
470498 av_freep(&track->eac3_priv);
471499
472500 return size;
@@ -3810,6 +3838,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 3337 unmodified lines
38103838 size = handle_eac3(mov, pkt, trk);
38113839 if (size < 0)
38123840 return size;
3841+ else if (!size)
3842+ goto end;
38133843 avio_write(pb, pkt->data, size);
38143844 } else {
38153845 avio_write(pb, pkt->data, size);
@@ -3889,6 +3919,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 73 unmodified lines
38893919 if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
38903920 ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,
38913921 reformatted_data, size);
3922+end:
38923923 av_free(reformatted_data);
38933924 return 0;
38943925 }

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