diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-10-01 21:56:27 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-10-02 01:09:12 +0200 |
commit | 4eb0f5f635462562275200ecb6b4e1b718fcae37 (patch) | |
tree | 73eb2afa736f9a5e1b3a74808d6b2eb48084d8d0 | |
parent | c4dba58f47a9b1b37458ddb2dd8500b7f3ea4d06 (diff) | |
download | ffmpeg-4eb0f5f635462562275200ecb6b4e1b718fcae37.tar.gz |
nutenc: use 1/sample rate as timebase for audio instead of framesize/sample rate
This way audio frames can be exactly stored even when they are not
aligned with timestamp 0
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/nutenc.c | 17 | ||||
-rw-r--r-- | tests/ref/lavf/nut | 6 | ||||
-rw-r--r-- | tests/ref/seek/lavf_nut | 70 |
3 files changed, 53 insertions, 40 deletions
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index f719c8ea59..955a6fb5fa 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -156,6 +156,13 @@ static void build_frame_code(AVFormatContext *s){ int is_audio= codec->codec_type == AVMEDIA_TYPE_AUDIO; int intra_only= /*codec->intra_only || */is_audio; int pred_count; + int frame_size = av_get_audio_frame_duration(codec, 0); + + if (codec->codec_id == AV_CODEC_ID_VORBIS && !frame_size) { + frame_size = 64; + } + if(!frame_size) + frame_size = 1; for(key_frame=0; key_frame<2; key_frame++){ if(intra_only && keyframe_0_esc && key_frame==0) @@ -185,7 +192,7 @@ static void build_frame_code(AVFormatContext *s){ ft->stream_id= stream_id; ft->size_mul=frame_bytes + 2; ft->size_lsb=frame_bytes + pred; - ft->pts_delta=pts; + ft->pts_delta=pts * frame_size; ft->header_idx= find_header_idx(s, codec, frame_bytes + pred, key_frame); start2++; } @@ -195,7 +202,7 @@ static void build_frame_code(AVFormatContext *s){ ft->flags= FLAG_KEY | FLAG_SIZE_MSB; ft->stream_id= stream_id; ft->size_mul=1; - ft->pts_delta=1; + ft->pts_delta=frame_size; start2++; } #endif @@ -221,6 +228,8 @@ static void build_frame_code(AVFormatContext *s){ int start3= start2 + (end2-start2)*pred / pred_count; int end3 = start2 + (end2-start2)*(pred+1) / pred_count; + pred_table[pred] *= frame_size; + for(index=start3; index<end3; index++){ FrameCode *ft= &nut->frame_code[index]; ft->flags= FLAG_KEY*key_frame; @@ -653,6 +662,10 @@ static int nut_write_header(AVFormatContext *s){ AVRational time_base; ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num); + if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->sample_rate) { + time_base = (AVRational){1, st->codec->sample_rate}; + } + avpriv_set_pts_info(st, 64, time_base.num, time_base.den); for(j=0; j<nut->time_base_count; j++){ diff --git a/tests/ref/lavf/nut b/tests/ref/lavf/nut index 81d07d7bb5..83cfda8764 100644 --- a/tests/ref/lavf/nut +++ b/tests/ref/lavf/nut @@ -1,3 +1,3 @@ -778e33e75965f1cb7b419a253ccd0ed8 *./tests/data/lavf/lavf.nut -319748 ./tests/data/lavf/lavf.nut -./tests/data/lavf/lavf.nut CRC=0x4780846b +6f0770a8eee4d6533d6520a1a62d3439 *./tests/data/lavf/lavf.nut +319823 ./tests/data/lavf/lavf.nut +./tests/data/lavf/lavf.nut CRC=0x3667030f diff --git a/tests/ref/seek/lavf_nut b/tests/ref/seek/lavf_nut index 83c77580d3..bb6fc432ee 100644 --- a/tests/ref/seek/lavf_nut +++ b/tests/ref/seek/lavf_nut @@ -1,53 +1,53 @@ -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 +ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 296 size: 208 ret: 0 st:-1 flags:0 ts:-1.000000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 522 size: 27837 ret: 0 st:-1 flags:1 ts: 1.894167 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st: 0 flags:0 ts: 0.800000 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st: 0 flags:1 ts:-0.320000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 -ret: 0 st: 1 flags:0 ts: 2.586122 -ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 -ret: 0 st: 1 flags:1 ts: 1.462857 -ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 +ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 522 size: 27837 +ret: 0 st: 1 flags:0 ts: 2.576667 +ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209 +ret: 0 st: 1 flags:1 ts: 1.470839 +ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209 ret: 0 st:-1 flags:0 ts: 0.365002 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st:-1 flags:1 ts:-0.740831 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 522 size: 27837 ret: 0 st: 0 flags:0 ts: 2.160000 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st: 0 flags:1 ts: 1.040000 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 -ret: 0 st: 1 flags:0 ts:-0.052245 -ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 28149 size: 208 -ret: 0 st: 1 flags:1 ts: 2.847347 -ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 +ret: 0 st: 1 flags:0 ts:-0.058322 +ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 296 size: 208 +ret: 0 st: 1 flags:1 ts: 2.835828 +ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209 ret: 0 st:-1 flags:0 ts: 1.730004 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st:-1 flags:1 ts: 0.624171 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st: 0 flags:0 ts:-0.480000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 522 size: 27837 ret: 0 st: 0 flags:1 ts: 2.400000 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 -ret: 0 st: 1 flags:0 ts: 1.306122 -ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 -ret: 0 st: 1 flags:1 ts: 0.208980 -ret: 0 st: 1 flags:1 dts: 0.182857 pts: 0.182857 pos: 71817 size: 209 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 +ret: 0 st: 1 flags:0 ts: 1.306667 +ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209 +ret: 0 st: 1 flags:1 ts: 0.200839 +ret: 0 st: 1 flags:1 dts: 0.182857 pts: 0.182857 pos: 71851 size: 209 ret: 0 st:-1 flags:0 ts:-0.904994 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 522 size: 27837 ret: 0 st:-1 flags:1 ts: 1.989173 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st: 0 flags:0 ts: 0.880000 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st: 0 flags:1 ts:-0.240000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 -ret: 0 st: 1 flags:0 ts: 2.664490 -ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 -ret: 0 st: 1 flags:1 ts: 1.567347 -ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 +ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 522 size: 27837 +ret: 0 st: 1 flags:0 ts: 2.671678 +ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209 +ret: 0 st: 1 flags:1 ts: 1.565850 +ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209 ret: 0 st:-1 flags:0 ts: 0.460008 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146337 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.520000 pts: 0.520000 pos: 146375 size: 27925 ret: 0 st:-1 flags:1 ts:-0.645825 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 522 size: 27837 |