Showing posts with label Linux command. Show all posts
Showing posts with label Linux command. Show all posts

Wednesday, December 13, 2017

Get the video time of all video in directory using the shell script

In this shell script we can calculate the video time of all video available in you directory or folder .

for f in *
do
echo -n "video_time = ";
DURATION="$(ffmpeg -i $f 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }')";
echo "$DURATION File Name = '$f';";
done



The output for this script is :

video_time = 135 File Name = 'video1.mp4';
video_time = 122 File Name = 'video2.mp4';
video_time = 351 File Name = 'video3.mp4';
video_time = 248 File Name = 'video4.mp4';
video_time = 288 File Name = 'video5.mp4';
video_time = 361 File Name = 'video6.mp4';
video_time = 190 File Name = 'video7.mp4';
video_time = 142 File Name = 'video8.mp4';
video_time = 171 File Name = 'video9.mp4';
video_time = 166 File Name = 'video10.mp4';
video_time = 56 File Name = 'video11.mp4';
video_time = 154 File Name = 'video12.mp4';
video_time = 87 File Name = 'video13.mp4';

Shell Script for getting total video duration of any video

In this Shell Script we can  get the total video duration of any video.

ffmpeg -i $f 2>&1 | grep -oP "(?<=Duration: ).*(?=, start.*)";

Here $f is the file name like myvideo.mp4

Example

ffmpeg -i myvideo.mp4 2>&1 | grep -oP "(?<=Duration: ).*(?=, start.*)";

00:03:59.93

The above time in string.

 If you want to calculate the video time in second then use the following command

ffmpeg -i myvideo.mp4 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'


result is

 239 second

Friday, December 1, 2017

Linux Important Command

 Linux Important Command  --

1. Create The Directory
  if you want to create the directory using the ubuntu terminal then you can use the following command
  type on the terminal--

mkdir  folderName.

2. Remove All folder and its content from particular directory
you can type following cammand on terminal

rm -r *

3. Make zip file by command

tar -zcf fileName.tar.gz  conetent(which you wnt to make zip)

 

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...