Convert any video to AMV format using ffmpeg – For use with Chinese MP4 players

Yes, really AMV format – the bane of many Chinese portable media players… Using Nautilus Actions Configuration, FFMEG, FFMPEG AMV Codec Tools

Sometime last year, I needed a tough portable media player that I could use with my electronic projects. I bought the Zebronics Zebmate Cinema 1.8 player thinking that I was getting 8 GB space and video playing ability for Rs. 1600. The touchscreen is resistive, not capacitative, but that exactly fits my needs. Ordinary users will not like the player and should steer clear of this device. The menu interface is difficult.

The Zebronics Zebmate 1.8 portable media player has a resistive screen and will not work with any video format except the obscure AMV

It will play videos in only one format – AMV. No video converter that I have in Linux and Windows supports this format. On my Linux system, I have a custom-compiled ffmpeg installation that I thought covered everything. Surprisingly, it did not support AMV. There was a Google Code project titled “amv-codec-tools” that seemed to tailor-made for my requirement. I installed that but the video that it generated was full of artifacts. I had given up.

Today, I tried several Windoze software but all the video files they generated gave a “Format Error” message. I then decided to give ffmpeg-amv another attempt. Apparently, the guys who coded this tool seem to be all-Windows folk. The video does not accept OGV or other new formats. When I tried converting a WMV file with ffmpeg-amv, it produced a AMV video file that played both on Linux and the player without any issues. Totem Media Player does not play AMV but not so with VLC. VLC plays everything.

Here is how you convert any video file to AMV in Linux:

  1. Compile and install FFMPEG as per the guide at https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide
  2. Install amv-codec-tools from https://github.com/vsubhash/amv-ffmpeg
  3. Use your regular FFMPEG executable to convert your existing videos (be they FLVs or MP4s) to WMV.
    ffmpeg -i "to-be-converted.mp4" -vcodec msmpeg4 -qscale 1 -r:v 16 -s 160x120 -acodec wmav2 wmv-converted.wmv
    
  4. Use ffmpeg-amv to convert the resultant WMV file to AMV format
    ffmpeg-amv -i "wmv-converted.wmv" -f amv -r 16 -ac 1 -ar 22050 -qmin 3 -qmax 3 converted.amv
    

animation-chinese-amv-player-videos

UPDATE: I then wrote a Nautilus Actions Configuration. That way, I can just right-click any video file and then convert it to AMV. I use two BASH scripts so that I can monitor the conversion process in a Terminal window. The first bash script opens the terminal window and executes the second bash script inside it. The script converts the file first to WMV and then converts the WMV file to AMV format. After this conversion, the script deletes the WMV file leaving only the AMV file on the desktop.

amv-convert-na.txt
gnome-terminal -x sh -c "bash $HOME/Scripts/amv-convert.txt ""$1"""
amv-convert.txt
sWMVFile=${2%.*}.wmv
sAMVFile=${sWMVFile%.*}.amv

echo -e "\n\nWAIT: Converting $2 to WMV\n\n"
ffmpeg -i "$1/$2"  -qscale 2 -vcodec msmpeg4 -r:v 16 -s 160x120 -acodec wmav2 "$1/$sWMVFile"
if [ $? -eq 0 ]; then
	echo -e "\n\nWAIT: Converting $sWMVFile to AMV\n\n"	
	amv-ffmpeg -i "$1/$sWMVFile" -f amv  -r 16 -ac 1 -ar 22050 -qmin 3 -qmax 3 "$1/$sAMVFile"
	if [ $? -eq 0 ]; then
		espeak "AMV conversion succeeded. Created $sAMVFile"
		echo "\n\nSUCCESS: Converted to $1/$sAMVFile"
		notify-send "AMV conversion" "Converted to $1/$sAMVFile"		
		rm "$sWMVFile"
	else
		espeak "AMV conversion failed."
		echo "\n\nFAILURE: Unable to convert $1/$sWMVFile to AMV"
		notify-send "AMV conversion" "Failed to $1/$sWMVFile to AMV"
	fi
else
	espeak "AMV conversion failed."
  echo "\n\nFAILURE: Could not convert $2 to WMV"
  notify-send "AMV conversion" "Failed to convert $1/$2 to WMV"
fi

Use this filter for Caja Actions or Nautilus Actions Configuration: *.3gp;*.asf;*.avi;*.dat;*.flv;*.ogv;*.ogm;*.mov;*.mp4;*.mpg;*.mpeg;*.mp4;*.swf;*.webm;*.wmv

Update (26-10-2018): The amv-ffmpeg converts to an intermediate format if the source video resolution and frame rate is different from that of the AMV container. So, the bash script has been updated to downsize the video in the WMV-creation step. Now, amv-ffmpeg converts directly to AMV. Earlier, the steps were as follows:

ffmpeg -i "to-be-converted.mp4" -qscale 1 -vcodec msmpeg4 -acodec wmav2 wmv-converted.wmv
ffmpeg-amv -i "wmv-converted.wmv" -f amv -s 160x120 -r 16 -ac 1 -ar 22050 -qmin 3 -qmax 3 converted.amv
Advertisements
This entry was posted in software and tagged , , , . Bookmark the permalink.