/* * extract_audio.c - extracts DVD audio channel from a VOB file * Copyright (C) 2000 Samuel Hocevar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* open */ #include /* printf */ #include int main (int argc, char *argv[]) { unsigned char c[65536]; unsigned int id, type, dummy, size, useful = 0, invalid = 0; int data; fprintf(stderr, "usage: %s ID\nID : audio stream (0, 1, 2...)\nstdin : VOB stream\nstdout : extracted audio\n", argv[0]); if (argc != 2) { exit (1); } id = atoi(argv[1]) + 0xc0; /* read the stream - 2048 bytes each time */ data = read(0, &c, 4); while (data) { if ((c[0] != 0x00) || (c[1] != 0x00) || (c[2] != 0x01)) { invalid++; c[0] = c[1]; c[1] = c[2]; c[2] = c[3]; data = read(0, &(c[3]), 1); continue; } if( invalid ) { if( useful ) { fprintf(stderr, "wrote %i valid bytes\n", useful); useful = 0; } fprintf(stderr, "skipped %i invalid bytes\n", invalid); invalid = 0; } //fprintf(stderr, "OK %.2x\n", c[3]); /* Skip 00 00 01 BA */ if( c[3] == 0xba ) { read(0, &c, 10); } else { dummy = c[3]; read( 0, &c, 2 ); size = ((c[0] << 8) | c[1]); read(0, &c, size); if( dummy == id ) { //fprintf(stderr, "size %.4x\n", size); dummy = 10; write(1, &(c[dummy]), size-dummy); useful += size - dummy; } } data = read(0, &c, 4); } fprintf(stderr, "wrote %i valid bytes\n", useful); }