FFmpeg How-to

(2/3/2013;)

When use libx264 option to create a MP4 video file, make sure the image resolution is both even numbers. For example 577×780 would produce ‘577 can’t be divided by 2.’

How to calculate video bitrate?

Kush gauge: pixel count x motion factor x 0.07 ÷ 1000 = bit rate in kbps
(frame width x height = pixel count) and motion factor is 1,2 or 4
Screencast example
For example if your video is a low motion 5fps screen cast in a 1280 x 720 frame size you would have a formula like this:

1280 x 720 = 921,600 pixel count
5 frames per second
1 = Low Motion

(921,600 x 5) x 1 x 0.07 = 322,560 bps / 1000 = 322 kbps bitrate

High action video example
Another example on the other side of the spectrum would be a 24 fps high action shot of an action scene with multiple quick cuts in a 1920 x 1080 frame size:

1920 x 1080 = 2,073,600 pixel count
24 frames per second
4 = High Motion

(2,073,600 x 24) x 4 x 0.07 = 13,934,592 bps / 1000 = 13,934 kbps bitrate

When using this gauge with a variable bitrate (VBR), 75% of the resulting bitrate can be used for the minimum rate and 150% for the maximum rate.

ffmpeg: the mother of all command-lines It explains thoroughly how to use the options. I’ll test some of options later on.

Source

How to convert a high quality file into a .flv file format

Now, lets up all this knowledge to convert a single high quality file you have shot from your video camera and convert it into a low quality file, say flv for a player. Although the flags and the method we are using is all that matters, I am using flv to just define the output video’s specs.

Video Bitrate: < 500 kbps

aspect ratio: 480×360

audio bitrate: 32kbps

Frames per second: 25

We will use the following command to make this happen.

ffmpeg -i recorded_file.mov -ar 22050 -ab 32k -r 25 -s 480x360 -vcodec flv -qscale 9.5 output_file.avi

1.9G GOPR0014.MP4
Length: 25:28
Media information:
Stream 0
Type: Video
Codec: H264 – MPEG-4 AVC (part 10) (avc1)
Language: English
Resolution: 1280×720
Frame rate: 29.970030
Stream 1
Type: Audio
Codec: MPEG AAC Audio (mp4a)
Language: English
Channels: Stereo
Sample rate: 48000 Hz

ffmpeg -qscale 4 -i infile.avi outfile.flv
ffmpeg -i recorded_file.mov -ar 22050 -ab 32k -r 25 -s 480×360 -vcodec flv -qscale 9.5 output_file.avi

ffmpeg -qscale 4 -i GOPR0014.MP4 -s 640×360 -vcodec flv Aug7ride.flv

$ ffmpeg -i GOPR0014.MP4 -ar 22050 -ab 32k -r 25 -s 480x360 -vcodec flv -qscale 4 Aug7thride.flv
FFmpeg version SVN-r0.5.9-4:0.5.9-1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --extra-version=4:0.5.9-1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libdirac --enable-libgsm --enable-libopenjpeg --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libfaad --enable-libdc1394 --enable-shared --disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 1 / 52.20. 1
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Jun 10 2012 08:33:06, gcc: 4.4.5

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (30000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘GOPR0014.MP4’:
Duration: 00:25:28.39, start: 0.000000, bitrate: 10126 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 1280×720, 29.97 tbr, 29.97 tbn, 59.94 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16
Output #0, flv, to ‘Aug7thride.flv’:
Stream #0.0(eng): Video: flv, yuv420p, 480×360, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream #0.1(eng): Audio: adpcm_swf, 22050 Hz, stereo, s16, 32 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
[h264 @ 0x1ccdc20]B picture before any references, skipping
[h264 @ 0x1ccdc20]decode_slice_header error
[h264 @ 0x1ccdc20]no frame!
Error while decoding stream #0.0
[h264 @ 0x1ccdc20]B picture before any references, skipping
[h264 @ 0x1ccdc20]decode_slice_header error
[h264 @ 0x1ccdc20]no frame!
Error while decoding stream #0.0
frame=38209 fps= 17 q=4.0 Lsize= 866644kB time=1528.29 bitrate=4645.4kbits/s
video:832463kB audio:33070kB global headers:0kB muxing overhead 0.128419%

Elapsed time: 39 min (start at 15:34, end at 16:13)
847M Aug 7 16:11 Aug7thride.flv

Compress MP4 video file
$ ffmpeg -i input.mp4 -acodec mp2 output.mp4

How to cut MP4 file?

ffmpeg -vcodec copy -ss START -t LENGTH -i ORIGINALFILE.mp4 OUTFILE.mp4
ffmpeg -vcodec copy -ss 0 -t 00:15:00 -i ORIGINALFILE.mp4 OUTFILE-1.mp4

How to convert MP4 file to AVI?
(09/03/2012;)

ffmpeg -i 0902tour2.mp4 -vcodec copy -acodec copy 0902tour2.avi

Merge mutiple MP4 files
(7/16/2017)

ffmpeg -f concat -i video_list.txt 20170716_musimchun_scene.mp4

# 7/16/2017 afternoon Musimchun scenes
file 'MAH00085.MP4'
file 'MAH00086.MP4'
file 'MAH00096.MP4'
file 'MAH00098.MP4'
file 'MAH00101.MP4'
file 'MAH00104.MP4'
file 'MAH00106.MP4'
file 'MAH00107.MP4'
file 'MAH00114.MP4'

About janpenguin

Email: janpenguin [at] riseup [dot] net Every content on the blog is made by Free and Open Source Software in GNU/Linux.
This entry was posted in GNU/Linux, Photography and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s