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
295}295}
296 296
297struct eac3_info {297struct eac3_info {
298 AVPacket pkt;
298 uint8_t ec3_done;299 uint8_t ec3_done;
300 uint8_t num_blocks;
299 301
300 /* Layout of the EC3SpecificBox */302 /* Layout of the EC3SpecificBox */
301 /* maximum bitrate */303 /* maximum bitrate */
@@ -412,11 +414,34 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) · 110 unmodified lines
412 }414 }
413 }415 }
414 416
415/* TODO: concatenate syncframes to have 6 blocks per entry */
416concatenate:417concatenate:
417 if (num_blocks != 6) {418 if (!info->num_blocks && num_blocks == 6)
418 avpriv_request_sample(track->enc, "%d block(s) in syncframe", num_blocks);419 return pkt->size;
419 return AVERROR_PATCHWELCOME;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;
420 }445 }
421 446
422 return pkt->size;447 return pkt->size;
@@ -436,8 +461,8 @@ static int mov_write_eac3_tag(AVIOContext *pb, MOVTrack *track) · 13 unmodified lines
436 size = 2 + 4 * (info->num_ind_sub + 1);461 size = 2 + 4 * (info->num_ind_sub + 1);
437 buf = av_malloc(size);462 buf = av_malloc(size);
438 if (!buf) {463 if (!buf) {
439 av_freep(&track->eac3_priv);464 size = AVERROR(ENOMEM);
440 return AVERROR(ENOMEM);465 goto end;
441 }466 }
442 467
443 init_put_bits(&pbc, buf, size);468 init_put_bits(&pbc, buf, size);
@@ -467,6 +492,9 @@ static int mov_write_eac3_tag(AVIOContext *pb, MOVTrack *track) · 23 unmodified lines
467 avio_write(pb, buf, size);492 avio_write(pb, buf, size);
468 493
469 av_free(buf);494 av_free(buf);
495
496end:
497 av_free_packet(&info->pkt);
470 av_freep(&track->eac3_priv);498 av_freep(&track->eac3_priv);
471 499
472 return size;500 return size;
@@ -3810,6 +3838,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 3337 unmodified lines
3810 size = handle_eac3(mov, pkt, trk);3838 size = handle_eac3(mov, pkt, trk);
3811 if (size < 0)3839 if (size < 0)
3812 return size;3840 return size;
3841 else if (!size)
3842 goto end;
3813 avio_write(pb, pkt->data, size);3843 avio_write(pb, pkt->data, size);
3814 } else {3844 } else {
3815 avio_write(pb, pkt->data, size);3845 avio_write(pb, pkt->data, size);
@@ -3889,6 +3919,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 73 unmodified lines
3889 if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)3919 if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
3890 ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,3920 ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,
3891 reformatted_data, size);3921 reformatted_data, size);
3922end:
3892 av_free(reformatted_data);3923 av_free(reformatted_data);
3893 return 0;3924 return 0;
3894}3925}

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