[FFmpeg-devel] [RFC][PATCH] Tool to sort files a bit

Michael Niedermayer michaelni
Sat Oct 9 19:52:52 CEST 2010


On Sat, Oct 09, 2010 at 11:23:30AM +0200, Stefano Sabatini wrote:
> On date Saturday 2010-10-09 00:12:17 +0200, Michael Niedermayer encoded:
> > Hi
> > 
> > The attached script creates directories and symlinks for multimedia files
> > based on container and codec in the file. I hope ive not done this work
> > redundantly
> > it needs to be checked by someone who knows shell escaping to make it
> > secure ive made no attempt at making it secure.
> > 
> > Also if people are ok with it id like to commit this so more people can work on
> > it, iam not an expert on shell programming ...
> > 
> > yes its intended to help with incoming / samples maybe at some point or even
> > to help people sort their personal file collections
> > 
> > 
> > commit ca9a964c2eba0ba6cda767cfe2d74b80c245dd4c
> > Author: Michael Niedermayer <michaelni at gmx.at>
> > Date:   Fri Oct 8 23:58:51 2010 +0200
> > 
> >     Tool to analyze multimedia files and create directories and symlinks for the
> >     container type and codecs in each file that point back to the file.
> > 
> > diff --git a/tools/jauche_sortierer.sh b/tools/jauche_sortierer.sh
> > new file mode 100755
> > index 0000000..517353f
> > --- /dev/null
> > +++ b/tools/jauche_sortierer.sh
> > @@ -0,0 +1,19 @@
> > +#!/bin/sh
> > +#GPL
> > +#TODO
> > +#add pixelformat/sampleformat into the path of the codecs
> > +
> > +FFP=../ffprobe
> > +TMP=./misthaufen
> 
> The name of the script and of $TMP are weird, as already noted...

I like the name of the script.


> 
> Also $TMP should contain at least the pid, in order to avoid conflicts
> with other concurrent instances of the script, so I suggest:
> TMP=$TMPDIR/$(basename $0)-$$

fixed differently, your variant is insecure


> 
> > +TARGET=$1
> > +shift
> > +
> > +for v do
> 
> what is v?

I probably dont understand your question
its a variable


> 
> > +    BASE=`basename $v`
> > +    echo $v | egrep -i '(public|private)' >/dev/null && echo Warning $v may be private
> > +    $FFP $v 2> $TMP
> > +    FORM=`(grep 'Input #0, ' -m1 $TMP || echo 'Input #0, unknown') | sed 's/Input #0, \([a-zA-Z0-9_]*\).*/\1/' `
> 
> Since we're using ffprobe the parsing can be simplified a lot (and
> made more robust), using ffprobe -show_streams -show_format, also it
> should make trivial to add support for other features like pixfmts,
> samplefmts, codec tags.

robuster yes, simpler iam not so sure
but suggestion or better patches are welcome if you know how to do it simpler


> 
> Also I tend to prefer the $(...) syntax over `...`, as it is generally
> more readable (and my editor allows to match opening and closing
> paren).

changed


> 
> > +    mkdir -p $TARGET/container/$FORM
> > +    ln -s $v $TARGET/container/$FORM/$BASE
> > +    eval `grep 'Stream #0\.[^:]*: [a-zA-Z0-9][^:]*: [a-zA-Z0-9]' $TMP | sed 's#[^:]*: \([a-zA-Z0-9]*\)[^:]*: \([a-zA-Z0-9]*\).*#mkdir -p '$TARGET'/\1/\2 ; ln -s '$v' '$TARGET'/\1/\2/'$BASE' ; #'`
> > +done
> 
> Missing rm $TMP at the end.

fixed

new patch below, will commit soon if there are no objections

commit 82f998e4f1e0ae98436e04c7185310d736253b0f
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Fri Oct 8 23:58:51 2010 +0200

    Tool to analyze multimedia files and create directories and symlinks for the
    container type and codecs in each file that point back to the file.

diff --git a/tools/jauche_sortierer.sh b/tools/jauche_sortierer.sh
new file mode 100755
index 0000000..1f84f1a
--- /dev/null
+++ b/tools/jauche_sortierer.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+#GPL
+#TODO
+#add pixelformat/sampleformat into the path of the codecs
+
+FFP=../ffprobe
+TMP=$(mktemp) || exit 1
+TARGET=$1
+shift
+
+for v do
+    BASE=$(basename $v)
+    echo $v | egrep -i '(public|private)' >/dev/null && echo Warning $v may be private
+    $FFP $v 2> $TMP
+    FORM=$((grep 'Input #0, ' -m1 $TMP || echo 'Input #0, unknown') | sed 's/Input #0, \([a-zA-Z0-9_]*\).*/\1/' )
+    mkdir -p $TARGET/container/$FORM
+    ln -s $v $TARGET/container/$FORM/$BASE
+    eval $(grep 'Stream #0\.[^:]*: [a-zA-Z0-9][^:]*: [a-zA-Z0-9]' $TMP | sed 's#[^:]*: \([a-zA-Z0-9]*\)[^:]*: \([a-zA-Z0-9]*\).*#mkdir -p '$TARGET'/\1/\2 ; ln -s '$v' '$TARGET'/\1/\2/'$BASE' ; #')
+done
+
+rm $TMP

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 1
"Used only once"    - "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101009/ffc76c0e/attachment.pgp>



More information about the ffmpeg-devel mailing list