maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N9 / N950 (https://talk.maemo.org/forumdisplay.php?f=51)
-   -   Encoding videos for N9 (using CLI tools) (https://talk.maemo.org/showthread.php?t=88358)

ladoga 2012-12-22 17:44

Encoding videos for N9 (using CLI tools)
 
I was playing with ffmpeg on my laptop trying to figure out good settings in encoding video for the N9. Settings that would also play nicely with Harmattan's default video player and support Dolby 5.1 surround when possible. I used Nokia Developer Wiki as a reference.

Encoding/Transcoding

For x264 baseline profile and 6 channel ac3 audio (ca. 700MB/h):
Code:

$ ffmpeg -i infile.mp4 -s 854x480 -r 25 -g 25 -vcodec libx264 -vb 1536k -vprofile baseline -acodec ac3 -ab 192k -ac 6 outfile.mp4
If you need a smaller file size (ca. 500MB/h) 1024kb/s video bit rate is also very watchable:
Code:

$ ffmpeg -i infile.mp4 -s 854x480 -r 25 -g 25 -vcodec libx264 -vb 1024k -vprofile baseline -acodec ac3 -ab 192k -ac 6 outfile.mp4
Ripping a DVD

One method to rip a DVD is to concatenate VOB files and pipe the output to ffmpeg:
Code:

$ cat VTS_02_1.VOB VTS_02_2.VOB VTS_02_3.VOB | ffmpeg -i - -r 25 -g 25 -vcodec libx264 -vb 1536k -vprofile baseline -acodec ac3 -ab 192k -ac 6 ~/outfile.mp4
You will often spot the correct VOB files on a DVD by simply looking at the filesize (larger ones usually contain the main movie, while the smaller ones are menus and extras). If unsure, play a VOB file with mplayer (or your player of choice) to see what it contains.

If you want to remove black borders when ripping a DVD you can play a VOB file using "mplayer -vf cropdetect" and simply copy & paste the crop filter string from its output (for example -vf crop=704:432:10:72) into your ffmpeg command.

Sometimes DVDs have several audio tracks for different languages and by default ffmpeg rips only the first one. If you need to select another audio track you can do that by using -map flags. For more information see: http://howto-pages.org/ffmpeg/#map

Legend

Flags in use (as of ffmpeg v.1.0.1):
-i = input file *
-s = video resolution
-r = frame rate **
-g = I-frame interval (frames) ***
-vcodec = video codec
-vb = video bit rate
-vprofile = video profile ****
-acodec = audio codec
-ab = audio bit rate
-ac = audio channels

* Most video formats/containers will work as input.
** Practical framerate limits for smooth playback are 30fps@854x480 and 25fps@1280x720. [thanks thedead1440]
*** More frequent I-frames improve error correction and seek performance at cost of filesize. (The Nokia Developer Wiki recommends one I-frame/s.)
**** -vpre in older versions, you can also try -profile

Any improvements/corrections/alternative methods are more than welcome.

anthonie 2012-12-22 17:48

Re: Encoding videos for N9 (using CLI tools)
 
Can't promote ffmpeg enough as the tool to use when encoding. Thanks for the clear instructions.

www.rzr.online.fr 2012-12-22 20:18

Re: Encoding videos for N9 (using CLI tools)
 
why not suggest a patent free output format ? like ogv theora or webm ? but will those codec be hardware accelerated ?

--
http://rzr.online.fr/q/codec

ladoga 2012-12-22 23:36

Re: Encoding videos for N9 (using CLI tools)
 
Quote:

Originally Posted by www.rzr.online.fr (Post 1306929)
why not suggest a patent free output format ? like ogv theora or webm ? but will those codec be hardware accelerated ?

--
http://rzr.online.fr/q/codec

I wanted to get smoothly playing 854x480 video and I presume that other formats are not HW accelerated (See the developer wiki, link in the first post). The audio codec is likewise chosen only because it's the only one supported for surround sound on the N9.

Using patent free formats would be better in every other respect. I hope someone wants to experiment with them to find out the best quality that we can play on our N9's and add to this thread.

thedead1440 2012-12-23 06:44

Re: Encoding videos for N9 (using CLI tools)
 
ladoga,

For the second command I think you mean to put it as -vb 1024k instead of 1536k


Edit: I know you hate resolutions higher than the stock but i tried and it works perfectly fine with 1280x720; will now attempt to use movgrab to download a file and encode it to 720p baseline at the same time so that one file can be played across your desktop and device...


Edit 2: I missed out on the "" marks in the movgrab stage and it wasn't working but it works now :D

Code:

~ $ X=input.mp4 ; movgrab -o "$X" -f mp4:1280x720 "http://www.youtube.com/watch?v=xxxxxxx" ; ffmpeg -i $X -s 1280x720 -r 25 -g 25 -vcodec libx264 -vb 1024k -vprofile baseline -acodec ac3 -ab 192k -ac 6 output.mp4 ; rm -rf $X

Edit 3: Update second edit with a cleaner command and changed fps to 25fps with 1 I-frame being created per second as per ladoga's method which results in smoother seeking in the video.


Edit 4: Just realized that the command in edit 2 says 1024k for the video bitrate; it can be safely increased to 1536k as per ladoga's first post.

ladoga 2012-12-25 18:41

Re: Encoding videos for N9 (using CLI tools)
 
Seems like burning srt subtitles into movies using ffmpeg is possible: http://ffmpeg.org/trac/ffmpeg/wiki/H...%20the%20video

Though with v.1.0.1 trying "-vf subtitles=whatever.srt" spits out "No such filter: 'subtitles'" in bold red :)

thedead1440 2012-12-26 03:58

Re: Encoding videos for N9 (using CLI tools)
 
Quote:

Originally Posted by ladoga (Post 1307672)
Seems like burning srt subtitles into movies using ffmpeg is possible: http://ffmpeg.org/trac/ffmpeg/wiki/H...%20the%20video

Though with v.1.0.1 trying "-vf subtitles=whatever.srt" spits out "No such filter: 'subtitles'" in bold red :)

Using that worked for me; maybe its the version of ffmpeg?

I'm using 7:201212231432-git-1 which seems to be after the 29/11/12 date the man page states for 'subtitles' support... I had followed the instructions here to get that version...


Edit: Hmmm I think I spoke too early; I first tried with a .sub file everything processed but at the end it sayed subtitle=0 so then tried with a .srt file which was detected but the resulting output.avi for some reason doesn't playback in VLC or GNOME Mplayer... Again in the video that used the .srt file the output said subtitle:0

Another thing I noticed was the dramatic down-sizing of the file; my input.avi was 732.4MB but the output.avi came to only a paltry 288.9MB... I have used it just like in the manpage:
Code:

ffmpeg -i input.avi -vf subtitles=/path/to/.srt/file output.avi
I think maybe an option or two in the command is missing :o


Edit 2: Just noticed when doing the above command this is what I got exactly:
Neither PlayResX nor PlayResY defined. Assuming 384x288

So it means the output.avi has to be defined? Will try later when I have some time on my hands :D

ladoga 2012-12-26 10:04

Re: Encoding videos for N9 (using CLI tools)
 
Quote:

Originally Posted by thedead1440 (Post 1307798)
Using that worked for me; maybe its the version of ffmpeg?

Or maybe it's about the version of libavfilter? I'll probably wait until debian multimedia gets newer ones. Meanwhile I can use (K)MPlayer on N9 to view subtitles.

Quote:

or GNOME Mplayer
If you need a good MPlayer frontend for desktop I suggest you to try out SMPlayer. Last time I checked (few years ago) the playback quality and subtitle rendering in MPlayer were noticeably better than in VLC. VLC has nice GUI though, but SMPlayer isn't bad either. My favorite feature is automated subtitle download/upload from opensubtitles.org. :)

I think you told earlier about audio video sync problems when playing some files on N9 with KMPlayer using MPlayer as backend. Here is a likely remedy for that. Try autosync=30 in ~/.mplayer/config to use more agressive a/v sync. Also you can look for "mc" flag (sets maximum allowed correction in seconds) in the documentation.

Silwer 2013-01-01 15:05

Re: Encoding videos for N9 (using CLI tools)
 
Thanks! Just converted some videos to "x264 baseline profile and 6 channel ac3 audio" and they work fine on N9. Just I found command line ffmpeg to difficult to use and used WinFF user interface: http://winff.org/html_new/downloads.html where I added custom preset as follows:

Preset Name: NokiaN9
Preset Label: Nokia N9
Preset command line parameters: $ -s 854x480 -r 25 -g 25 -vcodec libx264 -vb 1536k -vprofile baseline -acodec ac3 -ab 192k -ac 6
Output file extension: mp4

Rogatti 2013-01-01 16:41

Re: Encoding videos for N9 (using CLI tools)
 
Quote:

Originally Posted by ladoga (Post 1307672)
Seems like burning srt subtitles into movies using ffmpeg is possible: http://ffmpeg.org/trac/ffmpeg/wiki/H...%20the%20video

Though with v.1.0.1 trying "-vf subtitles=whatever.srt" spits out "No such filter: 'subtitles'" in bold red :)

using ffmpeg version git-2012-11-25-b473c99
-
ffmpeg -i input.mp4 -i input.srt -scodec copy output.mp4
-
with a bonus of 33% lower compared to the original file :D


All times are GMT. The time now is 20:04.

vBulletin® Version 3.8.8