diff --git a/src/video.h b/src/video.h index 6af2f99ab..dbf17fe83 100644 --- a/src/video.h +++ b/src/video.h @@ -66,7 +66,8 @@ typedef enum { JPEG, RAW, H264, - MJPG + MJPG, + VP8 } codec_t; enum interlacing_t { diff --git a/src/video_codec.c b/src/video_codec.c index 8d4750ca4..5550d377c 100644 --- a/src/video_codec.c +++ b/src/video_codec.c @@ -81,6 +81,7 @@ const struct codec_info_t codec_info[] = { {RAW, "raw", to_fourcc('r','a','w','s'), 0, 1.0, FALSE, TRUE}, /* raw SDI */ {H264, "H.264", to_fourcc('A','V','C','1'), 0, 1.0, FALSE, TRUE}, {MJPG, "MJPEG", to_fourcc('M','J','P','G'), 0, 1.0, FALSE, TRUE}, + {VP8, "VP8", to_fourcc('V','P','8','0'), 0, 1.0, FALSE, TRUE}, {(codec_t) 0, NULL, 0, 0, 0.0, FALSE, FALSE} }; diff --git a/src/video_compress/libavcodec.c b/src/video_compress/libavcodec.c index a644eb6ca..b04c5ae2c 100644 --- a/src/video_compress/libavcodec.c +++ b/src/video_compress/libavcodec.c @@ -92,7 +92,7 @@ static void usage() { printf("Libavcodec encoder usage:\n"); printf("\t-c libavcodec[:codec=][:bitrate=]\n"); printf("\t\t may be " - " one of \"H.264\" or " + " one of \"H.264\", \"VP8\" or " "\"MJPEG\" (default)\n"); printf("\t\t specifies requested bitrate\n"); printf("\t\t\t0 means codec default (same as when parameter omitted)\n"); @@ -223,6 +223,16 @@ static bool configure_with(struct libav_video_compress *s, struct video_frame *f compressed_desc.color_spec = MJPG; avg_bpp = 0.7; break; + case VP8: + codec_id = CODEC_ID_VP8; +#ifdef HAVE_AVCODEC_ENCODE_VIDEO2 + pix_fmt = AV_PIX_FMT_YUV420P; +#else + pix_fmt = PIX_FMT_YUV420P; +#endif + compressed_desc.color_spec = VP8; + avg_bpp = 0.5; + break; default: fprintf(stderr, "[lavc] Requested output codec isn't " "supported by libavcodec.\n"); @@ -295,6 +305,12 @@ static bool configure_with(struct libav_video_compress *s, struct video_frame *f av_opt_set(s->codec_ctx->priv_data, "preset", "ultrafast", 0); //av_opt_set(s->codec_ctx->priv_data, "tune", "fastdecode", 0); av_opt_set(s->codec_ctx->priv_data, "tune", "zerolatency", 0); + } else if(codec_id == CODEC_ID_VP8) { + s->codec_ctx->thread_count = 8; + s->codec_ctx->profile = 3; + s->codec_ctx->slices = 4; + s->codec_ctx->rc_buffer_size = s->codec_ctx->bit_rate / frame->fps; + s->codec_ctx->rc_buffer_aggressivity = 0.5; } else { // zero should mean count equal to the number of virtual cores if(s->codec->capabilities & CODEC_CAP_SLICE_THREADS) { diff --git a/src/video_decompress.c b/src/video_decompress.c index ec974d654..a2c238107 100644 --- a/src/video_decompress.c +++ b/src/video_decompress.c @@ -133,6 +133,7 @@ struct decode_from_to decoders_for_codec[] = { { H264, UYVY, LIBAVCODEC_MAGIC, 500 }, { JPEG, UYVY, LIBAVCODEC_MAGIC, 600 }, { MJPG, UYVY, LIBAVCODEC_MAGIC, 500 }, + { VP8, UYVY, LIBAVCODEC_MAGIC, 500 }, { (codec_t) -1, (codec_t) -1, NULL_MAGIC, 0 } }; const int decoders_for_codec_count = (sizeof(decoders_for_codec) / sizeof(struct decode_from_to)); diff --git a/src/video_decompress/libavcodec.c b/src/video_decompress/libavcodec.c index d5399c021..9a6c4a53d 100644 --- a/src/video_decompress/libavcodec.c +++ b/src/video_decompress/libavcodec.c @@ -102,6 +102,9 @@ static bool configure_with(struct state_libavcodec_decompress *s, fprintf(stderr, "[lavd] Warning: JPEG decoder " "will use full-scale YUV.\n"); break; + case VP8: + codec_id = CODEC_ID_VP8; + break; default: fprintf(stderr, "[lavd] Unsupported codec!!!\n"); return false;