LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-02-2021, 06:55 AM   #1
GPGAgent
Member
 
Registered: Oct 2018
Location: Cornwall UK
Distribution: Mint 20 xfce 64bit
Posts: 740
Blog Entries: 3

Rep: Reputation: 122Reputation: 122
Question Need to detect if a video has black borders


I can detect the black borders on a video and create a crop= parameter for ffmpeg like this:
Code:
# detect the cropping parameters
FFREPORT=file=CROPDATA.txt:level=32 ffmpeg -hide_banner -loglevel quiet -ss $1 -i $2  -vframes 2 -vf "cropdetect=24:16:0" -f null -

# Extract the cropping paramaters for the -vf switch
CROP=`awk  '/crop=/ {print $14}' CROPDATA.txt`

This works just fine
Code:
$ echo $CROP
crop=976:720:156:0
What I want to do is to check the last two crop parameters x and y and if both are zero the vdio has no black borders.


How can I extract these two values, 156 and 0.


What i would do is add these together and if their sum is zero then there is no border. If it's greater thatn one there is a border and my script can take the appropriate action


Seems simple, but I can't figure it out!
 
Old 05-02-2021, 08:08 AM   #2
GPGAgent
Member
 
Registered: Oct 2018
Location: Cornwall UK
Distribution: Mint 20 xfce 64bit
Posts: 740

Original Poster
Blog Entries: 3

Rep: Reputation: 122Reputation: 122
This is the best I've come up with
Code:
CROP=crop=976:720:156:0
LAST3=${CROP#*:}
LAST2=${LAST3#*:}
THIRD=${LAST2%:*}
FOURTH=${LAST2#*:}

echo $THIRD $FOURTH
156 0

TOTAL=$(($THIRD + $FOURTH))
echo $TOTAL
156
So if there are black borders then TOTAL will not be zero

If there are no black borders then TOTAL will be zero

Is there a neater/more concise way?
 
Old 05-02-2021, 10:16 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,238

Rep: Reputation: Disabled
If you are getting the crop parameter with awk anyway, why not extract the sum of two values immediately as well?
Code:
<<! read CROP TOTAL
$(awk '/crop=/ {
    split($14, a, /:/)
    print $14, a[3]+a[4]
  }' CROPDATA.txt)
!
or in Bash
Code:
read CROP TOTAL < <(
  awk '/crop=/ {
    split($14, a, /:/)
    print $14, a[3]+a[4]
  }' CROPDATA.txt)

Last edited by shruggy; 05-02-2021 at 11:31 AM.
 
Old 05-02-2021, 10:30 AM   #4
GPGAgent
Member
 
Registered: Oct 2018
Location: Cornwall UK
Distribution: Mint 20 xfce 64bit
Posts: 740

Original Poster
Blog Entries: 3

Rep: Reputation: 122Reputation: 122
Thumbs up

Quote:
Originally Posted by shruggy View Post
If you are getting the crop parameter with awk anyway, why not extract the sum of two values immediately as well?
Code:
<<! read CROP TOTAL
$(awk '/crop=/ {
    split($14, a, ":")
    print $14, a[3]+a[4]
  }' CROPDATA.txt)
!
Cheers Shruggy, I just don't know awk that well, I did look and this is exactly how I thought to do it - thanks
 
Old 05-02-2021, 11:37 AM   #5
GPGAgent
Member
 
Registered: Oct 2018
Location: Cornwall UK
Distribution: Mint 20 xfce 64bit
Posts: 740

Original Poster
Blog Entries: 3

Rep: Reputation: 122Reputation: 122
Question

Hey Shruggy,

So I included your code like this:
Code:
<<! read CROP TOTAL
TOTAL=$(awk '/crop=/ {
    split($14, a, ":")
    print $14, a[3]+a[4]
  }' CROPDATA.txt)
!
Could you explain what <<! read CROP TOTAL and the last ! do please
Cheers
 
Old 05-02-2021, 11:56 AM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,238

Rep: Reputation: Disabled
See 3.6.6 Here Documents in the GNU Bash Manual.

The usual way to write them is
Code:
read CROP TOTAL <<END
TOTAL=$(awk '/crop=/ {
    split($14, a, /:/)
    print $14, a[3]+a[4]
  }' CROPDATA.txt)
END
Here the output of awk is read into two variables: CROP and TOTAL. In Bash, you can achieve the same with the here string (<<<) or with the process redirection.

Last edited by shruggy; 05-02-2021 at 12:01 PM.
 
Old 05-02-2021, 12:01 PM   #7
GPGAgent
Member
 
Registered: Oct 2018
Location: Cornwall UK
Distribution: Mint 20 xfce 64bit
Posts: 740

Original Poster
Blog Entries: 3

Rep: Reputation: 122Reputation: 122
Thumbs up

Quote:
Originally Posted by shruggy View Post
See 3.6.6 Here Documents in the GNU Bash Manual.

The usual way to write them is
Code:
read CROP TOTAL <<END
TOTAL=$(awk '/crop=/ {
    split($14, a, /:/)
    print $14, a[3]+a[4]
  }' CROPDATA.txt)
END
Here the output of awk is read into two variables: CROP and TOTAL. In Bash you can achieve the same with the here string (<<<) or with the process redirection.
Many thanks, everyday is a school day, that was very helpful
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to crop a video of its black borders GPGAgent Linux - Software 24 12-25-2020 06:09 PM
Amiga Games that runs on Overscan (fullscreen without black borders)? patrick295767 Linux - Games 0 03-20-2016 08:44 PM
Compiz-fusion has no borders oldsko0l Linux - Software 4 08-01-2011 11:51 AM
Screen Resolution 800x600 with black borders JoSch1337 Linux - Hardware 6 11-10-2006 01:43 PM
Black borders and wrong monitor frequency on SuSE Linux 10.0 AnonymousX Linux - Newbie 10 03-14-2006 05:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:50 AM.

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