| 1 | /* |
| 2 | * fix_headers.c |
| 3 | * |
| 4 | * Copyright (C) Peter Schlaile - January 2001 |
| 5 | * |
| 6 | * This file is part of libdv, a free DV (IEC 61834/SMPTE 314M) |
| 7 | * codec. |
| 8 | * |
| 9 | * libdv is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU Lesser Public License as published by |
| 11 | * the Free Software Foundation; either version 2.1, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | * libdv is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Lesser Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser Public License |
| 20 | * along with libdv; see the file COPYING. If not, write to |
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | * |
| 23 | * The libdv homepage is http://libdv.sourceforge.net/. |
| 24 | */ |
| 25 | |
| 26 | #include "libdv/dv_types.h" |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <unistd.h> |
| 31 | #include <string.h> |
| 32 | #include <assert.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <fcntl.h> |
| 36 | #include <time.h> |
| 37 | |
| 38 | #include <libdv/headers.h> |
| 39 | |
| 40 | int read_frame(FILE* in_fp, unsigned char* frame_buf, int * isPAL) |
| 41 | { |
| 42 | if (fread(frame_buf, 1, 120000, in_fp ) != 120000) { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | *isPAL = (frame_buf[3] & 0x80); |
| 47 | |
| 48 | if (*isPAL) { |
| 49 | if (fread(frame_buf + 120000, 1, 144000 - 120000, in_fp) != |
| 50 | 144000 - 120000) { |
| 51 | return 0; |
| 52 | } |
| 53 | } |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | int main(int argc, const char** argv) |
| 58 | { |
| 59 | unsigned char frame_buf[144000]; |
| 60 | int isPAL; |
| 61 | int frame_count = 0; |
| 62 | time_t t = time(NULL); |
| 63 | int wide = 0; |
| 64 | if (argc == 2 && strcmp(argv[1], "-w") == 0) { |
| 65 | wide = 1; |
| 66 | } |
| 67 | |
| 68 | while (read_frame(stdin, frame_buf, &isPAL)) { |
| 69 | _dv_write_meta_data(frame_buf, frame_count++, isPAL, wide, &t); |
| 70 | fwrite(frame_buf, 1, isPAL ? 144000 : 120000, stdout); |
| 71 | } |
| 72 | return 0; |
| 73 | } |