works better.
pre-buffer everything also.
Code: Select all
#LIBAVFORMAT_VERSION_INT = ((51<<16)+(12<<8)+1)
#LIBAVFORMAT_VERSION = "51.12.1"
#LIBAVFORMAT_BUILD = #LIBAVFORMAT_VERSION_INT
#LIBAVFORMAT_IDENT = "Lavf"
#MAX_REORDER_DELAY = 4
#AVFMTCTX_NOHEADER = $0001
#MAX_STREAMS = 20
#AVSEEK_FLAG_BACKWARD = 1
#AVSEEK_FLAG_BYTE = 2
#AVSEEK_FLAG_ANY = 4
#FFM_PACKET_SIZE = 4096
#AVPROBE_SCORE_MAX = 100
#AVPROBE_PADDING_SIZE = 32
#PKT_FLAG_KEY = $0001
#AVFMT_NOFILE = $0001
#AVFMT_NEEDNUMBER = $0002
#AVFMT_SHOW_IDS = $0008
#AVFMT_RAWPICTURE = $0020
#AVFMT_GLOBALHEADER = $0040
#AVFMT_NOTIMESTAMPS = $0080
#AVFMT_GENERIC_INDEX = $0100
#CODEC_CAP_PARSE_ONLY = $0004
#CODEC_CAP_TRUNCATED = $0008
#AV_PARSER_PTS_NB = 4
#PARSER_FLAG_COMPLETE_FRAMES = $0001
#AV_OPT_FLAG_ENCODING_PARAM = 1
#AV_OPT_FLAG_DECODING_PARAM = 2
#AV_OPT_FLAG_METADATA = 4
#AV_OPT_FLAG_AUDIO_PARAM = 8
#AV_OPT_FLAG_VIDEO_PARAM = 16
#AV_OPT_FLAG_SUBTITLE_PARAM = 32
#PIX_FMT_RGB24 = 2 ; from avutil.h
Structure ByteIOContext
*buffer.c ;unsigned char *buffer;
buffer_size.l ;int buffer_size;
*buf_ptr.c ;
*buf_end.c ;unsigned char *buf_ptr, *buf_end;
*opaque.l ;void *opaque;
*read_packet.l ;Int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
*write_packet.l ;Int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
offset.q
*seek.l ;whence.l;offset_t (*seek)(void *opaque, offset_t offset, int whence);
pos.q ;.offset_t pos; /**< position in the file of the current buffer */
must_flush.l; /**< true if the next seek should flush */
eof_reached.l; /**< true if eof reached */
write_flag.l; /**< true if open for writing */
is_streamed.l;
max_packet_size.l;
checksum.l;
*checksum_ptr.c;
*update_checksum.l ;unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
error.l; ///< contains the error code or 0 if no error happened
EndStructure
Structure AVRational
num.l
den.l
EndStructure
Structure AVPacket
pts.q
dts.q
*data.b
size.l
stream_index.l
flags.l
duration.l
*destruct.l
*priv.l
pos.q
EndStructure
Structure AVFrac ;attribute_deprecated
val.q
num.q
den.q
EndStructure
Structure AVProbeData
*filename.b
*buf.b
buf_size.l
EndStructure
Structure AVFormatParameters
time_base.AVRational
sample_rate.l;
channels.l
width.l
height.l
channel.l
*device.b
*standard.b
; PB header conversion did strange things below, just made longs out of them
mpeg2ts_raw.l
mpeg2ts_compute_pcr.l
initial_pause.l
prealloced_context.l
EndStructure
Structure AVOutputFormat
*name.b
*long_name.b
*mime_type.b
*extensions.b
priv_data_size.l
*write_header.l
*write_packet.l
*write_trailer.l
flags.l
*set_parameters.l
*interleave_packet.l
*next.AVOutputFormat
EndStructure
Structure AVInputFormat
*name.b
*long_name.b
priv_data_size.l
*read_probe.l
*read_header.l
*read_packet.l
*read_close.l
*read_seek.l
*read_timestamp.l
flags.l
*extensions.b
value.l
*read_play.l
*read_pause.l
*next.AVInputFormat
EndStructure
Structure AVIndexEntry
pos.q
timestamp.q
flags.l
size.l
min_distance.l
EndStructure
;typedef struct AVCLASS AVClass;
Structure AVClass
class_name.c ;const char* class_name;
*item_name.c ;const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
; Or AVFormatContext, which begin With an AVClass.
; Needed because av_log is in libavcodec And has no visibility
; of AVIn/OutputFormat */
EndStructure
Structure AVFormatContext
*av_class.AVClass
*iformat.AVInputFormat
*oformat.AVOutputFormat
*priv_data.l
pb.ByteIOContext
nb_streams.l
*streams.AVStream[#MAX_STREAMS]
filename.b[1024]
timestamp.q
title.b[512]
author.b[512]
copyright.b[512]
comment.b[512]
album.b[512]
year.l
track.l
genre.b[32]
ctx_flags.l
*packet_buffer.AVPacketList
start_time.q
duration.q
file_size.q
bit_rate.l
*cur_st.AVStream
*cur_ptr.b
cur_len.l
cur_pkt.AVPacket
data_offset.q
index_built.l
mux_rate.l
packet_size.l
preload.l
max_delay.l
loop_output.l
flags.l
loop_input.l
probesize.l
max_analyze_duration.l
*key.b
keylen.l
EndStructure
Structure RcOverride
start_frame.l;
end_frame.l;
qscale.l; // if this is 0 then quality_factor will be used instead
quality_factor.f;
EndStructure;
Structure AVCodecContext
bit_rate.l;
bit_rate_tolerance.l;
flags.l;
sub_id.l;
me_method.l;
*extradata.l ;void *extradata;
extradata_size.l;
frame_rate.l;
width.l
height.l;
gop_size.l;
pixfmt.l ;pixfmt.PixelFormat ;enum PixelFormat pix_fmt;
rate_emu.l;
*draw_horiz_band.l
;void (*draw_horiz_band)(struct AVCodecContext *s,
; AVFrame *src, int offset[4],
; int y, int type, int height);
sample_rate.l; ///< samples per sec
channels.l;
sample_fmt.l; ///< sample format, currenly unused
frame_size.l; ///< in samples, initialized when calling 'init'
frame_number.l; ///< audio or video frame number
real_pict_num.l; ///< returns the real picture number of previous encoded frame
delay.l;
qcompress.f ;float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
qblur.f ;float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
qmin.l;
qmax.l;
max_qdiff.l;
max_b_frames.l;
b_quant_factor.f;
rc_strategy.l;
b_frame_strategy.l;
hurry_up.l;
*codec.AVCodec ;struct AVCodec *codec;
*priv_data.l ;void *priv_data;
rtp_mode.l; /* 1 for activate RTP friendly-mode */
rtp_payload_size.l; /* The size of the RTP payload: the coder will */
*rtp_callback.l
;void (*rtp_callback)(void *Data, int data_size,
; void *hdr, int hdr_size, void *priv_data);
mv_bits.l;
header_bits.l;
i_tex_bits.l;
p_tex_bits.l;
i_count.l;
p_count.l;
skip_count.l;
misc_bits.l;
frame_bits.l;
*opaque.l ;void *opaque;
codec_name.c[32];
codec_type.l ;enum CodecType codec_type; /* see CODEC_TYPE_xxx */
codec_id.l ;enum CodecID codec_id; /* see CODEC_ID_xxx */
codec_tag.l ;unsigned codec_tag;
workaround_bugs.l;
luma_elim_threshold.l;
chroma_elim_threshold.l;
strict_std_compliance.l;
b_quant_offset.f;
error_resilience.l;
*get_buffer.l ;(*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
*release_buffer.l ;void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
has_b_frames.l;
block_align.l; ///< used by some WAV based audio codecs
parse_only.l; /* - decoding only: if true, only parsing is done
mpeg_quant.l;
*stats_out.c;
*stats_in.c;
rc_qsquish.f;
rc_qmod_amp.f;
rc_qmod_freq.l;
*rc_override.RcOverride;
rc_override_count.l;
*rc_eq.c;
rc_max_rate.l;
rc_min_rate.l;
rc_buffer_size.l;
rc_buffer_aggressivity.f;
i_quant_factor.f;
i_quant_offset.f;
rc_initial_cplx.f;
dct_algo.l;
lumi_masking.f;
temporal_cplx_masking.f;
spatial_cplx_masking.f;
p_masking.f;
dark_masking.f;
unused.l
idct_algo.l;
slice_count.l;
*slice_offset.l;
error_concealment.l;
dsp_mask.l ;unsigned dsp_mask;
bits_per_sample.l;
prediction_method.l;
aspect_ratio.f;
*coded_frame.AVFrame ;AVFrame *coded_frame;
Debug.l;
error.q[4] ;uint64_t error[4];
mb_qmin.l;
mb_qmax.l;
me_cmp.l;
me_sub_cmp.l;
mb_cmp.l;
dia_size.l;
last_predictor_count.l;
pre_me.l;
me_pre_cmp.l;
pre_dia_size.l;
me_subpel_quality.l;
*get_format.l ;enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
dtg_active_format.l;
me_range.l;
frame_rate_base.l;
intra_quant_bias.l;
inter_quant_bias.l;
color_table_id.l;
internal_buffer_count.l;
*internal_buffer.l ;void *internal_buffer;
global_quality.l;
coder_type.l;
context_model.l;
slice_flags.l;
xvmc_acceleration.l;
mb_decision.l;
*intra_matrix.w ;uint16_t *intra_matrix;
*inter_matrix.w ;uint16_t *inter_matrix;
EndStructure
Structure AVCodecParser
codec_ids.l[5] ;int codec_ids[5]; /* several codec IDs are permitted */
priv_data_size.l ;int priv_data_size;
*parser_init.l ;AVCodecParserContext ;Int (*parser_init)(AVCodecParserContext *s);
*parser_parse.l ;AVCodecParserContext ;Int (*parser_parse)(AVCodecParserContext *s,
; AVCodecContext *avctx,
; uint8_t **poutbuf, int *poutbuf_size,
; const uint8_t *buf, int buf_size);
*parser_close.l ;AVCodecParserContext ;void (*parser_close)(AVCodecParserContext *s);
*split.l ;AVCodecContect ;Int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
*next.AVCodecParser ;struct AVCodecParser *Next;
EndStructure
Structure AVCodecParserContext
*priv_data.l ;void *priv_data;
*parser.AVCodecParser ;struct AVCodecParser *parser;
frame_offset.q ;int64_t frame_offset; /* offset of the current frame */
cur_offset.q ;int64_t cur_offset; /* current offset
; (incremented by each av_parser_parse()) */
last_frame_offset.q ;int64_t last_frame_offset; /* offset of the last frame */
;/* video info */
pict_type.l ;int pict_type; /* XXX: put it back in AVCodecContext */
repeat_pict.l ;int repeat_pict; /* XXX: put it back in AVCodecContext */
pts.q ;int64_t pts; /* pts of the current frame */
dts.q ;int64_t dts; /* dts of the current frame */
;/* private Data */
last_pts.q ;int64_t last_pts;
last_dts.q ;int64_t last_dts;
fetch_timestamp.l ;int fetch_timestamp;
cur_frame_start_index.l ;int cur_frame_start_index;
cur_frame_offset.q[#AV_PARSER_PTS_NB] ;int64_t cur_frame_offset[#AV_PARSER_PTS_NB];
cur_frame_pts.q[#AV_PARSER_PTS_NB] ;int64_t cur_frame_pts[#AV_PARSER_PTS_NB];
cur_frame_dts.q[#AV_PARSER_PTS_NB] ;int64_t cur_frame_dts[#AV_PARSER_PTS_NB];
flags.l ;int flags;
EndStructure
Structure AVStream
index.l
id.l
*codec.AVCodecContext
r_frame_rate.AVRational
*priv_data.l
codec_info_duration.q
codec_info_nb_frames.l
pts.AVFrac
time_base.AVRational
pts_wrap_bits.l
stream_copy.l
quality.f
start_time.q
duration.q
language.b[4]
*parser.AVCodecParserContext
cur_dts.q
last_IP_duration.l
last_IP_pts.q
*index_entries.AVIndexEntry
nb_index_entries.l
index_entries_allocated_size.l
nb_frames.q
pts_buffer.q[#MAX_REORDER_DELAY+1]
EndStructure
Structure AVPacketList
pkt.AVPacket
*next.AVPacketList
EndStructure
Structure AVFrame
FF_COMMON_FRAME.l
EndStructure
Structure AVOption
*name.c ;const char *name;
*help.c ; const char *help;
offset.l ;int offset;
type.l ;AVOptionType ;enum AVOptionType type;
default_val.d ;double default_val;
min.d ;double min;
max.d ;double max;
flags.l ; int flags;
; //FIXME think about enc-audio, ... style flags
*unit.c ;const char *unit;
EndStructure
Structure AVCodec
*name.c ;const char *name;
type.l ;CodecType ;enum CodecType type;
id.l; int id;
priv_data_size.l ;int priv_data_size;
*init.l ;AVCodecContext ;Int (*init)(AVCodecContext *);
*encode.l ;AVCodecContext ;Int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *Data);
*close.l ;AVCodecContext ;Int (*close)(AVCodecContext *);
*decode.l ;AVCodecContext ;Int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
;*buf.b; uint8_t *buf, int buf_size);
capabilities.l;
*options.AVOption ;const AVOption *options;
*next.AVCodec ;struct AVCodec *Next;
*flush.l ;AVCodecContext ;void (*flush)(AVCodecContext *);
EndStructure
If OpenLibrary(0, "avformat-51.dll") And OpenLibrary(1, "avcodec-51.dll")
; ADJUST FILENAME TO YOUR LOCAL VIDEO FILE!!!!
; --------------------------------------------
;D:\persoonlijk\interesant\misc\blender_first_stage.avi
;D:\persoonlijk\interesant\bruinsma\bb.laatste-klaas[1].asf
;D:\video\BBC.Supernatural.Science.Electric.Hands.DivX521.MP3.www.mvgroup.org.avi
;D:\persoonlijk\interesant\Dekkers\bb.20061203.asf
filename.s = "D:\persoonlijk\interesant\Dekkers\bb.20061203.asf"
; vars..
*pFormatCtx.AVFormatContext
*pCodecCtx.AVCodecContext
*pCodec.AVCodec
*pFrame.AVFrame
*pFrameRGB.AVFrame
numBytes.l
; Library 0 -> AVFORMAT.
; ----------------------
;Result = ExamineLibraryFunctions(0)
;If Result
; While NextLibraryFunction()
; Debug LibraryFunctionName()
; Wend
;EndIf
*F = GetFunction(0, "av_register_all")
If *F
Debug "av_register_all: "+Str(CallFunctionFast(*F))
EndIf
*F = GetFunction(0, "av_open_input_file")
If *F
open = CallFunctionFast(*F, @*pFormatCtx, filename.s, #Null, 0, #Null )
Debug "av_open_input_file: "+Str(open)
EndIf
*F = GetFunction(0, "av_find_stream_info")
If *F And open>-1
streaminfo = CallFunctionFast(*F, *pFormatCtx)
Debug "av_find_stream_info: "+Str(streaminfo)
EndIf
*F = GetFunction(0, "dump_format")
If *F And open>-1 And streaminfo>0
dumpformat = CallFunctionFast(*F, *pFormatCtx, 0, filename.s, 0) ;#False)
Debug "dump_format: "+Str(dumpformat)
;; -------------------------------
;; LIST AVFormatContext structure:
;; -------------------------------
;Debug "-> Sub-structure: *av_class.AVClass";
;Debug " -> *av_class\class_name = "+Str(*pFormatCtx\av_class\class_name)
;Debug " -> *av_class\item_name = "+Str(*pFormatCtx\av_class\item_name)
;Debug "-> Sub-structure: *iformat.AVInputFormat"
;Debug " -> *iformat\name = "+PeekS(*pFormatCtx\iformat\name)
;Debug " -> *iformat\long_name = "+PeekS(*pFormatCtx\iformat\long_name)
;Debug " -> *iformat\priv_data_size:"+Str(*pFormatCtx\iformat\priv_data_size)
;Debug " -> *iformat\read_probe: "+Str(*pFormatCtx\iformat\read_probe)
;Debug " -> *iformat\read_header: "+Str(*pFormatCtx\iformat\read_header)
;Debug " -> *iformat\read_packet: "+Str(*pFormatCtx\iformat\read_packet)
;Debug " -> *iformat\read_close: "+Str(*pFormatCtx\iformat\read_close)
;Debug " -> *iformat\read_seek: "+Str(*pFormatCtx\iformat\read_seek)
;Debug " -> *iformat\read_timestamp:"+Str(*pFormatCtx\iformat\read_timestamp)
;Debug " -> *iformat\flags: "+Str(*pFormatCtx\iformat\flags)
;Debug " -> *iformat\extensions: "+Str(*pFormatCtx\iformat\extensions)
;Debug " -> *iformat\value: "+Str(*pFormatCtx\iformat\value)
;Debug " -> *iformat\read_play: "+Str(*pFormatCtx\iformat\read_play)
;Debug " -> *iformat\read_pause: "+Str(*pFormatCtx\iformat\read_pause)
;Debug " -> *iformat\*next: "+Str(*pFormatCtx\iformat\next)
;Debug "-> Sub-structure: *oformat.AVOutputFormat - NOT FILLED YET!"
;Debug "Priv_data: "+Str(*pFormatCtx\priv_data) ;.l
;; pb.ByteIOContext
; nb_streams.l
;*streams.AVStream[#MAX_STREAMS]
Debug "------- INFO --------"
a$=""
For a = 0 To 1024-1
a$ + Chr(*pFormatCtx\filename[a])
Next
Debug "Filename: "+a$ ; WHY WE MISS THE FIRST LETTER!!!!! Hmmmm ..
a$=""
For a = 0 To 512-1
a$ + Chr(*pFormatCtx\title[a])
Next
Debug "Title: "+a$
a$=""
For a = 0 To 512-1
a$ + Chr(*pFormatCtx\author[a])
Next
Debug "Author: "+a$
a$=""
For a = 0 To 512-1
a$ + Chr(*pFormatCtx\copyright[a])
Next
Debug "Copyright:"+a$
a$=""
For a = 0 To 512-1
a$ + Chr(*pFormatCtx\comment[a])
Next
Debug "Comment: "+a$
a$=""
For a = 0 To 512-1
a$ + Chr(*pFormatCtx\album[a])
Next
Debug "Album: "+a$
Debug "Year: "+Str(*pFormatCtx\year)
Debug "Track: "+Str(*pFormatCtx\track)
a$=""
For a = 0 To 32-1
a$ + Chr(*pFormatCtx\genre[a])
Next
Debug "Genre: "+a$
Debug "---------------------"
EndIf
Debug "Streams: "+Str(PeekL(*pFormatCtx\nb_streams)) ;PeekL(*oc\nb_streams))
For i=0 To PeekL(*pFormatCtx\nb_streams) ;PeekL(*oc\nb_streams)
If (*pFormatCtx\streams[i]\codec\codec_type=0) ;*oc\streams[i]\codec\codec_type = 0) ;#CODEC_TYPE_VIDEO)
Debug "We have a video stream.."
Else
Debug "We have no video stream.."
EndIf
Next
; Library 1 -> AVCODEC.
; ---------------------
;Result = ExamineLibraryFunctions(1)
;If Result
; While NextLibraryFunction()
; Debug LibraryFunctionName()
; Wend
;EndIf
;codec = avcodec_find_decoder(ccx->codec_id);
*F = GetFunction(1, "avcodec_find_decoder")
If *F And open>-1
*pCodecCtx = @*pFormatCtx\streams[0]\codec
*pCodec = CallFunctionFast(*F, *pCodecCtx\codec_id)
;*pCodec = CallFunctionFast(*F, *pFormatCtx\streams[0]\codec\codec_id)
Debug "avcodec_find_decoder: "+Str(*pCodec)
If *pCodec=#Null
Debug "No decoder codec!": End
EndIf
EndIf
; If(pCodec->capabilities & CODEC_CAP_TRUNCATED) pCodecCtx->flags|=CODEC_FLAG_TRUNCATED;
If (*pCodec\capabilities & #CODEC_CAP_TRUNCATED)
*pCodecCtx\flags = #CODEC_CAP_TRUNCATED
EndIf
;err = avcodec_open(ccx, codec);
*F = GetFunction(1, "avcodec_open")
If *F And open>-1
;err = CallFunctionFast(*F, @*pCodecCtx, *pCodec) ; this one gives error!!
err = CallFunctionFast(*F, *pFormatCtx\streams[0]\codec, *pCodec)
Debug "avcodec_open: "+Str(err)
EndIf
If open>-1 And err>-1
;;If(pCodecCtx->frame_rate>1000 && pCodecCtx->frame_rate_base==1)
;; pCodecCtx->frame_rate_base=1000;
;Debug *pCodecCtx\frame_rate
;Debug *pFormatCtx\streams[0]\codec\frame_rate
;Debug *pCodecCtx\frame_rate_base ;frame_rate
;Debug *pFormatCtx\streams[0]\codec\frame_rate_base ;frame_rate
;; Strange value's .. hmm ...
;pFrame=avcodec_alloc_frame();
*F = GetFunction(1, "avcodec_alloc_frame")
If *F And open>-1
*pFrame = CallFunctionFast(*F) ;, *pFormatCtx\streams[0]\codec, *pCodec)
Debug "avcodec_alloc_frame: "+Str(*pFrame)
If *pFrame
;// Allocate an AVFrame Structure
;pFrameRGB=avcodec_alloc_frame(); ;If(pFrameRGB==NULL) ; Return -1;
*F = GetFunction(1, "avcodec_alloc_frame")
If *F And open>-1
*pFrameRGB = CallFunctionFast(*F)
Debug "avcodec_alloc_frame: "+Str(*pFrameRGB)
;// Determine required buffer size And allocate buffer
;numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
; pCodecCtx->height);
;buffer=new uint8_t[numBytes];
*F = GetFunction(1, "avpicture_get_size")
If *F
;numBytes = CallFunctionFast(*F, #PIX_FMT_RGB24, *pCodecCtx\width, *pCodecCtx\height)
; *pFormatCtx\streams[0]\codec
numBytes = CallFunctionFast(*F, #PIX_FMT_RGB24, *pFormatCtx\streams[0]\codec\width,@*pFormatCtx\streams[0]\codec\height)
If numBytes
*buffer = AllocateMemory(numBytes)
;Debug *pFormatCtx\streams[0]\codec\width ; 1000 ?????
;Debug *pFormatCtx\streams[0]\codec\height; 1 ?????
;// Assign appropriate parts of buffer To image planes in pFrameRGB
;avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
; pCodecCtx->width, pCodecCtx->height);
*F = GetFunction(1, "avpicture_fill")
If *F
err = CallFunctionFast(*F, *pFrameRGB, *buffer, #PIX_FMT_RGB24, *pFormatCtx\streams[0]\codec\width, *pFormatCtx\streams[0]\codec\height)
Debug "avpicture_fill: "+Str(err)
EndIf
FreeMemory(*buffer)
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
CloseLibrary(0)
CloseLibrary(1)
EndIf
End
Still help needed...