Back Forum Reply New

Rip (with DVDx) amp; encoding (with ffmpeg) on the fly

Well, shortly, I want to rip DVD with DVDx and encode ripped data with ffmpeg. But I dont still understand how transfer ripped frame from DVDx to ffmpeg:

DVDx Ripping function:

Code:
MPEG2GetFrameData( FRAME *yuv_frame , int *width,int *height, short int **samples, int *nb_sample )
... returns such ripped frame:

Code:
typedef struct { byte *y; byte *u; byte *v; byte *a; int  id; double  pts; int sy; int ey;
} FRAME;
/////////////////
So, that frame, I must tranfer on input to ffmpeg functions:

ffmpeg encoding function:

Code:
av_encode(output_files, nb_output_files, input_files, nb_input_files, stream_maps, nb_stream_maps);
inside this function:Code:
...   av_read_frame(is, amp;pkt)   av_pkt_dump(stdout, amp;pkt, do_hex_dump);   output_packet(ist, ist_index, ost_table, nb_ostreams, amp;pkt);   av_free_packet(amp;pkt);
...
//////////////////
where:

Code:
AVFormatContext *is, *os;
AVOutputStream *ost, **ost_table;
AVInputStream *ist, **ist_table;
AVFormatContext *input_files[MAX_FILES];
AVFormatContext *output_files[MAX_FILES];
///////////////////////
typedef struct AVPacket {   int64_t pts; /* presentation time stamp in AV_TIME_BASE units (or        pts_den units in muxers or demuxers) */   int64_t dts; /* decompression time stamp in AV_TIME_BASE units (or        pts_den units in muxers or demuxers) */   uint8_t *data;   int   size;   int   stream_index;   int   flags;   int   duration; /* presentation duration (0 if not available) */   void  (*destruct)(struct AVPacket *);   void  *priv;
} AVPacket;  
//////////////////////
typedef struct AVOutputStream {   int file_index;          /* file index */   int index;               /* stream index in the output file */   int source_index;        /* AVInputStream index */   AVStream *st;            /* stream in the output file */   int encoding_needed;     /* true if encoding needed for this stream */   int frame_number;   /* input pts and corresponding output pts      for A/V sync */   double sync_ipts;        /* dts from the AVPacket of the demuxer in second units */   int64_t sync_opts;       /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number   /* video only */   int video_resample;      /* video_resample and video_crop are mutually exclusive */   AVFrame pict_tmp;      /* temporary image for resampling */   ingReSampleContext *ing_resample_ctx; /* for image resampling */
   int video_crop;          /* video_resample and video_crop are mutually exclusive */   int topBand;             /* cropping area sizes */   int leftBand;      int video_pad;           /* video_resample and video_pad are mutually exclusive */   int padtop;              /* padding area sizes */   int padbottom;   int padleft;   int padright;      /* audio only */   int audio_resample;   ReSampleContext *resample; /* for audio resampling */   FifoBuffer fifo;     /* for compression: one audio fifo per codec */   FILE *logfile;
} AVOutputStream;
////////////////////////////////////////
typedef struct AVInputStream {   int file_index;   int index;   AVStream *st;   int discard;             /* true if stream data should be discarded */   int decoding_needed;     /* true if the packets must be decoded in 'raw_fifo' */   int64_t sample_index;      /* current sample */
   int64_t       start;     /* time when read started */   unsigned long frame;     /* current frame */   int64_t       next_pts;  /* synthetic pts for cases where pkt.pts                    is not defined */   int64_t       pts;       /* current pts */   int is_start;            /* is 1 at the start and after a discontinuity */
} AVInputStream;
/////////////////////////////////////////
typedef struct AVFormatContext {   AVClass *av_class; /* set by av_alloc_format_context */   /* can only be iformat or oformat, not both at the same time */   struct AVInputFormat *iformat;   struct AVOutputFormat *oformat;   void *priv_data;   ByteIOContext pb;   int nb_streams;   AVStream *streams[MAX_STREAMS];   char filename[1024]; /* input or output filename */   /* stream info */   int64_t timestamp;   char title[512];   char author[512];   char copyright[512];   char comment[512];   char album[512];   int year;  /* ID3 year, 0 if none */   int track; /* track number, 0 if none */   char genre[32]; /* ID3 genre */
   int ctx_flags; /* format specific flags, see AVFMTCTX_xx */   /* private data for pts handling (do not modify directly) */   /* This buffer is only needed when packets were already buffered but      not decoded, for example to get the codec parameters in mpeg      streams */   struct AVPacketList *packet_buffer;
   /* decoding: position of the first frame of the component, in      AV_TIME_BASE fractional seconds. NEVER set this value directly:      it is deduced from the AVStream values.  */   int64_t start_time;    /* decoding: duration of the stream, in AV_TIME_BASE fractional      seconds. NEVER set this value directly: it is deduced from the      AVStream values.  */   int64_t duration;   /* decoding: total file size. 0 if unknown */   int64_t file_size;   /* decoding: total stream bitrate in bit/s, 0 if not      available. Never set it directly if the file_size and the      duration are known as ffmpeg can compute it automatically. */   int bit_rate;
   /* av_read_frame() support */   AVStream *cur_st;   const uint8_t *cur_ptr;   int cur_len;   AVPacket cur_pkt;
   /* av_seek_frame() support */   int64_t data_offset; /* offset of the first packet */   int index_built;
} AVFormatContext;
/////////////////////////////////////////////////////////////////////////////////////////////

So, I have the frame and I need to transfer it to ffmpeg structures. I must make ffmpeg to work directly with frames to convert video on the fly. Please, help me understand how to do it.Sorry, I have no insight into usage of ffmpeg/libavcodec, too. On ffmpeg page is a example code how to use libavcodec to open a file:
~boehm...ibavcodec.html

If you do not get any usable answeres and hints here, I would recommend ffmpeg mailing lists.

Hellfred

EDIT:
In libavcodec/apiexample.c is an example code how to encode with liabvcodec. There the frames are stored in an instance of AVFrame and feed to the selected coded by the use of a methode called avcodec_encode_video(...).

moved

Really interesting, you're building a DVDx mod... cool !

Check out FairUse (links in my signature) too !

Here's my open source DVD tools / Encoders list @ ReactOS wiki.
¥
Back Forum Reply New