shithub: libvpx

Download patch

ref: 08b43fef3a72c3b1790d66b2410b7fa71677c1a4
parent: a3384f00a32fdc33b8d96d43a29d9720f0641d34
author: John Koleszar <jkoleszar@google.com>
date: Tue Nov 13 07:14:28 EST 2012

webm: add support for V_VP9

Tags VP9 tracks with the V_VP9 video type when writing to .webm files,
and supports decoding both from vpxdec without specifying --codec.

Change-Id: I0ef61dee06f4db2a74032b142a4b4976c51faf6e

--- a/nestegg/include/nestegg/nestegg.h
+++ b/nestegg/include/nestegg/nestegg.h
@@ -67,6 +67,7 @@
 
 #define NESTEGG_CODEC_VP8    0 /**< Track uses Google On2 VP8 codec. */
 #define NESTEGG_CODEC_VORBIS 1 /**< Track uses Xiph Vorbis codec. */
+#define NESTEGG_CODEC_VP9    2 /**< Track uses Google On2 VP9 codec. */
 
 #define NESTEGG_SEEK_SET 0 /**< Seek offset relative to beginning of stream. */
 #define NESTEGG_SEEK_CUR 1 /**< Seek offset relative to current position in stream. */
--- a/nestegg/src/nestegg.c
+++ b/nestegg/src/nestegg.c
@@ -127,6 +127,7 @@
 
 /* Track IDs */
 #define TRACK_ID_VP8            "V_VP8"
+#define TRACK_ID_VP9            "V_VP9"
 #define TRACK_ID_VORBIS         "A_VORBIS"
 
 enum vint_mask {
@@ -1668,6 +1669,9 @@
 
   if (strcmp(codec_id, TRACK_ID_VP8) == 0)
     return NESTEGG_CODEC_VP8;
+
+  if (strcmp(codec_id, TRACK_ID_VP9) == 0)
+    return NESTEGG_CODEC_VP9;
 
   if (strcmp(codec_id, TRACK_ID_VORBIS) == 0)
     return NESTEGG_CODEC_VORBIS;
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -537,6 +537,7 @@
              unsigned int     *fps_num) {
   unsigned int i, n;
   int          track_type = -1;
+  int          codec_id;
 
   nestegg_io io = {nestegg_read_cb, nestegg_seek_cb, nestegg_tell_cb, 0};
   nestegg_video_params params;
@@ -557,8 +558,13 @@
       goto fail;
   }
 
-  if (nestegg_track_codec_id(input->nestegg_ctx, i) != NESTEGG_CODEC_VP8) {
-    fprintf(stderr, "Not VP8 video, quitting.\n");
+  codec_id = nestegg_track_codec_id(input->nestegg_ctx, i);
+  if (codec_id == NESTEGG_CODEC_VP8) {
+    *fourcc = VP8_FOURCC;
+  } else if (codec_id == NESTEGG_CODEC_VP9) {
+    *fourcc = VP9_FOURCC;
+  } else {
+    fprintf(stderr, "Not VPx video, quitting.\n");
     exit(1);
   }
 
@@ -569,7 +575,6 @@
 
   *fps_den = 0;
   *fps_num = 0;
-  *fourcc = VP8_FOURCC;
   *width = params.width;
   *height = params.height;
   return 1;
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -86,6 +86,8 @@
 
 static const char *exec_name;
 
+#define VP8_FOURCC (0x00385056)
+#define VP9_FOURCC (0x00395056)
 static const struct codec_item {
   char const              *name;
   const vpx_codec_iface_t *(*iface)(void);
@@ -93,14 +95,14 @@
   unsigned int             fourcc;
 } codecs[] = {
 #if CONFIG_VP8_ENCODER && CONFIG_VP8_DECODER
-  {"vp8", &vpx_codec_vp8_cx, &vpx_codec_vp8_dx, 0x30385056},
+  {"vp8", &vpx_codec_vp8_cx, &vpx_codec_vp8_dx, VP8_FOURCC},
 #elif CONFIG_VP8_ENCODER && !CONFIG_VP8_DECODER
-  {"vp8", &vpx_codec_vp8_cx, NULL, 0x30385056},
+  {"vp8", &vpx_codec_vp8_cx, NULL, VP8_FOURCC},
 #endif
 #if CONFIG_VP9_ENCODER && CONFIG_VP9_DECODER
-  {"vp9", &vpx_codec_vp9_cx, &vpx_codec_vp9_dx, 0x30395056},
+  {"vp9", &vpx_codec_vp9_cx, &vpx_codec_vp9_dx, VP9_FOURCC},
 #elif CONFIG_VP9_ENCODER && !CONFIG_VP9_DECODER
-  {"vp9", &vpx_codec_vp9_cx, NULL, 0x30395056},
+  {"vp9", &vpx_codec_vp9_cx, NULL, VP9_FOURCC},
 #endif
 };
 
@@ -663,7 +665,8 @@
 write_webm_file_header(EbmlGlobal                *glob,
                        const vpx_codec_enc_cfg_t *cfg,
                        const struct vpx_rational *fps,
-                       stereo_format_t            stereo_fmt) {
+                       stereo_format_t            stereo_fmt,
+                       unsigned int               fourcc) {
   {
     EbmlLoc start;
     Ebml_StartSubElement(glob, &start, EBML);
@@ -696,7 +699,8 @@
         glob->track_id_pos = ftello(glob->stream);
         Ebml_SerializeUnsigned32(glob, TrackUID, trackID);
         Ebml_SerializeUnsigned(glob, TrackType, 1);
-        Ebml_SerializeString(glob, CodecID, "V_VP8");
+        Ebml_SerializeString(glob, CodecID,
+                             fourcc == VP8_FOURCC ? "V_VP8" : "V_VP9");
         {
           unsigned int pixelWidth = cfg->g_w;
           unsigned int pixelHeight = cfg->g_h;
@@ -2028,7 +2032,8 @@
     stream->ebml.stream = stream->file;
     write_webm_file_header(&stream->ebml, &stream->config.cfg,
                            &global->framerate,
-                           stream->config.stereo_fmt);
+                           stream->config.stereo_fmt,
+                           global->codec->fourcc);
   } else
     write_ivf_file_header(stream->file, &stream->config.cfg,
                           global->codec->fourcc, 0);
--