You are not logged in.

#1 2012-03-20 20:18:52

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

[SOLVED] mplayer autocrop script - some mplayer/awk oddness.

So I created this little one liner, to automatically crop a video while playing it.

mplayer -vf crop=`mplayer -quiet -vo null -vf cropdetect 1.avi -frames 100 | awk -F '[()]' '{sub(/^-vf crop=-/, "", $2); print $2}' | uniq | grep -Ev 'End of file' | tail -2` 1.avi

This does KIND of work, but it has a major problem: it starts from the beginning of the file, which most likely is black, resulting in negative numbers and non-working playback.
So I added the -ss 60 option to mplayer. This option makes mplayer start at 60 seconds of the clip. THATS ALL IT DOES.

And now look what happens in both cases:

 
➜  ~  mplayer -quiet -vo null -vf cropdetect 1.avi -frames 100 | awk -F '[()]' '{sub(/^-vf crop=-/, "", $2); print $2}' | uniq | grep -Ev 'End of file' | tail -2 
 
640:-352:646:358
➜  ~  mplayer -quiet -ss 60 -vo null -vf cropdetect 1.avi -frames 100 | awk -F '[()]' '{sub(/^-vf crop=-/, "", $2); print $2}' | uniq | grep -Ev 'End of file' | tail -2                   
 
-vf crop=640:352:4:4

As you can see, as soon as I make mplayer start from a different position, the awk line fails. i have NO clue how this can even be possible tho smile

Last edited by Rasi (2012-03-20 20:49:42)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#2 2012-03-20 20:50:22

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: [SOLVED] mplayer autocrop script - some mplayer/awk oddness.

Ok... i simply used the whole output in the brackets now, which resulted in this:

#!/bin/sh
mplayer `mplayer -ao null -ss 60 -frames 100 -vf cropdetect -vo null "$1" | awk -F '[()]' '{print $2}' | uniq | grep -Ev 'End of file' | tail -2` "$1"

Last edited by Rasi (2012-03-20 20:52:20)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#3 2013-03-23 12:19:32

Gregiure.Favre
Member
Registered: 2010-03-28
Posts: 3

Re: [SOLVED] mplayer autocrop script - some mplayer/awk oddness.

Thanks for the nice script smile

Offline

Board footer

Powered by FluxBB