Commit 118e91f3 authored by Roman Shaposhnik's avatar Roman Shaposhnik

* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now

     possible. For example you can do:

          ffmpeg -i i.dv -i audio_track.mp3 -map 0.0 -map 1.0 \
	         -vcodec copy -acodec pcm_s16le out.dv

   * Preparations for getting rid of DVAUDIO codec, DV stream really
     contains PCM audio, so there's no codec needed if we have a
     decent demuxer.

   * Providing entry points for dv1394 write support.

Originally committed as revision 2174 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 8c5b5683
......@@ -13,7 +13,7 @@ PPOBJS=
# mux and demuxes
OBJS+=mpeg.o mpegts.o mpegtsenc.o ffm.o crc.o img.o raw.o rm.o \
avienc.o avidec.o wav.o swf.o au.o gif.o mov.o mpjpeg.o dv.o \
avienc.o avidec.o wav.o swf.o au.o gif.o mov.o mpjpeg.o dvcore.o dv.o \
yuv4mpeg.o 4xm.o flvenc.o flvdec.o movenc.o
ifeq ($(CONFIG_RISKY),yes)
......
......@@ -17,13 +17,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "avformat.h"
#define NTSC_FRAME_SIZE 120000
#define PAL_FRAME_SIZE 144000
#include "dvcore.h"
typedef struct DVDemuxContext {
int is_audio;
uint8_t buf[PAL_FRAME_SIZE];
uint8_t buf[144000];
int size;
} DVDemuxContext;
......@@ -39,7 +37,7 @@ static int dv_read_header(AVFormatContext *s,
return AVERROR_NOMEM;
vst->codec.codec_type = CODEC_TYPE_VIDEO;
vst->codec.codec_id = CODEC_ID_DVVIDEO;
vst->codec.bit_rate = 25000000;
ast = av_new_stream(s, 1);
if (!ast)
......@@ -60,18 +58,14 @@ static void __destruct_pkt(struct AVPacket *pkt)
static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, dsf;
int ret;
DVDemuxContext *c = s->priv_data;
if (!c->is_audio) {
ret = get_buffer(&s->pb, c->buf, 4);
if (ret <= 0)
return -EIO;
dsf = c->buf[3] & 0x80;
if (!dsf)
c->size = NTSC_FRAME_SIZE;
else
c->size = PAL_FRAME_SIZE;
c->size = dv_frame_profile(&c->buf[0])->frame_size;
ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
if (ret <= 0)
......@@ -94,20 +88,16 @@ static int dv_read_close(AVFormatContext *s)
return 0;
}
static AVInputFormat dv_iformat = {
"dv",
"DV video format",
sizeof(DVDemuxContext),
NULL,
dv_read_header,
dv_read_packet,
dv_read_close,
.extensions = "dv",
};
int dv_write_header(struct AVFormatContext *s)
{
DVMuxContext *c = s->priv_data;
if (s->nb_streams != 2 || dv_core_init(c, s->streams) != 0) {
fprintf(stderr, "Can't initialize DV format!\n"
"Make sure that you supply exactly two streams:\n"
" video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n");
return -1;
}
return 0;
}
......@@ -115,24 +105,52 @@ int dv_write_packet(struct AVFormatContext *s,
int stream_index,
unsigned char *buf, int size, int force_pts)
{
put_buffer(&s->pb, buf, size);
put_flush_packet(&s->pb);
DVMuxContext *c = s->priv_data;
if (stream_index == c->vst)
dv_assemble_frame(c, buf, NULL, 0);
else
dv_assemble_frame(c, NULL, buf, size);
if (c->has_audio && c->has_video) {
put_buffer(&s->pb, &c->frame_buf[0], c->sys->frame_size);
put_flush_packet(&s->pb);
}
return 0;
}
/*
* We might end up with some extra A/V data without matching counterpart.
* E.g. video data without enough audio to write the complete frame.
* Currently we simply drop the last frame. I don't know whether this
* is the best strategy of all
*/
int dv_write_trailer(struct AVFormatContext *s)
{
dv_core_delete((DVMuxContext *)s->priv_data);
return 0;
}
static AVInputFormat dv_iformat = {
"dv",
"DV video format",
sizeof(DVDemuxContext),
NULL,
dv_read_header,
dv_read_packet,
dv_read_close,
.extensions = "dv",
};
AVOutputFormat dv_oformat = {
"dv",
"DV video format",
NULL,
"dv",
0,
sizeof(DVMuxContext),
CODEC_ID_PCM_S16LE,
CODEC_ID_DVVIDEO,
CODEC_ID_DVAUDIO,
dv_write_header,
dv_write_packet,
dv_write_trailer,
......
This diff is collapsed.
/*
* DV format muxer/demuxer
* Copyright (c) 2003 Roman Shaposhnik
*
* Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
* of DV technical info, and SMPTE 314M specification.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <time.h>
#include "avformat.h"
/*
* DVprofile is used to express the differences between various
* DV flavors. For now it's primarily used for differentiating
* 525/60 and 625/50, but the plans are to use it for various
* DV specs as well (e.g. SMPTE314M vs. IEC 61834).
*/
typedef struct DVprofile {
int dsf; /* value of the dsf in the DV header */
int frame_size; /* total size of one frame in bytes */
int difseg_size; /* number of DIF segments */
int frame_rate;
int frame_rate_base;
int ltc_divisor; /* FPS from the LTS standpoint */
int height; /* picture height in pixels */
uint16_t *video_place; /* positions of all DV macro blocks */
int audio_stride; /* size of audio_shuffle table */
int audio_min_samples[3]; /* min ammount of audio samples */
/* for 48Khz, 44.1Khz and 32Khz */
int audio_samples_dist[5];/* how many samples are supposed to be */
/* in each frame in a 5 frames window */
const uint16_t (*audio_shuffle)[9]; /* PCM shuffling table */
} DVprofile;
typedef struct DVMuxContext {
const DVprofile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */
uint8_t frame_buf[144000]; /* frame under contruction */
FifoBuffer audio_data; /* Fifo for storing excessive amounts of PCM */
int frames; /* Number of a current frame */
time_t start_time; /* Start time of recording */
uint8_t aspect; /* Aspect ID 0 - 4:3, 7 - 16:9 */
int ast, vst; /* Audio and Video stream indecies */
int has_audio; /* frame under contruction has audio */
int has_video; /* frame under contruction has video */
} DVMuxContext;
void dv_format_frame(DVMuxContext *, uint8_t*);
void dv_inject_audio(DVMuxContext *, uint8_t*, uint8_t*);
void dv_inject_video(DVMuxContext *, uint8_t*, uint8_t*);
int dv_extract_audio(uint8_t*, uint8_t*, AVCodecContext*);
int dv_audio_frame_size(const DVprofile*, int);
void dv_assemble_frame(DVMuxContext *, uint8_t*, uint8_t*, int);
int dv_core_init(DVMuxContext *, AVStream*[]);
void dv_core_delete(DVMuxContext *);
const DVprofile* dv_frame_profile(uint8_t*);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment