ich versuche eine binär Datei, genau genommen ein AVCHD Stream, zu splitten in viele kleine "Dateistückchen" alle paar bytes, dazu habe ich eine seperate Datei mit offsets
cat "tempvalues"
Code: Alles auswählen
0
1311
121899
125784
130213
...usw
Code: Alles auswählen
dd if="$EINGABE_DATEI" of=$DATEI_SCHNITT skip="$OFFSET_OLD" bs=1 count="$BYTESTOWRITE"
Code: Alles auswählen
#!/bin/bash
FILE="00000.MTS"
echo "0" > tempvalues
cp -f "${FILE}-orig" "$FILE"
for VALUE in $(grep -aob "MDPM" "$FILE" | cut -d':' -f1); do
VALUE=$((VALUE -16))
echo "$VALUE" >> tempvalues
done
#set -x
# how many lines to parse *helper for the last bytes to write
READ_LINES="$(cat tempvalues | wc -l)"
# the size in bytes of the original file
FILE_SIZE_IN_BYTES="$(du -b $FILE | awk '{print $1}')"
# file part counter printf "%0*d\n" 5 $((00000+1))
CHUNK_COUNTER="0"
# old file offset
OFFSET_OLD="0"
# how much bytes in file parts toghter has been written
TOTAL_BYTES_WRITTEN="0"
# how much bytes are left for writing
BYTES_LEFT_TO_WRITE="0"
#set -x
while read OFFSET_CURRENT; do
#skip first line
#echo "READ_LINES: $READ_LINES"
if [ $OFFSET_CURRENT -eq 0 ]; then
OFFSET_OLD="$OFFSET_CURRENT"
READ_LINES="$(($READ_LINES-1))"
continue
fi
#if [ ! $OFFSET_CURRENT -eq 0 ]; then
# OFFSET_OLD="$(($OFFSET_OLD+1))"
#fi
echo "Writing from offset: $OFFSET_OLD -> $OFFSET_CURRENT"
READ_LINES="$(($READ_LINES-1))"
BYTESTOWRITE="$(($OFFSET_CURRENT - $OFFSET_OLD))"
echo "bytestowrite: $BYTESTOWRITE"
echo "skip=$OFFSET_OLD bs=1 count=$BYTESTOWRITE"
dd if="$FILE" of="$(printf "%0*d\n" 32 $(($CHUNK_COUNTER+1)))" skip="$OFFSET_OLD" bs=1 count="$BYTESTOWRITE"
#cat "$FILE" | dd of="$(printf "%0*d\n" 32 $(($CHUNK_COUNTER+1)))" skip="$OFFSET_OLD" bs=1 count="$BYTESTOWRITE"
#wait && sync
# +1 on CURRENT OFFSET cause write from 0-1311, then next chunk from 1312-nnnnn
OFFSET_OLD="$(($OFFSET_CURRENT+0))"
TOTAL_BYTES_WRITTEN="$(($TOTAL_BYTES_WRITTEN + $BYTESTOWRITE))"
echo "TOTAL_BYTES_WRITTEN: $TOTAL_BYTES_WRITTEN"
CHUNK_COUNTER="$(($CHUNK_COUNTER + 1))"
echo "CHUNK_COUNTER: $CHUNK_COUNTER"
BYTES_LEFT_TO_WRITE="$(($FILE_SIZE_IN_BYTES - $TOTAL_BYTES_WRITTEN))"
echo "BYTES_LEFT_TO_WRITE: $BYTES_LEFT_TO_WRITE"
echo "FILE_SIZE_IN_BYTES : $FILE_SIZE_IN_BYTES"
echo
# writes lates bytes of the orignal file
if [ $READ_LINES -eq 0 ]; then
echo "----"
echo "Writing from offset: $TOTAL_BYTES_WRITTEN -> $FILE_SIZE_IN_BYTES"
BYTESTOWRITE="$(($FILE_SIZE_IN_BYTES - $TOTAL_BYTES_WRITTEN))"
echo "bytestowrite: $BYTESTOWRITE"
echo "skip=$OFFSET_OLD bs=1 count=$BYTESTOWRITE"
dd if="$FILE" of="$(printf "%0*d\n" 32 $(($CHUNK_COUNTER+1)))" skip="$OFFSET_OLD" bs=1 count="$BYTESTOWRITE"
#cat "$FILE" | dd of="$(printf "%0*d\n" 32 $(($CHUNK_COUNTER+1)))" skip="$OFFSET_OLD" bs=1 count="$BYTESTOWRITE"
#wait && sync
# +1 on CURRENT OFFSET cause write from 0-1311, then next chunk from 1312-nnnnn
#OFFSET_OLD="$(($OFFSET_CURRENT+0))"
TOTAL_BYTES_WRITTEN="$(($TOTAL_BYTES_WRITTEN + $BYTESTOWRITE))"
echo "TOTAL_BYTES_WRITTEN: $TOTAL_BYTES_WRITTEN"
CHUNK_COUNTER="$(($CHUNK_COUNTER + 1))"
echo "CHUNK_COUNTER: $CHUNK_COUNTER"
BYTES_LEFT_TO_WRITE="$(($FILE_SIZE_IN_BYTES - $TOTAL_BYTES_WRITTEN))"
echo "BYTES_LEFT_TO_WRITE: $BYTES_LEFT_TO_WRITE"
echo "FILE_SIZE_IN_BYTES : $FILE_SIZE_IN_BYTES"
echo
fi
#if [ $CHUNK_COUNTER -eq "2" ]; then
# exit 0
#fi
done < tempvalues
[ -f tempvalues ] && rm -f tempvalues