PREFIX = /usr/local
TARGETS = cmcheckwave
-OBJ_TARGETS = cmcheckwave.o
+OBJ_TARGETS = cmcheckwave.o tclist.o
LANG=C
CC = gcc
#include <unistd.h>
#include <assert.h>
+#include "tclist.h"
+
static void usage(void){
exit(1);
}
static int defmax=9;
static int thumb=0;
static int txtrecheck=0;
+static int cmdexecute=0;
static char *MP4BOXCMD="/usr/local/bin/MP4Box -quiet -noprog";
static char *MP4BOXCMDRAPSTR="Adjusting chunk start time to previous random access at ";
{
int honstart,hcnt,totalsec;
int i,pre;
+ char *cptr,*cptr2,*tfptr;
+ TCLIST *cmdlist;
+ TCLIST *tflist;
honstart=0;
hcnt=0;
printf("# total %.2f\n\n",totalsec/1000.0);
+ cmdlist = tclistnew();
+ tflist = tclistnew();
for(i=0;i<hcnt;i++) {
if (wkfilename) {
- printf("%s -splitx %.2f:%.2f %s -out %s.%d%s\n",MP4BOXCMD,h[i].stsec/1000.0,h[i].edsec/1000.0,wkfilename,wkfilename,i,noaudioencode?".mp4":"");
+ asprintf(&tfptr,"%s.%d%s",wkfilename,i,noaudioencode?".mp4":"");
+ asprintf(&cptr,"%s -splitx %.2f:%.2f %s -out %s",MP4BOXCMD,h[i].stsec/1000.0,h[i].edsec/1000.0,wkfilename,tfptr);
+ tclistpush2(cmdlist,cptr);
+ tclistpush2(tflist,tfptr);
+ free(tfptr);
+ free(cptr);
+
if (!noaudioencode) {
- printf("%s -v 0 -i %s.%d -vn %s.%d.wav\n",FFMPEGCMD,wkfilename,i,wkfilename,i);
- printf("%s -v 0 -i %s.%d -an -vcodec copy %s.%d.mp4\n",FFMPEGCMD,wkfilename,i,wkfilename,i);
+ asprintf(&tfptr,"%s.%d.wav",wkfilename,i);
+
+ asprintf(&cptr,"%s -v 0 -i %s.%d -vn %s",FFMPEGCMD,wkfilename,i,tfptr);
+ tclistpush2(cmdlist,cptr);
+ tclistpush2(tflist,tfptr);
+ free(tfptr);
+ free(cptr);
+
+ asprintf(&tfptr,"%s.%d.mp4",wkfilename,i);
+ asprintf(&cptr,"%s -v 0 -i %s.%d -an -vcodec copy %s",FFMPEGCMD,wkfilename,i,tfptr);
+ tclistpush2(cmdlist,cptr);
+ tclistpush2(tflist,tfptr);
+ free(tfptr);
+ free(cptr);
}
}
else {
- printf("# %s -splitx %.2f:%.2f \n",MP4BOXCMD,h[i].stsec/1000.0,h[i].edsec/1000.0);
+ asprintf(&cptr,"# %s -splitx %.2f:%.2f ",MP4BOXCMD,h[i].stsec/1000.0,h[i].edsec/1000.0);
+ tclistpush2(cmdlist,cptr);
}
}
if (wkfilename) {
if (!noaudioencode) {
- printf("%s ",SOXCMD);
+ asprintf(&cptr2,"%s ",SOXCMD);
for(i=0;i<hcnt;i++) {
- printf(" %s.%d.wav ",wkfilename,i);
+ asprintf(&tfptr,"%s.%d.wav",wkfilename,i);
+ asprintf(&cptr,"%s %s ",cptr2,tfptr);
+ free(cptr2);
+ cptr2=cptr;
+ tclistpush2(tflist,tfptr);
+ free(tfptr);
}
- printf(" %s.wav\n",wkfilename);
- printf("%s %s.wav %s.aac 60\n",AACENCCMD,wkfilename,wkfilename);
+ asprintf(&tfptr,"%s.wav",wkfilename);
+ asprintf(&cptr,"%s %s",cptr2,tfptr);
+ free(cptr2);
+ tclistpush2(cmdlist,cptr);
+ tclistpush2(tflist,tfptr);
+ free(tfptr);
+
+ asprintf(&tfptr,"%s.aac",wkfilename);
+ asprintf(&cptr,"%s %s.wav %s 60",AACENCCMD,wkfilename,tfptr);
+ tclistpush2(cmdlist,cptr);
+ free(cptr);
+ tclistpush2(tflist,tfptr);
+ free(tfptr);
}
//再チェックの場合-new.mp4ファイルを削除する
if (txtrecheck) {
- printf("rm -f %s-new.mp4\n",wkfilename);
+ asprintf(&cptr,"rm -f %s-new.mp4",wkfilename);
+ tclistpush2(cmdlist,cptr);
+ free(cptr);
}
- printf("%s ",MP4BOXCMD);
+ asprintf(&cptr2,"%s",MP4BOXCMD);
for(i=0;i<hcnt;i++) {
- printf(" -cat %s.%d.mp4 ",wkfilename,i);
+ asprintf(&cptr,"%s -cat %s.%d.mp4 ",cptr2,wkfilename,i);
+ free(cptr2);
+ cptr2=cptr;
+ }
+ asprintf(&cptr,"%s %s-new.mp4",cptr2,wkfilename);
+ tclistpush2(cmdlist,cptr);
+ free(cptr);
+
+ if (!noaudioencode) {
+ asprintf(&cptr,"%s -add %s.aac %s-new.mp4",MP4BOXCMD,wkfilename,wkfilename);
+ tclistpush2(cmdlist,cptr);
}
- printf(" %s-new.mp4\n",wkfilename);
- if (!noaudioencode)
- printf("%s -add %s.aac %s-new.mp4\n",MP4BOXCMD,wkfilename,wkfilename);
- printf("rm -f %s.*\n\n",wkfilename);
+ for(i=0;i<tclistnum(tflist);i++) {
+ asprintf(&cptr,"rm -f %s",tclistval2(tflist,i));
+ tclistpush2(cmdlist,cptr);
+ free(cptr);
+ }
if (thumb) {
pre=0;
for(i=0;i<mcnt;i++) {
- printf("mplayer -ss %.2f -frames 1 -vo png %s ; mv 00000001.png %s-%d.png\n",(pre + (m[i].stsec-pre)/2)/1000.0,wkfilename,wkfilename,i);
+ asprintf(&cptr,"mplayer -ss %.2f -frames 1 -vo png %s ; mv 00000001.png %s-%d.png",(pre + (m[i].stsec-pre)/2)/1000.0,wkfilename,wkfilename,i);
+ tclistpush2(cmdlist,cptr);
pre = m[i].stsec;
}
}
}
+ for (i=0;i<tclistnum(cmdlist);i++) {
+ if (cmdexecute) {
+ FILE *pp;
+ char pbuf[1024];
+ pp = popen(tclistval2(cmdlist,i),"r");
+ if (pp==NULL) {printf("cmdfail %s\n",tclistval2(cmdlist,i));continue;}
+ while(fgets(pbuf,1024,pp)!=NULL){
+ }
+ pclose(pp);
+ }
+ else
+ printf("%s\n",tclistval2(cmdlist,i));
+ }
+
}
int rechecktext(FILE *f)
char *tmpenv;
ret = -1;
- while ((ch = getopt(argc, argv, "adtb:m:v:")) != -1){
+ while ((ch = getopt(argc, argv, "adtxb:m:v:")) != -1){
switch (ch){
case 'a':
noaudioencode=1;
case 't':
thumb=1;
break;
+ case 'x':
+ cmdexecute=1;
+ break;
default:
usage();
}
--- /dev/null
+/*************************************************************************************************
+ * The utility API of Tokyo Cabinet
+ * Copyright (C) 2006-2011 FAL Labs
+ * This file is part of Tokyo Cabinet.
+ * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
+ * the GNU Lesser General Public License as published by the Free Software Foundation; either
+ * version 2.1 of the License or any later version. Tokyo Cabinet 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 Lesser General Public
+ * License for more details.
+ * You should have received a copy of the GNU Lesser General Public License along with Tokyo
+ * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA.
+ *************************************************************************************************/
+
+#include "tclist.h"
+
+/* Get the larger value of two integers. */
+long tclmax(long a, long b){
+ return (a > b) ? a : b;
+}
+
+
+/* Create a list object. */
+TCLIST *tclistnew(void){
+ TCLIST *list;
+ TCMALLOC(list, sizeof(*list));
+ list->anum = TCLISTUNIT;
+ TCMALLOC(list->array, sizeof(list->array[0]) * list->anum);
+ list->start = 0;
+ list->num = 0;
+ return list;
+}
+
+/* Get the number of elements of a list object. */
+int tclistnum(const TCLIST *list){
+ assert(list);
+ return list->num;
+}
+
+/* Add a string element at the end of a list object. */
+void tclistpush2(TCLIST *list, const char *str){
+ assert(list && str);
+ int index = list->start + list->num;
+ if(index >= list->anum){
+ list->anum += list->num + 1;
+ TCREALLOC(list->array, list->array, list->anum * sizeof(list->array[0]));
+ }
+ int size = strlen(str);
+ TCLISTDATUM *array = list->array;
+ TCMALLOC(array[index].ptr, tclmax(size + 1, TCXSTRUNIT));
+ memcpy(array[index].ptr, str, size + 1);
+ array[index].size = size;
+ list->num++;
+}
+
+
+/* Add an element at the end of a list object. */
+void tclistpush(TCLIST *list, const void *ptr, int size){
+ assert(list && ptr && size >= 0);
+ int index = list->start + list->num;
+ if(index >= list->anum){
+ list->anum += list->num + 1;
+ TCREALLOC(list->array, list->array, list->anum * sizeof(list->array[0]));
+ }
+ TCLISTDATUM *array = list->array;
+ TCMALLOC(array[index].ptr, tclmax(size + 1, TCXSTRUNIT));
+ memcpy(array[index].ptr, ptr, size);
+ array[index].ptr[size] = '\0';
+ array[index].size = size;
+ list->num++;
+}
+
+/* Clear a list object. */
+void tclistclear(TCLIST *list){
+ int i;
+ assert(list);
+ TCLISTDATUM *array = list->array;
+ int end = list->start + list->num;
+ for(i = list->start; i < end; i++){
+ TCFREE(array[i].ptr);
+ }
+ list->start = 0;
+ list->num = 0;
+}
+
+const void *tclistval(const TCLIST *list, int index, int *sp){
+ assert(list && index >= 0 && sp);
+ if(index >= list->num) return NULL;
+ index += list->start;
+ *sp = list->array[index].size;
+ return list->array[index].ptr;
+}
+
+
+/* Get the string of an element of a list object. */
+const char *tclistval2(const TCLIST *list, int index){
+ assert(list && index >= 0);
+ if(index >= list->num) return NULL;
+ index += list->start;
+ return list->array[index].ptr;
+}
+
+
+
+void *tcmyfatal(const char *message){
+ assert(message);
+ fprintf(stderr, "fatal error: %s\n", message);
+ exit(1);
+ return NULL;
+}
+
--- /dev/null
+/*************************************************************************************************
+ * The utility API of Tokyo Cabinet
+ * Copyright (C) 2006-2011 FAL Labs
+ * This file is part of Tokyo Cabinet.
+ * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
+ * the GNU Lesser General Public License as published by the Free Software Foundation; either
+ * version 2.1 of the License or any later version. Tokyo Cabinet 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 Lesser General Public
+ * License for more details.
+ * You should have received a copy of the GNU Lesser General Public License along with Tokyo
+ * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA.
+ *************************************************************************************************/
+
+
+#ifndef _TCUTIL_H /* duplication check */
+#define _TCUTIL_H
+
+#include <stdlib.h>
+#if ! defined(__cplusplus)
+#include <stdbool.h>
+#endif
+#include <stdint.h>
+#include <time.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+#include <assert.h>
+
+
+/*************************************************************************************************
+ * array list
+ *************************************************************************************************/
+
+#define TCXSTRUNIT 12 // allocation unit size of an extensible string
+
+#define TCLISTUNIT 64 // allocation unit number of a list handle
+
+/* Show error message on the standard error output and exit.
+ `message' specifies an error message.
+ This function does not return. */
+void *tcmyfatal(const char *message);
+
+#define TCMALLOC(TC_res, TC_size) \
+ do { \
+ if(!((TC_res) = malloc(TC_size))) tcmyfatal("out of memory"); \
+ } while(false)
+
+#define TCCALLOC(TC_res, TC_nmemb, TC_size) \
+ do { \
+ if(!((TC_res) = calloc((TC_nmemb), (TC_size)))) tcmyfatal("out of memory"); \
+ } while(false)
+
+#define TCREALLOC(TC_res, TC_ptr, TC_size) \
+ do { \
+ if(!((TC_res) = realloc((TC_ptr), (TC_size)))) tcmyfatal("out of memory"); \
+ } while(false)
+
+#define TCFREE(TC_ptr) \
+ do { \
+ free(TC_ptr); \
+ } while(false)
+
+
+
+
+
+typedef struct { /* type of structure for an element of a list */
+ char *ptr; /* pointer to the region */
+ int size; /* size of the effective region */
+} TCLISTDATUM;
+
+typedef struct { /* type of structure for an array list */
+ TCLISTDATUM *array; /* array of data */
+ int anum; /* number of the elements of the array */
+ int start; /* start index of used elements */
+ int num; /* number of used elements */
+} TCLIST;
+
+
+/* Create a list object.
+ The return value is the new list object. */
+TCLIST *tclistnew(void);
+
+/* Get the number of elements of a list object.
+ `list' specifies the list object.
+ The return value is the number of elements of the list. */
+int tclistnum(const TCLIST *list);
+
+/* Add an element at the end of a list object.
+ `list' specifies the list object.
+ `ptr' specifies the pointer to the region of the new element.
+ `size' specifies the size of the region. */
+void tclistpush(TCLIST *list, const void *ptr, int size);
+
+/* Add a string element at the end of a list object.
+ `list' specifies the list object.
+ `str' specifies the string of the new element. */
+void tclistpush2(TCLIST *list, const char *str);
+
+/* Get the pointer to the region of an element of a list object.
+ `list' specifies the list object.
+ `index' specifies the index of the element.
+ `sp' specifies the pointer to the variable into which the size of the region of the return
+ value is assigned.
+ The return value is the pointer to the region of the value.
+ Because an additional zero code is appended at the end of the region of the return value,
+ the return value can be treated as a character string. If `index' is equal to or more than
+ the number of elements, the return value is `NULL'. */
+const void *tclistval(const TCLIST *list, int index, int *sp);
+
+
+/* Get the string of an element of a list object.
+ `list' specifies the list object.
+ `index' specifies the index of the element.
+ The return value is the string of the value.
+ If `index' is equal to or more than the number of elements, the return value is `NULL'. */
+const char *tclistval2(const TCLIST *list, int index);
+
+
+
+/* Clear a list object.
+ `list' specifies the list object.
+ All elements are removed. */
+void tclistclear(TCLIST *list);
+
+
+#endif /* duplication check */
+
+
+/* END OF FILE */
+