diff mbox

[FFmpeg-devel,1/6] lavf/movenc: add sdtp (sample dependency) box

Message ID 20171119204635.4593-2-jstebbins@jetheaddev.com
State Accepted
Commit 00d454ed2ca3f8b4d454a837e95931afe604c53f
Headers show

Commit Message

John Stebbins Nov. 19, 2017, 8:46 p.m. UTC
The sdtp is required by the AppleTV 4K in order to play 2160p60 video.
---
 libavcodec/avcodec.h |  6 ++++++
 libavformat/isom.h   |  5 +++++
 libavformat/movenc.c | 30 ++++++++++++++++++++++++++++++
 libavformat/movenc.h |  2 ++
 4 files changed, 43 insertions(+)

Comments

Carl Eugen Hoyos Nov. 19, 2017, 10:12 p.m. UTC | #1
2017-11-19 21:46 GMT+01:00 John Stebbins <jstebbins@jetheaddev.com>:
> The sdtp is required by the AppleTV 4K in order to play 2160p60 video.

> +/**
> + * Flag is used to indicate packets that contain frames that can
> + * be discarded by the decoder.  I.e. Non-reference frames.
> + */
> +#define AV_PKT_FLAG_DISPOSABLE 0x0010

What sets this flag?

Carl Eugen
John Stebbins Nov. 19, 2017, 10:25 p.m. UTC | #2
On 11/19/2017 02:12 PM, Carl Eugen Hoyos wrote:
> 2017-11-19 21:46 GMT+01:00 John Stebbins <jstebbins@jetheaddev.com>:
>> The sdtp is required by the AppleTV 4K in order to play 2160p60 video.
>> +/**
>> + * Flag is used to indicate packets that contain frames that can
>> + * be discarded by the decoder.  I.e. Non-reference frames.
>> + */
>> +#define AV_PKT_FLAG_DISPOSABLE 0x0010
> What sets this flag?
>
>

Encoders when encoding, demuxer when remuxing.  The subsequent patches set this flag for x264, x265, and mp4 demux.
Carl Eugen Hoyos Nov. 19, 2017, 10:29 p.m. UTC | #3
2017-11-19 23:25 GMT+01:00 John Stebbins <stebbins@jetheaddev.com>:
> On 11/19/2017 02:12 PM, Carl Eugen Hoyos wrote:
>> 2017-11-19 21:46 GMT+01:00 John Stebbins <jstebbins@jetheaddev.com>:
>>> The sdtp is required by the AppleTV 4K in order to play 2160p60 video.
>>> +/**
>>> + * Flag is used to indicate packets that contain frames that can
>>> + * be discarded by the decoder.  I.e. Non-reference frames.
>>> + */
>>> +#define AV_PKT_FLAG_DISPOSABLE 0x0010
>> What sets this flag?
>
> Encoders when encoding, demuxer when remuxing.

> The subsequent patches set this flag for x264, x265, and mp4 demux.

So does this patch alone work wrt the description: Does AppleTV play
4k with this patch alone?

Carl Eugen
John Stebbins Nov. 20, 2017, 3:35 p.m. UTC | #4
On 11/19/2017 02:29 PM, Carl Eugen Hoyos wrote:
> 2017-11-19 23:25 GMT+01:00 John Stebbins <stebbins@jetheaddev.com>:
>> On 11/19/2017 02:12 PM, Carl Eugen Hoyos wrote:
>>> 2017-11-19 21:46 GMT+01:00 John Stebbins <jstebbins@jetheaddev.com>:
>>>> The sdtp is required by the AppleTV 4K in order to play 2160p60 video.
>>>> +/**
>>>> + * Flag is used to indicate packets that contain frames that can
>>>> + * be discarded by the decoder.  I.e. Non-reference frames.
>>>> + */
>>>> +#define AV_PKT_FLAG_DISPOSABLE 0x0010
>>> What sets this flag?
>> Encoders when encoding, demuxer when remuxing.
>> The subsequent patches set this flag for x264, x265, and mp4 demux.
> So does this patch alone work wrt the description: Does AppleTV play
> 4k with this patch alone?
>
>

The commit message simply states that the atom is a requirement.  It doesn't say whether there are additional
requirements.  Are you saying you would like the commit message amended, or that the comment in the code needs to say
who must set the flag, or both?  Please be to the point.
Michael Niedermayer Dec. 2, 2017, 6:10 p.m. UTC | #5
On Sun, Nov 19, 2017 at 12:46:30PM -0800, John Stebbins wrote:
> The sdtp is required by the AppleTV 4K in order to play 2160p60 video.
> ---
>  libavcodec/avcodec.h |  6 ++++++
>  libavformat/isom.h   |  5 +++++
>  libavformat/movenc.c | 30 ++++++++++++++++++++++++++++++
>  libavformat/movenc.h |  2 ++
>  4 files changed, 43 insertions(+)

will apply

thanks

[...]
diff mbox

Patch

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 442b558d4b..4f4bebc586 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1443,6 +1443,12 @@  typedef struct AVPacket {
  * outside the packet may be followed.
  */
 #define AV_PKT_FLAG_TRUSTED   0x0008
+/**
+ * Flag is used to indicate packets that contain frames that can
+ * be discarded by the decoder.  I.e. Non-reference frames.
+ */
+#define AV_PKT_FLAG_DISPOSABLE 0x0010
+
 
 enum AVSideDataParamChangeFlags {
     AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT  = 0x0001,
diff --git a/libavformat/isom.h b/libavformat/isom.h
index ff08f5d090..65676fb0f5 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -318,6 +318,11 @@  void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
 #define MOV_TKHD_FLAG_IN_PREVIEW    0x0004
 #define MOV_TKHD_FLAG_IN_POSTER     0x0008
 
+#define MOV_SAMPLE_DEPENDENCY_UNKNOWN 0x0
+#define MOV_SAMPLE_DEPENDENCY_YES     0x1
+#define MOV_SAMPLE_DEPENDENCY_NO      0x2
+
+
 #define TAG_IS_AVCI(tag)                    \
     ((tag) == MKTAG('a', 'i', '5', 'p') ||  \
      (tag) == MKTAG('a', 'i', '5', 'q') ||  \
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 01ae467fa1..c9ff65d43d 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -252,6 +252,30 @@  static int mov_write_stss_tag(AVIOContext *pb, MOVTrack *track, uint32_t flag)
     return update_size(pb, pos);
 }
 
+/* Sample dependency atom */
+static int mov_write_sdtp_tag(AVIOContext *pb, MOVTrack *track)
+{
+    int i;
+    uint8_t leading, dependent, reference, redundancy;
+    int64_t pos = avio_tell(pb);
+    avio_wb32(pb, 0); // size
+    ffio_wfourcc(pb, "sdtp");
+    avio_wb32(pb, 0); // version & flags
+    for (i = 0; i < track->entry; i++) {
+        dependent = MOV_SAMPLE_DEPENDENCY_YES;
+        leading = reference = redundancy = MOV_SAMPLE_DEPENDENCY_UNKNOWN;
+        if (track->cluster[i].flags & MOV_DISPOSABLE_SAMPLE) {
+            reference = MOV_SAMPLE_DEPENDENCY_NO;
+        }
+        if (track->cluster[i].flags & MOV_SYNC_SAMPLE) {
+            dependent = MOV_SAMPLE_DEPENDENCY_NO;
+        }
+        avio_w8(pb, (leading << 6)   | (dependent << 4) |
+                    (reference << 2) | redundancy);
+    }
+    return update_size(pb, pos);
+}
+
 static int mov_write_amr_tag(AVIOContext *pb, MOVTrack *track)
 {
     avio_wb32(pb, 0x11); /* size */
@@ -2320,6 +2344,8 @@  static int mov_write_stbl_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext
          track->par->codec_tag == MKTAG('r','t','p',' ')) &&
         track->has_keyframes && track->has_keyframes < track->entry)
         mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE);
+    if (track->par->codec_type == AVMEDIA_TYPE_VIDEO && track->has_disposable)
+        mov_write_sdtp_tag(pb, track);
     if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS)
         mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE);
     if (track->par->codec_type == AVMEDIA_TYPE_VIDEO &&
@@ -5283,6 +5309,10 @@  int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
         if (trk->cluster[trk->entry].flags & MOV_SYNC_SAMPLE)
             trk->has_keyframes++;
     }
+    if (pkt->flags & AV_PKT_FLAG_DISPOSABLE) {
+        trk->cluster[trk->entry].flags |= MOV_DISPOSABLE_SAMPLE;
+        trk->has_disposable++;
+    }
     trk->entry++;
     trk->sample_count += samples_in_chunk;
     mov->mdat_size    += size;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index cc2a155d79..c4e966b7fb 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -53,6 +53,7 @@  typedef struct MOVIentry {
     int          cts;
 #define MOV_SYNC_SAMPLE         0x0001
 #define MOV_PARTIAL_SYNC_SAMPLE 0x0002
+#define MOV_DISPOSABLE_SAMPLE   0x0004
     uint32_t     flags;
 } MOVIentry;
 
@@ -89,6 +90,7 @@  typedef struct MOVTrack {
     long        sample_size;
     long        chunkCount;
     int         has_keyframes;
+    int         has_disposable;
 #define MOV_TRACK_CTTS         0x0001
 #define MOV_TRACK_STPS         0x0002
 #define MOV_TRACK_ENABLED      0x0004