기타

xavier 우분투에서 동영상 변환(mp4, avi)

아크리엑터 2023. 1. 8. 20:11
반응형

 

ffmpeg 프로그램으로 동영상을 변환할 수있다.

프로그램이 설치되어있지 않다면, 아래와 같이 설치를 한다.

$ sudo apt install ffmpeg

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apt-clone archdetect-deb bogl-bterm busybox-static cryptsetup-bin
  dctrl-tools dpkg-repack gir1.2-timezonemap-1.0 gir1.2-xkl-1.0 grub-common
  libavcodec-dev libavformat-dev libavresample-dev libavutil-dev
  libdc1394-22-dev libdebian-installer4 libexif-dev libfwupdplugin1
  libgdcm-dev libgdcm3.0 libgl2ps1.4 libgphoto2-dev libhdf5-openmpi-103
  libilmbase-dev libjbig-dev libjpeg-dev libjpeg-turbo8-dev libjpeg8-dev
  liblept5 liblzma-dev libnetcdf-c++4 libopencv-calib3d4.2
  libopencv-contrib4.2 libopencv-dnn4.2 libopencv-features2d4.2
  libopencv-flann4.2 libopencv-highgui4.2 libopencv-imgcodecs4.2
  libopencv-imgproc4.2 libopencv-ml4.2 libopencv-objdetect4.2
  libopencv-photo4.2 libopencv-shape4.2 libopencv-stitching4.2
  libopencv-superres4.2 libopencv-video4.2 libopencv-videoio4.2
  libopencv-videostab4.2 libopencv-viz4.2 libopencv4.2-java libopencv4.2-jni
  libopenexr-dev libsocket++1 libswresample-dev libswscale-dev libtesseract4
  libtiff-dev libtiffxx5 libtimezonemap-data libtimezonemap1 libvtk6.3
  libxmlb1 os-prober python3-icu python3-pam rdate tasksel tasksel-data
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libavdevice58
Suggested packages:
  ffmpeg-doc
The following NEW packages will be installed:
  ffmpeg libavdevice58
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,511 kB of archives.
After this operation, 2,286 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 libavdevice58 arm64 7:4.2.7-0ubuntu0.1 [71.4 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 ffmpeg arm64 7:4.2.7-0ubuntu0.1 [1,440 kB]
Fetched 1,511 kB in 5s (309 kB/s) 
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libavdevice58:arm64.
(Reading database ... 195849 files and directories currently installed.)
Preparing to unpack .../libavdevice58_7%3a4.2.7-0ubuntu0.1_arm64.deb ...
Unpacking libavdevice58:arm64 (7:4.2.7-0ubuntu0.1) ...
Selecting previously unselected package ffmpeg.
Preparing to unpack .../ffmpeg_7%3a4.2.7-0ubuntu0.1_arm64.deb ...
Unpacking ffmpeg (7:4.2.7-0ubuntu0.1) ...
Setting up libavdevice58:arm64 (7:4.2.7-0ubuntu0.1) ...
Setting up ffmpeg (7:4.2.7-0ubuntu0.1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

 

설치된 ffmepg의 사용법(--help)을 출력해본다.

$ ffmpeg --help
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Getting help:
    -h      -- print basic options
    -h long -- print more options
    -h full -- print all options (including all format and codec specific options, very long)
    -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf
    See man ffmpeg for detailed description of the options.

Print help / information / capabilities:
-L                  show license
-h topic            show help
-? topic            show help
-help topic         show help
--help topic        show help
-version            show version
-buildconf          show build configuration
-formats            show available formats
-muxers             show available muxers
-demuxers           show available demuxers
-devices            show available devices
-codecs             show available codecs
-decoders           show available decoders
-encoders           show available encoders
-bsfs               show available bit stream filters
-protocols          show available protocols
-filters            show available filters
-pix_fmts           show available pixel formats
-layouts            show standard channel layouts
-sample_fmts        show available audio sample formats
-colors             show available color names
-sources device     list sources of the input device
-sinks device       list sinks of the output device
-hwaccels           show available HW acceleration methods

Global options (affect whole program instead of just one file:
-loglevel loglevel  set logging level
-v loglevel         set logging level
-report             generate a report
-max_alloc bytes    set maximum size of a single allocated block
-y                  overwrite output files
-n                  never overwrite output files
-ignore_unknown     Ignore unknown stream types
-filter_threads     number of non-complex filter threads
-filter_complex_threads  number of threads for -filter_complex
-stats              print progress report during encoding
-max_error_rate maximum error rate  ratio of errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.
-bits_per_raw_sample number  set the number of bits per raw sample
-vol volume         change audio volume (256=normal)

Per-file main options:
-f fmt              force format
-c codec            codec name
-codec codec        codec name
-pre preset         preset name
-map_metadata outfile[,metadata]:infile[,metadata]  set metadata information of outfile from infile
-t duration         record or transcode "duration" seconds of audio/video
-to time_stop       record or transcode stop time
-fs limit_size      set the limit file size in bytes
-ss time_off        set the start time offset
-sseof time_off     set the start time offset relative to EOF
-seek_timestamp     enable/disable seeking by timestamp with -ss
-timestamp time     set the recording timestamp ('now' to set the current time)
-metadata string=string  add metadata
-program title=string:st=number...  add program with specified streams
-target type        specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")
-apad               audio pad
-frames number      set the number of frames to output
-filter filter_graph  set stream filtergraph
-filter_script filename  read stream filtergraph description from a file
-reinit_filter      reinit filtergraph on input parameter changes
-discard            discard
-disposition        disposition

Video options:
-vframes number     set the number of video frames to output
-r rate             set frame rate (Hz value, fraction or abbreviation)
-s size             set frame size (WxH or abbreviation)
-aspect aspect      set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-bits_per_raw_sample number  set the number of bits per raw sample
-vn                 disable video
-vcodec codec       force video codec ('copy' to copy stream)
-timecode hh:mm:ss[:;.]ff  set initial TimeCode value.
-pass n             select the pass number (1 to 3)
-vf filter_graph    set video filters
-ab bitrate         audio bitrate (please use -b:a)
-b bitrate          video bitrate (please use -b:v)
-dn                 disable data

Audio options:
-aframes number     set the number of audio frames to output
-aq quality         set audio quality (codec-specific)
-ar rate            set audio sampling rate (in Hz)
-ac channels        set number of audio channels
-an                 disable audio
-acodec codec       force audio codec ('copy' to copy stream)
-vol volume         change audio volume (256=normal)
-af filter_graph    set audio filters

Subtitle options:
-s size             set frame size (WxH or abbreviation)
-sn                 disable subtitle
-scodec codec       force subtitle codec ('copy' to copy stream)
-stag fourcc/tag    force subtitle tag/fourcc
-fix_sub_duration   fix subtitles duration
-canvas_size size   set canvas size (WxH or abbreviation)
-spre preset        set the subtitle options to the indicated preset

 

MP4파일 하나를 AVI파일로 변환해보자. 변환전 파일이 source.mp4로 변환후 파일을 target.avi 로 정했을 때, 아래와 같이 실행할 수 있다. 옵션은 다양하게 정할 수 있으나, 간단히 실행해서 변환할 수 있다.

$ ffmpeg -i source.mp4 target.avi
반응형