element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Problem running MENCODER or AVCONV from Cron
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 3 replies
  • Subscribers 676 subscribers
  • Views 620 views
  • Users 0 members are here
  • cron
  • problem
  • raspberry_pi
  • raspberry-pi
  • avconv
  • mencoder
Related

Problem running MENCODER or AVCONV from Cron

mikedavis
mikedavis over 10 years ago

I have a project where my Raspberry Pi starts taking pictures at 4:30AM and stops at 7:30AM everyday.  Then MENCODER or AVCONV should turn on to stitch them together into a movie.  Then a Dropbox Uploader uploads the movie to my dropbox account, and another process deletes all of the pictures.

 

The only one of those that is not working is the MENCODER or AVCONV portion.

 

I started out using MENCODER, and it works just fine when I use it in the terminal.  However, when I put it in Cron, it makes a movie with just one frame and then quits.  Apparently it is a known problem and this was posted to get around it.  I was not able to make the MAILTO solution work.  I guess I don't know where it goes in my Crontab file.

 

I moved to using AVCONV, and again it works just fine in the terminal.  However, when I put it in Cron as a scheduled task, nothing seems to happen.  The time when it is supposed to kick on comes and goes, and there is no sign of a movie file.  I searched and didn't find any kind of common problem with AVCONV.

 

This is my bash script for making the movie with MENCODER

#!/bin/bash

 

 

DATE=$(date +"%F")

ls *.jpg > stills.txt

mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o /home/pi/camera/$DATE.avi -mf type=jpeg:fps=17 mf://@stills.txt

 

This is my bash script for making the movie with AVCONV.

 

#!/bin/bash

DATE=$(date +"%Y%m%d")

avconv -r 10 -i frame_%04d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 $DATE.mp4

 

This is my crontab file

 

30 4 * * * python /home/pi/camera/camera.py &
35 7 * * * /home/pi/camera/avconv.sh 2>&1
35 10 * * * python /home/pi/upload.py &
35 11 * * * python /home/pi/clearpic.py &

 

Any assistance would be greatly appreciated.  As I mentioned, everything else works, and this is the one part that is keeping me from installing my project at a school.

 

Thank you!

  • Sign in to reply
  • Cancel
  • balearicdynamics
    0 balearicdynamics over 10 years ago

    Hello,

    as far as my not great experience with cron table, I suggest a couple of things that probably it is the worth to try. First of all, do not use the standard cron but create your own user cron so a lot of permissions and controls are managed better. But this is not the main problem, I suppose.

     

    Instead as you launch the python process with a file etc, as a matter of fact - in theory - we should expect that it works, but I have always saw that under debian there are a lot of problems with this approach.  try making a bash script, executing all, including the command and parameters in it. Give the execution permissions you need so cron should start a single command, e.g.

     

    • camerashot.sh (launch the pythong command etc.)
    • convertshooting.sh (executes avconv as shown)
    • uploadvideo.sh (launch the upload process via python call)
    • clearimages.sh (the last command clearpic.py)

     

    So as a matter of fact you will launch only one commmand every stage

    Check that your python command is in the path so it can be executed by cron. If you don't use the user crontab but the standard cron it runs as root, so there maybe problems finding the installed commands and so on.

    Last, as cron executes tasks launched by the system it seems having no sense the final & in every command. This is needed only when you start from the command line a process and want it to run in background but as per definition cron already launche a program in background so it seems sensless.

     

    Le me know if this work. I suggest you make on change at a time and see what happens to focus what - if any - of the possible issues is influencing the process to work as you expect.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago

    Try to include redirection like < for input and > for output.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mikedavis
    0 mikedavis over 10 years ago

    I think I got it solved.  I ended up doing two things:

     

    1. I added ssmtp so I could get emails from cron.  Now whenever a job is completed I should get an email.  That ended up being really helpful.  When I got those emails from the avconv job, I noticed that it just couldn't find the files.

    2.  I made the path for the jpg files and the output file absolute.  (/home/pi/camera/...)

     

    When I did that I saw a .mp4 file growing in my folder, and I was elated!  If I get an email around 10:45 saying that it was uploaded to Dropbox, then I can officially declare success!

     

    Thanks for your help!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube