Better video streaming quality with ffmpeg

General discussions.

Moderator: moderators

Linux?

Postby harbinger » Tue Aug 02, 2011 12:58 pm

I'm trying to put together something similar on my headless Ubuntu server (11.04) with an Intel Core 2 Quad processor. It shouldn't be too hard to write a similar script to OP's, but I'm not sure how to address the presets or if they're built into the package when using the latest ffmpeg version.

In any case, I'm going to be tinkering with things over the next few days and will post any discoveries of note.
harbinger
 
Posts: 1
Joined: Tue Aug 02, 2011 12:29 pm

Postby haifa » Fri Aug 05, 2011 5:27 am

thanks for sharing!!!
haifa
 
Posts: 6
Joined: Thu Jan 27, 2011 7:19 am

Re: Linux?

Postby marsmayhem » Wed Aug 10, 2011 6:57 pm

harbinger wrote:I'm trying to put together something similar on my headless Ubuntu server (11.04) with an Intel Core 2 Quad processor. It shouldn't be too hard to write a similar script to OP's, but I'm not sure how to address the presets or if they're built into the package when using the latest ffmpeg version.

In any case, I'm going to be tinkering with things over the next few days and will post any discoveries of note.


The presets are all individual files under the presets folder that comes with the ffmpeg download referred to in an earlier post. This folder needs to be placed in the transcode folder so subsonic/script can find it.
marsmayhem
 
Posts: 19
Joined: Wed Aug 10, 2011 7:09 am

Postby GJ51 » Fri Aug 12, 2011 11:58 pm

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


Sindre,

Can you post the string you used? I'm trying to get a .m2ts working, but when I add -threads:

ffmpeg -ss %o -i %s -threads 4 -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -

I get:

Video not found or access denied followed by the /stream?pathUtf8Hex=.....

ffmpeg -ss %o -i %s -async 30 -b %bk -r 23.976 -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -

Works, but gets frequent pauses.


ffmpeg -ss %o -i %s -async 30 -b %bk -r 23.976 -s %wx%h -ar 44100 -ac 2 -v 0 -threads 0 -f flv

Fails.

ffmpeg -threads 1 -ss %o -i %s -async 30 -b %bk -r 23.976 -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -

Works. Perhaps I need a different ffmpeg build?
Gary J

http://bios-mods.com
http://www.maplegrovepartners.com
http://theaverageguy.tv/category/tagpodcasts/cyberfrontiers/
User avatar
GJ51
 
Posts: 3492
Joined: Wed Oct 20, 2010 11:58 pm
Location: Western New York

Re: Better video streaming quality with ffmpeg

Postby MJRajs » Wed Sep 21, 2011 1:19 pm

Anyone know if i should use 4 threads or 8 threads with a Core i7 CPU? It is technically 4 cores BUT has 4 virtual cores too...so....

Thanks
MJRajs
 
Posts: 4
Joined: Wed Sep 21, 2011 1:16 pm

Re: Better video streaming quality with ffmpeg

Postby MJRajs » Wed Sep 21, 2011 7:23 pm

Thanks for the PM Sindre...Also, this was the best (most Barney style) explanation i found for the thread count

"Basically, multiple threads allows multiple cores and/or multiple CPUs to work on the job at the same time. Setting threads to 0 is a special case, it tells the encoder to decide for itself how many threads to use.

If you deliver goods with a truck and it takes you an hour to deliver one truck load, you can deliver twice as much using two trucks -- two truckloads per hour, three times as much with three trucks, etc. Eventually you get diminishing returns because your loading dock isn't fast enough to load all those trucks. If your loading dock can only load 4 trucks per hour then having 10 trucks won't get you any better throughput than 4."

POSTED FROM http://forum.videohelp.com/threads/3280 ... eg-Threads
MJRajs
 
Posts: 4
Joined: Wed Sep 21, 2011 1:16 pm

Re: Better video streaming quality with ffmpeg

Postby BKKKPewsey » Wed Sep 21, 2011 8:57 pm

Does that mean I have to load my Subsonic server on a truck to get it to work :D
Oh I can see the all the Help requests now :shock:
"I have installed SS but now it doesnt work have I got a flat tyre" (tire for some of you :) )

But seriously thanks for sharing.
:mrgreen:
Everyone is entitled to be stupid, Image but some abuse the privilege!

Due to the confusion from too many genres of music, we have decided to put both country music and rap music into the genre of Crap music.
User avatar
BKKKPewsey
 
Posts: 2080
Joined: Mon May 23, 2011 12:16 pm
Location: United Kingdom

Re: Better video streaming quality with ffmpeg

Postby onyx00 » Wed Dec 21, 2011 10:31 pm

I know this is a bit back from the dead - but I found an issue and wanted to document it here for anyone else stumbling on this thread and trying to optimize video streaming using subsonic.

SUMMARY: Use the latest Shared Build from here (32 or 64, I happened to use 64 on Win7 x64 for my purposes) - http://ffmpeg.zeranoe.com/builds/ . This resolved all issues with playback I was having with regards to re-buffering. Details of the bug causing the issue below.

DETAILS: The original post references a link to FFMPEG (http://ffmpeg.arrozcru.org/autobuilds/ffmpeg/mingw32/shared/). I installed the latest from there, which I later realized had not been updated since early 2011.

I was having issues where MKVs streaming (higher quality, 8GB+) were playing for a bit, then re-buffering. The default buffer size of 3 seconds produced this often, and extending the buffer size to 30 seconds reduced it, but was still an issue. I looked in to processor, memory, etc., etc., but I was running a Phenom II X4 830, plenty of horsepower for this. I only noticed that FFMPEG from the link above failed to really utilize the whole processor - I never saw more than 50% utilization even at "-threads 4" or any other mentioned variant of the threads setting.

Finally, I looked at the log for Subsonic and saw the error: "av_interleaved_write_frame(): Operation not permitted" that seemed to coincide with the re-buffering issue. I dug in to the FFMPEG bug list and basically saw it was an old bug that was fixed after the version of FFMPEG reference above was likely created. I went to find the latest Shared build of FFMPEG and grabbed it as referenced above int he summary and it resolve everything. No more error, no more re-buffering, no more issues period. I also noticed the latest version was now utilizing closer to 70% of the CPU. All of these combined seem to have done the trick.

Anyway - I was ready to pitch Subsonic, so in hopes of someone else avoiding the time and frustration, I wanted to document things. :D
onyx00
 
Posts: 2
Joined: Wed Dec 21, 2011 10:20 pm

Re: Better video streaming quality with ffmpeg

Postby Castius » Fri Dec 23, 2011 7:38 pm

Thanks for sharing
Castius
 
Posts: 34
Joined: Wed Sep 02, 2009 9:11 pm

Re: Better video streaming quality with ffmpeg

Postby wraithdu » Sun Jan 01, 2012 11:46 pm

Wow, I haven't been back to this thread in a while, glad to see it got some attention in the new Subsonic builds. I wanted to mention a few things:

1) The -threads switch only works for encoders that support multithreading, like x264. It does not work for the flash video encoder (not to be confused with the flv container format), and will produce an error.

2) I think -threads 0 is the best way to go. However you could experiment with a concrete number and a straight CLI encode with ffmpeg to determine what works best on your system.

3) Using BAT files opens up a world of possibilities. I've written a few for local and mobile profiles where I use the video size and my device screen size to optimize video transcode resolution. I find I get a lot better quality if ffmpeg does the resizing versus letting the flash player scale the video to full screen. I've also found the x264 gamma to be a bit high, so setting a filter to adjust it works well:
Code: Select all
-filter:v "mp=eq2=0.8"


Edit -
I've updated my first post with the new download site, as well as an updated command line for some of the recent ffmpeg syntax changes.
wraithdu
 
Posts: 50
Joined: Thu Apr 01, 2010 10:34 pm

Re: Better video streaming quality with ffmpeg

Postby wraithdu » Thu Jan 12, 2012 8:31 pm

I've updated my settings in the first post again. I finally found the x264 profile parameter bug/fix which allows setting the main profile, you have to use '-vprofile' which is an undocumented switch. This works much better (on Android at least) and video is much smoother (as compared to high profile). ffmpeg also now has a stable aac encoder, VisualOn's libvo_aacenc. I switched to that as well. However it doesn't do VBR, so I set it to 128k. You're free to change the bitrate or switch back to MP3 encoding with libmp3lame if you want. Another bonus is that the -filter:v gamma correction is no longer needed with the main profile.
wraithdu
 
Posts: 50
Joined: Thu Apr 01, 2010 10:34 pm

Re: Better video streaming quality with ffmpeg

Postby Aro » Wed Feb 01, 2012 5:44 pm

Hi all I'm new here ;)

I have a question - how to improve video streaming in subsonic. I'm using standalone version with FreeNAS 7.3 on my old school PC P3 1GHz [lol]
Transcoder setup:
ffmpeg -ss %o -i %s -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -vpre superfast -threads 0 -

quality is good but video playing isn't smooth.
Aro
 
Posts: 3
Joined: Wed Feb 01, 2012 5:38 pm

Re: Better video streaming quality with ffmpeg

Postby GJ51 » Wed Feb 01, 2012 6:09 pm

You don't have enough CPU for most video transcoding. Very low resolution video might be OK, but not anything of high quality, The other option for a low powered server is to preformat the videos to either mp4 or flv so that they can play in JW Player without any transcoding. That would eliminate the CPU bottleneck and make bandwidth the weakest link.

From another post:

Video playback can be a bit complex when trying to get reasonable results for your particular hardware. There are several factors involved, the most important of which may be the crunch power of the CPU on your server. Transcoding takes quite a bit of CPU power which varies with the resolution and bitrate of the video being played. Your not going to watch m2ts blue ray being sent from an atom pwered PC with 512Mb ram over a wireless G connection with satisfactory results.

The most practical way to get good video playback is to preformat the video into mp4 or flv and eliminate the transcoding. This takes the load off the CPU so that bandwidth between the server and the tablet are the limiting factor.

I've been playing with video on Subsonic for over a year now and I'm finally at a point where I'm pleased with the result. The positive result, however, can be attributed to the dual quad core 2.83GHz Xeon server with 16GB of ram that taps into a RAID 50 storage array that has 8 2TB hard drives putting out 350MB transfer rates. A bit extreme perhaps, but it will transcode 3 blue ray streams simultaneously, or at the same time, without any buffering.

So somewhere between an atom powered server and dual quad core CPU's you have to experiment with the capabilities of your hardware to identify bottlenecks and determine what is the best format and quality that can give good performance on your hardware. Be realistic and use task manager to monitor the CPU loads while your streaming to see the impact on the server.

HTH
Gary J

http://bios-mods.com
http://www.maplegrovepartners.com
http://theaverageguy.tv/category/tagpodcasts/cyberfrontiers/
User avatar
GJ51
 
Posts: 3492
Joined: Wed Oct 20, 2010 11:58 pm
Location: Western New York

Re: Better video streaming quality with ffmpeg

Postby Aro » Wed Feb 01, 2012 6:18 pm

You don't have enough CPU for most video transcoding. Very low resolution video might be OK, but not anything of high quality, The other option for a low powered server is to preformat the videos to either mp4 or flv so that they can play in JW Player without any transcoding. That would eliminate the CPU bottleneck and make bandwidth the weakest link.


Yes I know it's really old PC - It's something like a test environment :)
CPU usage when playing - 100% ;)

I have to add -f flv - at the end of this? ffmpeg -ss %o -i %s -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -vpre superfast -threads 0 -

Thanks for Your help
Aro
 
Posts: 3
Joined: Wed Feb 01, 2012 5:38 pm

Re: Better video streaming quality with ffmpeg

Postby GJ51 » Wed Feb 01, 2012 6:41 pm

ffmpeg -ss %o -i %s -async 30 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -preset superfast -threads 0 -

You may need to modify the -preset superfast setting. Google the options and how to use them.
Gary J

http://bios-mods.com
http://www.maplegrovepartners.com
http://theaverageguy.tv/category/tagpodcasts/cyberfrontiers/
User avatar
GJ51
 
Posts: 3492
Joined: Wed Oct 20, 2010 11:58 pm
Location: Western New York

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 30 guests