Tuesday, July 28, 2009

Sony Walkman NWZ-A828, NWZ-A8xx, NWZ-X1xxx --- h264 encoding settings, video encoding in Linux

 UPDATE: Avidemux 2.5.2 with libx264-85 in Ubuntu 10.04 probably won't work. It keeps switching the Main profile on. I tried but failed.


.
.
.


Following information is based on my personal experiments and some research on other people experiences.

Sony Walkman, its media player - not music player, supports media files in MP4 (MPEG-4 ISO) container.
e.g.:
$ file sample.mp4
$ ISO Media, MPEG v4 system, version 1

$ file sample2.mp4
$ ISO Media

Supported audio codec is only AAC-LC that is "MPEG2/4 Advanced Audio Coding" with LC - low complexity profile.

Supported video codecs are BOTH:
MPEG-4 part 2
fourcc: MP4V
ffmpeg encoding setting: vcodec=mpeg4
Avidemux encoding codec is:
"MPEG-4 ASP (lavc)"
AND
H.264 / AVC / MPEG-4 part 10 / MPEG-4 AVC at Baseline profile and level 1.3
fourcc: AVC1
ffmpeg encoding setting: vcodec=libx264
Avidemux encoding codec is: "MPEG-4 AVC (x264)"


Example1:
$ mp4info sample_mpeg4.mp4
$ mp4info version 1.6
$ Track Type Info
$ 1 video MPEG-4 Simple @ L1, 2625.998 secs, 0 kbps, 320x240 @ 23.976027 fps
$ 2 audio MPEG-4 AAC LC, 2625.856 secs, 112 kbps, 48000 Hz
$ Name: sample_mpeg4.mp4
$ Artist: Avidemux
$ Writer: Avidemux
$ Tool: Lavf51.12.1

Example2:
$ mp4info sample_mpeg4avc.mp4
$ mp4info version 1.6
$ Track Type Info
$ 1 video H264 Baseline@1.3, 183.480 secs, 400 kbps, 320x240 @ 25.000000 fps
$ 2 audio MPEG-4 AAC LC, 182.869 secs, 112 kbps, 48000 Hz
$ Name: sample_mpeg4avc.mp4
$ Artist: Avidemux
$ Writer: Avidemux
$ Tool: Lavf51.12.1



Notes:
FFmpeg itself works well, I found some shell-scripts, presented at the end of this blog. Using ffmpeg has an advantage of direct specification of H264 codec level (-level 13).
Avidemux has no direct settings to choose level or profile.

I recommend to have the x264 library version fresh enough
.

avidemux settings

Avidemux used is Debian package version: 2.4.4-0.2 with dependency on libx264-67 (>= 1:0.svn20090327).

screenshot 1


Note: usual stuff


screenshot 2

Note: usual stuff


screens
hot 3

Note: CABAC must not be used with Baseline profile.


screenshot 4

Note: No B-frames! Some partitioning can't be used.


screensho
t 5

Note: Proper settings for VBV buffer according to H264 level 1.3.

screenshot 6

Note: Default settings.

screensho
t 7


Note that newer x264 prints what a profile and level were estimated from Avidemux settings. Earlier versions did not have this estimation feature operating well and Walkman was not able to play resulting video.

ffmpeg settings
The most important is to
disable CABAC:
-coder 0
set level 1.3:
-level 13
set the VBV buffer params:
-maxrate 768k -bufsize 2M

Do not use options which enable higher H264 profiles, like B-frames etc.
Some macroblocks partitioning can't be used for Baseline profile.

# ############################################################
# ############################################################
#!/bin/bash

fname="E26"

ffmpeg -y -i "${fname}.avi" -threads 1 -vcodec libx264 -b 250k -maxrate 768k \
-flags +loop -cmp +chroma -partitions +parti4x4+partp4x4+parti8x8+partp8x8 \
-flags2 +mixed_refs -level 13 -refs 3 -subq 7 -trellis 2 -g 300 -s 320x240 \
-ab 128k -ar 44100 -ac 2 -acodec libfaac \
"${fname}.mp4"

# ############################################################
#!/bin/bash

fname="E26"

ffmpeg -i "${fname}.avi" \
-acodec libfaac -ab 128k -s 320x240 \
-vcodec libx264 -b 500k \
-flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 \
-flags2 +mixed_refs -me_method umh -subq 6 -trellis 1 -refs 5 -coder 0 -me_range 16 \
-g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 500k -maxrate 768k \
-bufsize 2M -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 13 \
-threads 0 -f mp4 "${fname}.mp4"


# ############################################################
#!/bin/bash

fname="E26"

ffmpeg -i "${fname}.avi" -an -pass 1 -s 320x240 \
-vcodec libx264 -b 512k -flags +loop -cmp +chroma -partitions 0 \
-me_method dia -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 \
-g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 512k \
-maxrate 768k -bufsize 2M -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 \
-level 13 -threads 0 -f mp4 /dev/null

ffmpeg -i "${fname}.avi" -acodec libfaac -ab 96k -pass 2 -s 320x240 \
-vcodec libx264 -b 512k \
-flags +loop -cmp +chroma \
-partitions +parti4x4+partp8x8+partb8x8 \
-flags2 +mixed_refs -me_method umh -subq 6 \
-trellis 1 -refs 5 -coder 0 -me_range 16 -g 250 \
-keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 \
-bt 512k -maxrate 768k -bufsize 2M -qcomp 0.6 \
-qmin 10 -qmax 51 -qdiff 4 -level 13 -threads 0 -f mp4 "${fname}.mp4"

# ############################################################
# ############################################################
# ############################################################

Some good resources to check:

x264 ffmpeg mapping and options guide


H264 profiles and levels

More about FFmpeg encoding for Sony Walkman:

Walkman X – Video encoding in Linux / Mac OS X


#

No comments:

Post a Comment