FFMPEG-Usage

FFMPEG-Usage

Usage

  Here, i'm trying to sequeeze a normal video to a n times faster. But, i found that there are many ways to relize this, such as

  • ffmpeg and adjust the speed while roamming, etc.
  • OpenCV requires being complied with ffmpeg, which i didn't have the condition and many video format(.mp4) is not well supported.

Installation

  • Under Linux
1
sudo apt install ffmpeg
  • Under Windows

Directly download the binary executable file from the official page. Move to the bin folder and run the ./ffmpeg in command line.

For example the "ffmpeg-master-latest-win64-gpl-shared" file.

Some common command line arguments

From ffmpeg official page.

  1. -y: (default) to automatically override the out file without further confirmation.
  2. -i: input file.
  3. -vf: video filter, e.g. v360 et al.
  4. -bufsize: set the buffer size.
  5. -c:v libx265: libx265 video encoder.
  6. -b:v 40000k: setting code rate of video.
  7. --preset: 主要调节编码速度和质量的平衡,有ultrafast(转码速度最快,视频往往也最模糊)、superfast、veryfast、faster、fast、medium、slow、slower、veryslow、placebo,从快到慢.

Video speed acceleration

  1. Speed or slow down the video, and the example as followings (but the content is not smooth at all): *** 4 times faster:+1:

ffmpeg -i origin.mp4 -vf "setpts=0.25\*PTS" UpTheOrigin.mp4 4 times slower

ffmpeg -i origin.mp4 -vf "setpts=4\*PTS" DownTheOrigin.mp4


  1. Change the video format

ffmpeg -i origin.ogv -vcodec h264 output.mp4

ffmpeg -i origin.ogv -vcodec mpeg4 output.mp4

ffmpeg -i origin.ogv -vcodec libxvid output.mp4

ffmpeg -i origin.mp4 -vcodec wmv1 output.wmv

ffmpeg -i origin.mp4 -vcodec wmv2 output.wmv


  1. Compress video into a smaller one.
1
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4
  1. More resources

Please dive the Blog.

Attach two images(videos) into one image(video)

1
.\ffmpeg.exe -i D:\CodeSpace\fisheye_image\0000000007-l.png -i D:\CodeSpace\fisheye_image\0000000007-r.png -filter_complex hstack -y ./dual_fisheye_image.png

-filter_complex hstack: hstack means images are stacked horizontally, vertically is set to vstack.

the raw separate images are here:

left image right image

the returned joined image (./dual_fisheye_image.png) is as followings:

References

Fisheye Image to equirectangular Image

  • For single dual fisheye image to equirectangular image.
1
./ffmpeg -i .\dual_fisheye_image.png -vf v360=dfisheye:e:ih_fov=185:iv_fov=185:yaw=-90 -y ./equirectangle_image.png

185 is the image FOV.

References

Sequence image to video back and forth

  • image to video
1
.\ffmpeg.exe -f image2 -r 1 -i xxx/000000000%d.png -vcodec libx265 -pix_fmt yuv420p -b:v 40000k -bufsize 5000k -preset ultrafast -c:a copy -y -r 1 ./fisheye_rgb.mp4

-f: image2 image type.

-r: video frame equal to 1, default by 25, which means extract 1(25) frames/s. Also known as definition how fast the pictures are read in. To note that, the position of the -r argument has different meanings. If we want to change the framerate of the output video, -r should be at the front of the ./fisheye_rgb.mp4

-pix_fmt yuv420p: is required under Windows platform.

  • video to image
1
.\ffmpeg.exe -i .\fisheye_rgb_l.mp4 -r 1 -q:v 1 -start_number 0 ./%10d.png

%10d: rename the out put images with int, e.g 0000000001.png.

-start_number 0: means the result image id will start from 0. Also this argument could be used for selecting the specific images for video generation. Deeper operations(e.g. glob, cat and etc) from reference1.

References

Dual fisheye image video to equirectangular video

  • For dual fisheye video to equirectangular video.
1
./ffmpeg -y -i $file -vf v360=dfisheye:e:yaw=-90:ih_fov=187.8:iv_fov=185 -c:v libx265 -b:v 40000k -bufsize 5000k -preset ultrafast -c:a copy out.mp4

here we choose the ==v360== filter, v360 basic command as followings: input:output:interp:w:h:in_stereo:out_stereo:yaw(pitch\roll):rorder:h_filp(v_flip\d_flip):ih_flip(iv_flip):in_trans:out_trans:h_offset(\v_offset):alpha_mask:reset_rot

and the corresponding parameters as followings:

dfisheye = input format is dual fisheye video for input.

e = 'Equirectangular projection' for output video format.

yaw = rotation along yaw direction for output video. Values in degrees.

ih_fov & iv_fov = is output horizontal/vertical/diagonal field of view. Values in degrees.

there are no blending operation for the basic command code.

References

  • More details at here
  • Basic pipeline from wiki (Recommand:+1::+1::+1:)
#
| visits
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×