Kirjoittaja Aihe: C:llä tehdyn ohjelman muokkaus -> .vro tiedostosta nauhoitus ajat ulos  (Luettu 1652 kertaa)

heksa

  • Käyttäjä
  • Viestejä: 53
    • Profiili
vrosplit ohjelma kopioi VRO tiedostosta filmin ja pätkii sen nauhoitusten mukaan kovalevylle. voisiko joku muokata tuota sen verran että se tulostaisi vain nauhoitusten ajat, eikä kopioisi mitään minnekkään, koska nyt joutuu odottamaan kaksinkertaisen ajan jotta tuon saa standardi dvd-videoksi?

ohjelman tuloste
Koodia: [Valitse]
/home/kayttaja/Videot/a1.mpg: 00:00:00.000-00:59:05.332
/home/kayttaja/Videot/a2.mpg: 00:00:00.000-00:09:43.701

vrosplit.h
Koodia: [Valitse]
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <argp.h>
#include <stdio.h>
#include <printf.h>
#include <string.h>
#include <err.h>

const char*argp_program_version="vrosplit 0.12";
const char*template="%d.mpeg";
const char*srcname="/media/dvd/DVD_RTAV/VR_MOVIE.VRO";


#define SECTOR_SIZE   2048
#define PACKET_START 0x1BA
#define FALSE 0

unsigned char sector_buffer[SECTOR_SIZE];
_Bool icaught;

error_t parse_opt(int key,char*arg,struct argp_state*state){
  switch(key){
    case'i':
      srcname=arg;
    case ARGP_KEY_END:
      return 0;

    case ARGP_KEY_ARG:
      if(!state->arg_num){
char*p;
int type[2];
int n=parse_printf_format(template=arg,2,type);
if(n==1){
  if(*type==PA_INT)
    return 0;
  p="Illegal conversion specification";
}else
  p=n<1?"No numeric conversion specification"
       :"Two or more conversion specifications";
argp_error(state,"%s: %s",arg,p);
      }
  }
  return ARGP_ERR_UNKNOWN;
}

void catch_alarm(int sig){
  icaught=signal(sig,catch_alarm);
}

inline double scr(void){
  const uint8_t*p=sector_buffer+4;
  uint_least64_t uscr=
    ((uint64_t)(*p&070)<<27) //     b7  b6  b5  b4  b3  b2  b1  b0
    +((ntohl(*(uint32_t*)(p-1)) //--+---------------------------------
       &0x3FFF8)<<12) // 0: 0   1 s32 s31 s30   1 s29 s28
    +((ntohl(*(uint32_t*)(p+1)) // 1: s27 s26 s25 s24 s23 s22 s21 s20
       &0x3FFF8)>>3); // 2: s19 s18 s17 s16 s15   1 s14 s13
  uint_least16_t ext= // 3: s12 s11 s10 s09 s08 s07 s06 s05
    (ntohs(*(uint16_t*)(p+4)) // 4: s04 s03 s02 s01 s00   1 e08 e07
     &0x3FE)>> 1; // 5: e06 e05 e04 e03 e02 e01 e00   1

  return uscr/90e3+ext/27e6;
};

#define BACKSCR 0x100
static void printSCR(double s,int c){
  if(c&BACKSCR)
    printf("\b\b\b\b\b\b\b\b\b\b\b\b");

  unsigned h= s /3600;
  unsigned m=(s-=h*3600)/  60;
  printf("%02u:%02u:%06.3f",h,m,s-m*60);

  if(c&=0xFF)
    putchar(c);

  fflush(stdout);
  icaught=FALSE;
}

int main(int argc,char*argv[]){
  argp_parse(&(struct argp){
       (struct argp_option[]){
{ "input", 'i', "VR_MOVIE.VRO", 0,
   "Input from VR_MOVIE.VRO" },
{ NULL }
       },parse_opt,"[template%02d.mpg]",
       "Split a VR-formatted DVD file to each titles"
     },argc,argv,0,NULL,NULL);
  FILE*src;
  if(!(src=fopen(srcname,"r")))
    err(EXIT_FAILURE,srcname);

  signal(SIGALRM,catch_alarm);
  setitimer(ITIMER_REAL,&(struct itimerval){{1},{1}},NULL);

  uint_least32_t packet_startn=htonl(PACKET_START);
  if(1>fread(sector_buffer,SECTOR_SIZE,1,src)){
    if(!feof(src))
rerr: err(EXIT_FAILURE,srcname);

    errx(EXIT_FAILURE,"%s: %s: File empty\n",
program_invocation_short_name,srcname);
  }
  for(int i=1;;){
    char*fname;
    asprintf(&fname,template,i++);

    FILE*dest;
    if(!(dest=fopen(fname,"w")))
werr: err(EXIT_FAILURE,fname);

    double last_scr;
    printf("%s: ",fname);
    printSCR(last_scr=scr(),'-');
    printSCR(last_scr,0);

    for(;;){
      if(1>fwrite(sector_buffer,SECTOR_SIZE,1,dest))
goto werr;

      if(1>fread(sector_buffer,SECTOR_SIZE,1,src)){
if(!feof(src))
  goto rerr;

printSCR(last_scr,BACKSCR|'\n');
return EXIT_SUCCESS;
      }
      if(*(uint32_t*)sector_buffer==packet_startn){
double t=scr();
if(t<last_scr)
  break;

if(icaught)
  printSCR(t,BACKSCR);

last_scr=t;
      }
    }
    printSCR(last_scr,BACKSCR|'\n');
    if(fclose(dest))
      goto werr;

    free(fname);
  }
}

koodi on GNU lisenssin alaista