Jump to content

Transcoding- cropping out black bars


zigzagtshirt

Recommended Posts

zigzagtshirt

I was experimenting with ffmpeg and I noticed that when Emby is transcoding it has ffmpeg leave the black bars untouched.  Wouldn't it be more efficient to remove the black bars while transcoding since clients will put them back in on their own anyway?  If I understand correctly, there would be performance gains and smaller file sizes in cropping out the black bars.  Please correct me if I'm wrong.

Edited by tsherran
Link to comment
Share on other sites

Waldonnis

Detecting the actual aspect ratio can go horribly wrong at times, so I wouldn't recommend trying it for a live transcode and would want a way to opt out if it were ever tried.  I have several movies that change aspect ratios several times during the film.  If I used something like Handbrake and turn on the auto crop settings for something like TRON Legacy, it almost always thinks that the initial aspect ratio is correct for the entire film, which incorrectly crops the lightcycle scene's IMAX footage instead of preserving the entire frame.  Other popular movies have changing aspect ratios as well, like Dark Knight, GotG, Capt. America: Civil War, the soon-to-be-released Doctor Strange, and a few others that were partially filmed with IMAX cameras (many of which only include uncropped IMAX footage on the 3D disc; the 2D-only BluRays maintain one aspect ratio throughout for many but not all of them).

 

There are ways to detect every change in aspect ratio, but they require more analysis of the file than I would expect Emby to do - and it can still go wrong in some specific circumstances.  The performance impact of preserving the letter/pillarbox bars vs cropping them should be pretty small anyway.  It's far better to crop the files with ffmpeg or other tools yourself so you can ensure that the presentation is correct compared to the source.  Admittedly, shifting aspect ratios within a single film is somewhat of a rarity and may not be something you need to worry about, but it seems to be increasingly common in some genres and with certain directors, so it's always good to double-check your source material to make sure you're not losing anything when autocropping.

Edited by Waldonnis
Link to comment
Share on other sites

zigzagtshirt

Great points. I didn't consider the impact it might have on variable aspect ratio films. I only keep original Blu ray rips in my library (which have the black bars of course). Most of the time I am direct playing/direct streaming them. However, I do set a bitrate cap when streaming over the Internet which of course means that transcoding occurs. I am running my server on older hardware and it can't quite keep up with what I consider acceptable quality settings during the transcoding. If I could only boost the efficiency a bit then it might get there. So I'm wondering what performance boost there would be (if any) in cropping the black bars.

 

If this could be an option (if even worth it), obviously it should have a toggle option either server-wide or on a per movie basis.

 

I did just run Interstellar through Handbrake out of curiosity and it did preserve the IMAX scenes perfectly.

 

Also, wouldn't having smaller file sizes be worth it on its own?

Edited by tsherran
Link to comment
Share on other sites

zigzagtshirt

Example:

 

This will check the ratio of 10 frames beginning at 90 seconds:

 

ffmpeg -ss 90 -i "E:\Video\Homefront (2013)\Homefront (2013).mkv" -vframes 10 -vf cropdetect -f null -

 

Perhaps this could run during import and save it for the future?  Not sure how you would capture the output and make it usable though.  

 

This would be a problem with movies with variable aspect ratios though, since this only take a small snapshot; it would take a lot of cpu and time upfront to check every frame in the whole movie.  

 

Once you have the aspect ratio, this will crop it:

 

ffmpeg -i "E:\Video\Homefront (2013)\Homefront (2013).mkv" -vf crop=1920:784:0:148 -c:a copy output.mp4

 

Again, I don't even know if all of this would be worth it or not.

 

Source: http://superuser.com/questions/810471/remove-mp4-video-top-and-bottom-black-bars-using-ffmpeg

Link to comment
Share on other sites

Jdiesel

I have always just cropped when making my rips so I don't have many movies with black bars. Wouldn't it make more sense to crop the source video permanently rather than do it each time it is transcoded that way even the videos that can be direct played benefit from the size savings?

Link to comment
Share on other sites

Ok so if that requires probing for additional information during the library scan then it's not really realistic. Anything that adds any additional time to the library scan just causes people to go ape crazy over it unfortunately.

Link to comment
Share on other sites

Waldonnis

I have always just cropped when making my rips so I don't have many movies with black bars. Wouldn't it make more sense to crop the source video permanently rather than do it each time it is transcoded that way even the videos that can be direct played benefit from the size savings?

 

That may not be possible, unfortunately.  In certain cases, it can be done without re-encoding, but that's heavily dependent on the source format and how the file was encoded originally (easy with lossless sources, not so much with codecs like h.264).  Letter/pillarbox bars tend to be compressed heavily and easily, so I'm not sure if the space/transcode load/bandwidth savings is really worth it.

Link to comment
Share on other sites

zigzagtshirt

Thanks for all the info. Agreed, doesn't seem worth it. Started out as a mere curiosity, but I did learn a few things.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...