简体   繁体   中英

How to set up a cron job for ffmpeg in centOS 6

I can convert from mp4 file to jpg file manually one by one with the below command on centOS 6 environment.

Now, could anyone help me out how to set up a cron for any mp4 file in the directory to be converted automatically to jpg file with the same file name as mp4 file such as 03052022_5a9d28723d2da.jpg for the below environment?

OS:centos-6 (x86_64)

ffmpeg version 2.2.2

Plesk 17.0.17

[root@server-xxxxxxxx-x ~]# ffmpeg -i                                \
  /var/www/vhosts/xxxxx.com/httpdocs/save/03052022_5a9d28723d2da.mp4 \
  /var/www/vhosts/xxxxx.com/httpdocs/save/03052022_5a9d28723d2da.jpg

With 's/.conf$/.jpg/p':

[root@server-xxxxxx-x ~]# for i in `find /var/www/vhosts/xxxxxx.com/httpdocs/save/ -type f -name "*.mp4"`; do ffmpeg -i $i `echo $i | sed -En 's/.conf$/.jpg/p'`; done

ffmpeg version 2.2.2 Copyright (c) 2000-2014 the FFmpeg developers built on Feb 21 2018 03:03:24 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18) configuration: libavutil 52. 66.100 / 52. 66.100 libavcodec 55. 52.102 / 55. 52.102 libavformat 55. 33.100 / 55. 33.100 libavdevice 55. 10.100 / 55. 10.100 libavfilter 4. 2.100 / 4. 2.100 libswscale 2. 5.102 / 2. 5.102 libswresample 0. 18.100 / 0. 18.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/vhosts/xxxxxx.com/httpdocs/save/03081956_5aa116c836015.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2018-02-14 04:42:34 Duration: 00:00:00.83, start: 0.000000, bitrate: 23270 kb/s Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 25370 kb/s, SAR 65536:65536 DAR 16:9, 29.73 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate : 90 creation_time : 2018-02-14 04:42:34 handler_name : VideoHandle Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default) Metadata: creation_time : 2018-02-14 04:42:34 handler_name : SoundHandle At least one output file must be specified Conversion failed!

With "s/.conf$/.jpg/p":

[root@server-xxxxxxx-x ~]# for i in `find /var/www/vhosts/xxxxxx.com/httpdocs/save/ -type f -name "*.mp4"`; do ffmpeg -i $i `echo $i | sed -En "s/.conf$/.jpg/p"`; done

ffmpeg version 2.2.2 Copyright (c) 2000-2014 the FFmpeg developers built on Feb 21 2018 03:03:24 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18) configuration: libavutil 52. 66.100 / 52. 66.100 libavcodec 55. 52.102 / 55. 52.102 libavformat 55. 33.100 / 55. 33.100 libavdevice 55. 10.100 / 55. 10.100 libavfilter 4. 2.100 / 4. 2.100 libswscale 2. 5.102 / 2. 5.102 libswresample 0. 18.100 / 0. 18.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/vhosts/xxxxxx.com/httpdocs/save/03081956_5aa116c836015.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2018-02-14 04:42:34 Duration: 00:00:00.83, start: 0.000000, bitrate: 23270 kb/s Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 25370 kb/s, SAR 65536:65536 DAR 16:9, 29.73 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate : 90 creation_time : 2018-02-14 04:42:34 handler_name : VideoHandle Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default) Metadata: creation_time : 2018-02-14 04:42:34 handler_name : SoundHandle At least one output file must be specified Conversion failed!

With "s/.mp4$/.jpg/p"

[root@server-xxxxx-x ~]# for i in `find /var/www/vhosts/xxxxxx.com/httpdocs/save/ -type f -name "*.mp4"`; do ffmpeg -i $i `echo $i | sed -En "s/.mp4$/.jpg/p"`; done

[image2 @ 0x2c488e0] Could not get frame filename number 2 from pattern '/var/www/vhosts/xxxxxx.com/httpdocs/save/03100013_5aa2a49bb67bc.jpg' (either set updatefirst or use a pattern like %03d within the filename pattern) av_interleaved_write_frame(): Invalid argument frame= 2 fps=0.0 q=3.2 Lsize=N/A time=00:00:00.06 bitrate=N/A video:289kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead -100.007446% Conversion failed!

Here is the command which will convert all .mp4 to .jpg in the mentioned directory:

# for i in `find /var/www/vhosts/xxxxx.com/httpdocs/save/ -type f -name "*.mp4"`; do ffmpeg -i $i `echo $i | sed -En 's/.conf$/.jpg/p'`; done

If you want to delete source .mp4 file upon the conversion, expand it as follows:

# for i in `find /var/www/vhosts/xxxxx.com/httpdocs/save/ -type f -name "*.mp4"`; do ffmpeg -i $i `echo $i | sed -En 's/.conf$/.jpg/p'`; rm -f $i; done

You can schedule this command as a regular cron job or via Tools & Settings > Scheduled Tasks > Add Task in Plesk. I executed the command string of the same complexity just now and it works as expected: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM