0

How can I use the following script to recursively convert a directory containing .mp4 to .png (1 frame only).

Right now it only converts the directory. It's not recursive.

for i in *.mp4
do name=`echo "$i" | cut -d'.' -f1`
echo "$name"
ffmpeg -i "$i" -r 0.0033 -vf scale=-1:1024 -vcodec png "${name}.png"
done
Ian Arman
  • 53
  • 5

1 Answers1

1
find . -type f -name '*.mp4' -exec sh -c '
    name="${1%.*}"
    echo "$name"
    ffmpeg -i "$1" -r 0.0033 -vf scale=-1:1024 -vcodec png "${name}.png"
' find-sh {} \;

Notes:

  • In your original code name=`echo "$i" | cut -d'.' -f1` is rather low quality fragment. It cuts at the first dot, this seems wrong. It's not the only problem but I won't elaborate. If you want to remove an extension, the right way is name="${i%.*}".
  • *.mp4 is quoted because of this.
  • Mind this.
  • find-sh is explained here.
  • find descends into subdirectories but it doesn't follow symbolic links by default. If all "subdirectories" in . are if fact links to directories then you may erroneously think the tool doesn't descend in general. Check man 1 find, -L option.
Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • hold on sir... you may have just won my personal award. I'm testing this on the larger directory – Ian Arman Mar 17 '20 at 04:47
  • I was reading your command "mind" this link - i'm familiar with the post - as I think I was looking in that direction. Please wait - as I have to setup a temporary "storage spage" and use the copy command before I'm able to test this solution. However - it worked perfectly (twice) on my sample directory structured as /a/1/2/3/ – Ian Arman Mar 17 '20 at 04:55
  • congratulations sir - you the winner of my personal award! – Ian Arman Mar 17 '20 at 07:08
  • @user2179760 Is [acceptance](https://superuser.com/help/accepted-answer) not included? – Kamil Maciorowski Mar 17 '20 at 07:26
  • it certainly is. please let me figure out how to properly "accept" your answer from within this Forum. i will complete this task for you. I already "upvoted your answer" please let me know if there are other steps – Ian Arman Mar 17 '20 at 09:16
  • @user2179760 [To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in.](https://superuser.com/help/someone-answers) I suggest reviewing answers to your other questions; maybe some of them deserve to be accepted. A question can have at most one accepted answer at any given time. – Kamil Maciorowski Mar 17 '20 at 09:20
  • hello @kamil I have accepted your answer. congratulations, you have won my "personal award" send a priv message for personal thank you – Ian Arman Mar 18 '20 at 03:30
  • > I suggest reviewing answers to your other questions; maybe some of them deserve to be accepted all my other questions were asking for the same solution. I will do as follows: "answer my own question" with your answer, and reference your answer (this one) as a "source" . I'm thinking this is good for both of us, because I (with 11 points) get more points and you with (38k points) get them too. – Ian Arman Mar 18 '20 at 03:34