static int audio_sync_method= 0;
static int copy_ts= 0;
static int opt_shortest = 0; //
+static int video_global_header = 0;
static int rate_emu = 0;
}
opkt.stream_index= ost->index;
- opkt.data= data_buf;
- opkt.size= data_size;
if(pkt->pts != AV_NOPTS_VALUE)
opkt.pts= av_rescale_q(av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base);
else
opkt.dts= av_rescale_q(dts + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base);
}
opkt.flags= pkt->flags;
+ if(av_parser_change(ist->st->parser, &ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY))
+ opkt.destruct= av_destruct_packet;
av_interleaved_write_frame(os, &opkt);
ost->st->codec.frame_number++;
ost->frame_number++;
+ av_free_packet(&opkt);
}
}
}
if(video_codec_tag)
video_enc->codec_tag= video_codec_tag;
- if (oc->oformat->flags & AVFMT_GLOBALHEADER)
+ if( (video_global_header&1)
+ || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER)))
video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
+ if(video_global_header&2)
+ video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
+
if (video_stream_copy) {
st->stream_copy = 1;
video_enc->codec_type = CODEC_TYPE_VIDEO;
{ "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
{ "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
{ "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
+ { "vglobal", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_global_header}, "video global header storage type", "" },
{ "copyts", OPT_BOOL | OPT_EXPERT, {(void*)©_ts}, "copy timestamps" },
{ "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
#define CODEC_FLAG2_FAST 0x00000001 ///< allow non spec compliant speedup tricks
#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< strictly enforce GOP size
#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< skip bitstream encoding
+#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< place global headers at every keyframe instead of in extradata
/* Unsupported options :
* Syntax Arithmetic coding (SAC)
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size);
void (*parser_close)(AVCodecParserContext *s);
+ int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
struct AVCodecParser *next;
} AVCodecParser;
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size,
int64_t pts, int64_t dts);
+int av_parser_change(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe);
void av_parser_close(AVCodecParserContext *s);
extern AVCodecParser mpegvideo_parser;
return index;
}
+int av_parser_change(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size, int keyframe){
+
+ if(s && s->parser->split){
+ if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) && !(avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){
+ int i= s->parser->split(avctx, buf, buf_size);
+ buf += i;
+ buf_size -= i;
+ }
+ }
+
+ *poutbuf= buf;
+ *poutbuf_size= buf_size;
+ if(avctx->extradata){
+ if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))
+ /*||(s->pict_type != I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
+ /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
+ int size= buf_size + avctx->extradata_size;
+ *poutbuf_size= size;
+ *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
+ memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
void av_parser_close(AVCodecParserContext *s)
{
if (s->parser->parser_close)
int frame_rate_ext_n, frame_rate_ext_d;
int picture_structure, top_field_first, repeat_first_field, progressive_frame;
int horiz_size_ext, vert_size_ext, bit_rate_ext;
-
+//FIXME replace the crap with get_bits()
s->repeat_pict = 0;
buf_end = buf + buf_size;
while (buf < buf_end) {
return next;
}
+static int mpegvideo_split(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ int i;
+ uint32_t state= -1;
+
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100)
+ return i-4;
+ }
+ return 0;
+}
+
void ff_parse_close(AVCodecParserContext *s)
{
ParseContext *pc = s->priv_data;
return next;
}
+static int mpeg4video_split(AVCodecContext *avctx,
+ const uint8_t *buf, int buf_size)
+{
+ int i;
+ uint32_t state= -1;
+
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if(state == 0x1B3 || state == 0x1B6)
+ return i-4;
+ }
+ return 0;
+}
+
/*************************/
typedef struct MpegAudioParseContext {
NULL,
mpegvideo_parse,
parse1_close,
+ mpegvideo_split,
};
AVCodecParser mpeg4video_parser = {
mpeg4video_parse_init,
mpeg4video_parse,
parse1_close,
+ mpeg4video_split,
};
AVCodecParser mpegaudio_parser = {
#define PKT_FLAG_KEY 0x0001
void av_destruct_packet_nofree(AVPacket *pkt);
+void av_destruct_packet(AVPacket *pkt);
/* initialize optional fields of a packet */
static inline void av_init_packet(AVPacket *pkt)
/**
* Default packet destructor
*/
-static void av_destruct_packet(AVPacket *pkt)
+void av_destruct_packet(AVPacket *pkt)
{
av_free(pkt->data);
pkt->data = NULL; pkt->size = 0;
/* select current input stream component */
st = s->cur_st;
if (st) {
- if (!st->parser) {
+ if (!st->need_parsing || !st->parser) {
/* no parsing needed: we just output the packet as is */
/* raw data support */
*pkt = s->cur_pkt;
/* return the last frames, if any */
for(i = 0; i < s->nb_streams; i++) {
st = s->streams[i];
- if (st->parser) {
+ if (st->parser && st->need_parsing) {
av_parser_parse(st->parser, &st->codec,
&pkt->data, &pkt->size,
NULL, 0,
if(!st->codec.time_base.num)
st->codec.time_base= st->time_base;
}
+ //only for the split stuff
+ if (!st->parser) {
+ st->parser = av_parser_init(st->codec.codec_id);
+ }
}
for(i=0;i<MAX_STREAMS;i++){
if( st->codec.time_base.den >= 1000LL*st->codec.time_base.num
&& duration_count[i]<20 && st->codec.codec_type == CODEC_TYPE_VIDEO)
break;
+ if(st->parser && st->parser->parser->split && !st->codec.extradata)
+ break;
}
if (i == ic->nb_streams) {
/* NOTE: if the format has no header, then we need to read
}
last_dts[pkt->stream_index]= pkt->dts;
}
+ if(st->parser && st->parser->parser->split && !st->codec.extradata){
+ int i= st->parser->parser->split(&st->codec, pkt->data, pkt->size);
+ if(i){
+ st->codec.extradata_size= i;
+ st->codec.extradata= av_malloc(st->codec.extradata_size);
+ memcpy(st->codec.extradata, pkt->data, st->codec.extradata_size);
+ }
+ }
+
/* if still no information, we try to open the codec and to
decompress the frame. We try to avoid that in most cases as
it takes longer and uses more memory. For MPEG4, we need to