Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Automating video conversion for a beginner

  1. #1
    Join Date
    Aug 2008
    Beans
    8

    Automating video conversion for a beginner

    Hey guys, my job requires me to convert video from raw files ripped from DV tapes to mpegs. No problem. From there, the mpegs get used to make a DVD video and then a DVD is burnt, and the mpeg gets converted to a flash file that I send to the networking guy to upload to a server, or whatever it is he does with it. All of this I can do.

    However, I want to figure out how to automate the process. I want to start easy, though. So my question is, how can I make it so I drop video files in a folder on my computer and then at a certain time- let's say midnight to ensure I've done everything I need to do that day -the computer system:
    1) Converts the video to flash
    2) Deletes the source file from the folder
    3) After it runs out of files, shuts down

    I use the command "ffmpeg -i sourcefile.mpg -ab 128 output.flv" to convert the video, which works really well, but I don't know how to delete the file from terminal, shut down the computer, or automate the process. Help would be appreciated.

    My Workstation:
    -Ubuntu Linux (Ubuntu Studio Release)- Hardy Heron

  2. #2
    Join Date
    Sep 2006
    Beans
    3,599

    Re: Automating video conversion for a beginner

    Why do you convert from DV to mpeg to flv? Why not DV to flv and DV to mpeg separately? That way you don't go from one lossy format to another. You can do this with cron and a bash script:
    Code:
    #!/bin/bash
    
    # Convert all dv files to mpeg
    find -iname "*dv" -exec ffmpeg -i {} -target dvd {}.mpg \;
    
    # Convert all dv files to flv
    find -iname "*dv" -exec ffmpeg -i {} -ab 128k {}.flv \;
    
    # Remove dv files
    rm *.dv
    
    # Sleep for a bit before shutting down
    sleep 3
    
    # Shutdown computer
    sudo shutdown -h now
    I didn't test this script and I'm no programmer, but it should convert all .dv files that are in the same folder as the script and then shutdown. You should add a check to see if it actually converted the files before deleting the dv files. Save the above text to a file named "encode.sh" and give it executable permission:
    Code:
    chmod +x encode.sh
    You need to edit your sudoers file so a certain user can execute the shutdown command without needing to add the password, otherwise your computer will sit there asking for the password when trying to shutdown:
    Code:
    sudo visudo
    At the bottom of the file add:
    Code:
    angryscotsman     ALL=NOPASSWD:/sbin/shutdown
    This will give passwordless shutdown ability to angryscotsman. The last step is to make the script run when you want it to. This is easy to do with a crontab and is explained here: How-to for crontab.
    Last edited by FakeOutdoorsman; October 28th, 2008 at 01:16 AM.

  3. #3
    Join Date
    Aug 2008
    Beans
    8

    Re: Automating video conversion for a beginner

    Wow, that's pretty cool. Thanks. Now, how do I limit the search to just a particular folder? I don't want it converting all my files, just the ones I'm done editing and drop in a folder for the night. It would be /home/avuser/flvconversions, let's say.

    Also, that was a good tip on the lossy format thing. Didn't even think of that.

  4. #4
    Join Date
    Sep 2006
    Beans
    3,599

    Re: Automating video conversion for a beginner

    Quote Originally Posted by CityOflawrence View Post
    Wow, that's pretty cool. Thanks. Now, how do I limit the search to just a particular folder? I don't want it converting all my files, just the ones I'm done editing and drop in a folder for the night. It would be /home/avuser/flvconversions, let's say.

    Also, that was a good tip on the lossy format thing. Didn't even think of that.
    Here's a new version with some variables that you can change:
    Code:
    #!/bin/bash
    # Encoding Script
    
    # Location of source videos
    sourcelocation="/home/avuser/flvconversions"
    # Extension of source videos
    sourceext="dv"
    
    # Convert all dv files to mpeg
    find ${sourcelocation} -iname "*${sourceext}" -exec ffmpeg -i {} -target dvd {}.mpg \;
    
    # Convert all dv files to flv
    find ${sourcelocation} -iname "*${sourceext}" -exec ffmpeg -i {} -ab 128k {}.flv \;
    
    # Check to see if videos were encoded, then delete source vids and shutdown
    if [ -e "${sourcelocation}/*.mpeg" ] && [ -e "${sourcelocation}/*.flv" ]; then
    	# Delete videos	
    	rm ${sourcelocation}/*.dv
    	# Sleep for 10 seconds before shutting down
    	sleep 10
    	# Shutdown computer
    	sudo shutdown -h now
    else
    	echo "Encoding FAILED"
    fi
    
    exit
    The error checking part of the script sucks. Basically it is just checking if any flv and mpeg files were made, and if so then it will delete all *.dv files and shutdown. I didn't test this script, so I don't know if it will work at all. You should head on over to #bash IRC and ask for a better way to do the check, or post the script in Programming Talk.
    Last edited by FakeOutdoorsman; October 29th, 2008 at 11:06 PM. Reason: change URL to "programming talk"

  5. #5
    Join Date
    Mar 2009
    Location
    The Moon
    Beans
    130
    Distro
    Ubuntu

    Talking Re: Automating video conversion for a beginner

    #!/bin/bash
    # ffmpeg and mencoder script
    # Grab thumb from avi, start encoding to ITU h264 using mencoder, ffmpeg is doing thumb processing

    # Bash script for operating system Ubuntu 8.10
    # packages used : FFMPEG, MENCODER ,MPLAYER ENCODING ENGINE
    # VIDEO CODEC ITU H264 AUDIO MP3


    # Written by FakeOutdoorsman and updated by mysoogal
    # Attribution-Noncommercial 3.0 Unported
    # http://creativecommons.org/licenses/by-nc/3.0/deed.en
    # trackback http://ubuntuforums.org/showthread.php?t=960627

    # Location of source videos
    sourcelocation="/var/www/uploads/"
    # Extension of source videos
    sourceext="mpeg"


    # grab thumbs hehehe ! yahhoo hope this works!
    find ${sourcelocation} -iname "*${sourceext}" -exec /usr/local/bin/ffmpeg -v 0 -y -i {} -vframes 1 -ss 200 -vcodec mjpeg -f rawvideo -s 200x130 -aspect 16:9 {}.jpg \;
    # Check to see if videos were encoded, then delete source vids and shutdown
    if [ -e "${sourcelocation}*.avi" ] && [ -e "${sourcelocation}/*.jpg" ]; then
    # Delete videos
    rm ${sourcelocation}/*.avi
    # Sleep for 10 seconds before shutting down
    sleep 10
    # Shutdown computer
    # sudo shutdown -h now
    else
    echo "Encoding FAILED"
    fi


    # Convert all video clips to ITU H264 OGM video container
    find ${sourcelocation} -iname "*${sourceext}" -exec mencoder {} -o {}.ogm -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encopts bitrate=300:level_idc=41:bframes=3:frameref=2: nopsnr: nossim: pass=1: threads=auto -oac mp3lame \;


    exit

    updated ffmpeg path so it gets jpg, when you run this script through crontab, it seems that ffmpeg needs to have full paths, and mencoder doesnt need it. weird
    Last edited by mysoogal; May 29th, 2009 at 09:59 PM. Reason: updated ffmpeg paths !
    sudo -s

  6. #6
    Join Date
    May 2007
    Beans
    601

    Re: Automating video conversion for a beginner

    Will sudo somecommand work in a script without modification of the command properties?

  7. #7
    Join Date
    Sep 2006
    Beans
    3,599

    Re: Automating video conversion for a beginner

    Quote Originally Posted by xzero1 View Post
    Will sudo somecommand work in a script without modification of the command properties?
    I don't understand what you are asking. Can you clarify your question? Apologies if I am missing something simple.

  8. #8
    Join Date
    Mar 2009
    Location
    The Moon
    Beans
    130
    Distro
    Ubuntu

    Smile Re: Automating video conversion for a beginner

    Quote Originally Posted by xzero1 View Post
    Will sudo somecommand work in a script without modification of the command properties?
    you mean if you use sudo to get bash script to start work ?

    it seems to be working for me just asked me for password and i put my password and encoding started

    Code:
    yugo@ubuntu:~$ cd /home/yugo/Desktop
    yugo@ubuntu:~/Desktop$ cd video
    yugo@ubuntu:~/Desktop/video$ sudo bash h264
    [sudo] password for yugo:
    sudo -s

  9. #9
    Join Date
    May 2007
    Beans
    601

    Re: Automating video conversion for a beginner

    No, what I mean is when the script executes sudo shutdown, there will be no one there to enter the password.

    Edit:
    Yes, you should edit the "sudoers" file. See this thread http://ubuntuforums.org/archive/inde...t-1121628.html

    BTW, starting the script with sudo won't work and is not needed.
    Last edited by xzero1; May 25th, 2009 at 03:34 AM.

  10. #10
    Join Date
    Mar 2009
    Location
    The Moon
    Beans
    130
    Distro
    Ubuntu

    Smile Re: Automating video conversion for a beginner

    Quote Originally Posted by xzero1 View Post
    No, what I mean is when the script executes sudo shutdown, there will be no one there to enter the password. I know this can be modified to work, but I don't recall the specifics at this time.
    oh i see,

    im not sure i have to read more about it
    sudo -s

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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