LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-13-2013, 05:26 AM   #1
rs232
Member
 
Registered: Oct 2005
Posts: 51

Rep: Reputation: 0
using bash to detect broken video file


Hi all,

I would like to write a script that scans my NAS video folder and detects videos files reporting on problems if any. A future version might even try to automatically repair but that's not what I need now...

Any ways, I'm looking for some input on things that can be detected using a script and how to do it. Things I've though about are:

- broken avi index
- unnecessary black bars
- file extension not matching encoding (e.g. .mov called .avi)
- unusual aspect ratio (not 4:3 or 16:9)

please do feed in any other thing you might think about!

I know ffmpeg can help, but before writing anything I would really appreciate your input!

Thanks!
 
Old 05-13-2013, 08:05 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
have you seen this http://606u.dir.bg/avicheck/ ?
 
Old 05-13-2013, 08:18 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by rs232 View Post
- file extension not matching encoding (e.g. .mov called .avi)
man file

also, look into mkvmerge -i

Last edited by schneidz; 05-13-2013 at 09:00 AM.
 
Old 05-14-2013, 03:48 AM   #4
rs232
Member
 
Registered: Oct 2005
Posts: 51

Original Poster
Rep: Reputation: 0
Thanks both! I really appreciate your inputs

I did write something in the past using information on the link provided above. I basically scanned directory recursively and parse .avi with ffmpeg for errors.

The relevant part can be found here below:

Code:
find -mindepth 2 -maxdepth 4 -type d -printf '%T@ %p\n' | sort -r | cut -b 25- |
while read f; do 
rootdir=`echo $f | cut -b 4`

cd "$basedir/$f" 

	Video=`ls -1 *.avi 2>/dev/null | head -1`
	Videoext=`echo $Video|awk -F . '{print $NF}'`

if [[ $Videoext == "avi" ]]; then
	if [ ! -f error.log ]; then
		/usr/bin/ffmpeg -v 1 -i *.avi -f null - 2>error.log 
		errors=`more error.log | egrep -i 'error|invalid' | wc -l` 
		if [[ $errors -gt "1" ]]; then
			echo -e "$f might have AVI encoding problems \r"
		else
			echo -e "$f is well encoded \r"
		fi
	else
		echo -e "$f has already been processed \r"
	fi
else
	echo -e "$f is not AVI \r"
fi

The output log can be found in attachment. The point where I am at the moment is that I look for "error or invalid" but that's really my best guess on what it might go wrong on a file. I would need help identifying all the possible things that might go wrong with a video file and how ffmpeg would report on those.

About file and mkvmerge, can you please elaborate? I guess mkv merge can help with mkv files only (which is a fair enough to me)

Thanks again for your help/input
:-)
Attached Files
File Type: log error.log (31.0 KB, 68 views)
 
Old 05-14-2013, 04:04 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
actually you need to investigate and find out what kind of errors you want to take into account at all.
man file is a good start, or just try it.
about your script:
to check these files you do not need to sort them, so find <path> -type f -name \*.avi would be probably better.
rootdir is not used
Video=$f, the ls -1 .... is not required at all (f is the loop variable)
Videoext=${Video##*.} is much quicker than your solution (to get the extension)

errors=`more error.log | egrep -i 'error|invalid' | wc -l` can be replaced by a single grep:
errors=$(grep -ci 'error|invalid' error.log) - (or similar)
 
Old 05-14-2013, 07:19 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by rs232 View Post
...
About file and mkvmerge, can you please elaborate? I guess mkv merge can help with mkv files only (which is a fair enough to me)
file is a very simple command so it would be hard to elaborate:
Code:
[schneidz@hyper stuff]$ file video.xyz 
video.xyz: RIFF (little-endian) data, AVI, 720 x 480, ~30 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
[schneidz@hyper stuff]$ mkvmerge -i video.xyz 
File 'video.xyz': container: AVI
Track ID 0: video (MP4V)
Track ID 1: audio (MP3)
Quote:
Originally Posted by pan64 View Post
...
Videoext=${Video##*.} is much quicker than your solution (to get the extension)
...
since op mentioned that some file names are mislabeled i think it would be better to find the actual file type using the file command.

Last edited by schneidz; 05-14-2013 at 07:24 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slack: script to detect orphaned libraries, broken lib links, missing dependencies GrapefruiTgirl Slackware 69 10-13-2019 03:39 PM
[SOLVED] The way to detect broken mp3 file. kaz2100 Linux - Software 4 03-21-2011 09:21 PM
How to detect broken connection before sending data with sockets Fabio Paolini Linux - Networking 3 11-03-2010 04:59 AM
Bash Script Now Broken paulclark Programming 10 08-11-2009 12:45 PM
How to detect broken pipe in C (Linux)? alanwolfen Programming 4 02-23-2005 01:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration