Commit 4eb0f5f6 authored by Michael Niedermayer's avatar Michael Niedermayer

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: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent c4dba58f
...@@ -156,6 +156,13 @@ static void build_frame_code(AVFormatContext *s){ ...@@ -156,6 +156,13 @@ static void build_frame_code(AVFormatContext *s){
int is_audio= codec->codec_type == AVMEDIA_TYPE_AUDIO; int is_audio= codec->codec_type == AVMEDIA_TYPE_AUDIO;
int intra_only= /*codec->intra_only || */is_audio; int intra_only= /*codec->intra_only || */is_audio;
int pred_count; 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++){ for(key_frame=0; key_frame<2; key_frame++){
if(intra_only && keyframe_0_esc && key_frame==0) if(intra_only && keyframe_0_esc && key_frame==0)
...@@ -185,7 +192,7 @@ static void build_frame_code(AVFormatContext *s){ ...@@ -185,7 +192,7 @@ static void build_frame_code(AVFormatContext *s){
ft->stream_id= stream_id; ft->stream_id= stream_id;
ft->size_mul=frame_bytes + 2; ft->size_mul=frame_bytes + 2;
ft->size_lsb=frame_bytes + pred; 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); ft->header_idx= find_header_idx(s, codec, frame_bytes + pred, key_frame);
start2++; start2++;
} }
...@@ -195,7 +202,7 @@ static void build_frame_code(AVFormatContext *s){ ...@@ -195,7 +202,7 @@ static void build_frame_code(AVFormatContext *s){
ft->flags= FLAG_KEY | FLAG_SIZE_MSB; ft->flags= FLAG_KEY | FLAG_SIZE_MSB;
ft->stream_id= stream_id; ft->stream_id= stream_id;
ft->size_mul=1; ft->size_mul=1;
ft->pts_delta=1; ft->pts_delta=frame_size;
start2++; start2++;
} }
#endif #endif
...@@ -221,6 +228,8 @@ static void build_frame_code(AVFormatContext *s){ ...@@ -221,6 +228,8 @@ static void build_frame_code(AVFormatContext *s){
int start3= start2 + (end2-start2)*pred / pred_count; int start3= start2 + (end2-start2)*pred / pred_count;
int end3 = start2 + (end2-start2)*(pred+1) / pred_count; int end3 = start2 + (end2-start2)*(pred+1) / pred_count;
pred_table[pred] *= frame_size;
for(index=start3; index<end3; index++){ for(index=start3; index<end3; index++){
FrameCode *ft= &nut->frame_code[index]; FrameCode *ft= &nut->frame_code[index];
ft->flags= FLAG_KEY*key_frame; ft->flags= FLAG_KEY*key_frame;
...@@ -653,6 +662,10 @@ static int nut_write_header(AVFormatContext *s){ ...@@ -653,6 +662,10 @@ static int nut_write_header(AVFormatContext *s){
AVRational time_base; AVRational time_base;
ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num); 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); avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
for(j=0; j<nut->time_base_count; j++){ for(j=0; j<nut->time_base_count; j++){
......
778e33e75965f1cb7b419a253ccd0ed8 *./tests/data/lavf/lavf.nut 6f0770a8eee4d6533d6520a1a62d3439 *./tests/data/lavf/lavf.nut
319748 ./tests/data/lavf/lavf.nut 319823 ./tests/data/lavf/lavf.nut
./tests/data/lavf/lavf.nut CRC=0x4780846b ./tests/data/lavf/lavf.nut CRC=0x3667030f
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:-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:-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: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 ts:-0.320000
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:0 ts: 2.586122 ret: 0 st: 1 flags:0 ts: 2.576667
ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209
ret: 0 st: 1 flags:1 ts: 1.462857 ret: 0 st: 1 flags:1 ts: 1.470839
ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 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:-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:-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: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 ts: 1.040000
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:0 ts:-0.052245 ret: 0 st: 1 flags:0 ts:-0.058322
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 28149 size: 208 ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 296 size: 208
ret: 0 st: 1 flags:1 ts: 2.847347 ret: 0 st: 1 flags:1 ts: 2.835828
ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 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:-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:-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: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 ts: 2.400000
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:0 ts: 1.306122 ret: 0 st: 1 flags:0 ts: 1.306667
ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209
ret: 0 st: 1 flags:1 ts: 0.208980 ret: 0 st: 1 flags:1 ts: 0.200839
ret: 0 st: 1 flags:1 dts: 0.182857 pts: 0.182857 pos: 71817 size: 209 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:-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:-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: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 ts:-0.240000
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:0 ts: 2.664490 ret: 0 st: 1 flags:0 ts: 2.671678
ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271188 size: 209
ret: 0 st: 1 flags:1 ts: 1.567347 ret: 0 st: 1 flags:1 ts: 1.565850
ret: 0 st: 1 flags:1 dts: 0.862041 pts: 0.862041 pos: 271130 size: 209 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:-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:-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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment