[FFmpeg-devel] [PATCH 2/2] avformat/movenc: Support merging h264 fields into field pairs
Michael Niedermayer
michaelni at gmx.at
Mon Mar 10 02:58:34 CET 2014
Fixes Ticket3393
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavformat/movenc.c | 12 ++++++++++++
libavformat/movenc.h | 3 +++
2 files changed, 15 insertions(+)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index b917a59..af73380 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -31,6 +31,7 @@
#include "isom.h"
#include "avc.h"
#include "libavcodec/get_bits.h"
+#include "libavcodec/h264_merge_fields.h"
#include "libavcodec/put_bits.h"
#include "libavcodec/vc1.h"
#include "internal.h"
@@ -67,6 +68,7 @@ static const AVOption options[] = {
{ "ism_lookahead", "Number of lookahead entries for ISM files", offsetof(MOVMuxContext, ism_lookahead), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
{ "use_editlist", "use edit list", offsetof(MOVMuxContext, use_editlist), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
{ "video_track_timescale", "set timescale of all video tracks", offsetof(MOVMuxContext, video_track_timescale), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+ { "merge_fields", "Store field pairs as frames", offsetof(MOVMuxContext, merge_fields), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
{ NULL },
};
@@ -3275,6 +3277,16 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
int size = pkt->size;
uint8_t *reformatted_data = NULL;
+ if (enc->codec_id == AV_CODEC_ID_H264 && mov->merge_fields) {
+ int ret;
+
+ if (!trk->merge_fields_context)
+ trk->merge_fields_context = avpriv_h264_merge_fields_init();
+ ret = avpriv_h264_merge_fields(trk->merge_fields_context, enc, pkt);
+ if (ret <= 0)
+ return ret;
+ }
+
if (trk->entry) {
int64_t duration = pkt->dts - trk->cluster[trk->entry - 1].dts;
if (duration < 0 || duration > INT_MAX) {
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 09f3ea7..753f408 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -133,6 +133,8 @@ typedef struct MOVTrack {
MOVFragmentInfo *frag_info;
unsigned frag_info_capacity;
+ struct H264MergeFieldsContext *merge_fields_context;
+
struct {
int64_t struct_offset;
int first_packet_seq;
@@ -170,6 +172,7 @@ typedef struct MOVMuxContext {
int use_editlist;
int video_track_timescale;
+ int merge_fields;
int reserved_moov_size; ///< 0 for disabled, -1 for automatic, size otherwise
int64_t reserved_moov_pos;
--
1.7.9.5
More information about the ffmpeg-devel
mailing list