How to set FFmpeg output directory? [SOLVED]

Omer Cakmak

Tips and Tricks, Linux

FFmpeg is a free (LGPL, GPL licensed) software project that produces programs and libraries for managing multimedia files. It can convert any video format to another video format by changing the codecs as well.

FFmpeg can be used by end users and system administrators. Specifying FFmpeg's output directory may be different for the 2 user types. In this article "How to set ffmpeg output directory?" We will answer the question.


How to set ffmpeg output directory?

The usage of FFmpeg is as follows:

ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...

If you are going to work on only one file, you just need to be in the directory where the file is located:

[foc@rocky9 ~]$ pwd
[foc@rocky9 ~]$ ls


Simple Usage Example

Let's do an example on a file according to FFmpeg standard usage. To convert answer.m4a to answer.mp3, the command should be written like this:

[foc@rocky9 ~]$ ffmpeg -i answer.m4a answer.mp3
ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 11 (GCC)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 ' --extra-cflags=' -I/usr/include/rav1e' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --enable-chromaprint --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libbs2b --enable-libcdio --enable-libdrm --enable-libjack --enable-libjxl --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libilbc --enable-libmp3lame --enable-libmysofa --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librav1e --enable-librubberband --enable-libsmbclient --enable-version3 --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-vulkan --enable-libshaderc --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-avfilter --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-lto --enable-libmfx --enable-runtime-cpudetect
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'answer.m4a':
    major_brand     : 3gp4
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2022-12-25T18:35:05.000000Z 13
  Duration: 00:23:02.76, start: 0.000000, bitrate: 130 kb/s
  Stream #0:0[0x1](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 128 kb/s (default)
      creation_time   : 2022-12-25T18:35:05.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'answer.mp3':
    major_brand     : 3gp4
    minor_version   : 0
    compatible_brands: isom3gp4 13
    TSSE            : Lavf59.27.100
  Stream #0:0(eng): Audio: mp3, 44100 Hz, mono, fltp (default)
      creation_time   : 2022-12-25T18:35:05.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.37.100 libmp3lame
size=   10804kB time=00:23:02.76 bitrate=  64.0kbits/s speed= 144x    
video:0kB audio:10803kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.003200%

As can be seen in the command output, the directory where the file is located is detected as both input folder and output folder. Because we did not assign any input/output folder.

And after the command the convert process is completed. A new file has been created in the active folder.

[foc@rocky9 ~]$ ls
answer.m4a  answer.mp3

If the files are not in the active folder, their location is written after the -i parameter:

[foc@rocky9 ~]$ sudo ffmpeg -i /opt/answer.m4a /opt/answer.mp4
Output #0, mp4, to '/opt/answer.mp4':
    major_brand     : 3gp4
    minor_version   : 0
    compatible_brands: isom3gp4

You can see the Output folder in the command output.


Using FFmpeg in Bash Script

If you are going to convert on a single file or once, the above step will be enough for you. If the convert process is to be repeated over and over, it must of course be automated with a bash script.

Let's write an example script. Let's give the output and input directory information as constant in the script:

[foc@rocky9 ~]$ cat 

ffmpeg -i $input/answer.m4a $output/answer.mp3

Run the script:

[foc@rocky9 ~]$ ./

You can see the input and output folder directories in the script output:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/foc/convert-input/answer.m4a':
Output #0, mp3, to '/home/foc/convert-output/answer.mp3':

You can give directory information as environment variable:

[foc@rocky9 ~]$ export ffmpeg_input="/home/foc/convert-input"
[foc@rocky9 ~]$ export ffmpeg_output="/home/foc/convert-output"
[foc@rocky9 ~]$ echo $ffmpeg_output
[foc@rocky9 ~]$ echo $ffmpeg_input

Then we can edit the script like this:

[foc@rocky9 ~]$ cat

ffmpeg -i $ffmpeg_input/answer.m4a $ffmpeg_output/answer.mp3

Then you won't need to give the input/output folder in the script.



In this article, we have made examples of setting the input/output folder using ffmpeg. If you haven't installed ffmpeg before, you can start from the article "Install FFmpeg in Rocky Linux 9 [Step-by-Step]".


References - ffmpeg Documentation - How do I specify ffmpeg video directory?


Views: 149

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on LinkedIn or check his projects on GitHub page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to

Thank You for your support!!

Leave a Comment

We try to offer easy-to-follow guides and tips on various topics such as Linux, Cloud Computing, Programming Languages, Ethical Hacking and much more.

Programming Languages