Better video streaming quality with ffmpeg

General discussions.

Moderator: moderators

Better video streaming quality with ffmpeg

Postby wraithdu » Sat Jan 29, 2011 10:43 pm

I wasn't happy with the FLV codec that was used by default with ffmpeg and the '-f flv' option, especially at low bitrates streaming to my android phone. So I did some experimenting and came up with this, which is a huge improvement over the default.

1) Optional?
Download the latest version of ffmpeg from this site:
http://ffmpeg.zeranoe.com/builds/

You can pick either the 32-bit or 64-bit build based on your system, and the static or shared build based on your preference. Unzip the contents of the 'bin' folder into your transcode folder.

The presets are no longer required, as the basic presets are built into the binary now.

2) I prefer using a BAT file on windows to simplify some of the command lines, so change your transcoding settings to:
Code: Select all
ff-flv.bat %o %s %b %w %h


3) In your transcode folder, create a BAT file with the following contents:
Code: Select all
@echo off
setlocal

REM 1-start, 2-file, 3-bitrate, 4-width, 5-height
cd c:\subsonic\transcode
ffmpeg.exe -ss %1 -i %2 -loglevel quiet -async 30 -codec:a libvo_aacenc -b:a 128k -codec:v libx264 -b:v %3k -s %4x%5 -threads 0 -preset medium -vprofile main -f flv -

You may have to change the location of the transcode folder if yours is different.

Here are the old MP3 audio settings if you want to switch back:
Code: Select all
-codec:a libmp3lame -ar 44100 -q:a 6


4) Optionally change the libx264 preset that is used if your computer is not fast enough to use the medium preset, or if you just want to try something else.

Good luck!
Last edited by wraithdu on Thu Jan 12, 2012 10:26 pm, edited 7 times in total.
wraithdu
 
Posts: 50
Joined: Thu Apr 01, 2010 10:34 pm

Postby Castius » Tue Feb 08, 2011 8:07 am

I had no idea subsonic could handle a bat file like this.
Thank you very much for sharing this.
Castius
 
Posts: 34
Joined: Wed Sep 02, 2009 9:11 pm

Postby jah » Mon Mar 07, 2011 7:03 am

Hey-

Thanks for the tip. x264 looks a ton better than the default settings. That said, I was getting pretty choppy playback but noticed my [triple core] cpu was only being utilized 33% in task manager. After a little research, I found out that there's an additional handle for your command string to use more than a single core for encoding:

@echo off
setlocal

REM 1-start, 2-file, 3-bitrate, 4-width, 5-height
cd c:\subsonic\transcode
ffmpeg.exe -ss %1 -i %2 -async 1 -b %3k -s %4x%5 -ar 44100 -ac 2 -v 0 -threads 0 -vcodec libx264 -fpre .\presets\libx264-faster.ffpreset -f flv -


Now playback is buttery smooth. Another thing I've been trying to tackle is how to control the audio encoding. I'd like to use AAC because it's more efficient. I've been trying this:

@echo off
setlocal

REM 1-start, 2-file, 3-bitrate, 4-width, 5-height
cd c:\subsonic\transcode
ffmpeg.exe -ss %1 -i %2 -async 1 -b %3k -s %4x%5 -acodec libfaac -ar 44100 -ab 128k -ac 2 -v 0 -threads 0 -vcodec libx264 -fpre .\presets\libx264-faster.ffpreset -f flv -


This produces an error along the lines of "Video not found or access denied:..." Any idea what's wrong?

The guide where I found the threads handle: http://rob.opendot.cl/index.php/useful- ... ing-guide/
jah
 
Posts: 4
Joined: Mon Mar 07, 2011 6:45 am

Postby jah » Tue Mar 08, 2011 12:51 am

Today I realized that most of my video is already pretty well compressed--in many cases no need to re-encode unless I'm having bandwidth issues or need to stream over 3G. If that's the case for you, you can really lighten the load on your server by copying the video stream instead of transcoding it:

@echo off
setlocal

REM 1-start, 2-file, 3-bitrate, 4-width, 5-height
cd c:\subsonic\transcode
ffmpeg.exe -ss %1 -i %2 -async 1 -ar 44100 -ac 2 -v 0 -threads 0 -vcodec copy -f flv -


What you can now do is have multiple players each using their own transcoder sets: one for local/broadband with video-stream-copy, and one with transcoding for something like your phone or crappy wifi.

After doing some more research on my above post, I think the issue with transcoding audio in the stream has to do with what audio codecs were compiled with the version of ffmpeg you end up using. You may have to recompile to add in additional codecs if the one you want isn't included. I'll post back if I have any success. In the meantime I'll be checking out http://www.audiocoding.com/index.html to see about adding in AAC (either FAAC or Nero which is supposed to be a lot better).
jah
 
Posts: 4
Joined: Mon Mar 07, 2011 6:45 am

Postby privatesam » Wed Mar 09, 2011 1:12 pm

Some really useful, interesting ideas on this thread - thanks so much for sharing.

Any video streaming I've been doing with Subsonic remotely through browsers always buffers too much. I wonder if by tweaking the scripts above I could make the video streaming smooth and of acceptable quality just in a browser? I have good upload speeds (2.5meg) so in theory I should be able to get this working.

Also I've recently been hooked by an idea suggested by Calvinhtml on these forums at this thread: http://forum.subsonic.org/forum/viewtopic.php?t=5893&highlight= to use GPU accelerated transcoding, specfically Badaboom by Nvidia for super fast transcoding. Badaboom has command line interface and uses ffmpeg inside the software. In the documentation it talks about writing a batch file using these commands:
Now to the fun part: choosing your output settings! The next command string, which starts with “for /f “tokens=*”…” is the string that will convert all your video files (i.e. all except VIDEO_TS folders) to the settings you provide. Only certain settings can be edited, as described below, and only the numerals should be edited (besides the output device).
a. First, name the folder that will collect the videos with these output settings. This video will be located inside the destination folder, and will be created if it doesn’t already exist. You can see the example is “BadaboomOutputiPhone.”
b. The next part of the string are your encode settings:
Badaboom 2.0 User Guide www.badaboomit.com 16
-w = overwrite This must not be changed. If a file already exists with the same name in destination location, it will be overwritten. This is to keep the Badaboom batch file from getting stuck.
-res = resolution Set your output display resolution. This resolution must exist in the Display Resolution dropdown menu in the Picture Settings of Badaboom. Width followed by height.
-br = bit rate Set the bit rate (in total bits). The example given shows 1500000, which is the default iPhone bit rate. (1500000 bps = 1500 kbps = 1.5 mbps). This number can be between 500000 and 25000000.
-ag = audio gain Set a desired volume reduction or increase. This number can be between -20 and 6.
-outdev = device Select an output device profile and the transcode will use the rest of its default settings which cannot be edited here. Make sure you type the device name as it appears in the UI.
c. To convert the files to an additional output profile, copy the string and paste it below the first one. Then change the collection folder (to BadaboomOutputiPad, for example) and edit the settings of the string.


The big issue as I see it is that a) Badaboom is a paid for software and b) it only outputs to H.264 (MP4) with AAC-LC (2 channel) NOT flv. However as I understand it JWPlayer can deal with MP4, so assuming the transcoding is swift enough this would be ok?

Any thoughts would be great.
privatesam
 
Posts: 19
Joined: Fri Feb 26, 2010 10:09 am

Postby sekhu » Thu Mar 10, 2011 3:03 pm

hi

this looks great and shoudl help a lot. however, i'm unsure what to do in windows x64 - can I still use this method? the package in the link in the first post for x64 is dated april 2010 - and since then several revisions of ffmepg have been released. how can i use this method to transcode/stream video better in an x64 windows 7 environment?

thanks in advance
sekhu
 
Posts: 20
Joined: Fri Mar 04, 2011 10:47 pm

Postby jah » Fri Mar 11, 2011 12:58 am

32-bit apps typically run fine on x64. Just download the x86/32-bit version and give it a shot. If you have trouble, try an x64 version and see if it does what you need.
jah
 
Posts: 4
Joined: Mon Mar 07, 2011 6:45 am

Postby alreadyfoll » Fri Mar 11, 2011 5:19 am

jah wrote:Hey-

Thanks for the tip. x264 looks a ton better than the default settings. That said, I was getting pretty choppy playback but noticed my [triple core] cpu was only being utilized 33% in task manager. After a little research, I found out that there's an additional handle for your command string to use more than a single core for encoding:

@echo off
setlocal

REM 1-start, 2-file, 3-bitrate, 4-width, 5-height
cd c:\subsonic\transcode
ffmpeg.exe -ss %1 -i %2 -async 1 -b %3k -s %4x%5 -ar 44100 -ac 2 -v 0 -threads 0 -vcodec libx264 -fpre .\presets\libx264-faster.ffpreset -f flv -


Now playback is buttery smooth. ps3 headset, ps3 controller Another thing I've been trying to tackle is how to control the audio encoding. I'd like to use AAC because it's more efficient. I've been trying this:

@echo off
setlocal

REM 1-start, 2-file, 3-bitrate, 4-width, 5-height
cd c:\subsonic\transcode
ffmpeg.exe -ss %1 -i %2 -async 1 -b %3k -s %4x%5 -acodec libfaac -ar 44100 -ab 128k -ac 2 -v 0 -threads 0 -vcodec libx264 -fpre .\presets\libx264-faster.ffpreset -f flv -


This produces an error along the lines of "Video not found or access denied:..." Any idea what's wrong?

The guide where I found the threads handle: http://rob.opendot.cl/index.php/useful- ... ing-guide/


how can i use this method to transcode/stream video better in an x64 windows 7 environment?
alreadyfoll
 
Posts: 1
Joined: Fri Mar 11, 2011 4:59 am

Postby kujon » Thu Mar 24, 2011 9:46 am

i cannot for the life of me get this to work. whenever i change the transcoding commands in the web browser settings>transcoding, it refuses to stream my videos anymore. i'm pretty sure i did everything as the op instructed...
kujon
 
Posts: 1
Joined: Thu Mar 24, 2011 9:45 am

Postby johnp338 » Tue Mar 29, 2011 9:53 pm

kujon wrote:i cannot for the life of me get this to work. whenever i change the transcoding commands in the web browser settings>transcoding, it refuses to stream my videos anymore. i'm pretty sure i did everything as the op instructed...


I'm having the same problem. Windows 7 Ultimate x64. I downloaded the latest ffmpeg and extracted it, placed "ffmpeg.exe" in my "C:\subsonic\transcode" folder. I then went to the transcoding page in settings in the web interface, and changed the string under "Step 1" (for mkv > flv, since that's what i decided to test) to
Code: Select all
ff-flv.bat %o %s %b %w %h


Then I opened notepad, created a text document "ff-flv.txt" containing the following
Code: Select all
@echo off
setlocal

REM 1-start, 2-file, 3-bitrate, 4-width, 5-height
cd c:\subsonic\transcode
ffmpeg.exe -ss %1 -i %2 -async 30 -b %3k -s %4x%5 -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -fpre .\presets\libx264-medium.ffpreset -


I then saved the file, renamed it to "ff-flv.bat" and placed it in the "C:\subsonic\transcode" directory. However, when I attempt to play a video, I get an error with a long string that I don't understand (in white text on the black background of the flash player). I would really appreciate any help you can offer. Thanks
johnp338
 
Posts: 4
Joined: Tue Mar 29, 2011 9:47 pm

Not working for me either

Postby JMilesT » Wed Mar 30, 2011 9:49 pm

kujon wrote:i cannot for the life of me get this to work. whenever i change the transcoding commands in the web browser settings>transcoding, it refuses to stream my videos anymore. i'm pretty sure i did everything as the op instructed...

Same issue here. This looked like something great but it's not working for me.

I'm running Windows 7 Ultimate x64.

I couldn't help but notice that the newer version of ffmpeg is only has a 120K filesize, while the version I had prior to that was over 10MB. Is there something missing from this new executable?
JMilesT
 
Posts: 23
Joined: Mon Jun 14, 2010 4:54 am

Postby johnp338 » Fri Apr 01, 2011 1:20 am

It seems I'm not the best in the world at following directions. I tried going through all of the steps again, and it turns out that I screwed up extracting the contents of the "bin" folder into the "transcode" folder. Once I followed the directions properly, I was able to play videos using the improved settings. Thanks!

Edit: One side note: playing videos back in the browser on my Moto Xoom does result in a message "this video is not optimized for mobile." The quality, however, is much improved.

Achieved using Windows 7 Ultimate (x64)
johnp338
 
Posts: 4
Joined: Tue Mar 29, 2011 9:47 pm

Postby spitefulmonkey » Sun Jul 10, 2011 8:54 pm

Anyone ever get Badaboom 2.0 transcoding in Subsonic? Since it now supports Intel's Quick Sync it would be awesome if I could take advantage of that. I purchased it (it's cheap) to play with. No great documentation on the command line though.

If anyone wants to share a working .bat file for use with it in subsonic, it would be appreciated.
spitefulmonkey
 
Posts: 6
Joined: Tue Jun 28, 2011 4:44 am

Postby sindre_mehus » Thu Jul 28, 2011 1:28 pm

Very interesting! I will look into this in more detail and possibly set it as the default setting in a later release.

On my quad-core computer, encoding was 3.2 times faster when adding a "-threads 4" flag.

Thanks,
Sindre
Subsonic developer
User avatar
sindre_mehus
 
Posts: 1955
Joined: Tue Nov 29, 2005 6:19 pm
Location: Oslo, Norway

Postby rvandaalen » Mon Aug 01, 2011 12:03 am

sindre_mehus wrote:Very interesting! I will look into this in more detail and possibly set it as the default setting in a later release.

On my quad-core computer, encoding was 3.2 times faster when adding a "-threads 4" flag.

Thanks,
Sindre


That would be most welcome. H264 looks much better. I get DVD quality streaming in my browser, it looks really good.
rvandaalen
 
Posts: 10
Joined: Mon Mar 07, 2011 2:45 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests