Build video enc

From M1Research

Revision as of 16:40, 6 July 2006 by Verem (Talk | contribs)
Jump to: navigation, search

Contents

Encoding video using ffmpeg

One-pass encoding video MPEG4,h264,h263; audio AAC

Encoding mpeg4 video example:

ffmpeg -i /home/video/U0003765.avi -vcodec mpeg4 -r 12 -s qcif -b 64 -acodec aac -ac 1 -ar 16000 -ab 16 /home/enc/test01.mp4

Where

  • -vcodec h263 - video codec h263
  • -r 12 - 12 frame per seconds
  • -s qcif - qcif=176x144 pixels
  • -b 64 - 64kbit/s video stream
  • -acodec aac - audio codec is AAC
  • -ac 1 - 1 audio channel (mono)
  • -ar 16000 - audio sampling frequency - 16kHz
  • -ab 16 - 16kBit/s audio stream

For lower bitrates i used 24kHz/32kBit (-ar 24000 -ab 32) or 16kHz/16kBit (-ar 16000 -ab 16).

Encoding h264 video example:

ffmpeg -i /home/video/U0003765.avi -vcodec h264 -r 12 -s qcif -b 64 -acodec aac -ac 1 -ar 16000 -ab 16 /home/enc/test02.mp4

Encoding h263 video example (QT player required, IMHO, .3pg extension for files with h263 codec):

ffmpeg -i /home/video/U0003765.avi -vcodec h263 -r 12 -s qcif -b 64 -acodec aac -ac 1 -ar 16000 -ab 16 /home/enc/test04.mp4

Two-pass encoding video h263,MPEG4,h264; audio AAC

Using two pass encoding could be VERY usefull to create more smother video. If you have pre-recorded material - use two pass encoding.

MPEG4,AAC (h264 has the same manner):

#pass 1
ffmpeg -i /home/video/U0003773.avi -pass 1 -passlogfile logfile -vcodec mpeg4 -r 12 -s qcif -b 64 -an /home/enc/test04.mp4

#delete temp file
rm -f /home/enc/test04.mp4

#pass 2
ffmpeg -i /home/video/U0003773.avi -pass 2 -passlogfile logfile -vcodec mpeg4 -r 12 -s qcif -b 64 -acodec aac -ac 1 -ar 24000 -ab 32 /home/enc/test06.3gp

H263,AAC:

#pass 1
ffmpeg -i /home/video/U0003773.avi -pass 1 -passlogfile logfile -vcodec h263 -r 12 -s qcif -b 64 -an /home/enc/test04.mp4

#delete temp file
rm -f /home/enc/test06.3gp

#pass 2
ffmpeg -i /home/video/U0003773.avi -pass 2 -passlogfile logfile -vcodec h263 -r 12 -s qcif -b 64 -acodec aac -ac 1 -ar 24000 -ab 32 /home/enc/test06.3gp

Encoding H263+amr_nb (amr narrow band)

Befor start to encode check if your ffmpeg version support AMR codec:

[root@dev-3 enc]# ffmpeg -formats | grep amr
FFmpeg version SVN-r5504, Copyright (c) 2000-2004 Fabrice Bellard
  configuration:  --prefix=/usr/local/enctools --enable-mp3lame --enable-libogg --enable-vorbis --enable-theora --enable-faad --enable-faadbin --enable-faac --enable-xvid --enable-x264 --enable-a52 --enable-a52bin --enable-amr_nb --enable-amr_wb --enable-dc1394 --enable-gpl --enable-pp --enable-shared --extra-cflags=-I/usr/local/enctools/include --extra-ldflags=-L/usr/local/enctools/lib
  libavutil version: 49.0.0
  libavcodec version: 51.9.0
  libavformat version: 50.4.0
  built on Jun 29 2006 13:27:24, gcc: 4.1.1 20060525 (Red Hat 4.1.1-1)
 DE amr             3gpp amr file format
 DEA    amr_nb
 DEA    amr_wb

Used amr encoder supports sampling freq is 8kHz only ( -ar 8000 ) and eight bitrate ranges:

min,Hz	  max,Hz    Bitrate
0         4999      MR475
5000      5899      MR515
5900      6699      MR59
6700      7000      MR67
7001      7949      MR74
7950      9999      MR795
10000     11999     MR102
12000     64000     MR122

encoding h263, arm_nb (4.75kBit):

ffmpeg -i /home/video/U0003765.avi -vcodec h263 -r 12 -s qcif -b 64 -acodec amr_nb -ac 1 -ar 8000 -ab 4 /home/enc/test07.3gp

encoding h263, arm_nb (12.2kBit):

ffmpeg -i /home/video/U0003765.avi -vcodec h263 -r 12 -s qcif -b 64 -acodec amr_nb -ac 1 -ar 8000 -ab 12 /home/enc/test08.3gp

Two-pass encoding could be processed like in previous topic (h263,5fps,32kbs;amr_nb,8kHz,12kB/s):

#pass 1
ffmpeg -i /home/video/U0003773.avi -pass 1 -passlogfile logfile -vcodec h263 -r 5 -s qcif -b 32 -an /home/enc/test10.3gp

#delete temp file
rm -f /home/enc/test10.3gp

#pass 2
ffmpeg -i /home/video/U0003773.avi -pass 2 -passlogfile logfile -vcodec h263 -r 5 -s qcif -b 32 -acodec amr_nb -ac 1 -ar 8000 -ab 12 /home/enc/test10.3gp

Encoding video using VLC.

Single file encoding

Encoding MPEG4,AAC video:

vlc -I dummy /home/video/R0004529.avi vlc:quit --sout '#transcode{
vcodec=mp4v,vb=168,width=176,height=144,deinterlace,
acodec=mp4a,ab=32,channels=2,samplerate=22100}:
std{access=file,mux=mp4,dst=/home/enc/test12.mp4}'

Where:

  • -I dummy - use text mode (do not start GUI)
  • vlc:quit - exit from VLC after end of playlist (finish encoding)
  • vcodec=mp4v - encode video with MPEG4 codec.
  • vb=168 - with 168kB/s bitrate.
  • width=176,height=144 - scale video to 176x144 px.
  • deinterlace - deinterlace incoming video.
  • fps=12 - frame rate to 12 fps.
  • acodec=mp4a - encode audio with AAC codec
  • ab=32 - with 32kB/s bitrate.
  • channels=2 - stereo
  • samplerate=22100

In the same manner encoding h264,H263:

vlc -I dummy /home/video/R0004529.avi vlc:quit 
--sout '#transcode{
vcodec=h264,vb=168,width=176,height=144,deinterlace,
acodec=mp4a,ab=32,channels=2,samplerate=22100
}:std{access=file,mux=mp4,dst=/home/enc/test13.mp4}'

vlc -I dummy /home/video/R0004529.avi vlc:quit --sout '#transcode{
vcodec=H263,vb=168,width=176,height=144,deinterlace,
acodec=mp4a,ab=32,channels=2,samplerate=22100
}:std{access=file,mux=mp4,dst=/home/enc/test14.3gp}'

Multiple files encoding

Using duplicate feature of VLC (multiple files output from one source):

vlc -vvv -I dummy /home/video/R0004529.avi vlc:quit --sout '#duplicate{
dst="transcode{
vcodec=H263,vb=96,width=352,height=288,deinterlace,fps=10,
acodec=mp4a,ab=32,channels=2,samplerate=22050}:
std{access=file,mux=mp4,dst=/home/enc/test14_a.3gp}
",dst="transcode{
vcodec=mp4v,vb=96,width=352,height=288,deinterlace,fps=10,
acodec=mp4a,ab=32,channels=2,samplerate=22050}:
std{access=file,mux=mp4,dst=/home/enc/test14_b.mp4}
",dst="transcode{
vcodec=h264,vb=96,width=352,height=288,deinterlace,fps=10,
acodec=mp4a,ab=32,channels=2,samplerate=22050}:
std{access=file,mux=mp4,dst=/home/enc/test14_c.mp4}
"}'

Hinting.

For hinting media files we will use mpeg4ip packet. ([1])

NB!
mp4creator use extension to determinate file type. Next extensions should be used to name elementary stream files (in our case):

.263            - h263 elementary stream
.264            - h264 elementary stream
.mp4v, .m4v     - mpeg4 elementary stream
.aac            - aac elementary stream
.amr            - amr elementary stream

Hinting mp4 files

check content of file:

[root@dev-3 enc]# mp4creator -list test05.mp4
Track   Type    Info
1       video   H264 Baseline@5.1, 222.166 secs, 75 kbps, 176x144 @ 12.000036 fps
2       audio   MPEG-4 AAC LC, 221.909 secs, 0 kbps, 24000 Hz
[root@dev-3 enc]# mp4creator -list test04.mp4
Track   Type    Info
1       video   MPEG-4 Simple @ L1, 222.166 secs, 0 kbps, 176x144 @ 12.000036 fps
2       audio   MPEG-4 AAC LC, 221.909 secs, 0 kbps, 24000 Hz

For creating proper mp4 or 3gp file with hint tracks we should remultplex and add hint track:

remultiplex:

[root@dev-3 enc]# mp4creator -extract=1 test05.mp4 test05.264
[root@dev-3 enc]# mp4creator -extract=2 test05.mp4 test05.aac

[root@dev-3 enc]# mp4creator -extract=1 test04.mp4 test04.mp4v
[root@dev-3 enc]# mp4creator -extract=2 test04.mp4 test04.aac

compose new file (mp4: h264,aac):

[root@dev-3 enc]# mp4creator -create=test05.264 -rate=12 -optimize -variable-frame-rate test05_r.mp4
[root@dev-3 enc]# mp4creator -hint=1 test05_r.mp4
[root@dev-3 enc]# mp4creator -create=test05.aac -interleave -optimize test05_r.mp4
[root@dev-3 enc]# mp4creator -hint=3 test05_r.mp4
[root@dev-3 enc]# mp4creator -list test05_r.mp4
Track   Type    Info
1       video   H264 Baseline@5.1, 222.166 secs, 75 kbps, 176x144 @ 12.000036 fps
2       hint    Payload H264 for track 1
3       audio   MPEG-4 AAC LC, 221.909 secs, 32 kbps, 24000 Hz
4       hint    Payload mpeg4-generic for track 3 

compose new file (mp4: mpeg4,aac):

[root@dev-3 enc]# mp4creator -create=test04.mp4v -rate=12 -optimize -variable-frame-rate test04_r.mp4
[root@dev-3 enc]# mp4creator -hint=1 test04_r.mp4
[root@dev-3 enc]# mp4creator -create=test04.aac -interleave -optimize test04_r.mp4
[root@dev-3 enc]# mp4creator -hint=3 test04_r.mp4
[root@dev-3 enc]# mp4creator -make-isma-10-compliant test04_r.mp4
[root@dev-3 enc]# mp4creator -list test04_r.mp4
Track   Type    Info
1       video   MPEG-4 Simple @ L1, 222.166 secs, 64 kbps, 176x144 @ 12.000036 fps
2       hint    Payload MP4V-ES for track 1
3       audio   MPEG-4 AAC LC, 221.909 secs, 32 kbps, 24000 Hz
4       hint    Payload mpeg4-generic for track 3
5       od      Object Descriptors
6       scene   BIFS

Hinting 3gp files

check content of source files:

[root@dev-3 enc]# mp4creator -list test06.3gp
Track   Type    Info
1       video   H.263, 222.166 secs, 64 kbps, 176x144 @ 12.000036 fps
2       audio   MPEG-4 AAC LC, 221.909 secs, 0 kbps, 24000 Hz
[root@dev-3 enc]# mp4creator -list test10.3gp
Track   Type    Info
1       video   H.263, 222.400 secs, 32 kbps, 176x144 @ 5.000000 fps
2       audio   AMR, 222.020 secs, 13 kbps, 8000 Hz

demultiplex:

[root@dev-3 enc]# mp4creator -extract=1 test06.3gp test06.263
[root@dev-3 enc]# mp4creator -extract=2 test06.3gp test06.aac

[root@dev-3 enc]# mp4creator -extract=1 test10.3gp test10.263
[root@dev-3 enc]# mp4creator -extract=2 test10.3gp test10.amr

multiplex (h263,aac):

[root@dev-3 enc]# mp4creator -create=test06.263 -rate=12 -force3GPCompliance -optimize test06_r.3gp
[root@dev-3 enc]# mp4creator -create=test06.aac -interleave -optimize test06_r.3gp
[root@dev-3 enc]# mp4creator -hint=1 test06_r.3gp
[root@dev-3 enc]# mp4creator -hint=2 test06_r.3gp
[root@dev-3 enc]# mp4creator -list test06_r.3gp
Track   Type    Info
1       video   H.263, 222.088 secs, 64 kbps, 176x144 @ 12.004251 fps
2       audio   MPEG-4 AAC LC, 221.909 secs, 32 kbps, 24000 Hz
3       hint    Payload H263-2000 for track 1
4       hint    Payload mpeg4-generic for track 2

multiplex (h263,amr):

[root@dev-3 enc]# mp4creator -create=test10.263 -rate=5 -force3GPCompliance -optimize test10_r.3gp
[root@dev-3 enc]# mp4creator -create=test10.amr -interleave -optimize test10_r.3gp
[root@dev-3 enc]# mp4creator -hint=1 test10_r.3gp
[root@dev-3 enc]# mp4creator -hint=2 test10_r.3gp
[root@dev-3 enc]# mp4creator -list test10_r.3gp
Track   Type    Info
1       video   H.263, 222.222 secs, 32 kbps, 176x144 @ 5.004005 fps
2       audio   AMR, 222.020 secs, 13 kbps, 8000 Hz
3       hint    Payload H263-2000 for track 1
4       hint    Payload AMR for track 2
Personal tools