ashi (ashi) wrote,
ashi
ashi

  • Mood:

Converting video files for Palm Pre

This may work for other phones with 480x320 screens, and could easily be adapted for others. I played around with mencoder and found settings that work to play video on my phone using the built-in codecs.

I wrote it into a bash script for Linux, but the settings themselves should work for Mac or Windows. For batch processing, for now I'll just run the command several times on different files with && between them, but more automation would be nice.



Edit: The first few files worked fine, and then the next kept getting:

Too many video packets in the buffer: (1008 in 8395438 bytes).
Maybe you are playing a non-interleaved stream/file or the codec failed?
For AVI files, try to force non-interleaved mode with the -ni option.

I tried adding -ni but still getting the error. Will troubleshoot later.

The audio and subtitle options match most of what I watch, Japanese audio and English subtitles.

The video files I'm using are 1280x720. When I scale the width down to 480 proportionally, the height winds up 272. If I play the file, it expands the width to match the height and cuts off some video and messes with the subtitles. I can press a button to zoom it how I like every time I play a file, or I can use "expand" to add black lines and expand it to a height of 320.

With mencoder in Linux anyway, this tends to leave subtitle artefacts in the black lines if I encode it all at once, so I actually make a second pass just to add these black lines.

I had -noskip in there, copied from someone else's conversion for a different phone, but that was causing some "Too many video packets in the buffer:" errors. Thanks for the suggestion, repura! Also took the suggestion to loop it while it has input so I can, say, ./preconv.sh *.mkv

preconv.sh

#!/usr/bin/env bash

for input_file in "$@";
do

touch temp.mp4
rm -f temp.mp4

output_file=$input_file.mp4
subtitle_width="-subwidth 90"
subtitle_font_text_scale="-subfont-text-scale 4"
subtitle_language="-slang eng,und"
audio_language="-alang jpn,und"
audio_codec="-oac lavc"
video_codec="-ovc lavc"
lavc_options="-lavcopts aglobal=1:vglobal=1:acodec=libfaac:abitrate=128:vcodec=mpeg4:keyint=25"
output_format="-of lavf"
lavf_options="-lavfopts format=mp4"
audio_filter="-af lavcresample=44100"
video_filter1="-vf harddup,scale=480:272"
video_filter2="-vf harddup,expand=480:320"
maximum_sync_correction_per_frame="-mc 0"
do_not_skip_frames="-noskip"
force_non_interleaved="-ni"

/usr/bin/mencoder $input_file -o temp.mp4 $subtitle_width $subtitle_font_text_scale $subtitle_language $audio_language $audio_codec $video_codec $lavc_options $output_format $lavf_options $audio_filter $video_filter1 $maximum_sync_correction_per_frame $force_non_interleaved

/usr/bin/mencoder temp.mp4 -o $output_file $audio_codec $video_codec $lavc_options $output_format $lavf_options $audio_filter $video_filter2 $maximum_sync_correction_per_frame

done


When I run it with sample.mkv, it does this:

/usr/bin/mencoder sample.mkv -o temp.mp4 -subwidth 90 -subfont-text-scale 4 -slang eng,und -alang jpn,und -oac lavc -ovc lavc -lavcopts aglobal=1:vglobal=1:acodec=libfaac:abitrate=128:vcodec=mpeg4:keyint=25 -of lavf -lavfopts format=mp4 -af lavcresample=44100 -vf harddup,scale=480:272 -mc 0 -ni

/usr/bin/mencoder temp.mp4 -o sample.mkv.mp4 -oac lavc -ovc lavc -lavcopts aglobal=1:vglobal=1:acodec=libfaac:abitrate=128:vcodec=mpeg4:keyint=25 -of lavf -lavfopts format=mp4 -af lavcresample=44100 -vf harddup,expand=480:320 -mc 0
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 7 comments