LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-09-2013, 04:57 PM   #1
Liquid_Squelch
LQ Newbie
 
Registered: May 2006
Location: Long Island, NY
Distribution: CentOS, OpenSuSE, Ubuntu, Raspbian
Posts: 14

Rep: Reputation: 0
ffmpeg fails to run in cron but ok from command line


I'm trying to grab a RTSP stream from my CCTV system. Right now, I am only interested in a single camera source.

The RTSP string works fine in VLC.
The command line to connect to the CCTV Camera using ffmpeg and save a jpg image also works fine.

HOWEVER, once i put the same command into my users' cron, or into the root's cron, I get the following error (again, this error doesn't exist if I run the same command from shell)

Code:
ffmpeg: relocation error: /usr/lib/libswresample.so.0: symbol av_get_packed_sample_fmt, version LIBAVUTIL_51 not defined in file libavutil.so.51 with link time reference
Running in shell, this is how the output works

Code:
Phil@linux-zitz:~/CCTV/Snapshots> bash -x capture.sh
++ date +%Y%m%d%H%M
+ DATETIME=201302091640
++ date +%Y%m%d
+ DATE=20130209
+ echo='WE BE RUNNING!'
+ ffmpeg -i 'rtsp://<ip>:<port>/cam/realmonitor?channel=1&subtype=00&authbasic=<hash>' -ss 0 -vframes 1 -f image2 /<path>/CCTV/Snapshots/cam01/201302091640.jpg
ffmpeg version 0.8.3, Copyright (c) 2000-2011 the FFmpeg developers
  built on Sep 20 2011 19:40:02 with gcc 4.5.1 20101208 [gcc-4_5-branch revision 167585]
  configuration: --enable-shared
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  7. 0 / 53.  7. 0
  libavformat  53.  4. 0 / 53.  4. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    2.  0. 0 /  2.  0. 0
[rtsp @ 0x9367340] Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 100.00 (100/1)
Input #0, rtsp, from 'rtsp://<ip>:<port>/cam/realmonitor?channel=1&subtype=00&authbasic=<hash>':
  Metadata:
    title           : h264.mp4
  Duration: N/A, start: 0.120000, bitrate: N/A
    Stream #0.0: Video: h264 (Constrained Baseline), yuv420p, 704x480, 100 tbr, 90k tbn, 180k tbc
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer @ 0x9369020] w:704 h:480 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[buffersink @ 0x952fd00] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x9530a40] w:704 h:480 fmt:yuv420p -> w:704 h:480 fmt:yuvj420p flags:0x4
Output #0, image2, to '/<path>/CCTV/Snapshots/cam01/201302091640.jpg':
  Metadata:
    title           : h264.mp4
    encoder         : Lavf53.4.0
    Stream #0.0: Video: mjpeg, yuvj420p, 704x480, q=2-31, 200 kb/s, 90k tbn, 100 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop, [?] for help
frame=    1 fps=  0 q=7.1 Lsize=      -0kB time=00:00:00.01 bitrate= -17.6kbits/s    
video:34kB audio:0kB global headers:0kB muxing overhead -100.063075%
Phil@linux-zitz:~/CCTV/Snapshots>
This is a OpenSUSE 12.2 system

Any ideas as to why this will work fine via a command prompt, but fail in cron? My goal here is to take 1 minute snapshots and create a time lapse video.

Please keep in mind, I'm not a linux expert. I'm still a 'work in progress'

Again, the command works fine in shell, it just doesn't want to run in cron..

Thanks

Last edited by Liquid_Squelch; 02-09-2013 at 05:11 PM.
 
Old 02-09-2013, 05:16 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Whose crontab is it in? If it's in root's crontab, can you run the ffmpeg command successfully as root?
 
Old 02-09-2013, 05:29 PM   #3
Liquid_Squelch
LQ Newbie
 
Registered: May 2006
Location: Long Island, NY
Distribution: CentOS, OpenSuSE, Ubuntu, Raspbian
Posts: 14

Original Poster
Rep: Reputation: 0
It is my user's crontab. My user can run the ffmpeg command fine, and it saves the image as expected. However, when I put the same command in cron, it fails with the error.

To see if it was a permission's issue, I ran the same command as SU and it works fine. So I added the command into root's crontab, and again, it failed with the same error as the users/my crontab.
 
Old 02-09-2013, 06:20 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Liquid_Squelch View Post
Any ideas as to why this will work fine via a command prompt, but fail in cron?
sure do, environment. What is "the command" exactly?
 
Old 02-10-2013, 05:17 PM   #5
Liquid_Squelch
LQ Newbie
 
Registered: May 2006
Location: Long Island, NY
Distribution: CentOS, OpenSuSE, Ubuntu, Raspbian
Posts: 14

Original Poster
Rep: Reputation: 0
Here is the script <with minor edits for security>
cat capture.sh
Code:
#!/bin/sh
DATETIME=`date +%Y%m%d%H%M`
DATE=`date +%Y%m%d`

echo="WE BE RUNNING!"



ffmpeg -i "rtsp://<ip>:<port>/cam/realmonitor?channel=1&subtype=00&authbasic=<user/pass_hash>" -ss 0 -vframes 1 -f image2 /<path>/Snapshots/cam01/$DATETIME.jpg

#EOF
This is executed as my main user (non-root) and will work fine if I type ./capture.sh from command line.

Last edited by Liquid_Squelch; 02-10-2013 at 05:20 PM.
 
Old 02-10-2013, 11:21 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,814

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
Here's a few things that might help

1. the default env in cron is minimal. Usually we recommend using absolute full paths to all cmds (unless they are built-in shell cmds) and also for all files used.
You can get around this by setting/sourcing the correct env near the top of the script.

2. Try putting the script in cron and saving the output and stderr, inc full debugging 'set -xv'
Code:
min hr dayofmth mth dayofwk /path/to/script >/tmp/script.log 2>&1
Code:
#top of script
#!/bin/bash
set -xv
3. it looks like it might be a library setting; can you check LD_LIBRARY and ensure its set the same in the script

4. does ffmpeg cmd require/expect the presence of a terminal/screen ? (never used it myself)
 
Old 02-11-2013, 01:09 AM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,285

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
As a test, to prove to yourself that it is an environment issue, change your current cron job from "capture.sh" to ". /home/username/.bash_profile; capture.sh" and see if it works with this. Obviously, /home/username/.bash_profile will have to be replaced with the correct fully qualified pathname to your specific profile.
 
Old 02-11-2013, 05:29 PM   #8
Liquid_Squelch
LQ Newbie
 
Registered: May 2006
Location: Long Island, NY
Distribution: CentOS, OpenSuSE, Ubuntu, Raspbian
Posts: 14

Original Poster
Rep: Reputation: 0
Thank you everyone for the help..

I had to add the following into my capture.sh file

Code:
#Set Path for ffmpeg Libraries
export LD_LIBRARY_PATH=/usr/lib/
Thank you all for the help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cron run fails at random points, throws: Attempting to re-run cron while.... Nighteyes Linux - Newbie 2 06-22-2012 06:08 AM
[SOLVED] Partial list with ls-l in bash script run in cron but full list run from command line redgshost Linux - General 29 01-16-2011 01:14 PM
cron backup job fails to run bluethundr Linux - Newbie 5 01-06-2011 06:50 AM
Bash script works from command line, fails from cron cmfarley19 Linux - General 4 08-14-2009 01:24 PM
where is the ffmpeg command line tool? leodemario Linux - Desktop 5 02-25-2007 04:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration