| 1 |
/* dvbcut |
| 2 |
Copyright (c) 2005 Sven Over <[email protected]> |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id$ */ |
| 20 |
|
| 21 |
#ifndef _DVBCUT_LAVFMUXER_H |
| 22 |
#define _DVBCUT_LAVFMUXER_H |
| 23 |
|
| 24 |
extern "C" { |
| 25 |
#include <libavformat/avformat.h> |
| 26 |
} |
| 27 |
|
| 28 |
#include "mpgfile.h" |
| 29 |
#include "muxer.h" |
| 30 |
|
| 31 |
/** |
| 32 |
@author Sven Over |
| 33 |
*/ |
| 34 |
class lavfmuxer : public muxer |
| 35 |
{ |
| 36 |
protected: |
| 37 |
struct stream |
| 38 |
{ |
| 39 |
AVStream *avstr; |
| 40 |
int stream_index; |
| 41 |
|
| 42 |
stream() : avstr(0), stream_index(0) |
| 43 |
{} |
| 44 |
~stream() |
| 45 |
{ |
| 46 |
if (avstr) |
| 47 |
av_free(avstr); |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
const AVOutputFormat *fmt; |
| 52 |
AVFormatContext *avfc; |
| 53 |
|
| 54 |
stream st[MAXAVSTREAMS]; |
| 55 |
|
| 56 |
bool fileopened; |
| 57 |
|
| 58 |
public: |
| 59 |
lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg, const char *filename); |
| 60 |
|
| 61 |
~lavfmuxer(); |
| 62 |
|
| 63 |
bool putpacket(int str, const void *data, int len, pts_t pts, pts_t dts, uint32_t flags=0) |
| 64 |
{ |
| 65 |
if (len<=0) |
| 66 |
return 0; |
| 67 |
|
| 68 |
AVPacket* avp = av_packet_alloc(); |
| 69 |
avp->data = (uint8_t*)data; |
| 70 |
avp->size = len; |
| 71 |
avp->pts = pts; |
| 72 |
avp->dts = dts; |
| 73 |
avp->stream_index = st[str].stream_index; |
| 74 |
if (flags & MUXER_FLAG_KEY) |
| 75 |
avp->flags |= AV_PKT_FLAG_KEY; |
| 76 |
|
| 77 |
int rv = av_interleaved_write_frame(avfc, avp); |
| 78 |
|
| 79 |
av_packet_free(&avp); |
| 80 |
return rv>=0; |
| 81 |
} |
| 82 |
|
| 83 |
virtual bool ready() |
| 84 |
{ |
| 85 |
return bool(avfc); |
| 86 |
} |
| 87 |
virtual void finish() |
| 88 |
{ |
| 89 |
return; |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
#endif |