[FFmpeg-devel] [PATCH 2/3] avformat/mxfenc: remove dependancy on H264Context, use fields from AVCodecContext
Michael Niedermayer
michaelni at gmx.at
Sat Sep 13 12:36:05 CEST 2014
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavformat/mxfenc.c | 74 ++++++++++++++------------------------------------
1 file changed, 20 insertions(+), 54 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 98f3479..1cfa176 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -38,6 +38,7 @@
#include "libavutil/random_seed.h"
#include "libavutil/timecode.h"
#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/dnxhddata.h"
#include "libavcodec/h264.h"
@@ -1596,15 +1597,14 @@ static const UID mxf_h264_codec_uls[] = {
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x09 }, // AVC High 422 Intra RP2027 Class 100 720/50p
};
-static const UID *mxf_get_h264_codec_ul(AVCodecContext *avctx, SPS *sps)
+static const UID *mxf_get_h264_codec_ul(AVCodecContext *avctx)
{
int long_gop = avctx->gop_size > 1 || avctx->has_b_frames;
- if ((sps->constraint_set_flags >> 3) & 1) {
- if (sps->profile_idc == 110)
- return &mxf_h264_codec_uls[2];
- else if (sps->profile_idc == 122)
- return &mxf_h264_codec_uls[9];
+ if (avctx->profile == FF_PROFILE_H264_HIGH_10_INTRA) {
+ return &mxf_h264_codec_uls[2];
+ } else if (avctx->profile == FF_PROFILE_H264_HIGH_422_INTRA) {
+ return &mxf_h264_codec_uls[9];
}
if (long_gop)
return &mxf_h264_codec_uls[0];
@@ -1616,11 +1616,10 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st,
AVPacket *pkt, MXFIndexEntry *e)
{
MXFStreamContext *sc = st->priv_data;
- H264Context h;
const uint8_t *buf = pkt->data;
const uint8_t *buf_end = pkt->data + pkt->size;
uint32_t state = -1;
- AVRational sar = {1, 1};
+ AVRational dar = {st->codec->width, st->codec->height};
if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) {
av_log(s, AV_LOG_ERROR, "h264 bitstream malformated, "
@@ -1628,63 +1627,27 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st,
return 0;
}
- memset(&h, 0, sizeof(h));
- h.avctx = st->codec;
- h.thread_context[0] = &h;
- h.prev_frame_num = -1;
+ if (st->sample_aspect_ratio.num > 0 && st->sample_aspect_ratio.den > 0) {
+ dar.num = st->codec->width * st->sample_aspect_ratio.num;
+ dar.den = st->codec->height * st->sample_aspect_ratio.den;
+ }
+ av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
+ dar.num, dar.den, 1024*1024);
- for (;;) {
- int src_length, dst_length, consumed;
- const uint8_t *ptr;
+ sc->interlaced = st->codec->field_order > AV_FIELD_PROGRESSIVE;
+ sc->codec_ul = mxf_get_h264_codec_ul(st->codec);
+
+ for (;;) {
buf = avpriv_find_start_code(buf, buf_end, &state);
if (buf >= buf_end)
break;
--buf;
- src_length = buf_end - buf;
switch (state & 0x1f) {
- case NAL_SLICE:
- case NAL_IDR_SLICE:
- // Do not walk the whole buffer just to decode slice header
- if (src_length > 20)
- src_length = 20;
- break;
- }
-
- ptr = ff_h264_decode_nal(&h, buf, &dst_length, &consumed, src_length);
- if (!ptr || dst_length < 0)
- break;
-
- init_get_bits(&h.gb, ptr, 8*dst_length);
- //av_log(avctx, AV_LOG_DEBUG, "nal_unit_type:%d\n", h.nal_unit_type);
- switch (h.nal_unit_type) {
case NAL_SPS:
- ff_h264_decode_seq_parameter_set(&h);
- if (h.sps.sar.num > 0 && h.sps.sar.den > 0) {
- sar.num = st->codec->width * h.sps.sar.num;
- sar.den = st->codec->height * h.sps.sar.den;
- }
- sc->aspect_ratio.num = st->codec->width * sar.num;
- sc->aspect_ratio.den = st->codec->height * sar.den;
- av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
- sar.num, sar.den, 1024*1024);
-
- sc->interlaced = !h.sps.frame_mbs_only_flag;
- sc->component_depth = h.sps.bit_depth_luma;
-
- sc->codec_ul = mxf_get_h264_codec_ul(st->codec, &h.sps);
e->flags |= 0x40;
break;
case NAL_PPS:
- ff_h264_decode_picture_parameter_set(&h, h.gb.size_in_bits);
- if (h.sps.timing_info_present_flag) {
- if (st->codec->time_base.num != h.sps.num_units_in_tick ||
- st->codec->time_base.den*2 != h.sps.time_scale) {
- av_log(s, AV_LOG_ERROR, "framerate does not match bitstream values: %d/%d != %d/%d\n",
- h.sps.num_units_in_tick, h.sps.time_scale, st->codec->time_base.num, st->codec->time_base.den*2);
- return 0;
- }
- }
if (e->flags & 0x40) // sequence header present
e->flags |= 0x80; // random access
break;
@@ -1844,8 +1807,11 @@ static int mxf_write_header(AVFormatContext *s)
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
// TODO: should be avg_frame_rate
AVRational rate, tbc = st->time_base;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codec->pix_fmt);
// Default component depth to 8
sc->component_depth = 8;
+ if (desc)
+ sc->component_depth = desc->comp[0].depth_minus1 + 1;
mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
spf = ff_mxf_get_samples_per_frame(s, tbc);
if (!spf) {
--
1.7.9.5
More information about the ffmpeg-devel
mailing list