Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

ive written a ffmpeg script to mass convert mkv into mp4. when i run the script as my user, and enter my password for sudo privileges it works very well from the command line. the script is:

#! /bin/bash

for INF in *.mkv
  sudo ffmpeg -i "$INF" -vcodec copy -acodec ac3 "${INF%.*}.mp4"

very simple and works. however, when i run it as a cron job (setup through webmin) as root it runs ffmpeg but then says:

ffmpeg version git-2013-05-14-56ba331 Copyright (c) 2000-2013 the FFmpeg developers
  built on May 13 2013 23:50:16 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-version3
  libavutil      52. 31.100 / 52. 31.100
  libavcodec     55.  9.100 / 55.  9.100
  libavformat    55.  7.100 / 55.  7.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 65.100 /  3. 65.100
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
*.mkv: No such file or directory

for some reason it seems like it cant access the mkv files or INF doesnt work with cron jobs? i dont know. any push in the right direction would be very helpful.

edit: when i run this the script ( is in a certain dir (/mnt/sdb1/temp) do i need to have that in the script? would it be giving me that error because its running it somewhere else that actually doenst have mkv files?

share|improve this question

marked as duplicate by kos command-line May 7 at 11:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

i figured it out.

i needed to change this line:

for INF in *.mkv

to point directly at the folder:

for INF in /mnt/sdb1/temp/*.mkv
share|improve this answer
In general, in scripts, use the full path – bodhi.zazen May 23 '13 at 3:30
Or change to the desired directory. cd /mnt/sdb1/temp || exit; for inf in ./*.mkv; do. On a side note, avoid using all uppercase variable names. Special shell variables and environment variables are (almost) always all uppercase, so using lowercase variable names avoids accidentally overriding special shell variables or environment variables. – geirha May 23 '13 at 18:42

Try using full paths and avoid using sudo in cron jobs. For instance, change "BASEPATH" and try:

find /BASEPATH -name "*.mkv" -execdir sh -c \ 
  'ffmpeg -y -i "{}" -vcodec copy -acodec ac3 "$(basename "{}" .mkv).mp4"' \;

The sh -c, instead of -exec (or -execdir), makes basename work ok, and avoids the double extension ".mkv.mp4" in:

find /BASEPATH -name "*.mkv" -exec \ 
   ffmpeg -y -i "{}" -vcodec copy -acodec ac3 "{}.mp4" \;

NOTE: I added -y option to avoid ffmpeg asking "Overwrite ? [y/N]" existing files. I use backslashes at end-of-line to improve readability,

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.