[FFmpeg-devel] [PATCH 4/4] avformat/mov: add support for reading end padding from gapless itunes metadata
Marton Balint
cus at passwd.hu
Mon Mar 21 01:06:21 CET 2016
Signed-off-by: Marton Balint <cus at passwd.hu>
---
libavformat/mov.c | 13 ++++++++++---
tests/ref/fate/gaplessenc-itunes-to-ipod-aac | 12 ++++++------
tests/ref/fate/gaplessinfo-itunes1 | 2 +-
tests/ref/fate/gaplessinfo-itunes2 | 2 +-
4 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 18335db..4e474fe 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3248,10 +3248,17 @@ static int mov_read_custom(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if (mean && key && val) {
if (strcmp(key, "iTunSMPB") == 0) {
- int priming, remainder, samples;
- if(sscanf(val, "%*X %X %X %X", &priming, &remainder, &samples) == 3){
- if(priming>0 && priming<16384)
+ int priming, remainder;
+ int64_t samples;
+ if (sscanf(val, "%*X %X %X %"PRIX64, &priming, &remainder, &samples) == 3) {
+ if (priming > 0 && priming < 16384) {
sc->start_pad = priming;
+ if (st->codec->sample_rate) {
+ int64_t time_offset_in_samples = av_rescale(sc->time_offset, sc->time_scale, st->codec->sample_rate);
+ st->first_discard_sample = samples + priming - time_offset_in_samples;
+ st->last_discard_sample = samples + priming + remainder - time_offset_in_samples;
+ }
+ }
}
}
if (strcmp(key, "cdec") != 0) {
diff --git a/tests/ref/fate/gaplessenc-itunes-to-ipod-aac b/tests/ref/fate/gaplessenc-itunes-to-ipod-aac
index e04934b..8fbbd9b 100644
--- a/tests/ref/fate/gaplessenc-itunes-to-ipod-aac
+++ b/tests/ref/fate/gaplessenc-itunes-to-ipod-aac
@@ -1,11 +1,11 @@
[STREAM]
index=0
start_pts=0
-duration_ts=104384
+duration_ts=103424
[/STREAM]
[FORMAT]
start_time=0.000000
-duration=2.367000
+duration=2.346000
[/FORMAT]
packet|pts=-1024|dts=-1024|duration=1024
packet|pts=0|dts=0|duration=1024
@@ -15,6 +15,7 @@ packet|pts=3072|dts=3072|duration=1024
packet|pts=4096|dts=4096|duration=1024
packet|pts=5120|dts=5120|duration=1024
packet|pts=6144|dts=6144|duration=1024
+packet|pts=94208|dts=94208|duration=1024
packet|pts=95232|dts=95232|duration=1024
packet|pts=96256|dts=96256|duration=1024
packet|pts=97280|dts=97280|duration=1024
@@ -22,8 +23,7 @@ packet|pts=98304|dts=98304|duration=1024
packet|pts=99328|dts=99328|duration=1024
packet|pts=100352|dts=100352|duration=1024
packet|pts=101376|dts=101376|duration=1024
-packet|pts=102400|dts=102400|duration=1024
-stream|nb_read_packets=102
+stream|nb_read_packets=101
frame|pkt_pts=0|pkt_dts=0|best_effort_timestamp=0|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=1024|pkt_dts=1024|best_effort_timestamp=1024|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=2048|pkt_dts=2048|best_effort_timestamp=2048|pkt_duration=1024|nb_samples=1024
@@ -32,6 +32,7 @@ frame|pkt_pts=4096|pkt_dts=4096|best_effort_timestamp=4096|pkt_duration=1024|nb_
frame|pkt_pts=5120|pkt_dts=5120|best_effort_timestamp=5120|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=6144|pkt_dts=6144|best_effort_timestamp=6144|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=7168|pkt_dts=7168|best_effort_timestamp=7168|pkt_duration=1024|nb_samples=1024
+frame|pkt_pts=94208|pkt_dts=94208|best_effort_timestamp=94208|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=95232|pkt_dts=95232|best_effort_timestamp=95232|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=96256|pkt_dts=96256|best_effort_timestamp=96256|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=97280|pkt_dts=97280|best_effort_timestamp=97280|pkt_duration=1024|nb_samples=1024
@@ -39,5 +40,4 @@ frame|pkt_pts=98304|pkt_dts=98304|best_effort_timestamp=98304|pkt_duration=1024|
frame|pkt_pts=99328|pkt_dts=99328|best_effort_timestamp=99328|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=100352|pkt_dts=100352|best_effort_timestamp=100352|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=101376|pkt_dts=101376|best_effort_timestamp=101376|pkt_duration=1024|nb_samples=1024
-frame|pkt_pts=102400|pkt_dts=102400|best_effort_timestamp=102400|pkt_duration=1024|nb_samples=1024
-stream|nb_read_frames=101
+stream|nb_read_frames=100
diff --git a/tests/ref/fate/gaplessinfo-itunes1 b/tests/ref/fate/gaplessinfo-itunes1
index 717a2a8..84bb2ec 100644
--- a/tests/ref/fate/gaplessinfo-itunes1
+++ b/tests/ref/fate/gaplessinfo-itunes1
@@ -39,5 +39,5 @@ frame|pkt_pts=1289216|pkt_dts=1289216|best_effort_timestamp=1289216|pkt_duration
frame|pkt_pts=1290240|pkt_dts=1290240|best_effort_timestamp=1290240|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=1291264|pkt_dts=1291264|best_effort_timestamp=1291264|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=1292288|pkt_dts=1292288|best_effort_timestamp=1292288|pkt_duration=1024|nb_samples=1024
-frame|pkt_pts=1293312|pkt_dts=1293312|best_effort_timestamp=1293312|pkt_duration=1024|nb_samples=1024
+frame|pkt_pts=1293312|pkt_dts=1293312|best_effort_timestamp=1293312|pkt_duration=515|nb_samples=515
stream|nb_read_frames=1262
diff --git a/tests/ref/fate/gaplessinfo-itunes2 b/tests/ref/fate/gaplessinfo-itunes2
index be15113..ff8b5e3 100644
--- a/tests/ref/fate/gaplessinfo-itunes2
+++ b/tests/ref/fate/gaplessinfo-itunes2
@@ -39,5 +39,5 @@ frame|pkt_pts=100352|pkt_dts=100352|best_effort_timestamp=100352|pkt_duration=10
frame|pkt_pts=101376|pkt_dts=101376|best_effort_timestamp=101376|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=102400|pkt_dts=102400|best_effort_timestamp=102400|pkt_duration=1024|nb_samples=1024
frame|pkt_pts=103424|pkt_dts=103424|best_effort_timestamp=103424|pkt_duration=1024|nb_samples=1024
-frame|pkt_pts=104448|pkt_dts=104448|best_effort_timestamp=104448|pkt_duration=1024|nb_samples=1024
+frame|pkt_pts=104448|pkt_dts=104448|best_effort_timestamp=104448|pkt_duration=64|nb_samples=64
stream|nb_read_frames=101
--
2.6.2
More information about the ffmpeg-devel
mailing list