Build video enc

From M1Research

(Difference between revisions)
Jump to: navigation, search
(Single file encoding)
Line 1: Line 1:
-
== Encoding video using <i>ffmpeg</i> ==
+
Article migrated to [http://streaming411.com/wiki/index.php?title=Encoding_prerecorded_video Encoding prerecorded video] at [http://streaming411.com streaming411.com].
-
 
+
-
===One-pass encoding video MPEG4,h264,h263; audio AAC ===
+
-
 
+
-
Encoding mpeg4 video example:
+
-
 
+
-
<pre>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</pre>
+
-
 
+
-
Where
+
-
*<code>-vcodec h263</code> - video codec h263
+
-
*<code>-r 12</code> - 12 frame per seconds
+
-
*<code>-s qcif</code> - qcif=176x144 pixels
+
-
*<code>-b 64</code> - 64kbit/s video stream
+
-
 
+
-
*<code>-acodec aac</code> - audio codec is AAC
+
-
*<code>-ac 1</code> - 1 audio channel (mono)
+
-
*<code>-ar 16000</code> - audio sampling frequency - 16kHz
+
-
*<code>-ab 16</code> - 16kBit/s audio stream
+
-
 
+
-
For lower bitrates i used 24kHz/32kBit (<code>-ar 24000 -ab 32</code>) or 16kHz/16kBit (<code>-ar 16000 -ab 16</code>).
+
-
 
+
-
Encoding h264 video example:
+
-
<pre>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</pre>
+
-
 
+
-
Encoding h263 video example (QT player required, IMHO, <code>.3pg</code> extension for files with h263 codec):
+
-
<pre>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</pre>
+
-
 
+
-
===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):
+
-
 
+
-
<pre>
+
-
#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
+
-
</pre>
+
-
 
+
-
H263,AAC:
+
-
<pre>
+
-
#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
+
-
</pre>
+
-
 
+
-
===Encoding H263+amr_nb (amr narrow band) ===
+
-
 
+
-
Befor start to encode check if your ffmpeg version support AMR codec:
+
-
<pre>[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</pre>
+
-
 
+
-
Used amr encoder supports sampling freq is 8kHz only ( -ar 8000 ) and eight bitrate ranges:
+
-
<pre>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</pre>
+
-
 
+
-
encoding h263, arm_nb (4.75kBit):
+
-
<pre>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</pre>
+
-
 
+
-
encoding h263, arm_nb (12.2kBit):
+
-
<pre>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</pre>
+
-
 
+
-
Two-pass encoding could be processed like in previous topic (h263,5fps,32kbs;amr_nb,8kHz,12kB/s):
+
-
<pre>
+
-
#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
+
-
</pre>
+
-
 
+
-
==Encoding video using <i>VLC</i>.==
+
-
 
+
-
=== Single file encoding ===
+
-
 
+
-
Encoding MPEG4,AAC video:
+
-
<pre>
+
-
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}'
+
-
</pre>
+
-
Where:
+
-
*<code>-I dummy</code> - use text mode (do not start GUI)
+
-
*<code>vlc:quit</code> - exit from VLC after end of playlist (finish encoding)
+
-
*<code>vcodec=mp4v</code> - encode video with MPEG4 codec.
+
-
*<code>vb=168</code> - with 168kB/s bitrate.
+
-
*<code>width=176,height=144</code> - scale video to 176x144 px.
+
-
*<code>deinterlace</code> - deinterlace incoming video.
+
-
*<code>fps=12</code> - frame rate to 12 fps.
+
-
*<code>acodec=mp4a</code> - encode audio with AAC codec
+
-
*<code>ab=32</code> - with 32kB/s bitrate.
+
-
*<code>channels=2</code> - stereo
+
-
*<code>samplerate=22100</code> - audio sampling freq
+
-
 
+
-
In the same manner encoding h264,H263:
+
-
<pre>
+
-
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}'
+
-
</pre>
+
-
 
+
-
=== Multiple files encoding ===
+
-
 
+
-
Using <code>duplicate</code> feature of VLC (multiple files output from one source):
+
-
<pre>
+
-
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}
+
-
"}'
+
-
</pre>
+
-
 
+
-
==Hinting.==
+
-
 
+
-
For hinting media files we will use mpeg4ip packet. ([http://wwww.mpeg4ip.net])
+
-
 
+
-
<b>NB!</b><br>
+
-
mp4creator use extension to determinate file type. Next extensions should be used to name elementary stream files (in our case):
+
-
<pre>.263            - h263 elementary stream
+
-
.264            - h264 elementary stream
+
-
.mp4v, .m4v    - mpeg4 elementary stream
+
-
.aac            - aac elementary stream
+
-
.amr            - amr elementary stream</pre>
+
-
 
+
-
===Hinting mp4 files===
+
-
 
+
-
check content of file:
+
-
 
+
-
<pre>[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</pre>
+
-
 
+
-
<pre>[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</pre>
+
-
 
+
-
For creating proper mp4 or 3gp file with hint tracks we should remultplex and add hint track:
+
-
 
+
-
remultiplex:
+
-
<pre>[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</pre>
+
-
 
+
-
compose new file (mp4: h264,aac):
+
-
<pre>
+
-
[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 </pre>
+
-
 
+
-
compose new file (mp4: mpeg4,aac):
+
-
<pre>[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</pre>
+
-
 
+
-
===Hinting 3gp files===
+
-
 
+
-
check content of source files:
+
-
<pre>[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</pre>
+
-
 
+
-
<pre>[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</pre>
+
-
 
+
-
demultiplex:
+
-
<pre>[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</pre>
+
-
 
+
-
multiplex (h263,aac):
+
-
<pre>[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</pre>
+
-
 
+
-
multiplex (h263,amr):
+
-
<pre>[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</pre>
+

Revision as of 13:24, 28 July 2006

Article migrated to Encoding prerecorded video at streaming411.com.

Personal tools