Find the answer to your Linux question:
Results 1 to 2 of 2
Hey guys. I'm in this summer history class and have to make this presentation thing, so I'm adding music I got from downloading off youtube with youtube-dl. However, I have ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Location
    Illinois
    Posts
    24

    single-use script for repeating ffmpeg on files


    Hey guys. I'm in this summer history class and have to make this presentation thing, so I'm adding music I got from downloading off youtube with youtube-dl.

    However, I have better things to do than ffmpeg, wait for the video to convert, then ffmpeg again to get the sound off. Like actual research for the project.

    I'm a noob to this shell scripting thing, and I thought it was going to be sort of like batch, but as much as I look at all the "How to shell script" tutorials for noobs, it's like you're programming something.

    which is cool, but I kind of just wanted to have it execute commands just like a terminal, only I don't have to sit around and watch it in the corner of my eye, it'll just keep going through all the files and when I'm finished editing, all the music and videos I want to embed in my presentation will be there.

    Clearly, I'm doing this wrong, since I'm getting all sorts of errors like "-i: command not found" (well of course not, it's an option) and it's also trying to treat files as commands in errors like "from-me-to-you.mp3: command not found".

    so do I actually need to learn how to program something? Or is there a different, smarter way to just feed a terminal a list of commands and say "do this while I go read my textbook"?

    Code:
    #!/bin/sh
    PATH=/home/nicholas
    $cd /home/nicholas
    $ffmpeg-i 2Cfz33QIsdY.webm 2Cfz33QIsdY.mpg
    $ffmpeg-i 2Cfz33QIsdY.mpg -vn -ar 44100 -ac 2 -ab 192 -f mp3 bobbys-girl.mp3
    $mv bobbys-girl.mp3 /home/nicholas/Documents/survey_american_history/bobbys-girl.mp3
    $ffmpeg-i 23UkIkwy5ZM.webm 23UkIkwy5ZM.mpg
    $ffmpeg-i 23UkIkwy5ZM.mpg -vn -ar 44100 -ac 2 -ab 192 -f mp3 baby-love.mp3
    $mv baby-love.mp3 /home/nicholas/Documents/survey_american_history/baby-love.mp3
    $ffmpeg -i 68i4tMmv9F4.webm 68i4tMmv9F4.mpg
    $ffmpeg -i 68i4tMmv9F4.mpg -vn -ar 44100 -ac 2 -ab 192 -f mp3 black-and-white.mp3
    $mv black-and-white.mp3 /home/nicholas/Documents/survey_american_history/black-and-white.mp3
    $ffmpeg-i cTBx-hHf4BE.webm cTBx-hHf4BE.mpg
    $ffmpeg-i cTBx-hHf4BE.mpg -vn -ar 44100 -ac 2 -ab 192 -f mp3 one-tin-soldier.mp3
    $mv one-tin-soldier.mp3 /home/nicholas/Documents/survey_american_history/one-tin-soldier.mp3
    #and so on and so forth... this goes on for a while with a bunch of vids.

  2. #2
    Just Joined!
    Join Date
    Jun 2010
    Location
    Illinois
    Posts
    24
    Okay, after about nine hours of wasting my time (so much for saving time on this assignment, but now I'll have the script for the fall semester) doing trial-and-error and a bit of research (that I mostly didn't understand, since it was for more advanced use-cases) I finally figured out how to make a script that is literally just a list of tasks for the terminal to do with out my input.

    First mistake (I'm guessing) is that my path was wrong- I think it's supposed to be the path where it looks for any other scripts called on, not where the location of the active script is.

    Second thing, I didn't need all those dollar signs. I don't know what they do, but they were messing it up.

    third thing, I switched from #! /bin/sh to #! /bin/bash Seems like bash has quite the fandom.

    In gedit, there was a little syntax highlighting, which I do not understand the meaning of but can guess whether or not I've made a meaningful change by making things swap colors. Dollar signs turned things bright, like the PATH, so I'm guessing that they've got some similar characteristic. commands that aren't scripts were bolded, so I was confused as to why the mv could be bolded, and get errors for nothing to do, when ffmpeg wouldn't bold, and not execute (therefore not creating the files that mv was supposed to move)

    there was also this exec thing I found. I tried using exec on everything, with all sorts of variations in the spacing (still couldn't figure out why -i was being treated as a command) and just a few minutes ago I figured it out: even though I installed it with YUM, ffmpeg must not be some sort of binary program, but a shell script. mv is a binary program, so it's called upon when the path to the bins is correct.

    so eventually, exec to execute ffmpeg works properly, and mv will execute on its own. and in about the three minutes I've been writing this my script has executed in full.

    This is what proper "batch" type script will look like, for when it calls on normal commands and other scripts. (For all you noobs out there, now you do not have to waste nine hours tooling around.)

    Code:
    #! /bin/bash
    PATH=/usr/bin
    exec ffmpeg -i  cTBx-hHf4BE.mpg -vn -ar 44100 -ac 2 -ab 192 -f mp3 one-tin-soldier.mp3
    mv one-tin-soldier.mp3 /home/nicholas/Documents/survey_american_history/one-tin-soldier.mp3
    exec ffmpeg -i  dBJnoMP1Uyc.webm dBJnoMP1Uyc.mpg
    exec ffmpeg -i  dBJnoMP1Uyc.mpg -vn -ar 44100 -ac 2 -ab 192 -f mp3 try-harder.mp3
    mv try-harder.mp3 /home/nicholas/Documents/survey_american_history/try-harder.mp3
    exec ffmpeg -i  hiF7FIz0f5k.webm hiF7FIz0f5k.mpg
    exec ffmpeg -i  hiF7FIz0f5k.mpg protest.avi
    mv protest.avi /home/nicholas/Documents/survey_american_history/protest.avi
    #and so on and so forth through all the media I'm going to embed in the presentation
    Now the only thing left to do for me is to go pile this into LibreOffice Impress and turn in a purposefully massive file as retribution for the silly request of making a "movie/news-report" in presentation software.

    Cheers, Pike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •