Getting Exiftool duration without fuzzy time - exiftool

When I use exiftool to get the duration of an audio file, if the file is over 24 hours I get “1 day 1:23:45” instead of 25:23:45. Sometimes I get “approx 13:17:23”.
Is it possible to tell exiftool to only return HH:MM:SS regardless of how long the file actually is and if it thinks the time is approximate or not (I can strip out the approximate if I have to, but if there’s a way to specify the output format I can’t find it)?
exiftool -d "%H:%M:%S" -Duration Audiobook.m4a
Duration : 1 days 1:17:20
This works, assuming there its no way to get exiftool to output the hours:
if [[ $DURA == *"days"* ]]; then
EXIF=$(exiftool -duration# "$FILE")
SEC=$(awk -F": " '/Dura/ {print $2}' <<<"$EXIF" |awk -F'.' '{print $1}')
HOR=$(($SEC / 3600))
MIN=$(($SEC % 3600/60))
SES=$(($SEC % 60))
DURA="$HOR:$MIN:$SES"
fi

Answer: no way to do this in efixtool, so work around somehow (I chose bash script, but whatever).

Related

ffmpeg blackdetect, start_black value to mkv chapter?

I'm trying to do automatic detect chapter with blackdetect with ffmpeg.
When I use blackdetect I get result but what is the result? Its not frames? Also. Is it possible to do a script/bat-file (for windows 10, powershell or cmd) to convert the result to a "mkv xml-file" so It can be imported with mkvtoolnix?
ffmpeg -i "movie.mp4" -vf blackdetect=d=0.232:pix_th=0.1 -an -f null - 2>&1 | findstr black_duration > output.txt
result:
black_start:2457.04 black_end:2460.04 black_duration:3
black_start:3149.46 black_end:3152.88 black_duration:3.41667
black_start:3265.62 black_end:3268.83 black_duration:3.20833
black_start:3381.42 black_end:3381.92 black_duration:0.5
black_start:3386.88 black_end:3387.38 black_duration:0.5
black_start:3390.83 black_end:3391.33 black_duration:0.5
black_start:3824.29 black_end:3824.58 black_duration:0.291667
black_start:3832.71 black_end:3833.08 black_duration:0.375
black_start:3916.29 black_end:3920.29 black_duration:4
Please see the documentation on this function here. Specifically this line:
Output lines contains the time for the start, end and duration of the detected black interval expressed in seconds.
If you read further down the page you will see another function blackframe which does a similar thing but outputs the frame number rather than seconds.
If the mkvtoolnix xml file has a chapter definition facility you will be able to create a script that takes the ffmpeg output and dumps it into the correct format in any language of your choice.

get the lines that have date in comparing to the given date

I have a log file that has text (a list of filenames), which are of this format:
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401164500025
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401170000022
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401171500018
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401173000018
Now, in a ksh script, I'm trying to retrieve two lists with the lines - one that have date OLDER date and other list that have NEWER date for a give date: 20170401 17:12
The first two lines into one older_list and last two lines into newer_list:
like,
older_list file has these:
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401164500025
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401170000022
newer_list file has these:
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401171500018
/dir1/dir2/dir3/dir4/dir5/dir6/dir7/us.ca.sf.release123.20170401173000018
can you guys please throw me the script that can handle this.
our is an old version
oslevel
5.3.0.0
Thanks
You could use for example awk tool in order to achieve your task:
Example:
> TIME=201704011700 # for same matter you could set it with current date TIME=$(date %Y%m%d%H%M)
> awk -F'\.' -v time=$TIME '{if (substr($5,1,12) >= time) {print $0 }}' your_input_log_file > fitered_after_$TIME
> awk -F'\.' -v time=$TIME '{if (substr($5,1,12) < time) {print $0 }}' your_input_log_file > fitered_before_$TIME
Explanation:
TIME is an variable defined in your shell
awk parameter -F
will define the . as a field delimiter thus your field we are
interested in as per your example would be $5.
-v option will
define for awk a variable time before starting with the value of
your TIME shell variable.

Perl script to copy logs with timestamp for every hour and paste into different file

First of all, I'm very new to programming and so would need your help in writing a perl script to do the following on windows.
I have a big log file with timestamp (1gb) and its difficult to read the logs as it takes a lot of time to open. so my requirement is to copy the logs from the bigger log file for the last one hour and paste it to another file and then copy the next 1 hr of data to different file(so we will have 24 files for a day). The next day the data in these files needs to be over written or delete & create a new file.
Sample log :
09092016-00:02:00,..................
09092016-00:02:08,..................
09092016-00:02:15,..................
09092016-00:02:18,..................
Please help me with this and thanks for your help in advance.
Thanks,
A simpler solution would be to use the split command to split the files into manageable sizes.
split -l 1000 logfile
Will split your logfile into smaller files of 1000 lines each.
You can then just use grep to find the files that contain the day you need.
grep 09092016 logfile*
for example:
logfile="./log"
while read -r d m y h; do
grep "^$d$m$y-$h" "$logfile" > "partial-${y}${m}{$d}-${h}.log"
done < <(sed -n 's/\(..\)\(..\)\(....\)-\(..\)\(.*\)/\1 \2 \3 \4/p' "$logfile" | sort -u)
easy, but not efficient. It reads the whole big logfile 25x for the split. (1x for gathering the existing ddmmyyyy-hh lines in the log, and again for every different found date-hour.)

day difference between dates and check convert the text in date

My intention of writing a shell-script (ksh) is to list all the files in a directory and check the creted date. If the date exceeds 30 days, the files are zipped in another location.
ksh code :
--extracts the day and date of the file
ls -al | awk '{print $6$7}'
output
May23 Jun13 .......
Now, when i extract the day and date, i believe it is in text. Now, my requirement is to change the text into date and check the created date whether less than 30 days or greater.
However, i googled out an found some good suggestions but none satisfoes mine(as far as i searched).
Could you please suggest as what is required to do?
Thanks in advance.
Don't use ls for this. Use find, e.g.
find . -type f -ctime +30
or similar-type command.

Perl Strange -M Flag in 'If' statement

What is this flag?
if (-M ..filepath..)
what is the '-M' flag?
perldoc -f -M will answer your question...
This is the modification "age" of the file, in fractional days. That is, it is the number of days since the file was modified, as of the script start time (or as of some other time, if you explicitly set the $^T variable).
I sure hope that the actual code is along the lines of -M filepath > ...; just testing -M's result for truth is pointless.
Script start time minus file modification time (aka file modification age), in days.
In other words, it returns the age of OPERAND in days when the program started.
Also see a full list of file test operators in perldoc perlfunc (-X section)
Modification age (measured in days)
from http://www.devshed.com/c/a/Perl/File-Tests-in-Perl/
if we have something like this:
$age = -M FILE;
$age will contain the days since the file was modified.