2014-11-30 1:45 GMT+01:00 Christophe Gisquet christophe.gisq...@gmail.com:
From: Zongyi Zhou zho...@os.pku.edu.cn
Squashed and updated patch attached.
From a49425e6af4e3e488c390d94d8f86c5d1745dda3 Mon Sep 17 00:00:00 2001
From: Zongyi Zhou zho...@os.pku.edu.cn
Date: Sat, 29 Nov 2014 15:04:37 +0100
Subject: [PATCH 2/4] h264_changesps_bsf: import code
Mostly unverified, but seems to have been extensively tested here:
http://forum.doom9.org/showthread.php?t=152419
The code has been slightly edited to avoid hackish solutions to passing
arguments and using the H.264 aspect ratio.
Signed-off-by: Christophe Gisquet christophe.gisq...@gmail.com
---
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/h264_changesps_bsf.c | 604
3 files changed, 606 insertions(+)
create mode 100644 libavcodec/h264_changesps_bsf.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fa0f53d..8eecf51 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -820,6 +820,7 @@ OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += aac_adtstoasc_bsf.o aacadtsdec.o \
mpeg4audio.o
OBJS-$(CONFIG_CHOMP_BSF) += chomp_bsf.o
OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
+OBJS-$(CONFIG_H264_CHANGESPS_BSF) += h264_changesps_bsf.o
OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF) += h264_mp4toannexb_bsf.o
OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
OBJS-$(CONFIG_MJPEG2JPEG_BSF) += mjpeg2jpeg_bsf.o mjpeg.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 0d39d33..0380824 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -581,6 +581,7 @@ void avcodec_register_all(void)
REGISTER_BSF(AAC_ADTSTOASC, aac_adtstoasc);
REGISTER_BSF(CHOMP, chomp);
REGISTER_BSF(DUMP_EXTRADATA,dump_extradata);
+REGISTER_BSF(H264_CHANGESPS,h264_changesps);
REGISTER_BSF(H264_MP4TOANNEXB, h264_mp4toannexb);
REGISTER_BSF(IMX_DUMP_HEADER, imx_dump_header);
REGISTER_BSF(MJPEG2JPEG,mjpeg2jpeg);
diff --git a/libavcodec/h264_changesps_bsf.c b/libavcodec/h264_changesps_bsf.c
new file mode 100644
index 000..a166748
--- /dev/null
+++ b/libavcodec/h264_changesps_bsf.c
@@ -0,0 +1,604 @@
+/*
+ * H.264 change sps filter
+ * Copyright (c) 2010 Zongyi Zhou zho...@os.pku.edu.cn
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include avcodec.h
+#include golomb.h
+#include h264.h
+#include h264data.h
+
+typedef struct H264SPSContext {
+uint8_t state;
+uint8_t bs_type; // 1=annexb 2=mp4
+int8_t fps_mode;
+int8_t remove_hrd;
+int32_t fps_den, fps_num;
+int32_t predefined_sar;
+int32_t level;
+int32_t refs;
+uint32_t remove_nal_flags, delay_remove_flags;
+int16_t sar_x, sar_y;
+int16_t crop_x, crop_y;
+int8_t fullrange, colorprim, transfer, colmatrix;
+} H264SPSContext;
+
+static int parse_args(struct H264SPSContext *c, const char *args)
+{
+int r = 0;
+int32_t sarx = -1, sary = -1, cropx = -1, cropy = -1, level = -1,
+refs = -1, colorprim = -1, transfer = -1, colmatrix = -1;
+if (!args) return 0;
+c-fps_den = c-fps_num = c-fps_mode = -1;
+c-fullrange = -1;
+c-remove_nal_flags = c-delay_remove_flags = 0;
+while (*args) {
+if (sscanf(args, fps=%u:%u, c-fps_num, c-fps_den) == 2 ||
+sscanf(args, sar=%u:%u, sarx, sary) == 2 ||
+sscanf(args, crop=%u:%u, cropx, cropy) == 2 ||
+sscanf(args, level=%u, level) == 1 ||
+sscanf(args, ref=%u, refs) == 1 ||
+sscanf(args, colorprim=%u, colorprim) == 1 ||
+sscanf(args, transfer=%u, transfer) == 1 ||
+sscanf(args, colormatrix=%u, colmatrix) == 1)
+r++;
+else if (!strncmp(args, vfr, 3)) {
+r++;
+c-fps_mode = 0;
+} else if (!strncmp(args, cfr, 3)) {
+r++;
+c-fps_mode = 1;
+} else if (!strncmp(args, fullrange, 9)) {
+r++;
+c-fullrange = 1;
+} else if (!strncmp(args, removesei, 9)) {
+r++;
+