Hello,
I am trying to do the equivalent of
ffmpeg -f dvd -acodec copy -vcodec copy -scodec copy -i foo.ts foo.mpg
with as little CPU as possible. I do _not_ want any decoding/encoding
to be done. Simply demux the Transport Stream and mux it into a Program
Stream.
I have worked through the tutorial, output_example.c and read through
the mailing list archives. But I can still not figure out how to do
that properly. The program keeps crashing with SIGFPE.
I have attached my code as well as output from gdb below. I guess the
loop titled "Copy all stream information" fails to initialize important
attributes. Any ideas what I have messed up?
Here is the code:
# include <stdlib.h>
# include <string.h>
# include <ffmpeg/avformat.h>
static char *progname;
# define FATAL(args) { \
stdout = stderr; \
printf ("%s:%s:%d ", progname, __FILE__, __LINE__); \
printf args; \
printf ("\n"); \
exit (EXIT_FAILURE); \
}
int main (int argc, char *argv[])
{
int i;
AVPacket packet;
AVFormatContext *InFmtCtx;
AVFormatContext *OutFmtCtx;
char *infile = argv[1];
char *outfile = argv[2];
progname = argv[0];
if (argc!=3) FATAL (("Usage: tstops <infile> <outfile>"));
/* Do I really need to register all formats/codecs/whatever?
I only need MPEG-TS and MPEG-PS
*/
av_register_all ();
/* Open input
*/
if (av_open_input_file (&InFmtCtx, infile, NULL, 0, NULL))
FATAL (("Can not open input file '%s'", infile));
if (av_find_stream_info (InFmtCtx) < 0)
FATAL (("Can not find stream info"));
/* Open output
*/
if (!(OutFmtCtx = av_alloc_format_context ()))
FATAL (("No memory"));
/* "dvd" gives MPEG-PS? Why not mpegps in analogy to mpegts?
*/
if (!(OutFmtCtx->oformat = guess_format ("dvd", NULL, NULL)))
FATAL (("Can not determine output format"));
av_strlcpy (OutFmtCtx->filename, outfile, sizeof (OutFmtCtx->filename));
/* Copy all stream information
*/
for (i=0; i<InFmtCtx->nb_streams; i++) {
AVStream *st;
if (!(st = av_new_stream (OutFmtCtx, i)))
FATAL (("Can not add stream %d\n", i));
st->codec = InFmtCtx->streams[i]->codec;
st->stream_copy = 1;
}
/* What is this good for?
*/
if (av_set_parameters (OutFmtCtx, NULL))
FATAL (("Invalid output format parameters"));
dump_format (InFmtCtx, 0, infile, 0);
dump_format (OutFmtCtx, 0, outfile, 1);
if (!(OutFmtCtx->oformat->flags & AVFMT_NOFILE)) {
if (url_fopen (&OutFmtCtx->pb, outfile, URL_WRONLY) < 0) {
FATAL (("Could not open '%s'\n", outfile));
}
}
/* here we start the conversion
*/
av_write_header (OutFmtCtx); /* Here I get SIGFPE */
while (av_read_frame (InFmtCtx, &packet) >= 0) {
if (av_write_frame (OutFmtCtx, &packet))
FATAL (("Write frame failed"));
av_free_packet (&packet);
}
/* Close the files
*/
av_close_input_file (InFmtCtx);
if (!(OutFmtCtx->oformat->flags & AVFMT_NOFILE))
url_fclose (OutFmtCtx->pb);
/* Free the streams
*/
av_free (OutFmtCtx);
exit (0);
}
And here is the gdb output
[EMAIL PROTECTED]:~> make
cc -g -lavformat -lavcodec -lavutil -lswscale -lSDL -o tstops tstops.c
gdb --args ./tstops ../z.ts ../z.ps
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...Using host libthread_db library
"/lib/tls/libthread_db.so.1".
[Thread debugging using libthread_db enabled]
[New Thread 1089876704 (LWP 1690)]
Input #0, mpegts, from '../z.ts':
Duration: 00:00:33.2, start: 49407.058411, bitrate: 5735 kb/s
Program 28006
Stream #0.0[0x6e]: Video: mpeg2video, yuv420p, 720x576 [PAR 64:45 DAR
16:9], 15000 kb/s, 25.00 tb(r)
Stream #0.1[0x78](deu): Audio: mp2, 48000 Hz, stereo, 256 kb/s
Stream #0.2[0x79](2ch): Audio: mp2, 48000 Hz, mono, 128 kb/s
Stream #0.3[0x7d](dd): Audio: liba52
Stream #0.4[0x83](deu): Subtitle: dvbsub
Output #0, dvd, to '../z.ps':
Stream #0.0: Video: mpeg2video, yuv420p, 720x576 [PAR 64:45 DAR 16:9],
q=2-31, 15000 kb/s, 25.00 tb(c)
Stream #0.1: Audio: libmp3lame, 48000 Hz, stereo, 256 kb/s
Stream #0.2: Audio: libmp3lame, 48000 Hz, mono, 128 kb/s
Stream #0.3: Audio: ac3
Stream #0.4: Subtitle: dvbsub
[dvd @ 0x400b0400]sample rate not set
Program received signal SIGFPE, Arithmetic exception.
[Switching to Thread 1089876704 (LWP 1690)]
0x400af987 in udp_set_remote_url () from /usr/lib/libavformat.so.52
(gdb) bt
#0 0x400af987 in udp_set_remote_url () from /usr/lib/libavformat.so.52
#1 0x4005267b in av_write_header () from /usr/lib/libavformat.so.52
(gdb)
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user