[SOLVED] ffmpeg fails to run in cron but ok from command line
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 04:11 PM.
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.
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)
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.