Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > (HD) DVD, Blu-ray & (S)VCD > (HD) DVD & Blu-ray authoring

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th September 2008, 19:37   #1  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Adding borders to H264 stream

Hello,

Does anyone know of a good program/method to add borders to an existing H264 stream? For example, I have a 1920x800 stream here, that I'd like to re-encode subtitles in (hardcoded). I just don't want the subtitles to appear within the 800px height (as would be the case now). Rather, I'd like to pad the 800 to 1080, and ideally shift the main movie 'up' a bit too, so as to keep room underneath for the subtitles. Is this possible yet?

Thanks
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 16th September 2008, 21:58   #2  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Of course it's possible. Better to use your original source material, though, than to re-encode the H264 stream. Just put the appropriate AddBorders() call in your Avisynth script.
Guest is offline   Reply With Quote
Old 16th September 2008, 22:19   #3  |  Link
kaid
Registered User
 
Join Date: Jul 2008
Posts: 96
Quote:
Originally Posted by asarian View Post
Hello,

Does anyone know of a good program/method to add borders to an existing H264 stream? For example, I have a 1920x800 stream here, that I'd like to re-encode subtitles in (hardcoded). I just don't want the subtitles to appear within the 800px height (as would be the case now). Rather, I'd like to pad the 800 to 1080, and ideally shift the main movie 'up' a bit too, so as to keep room underneath for the subtitles. Is this possible yet?

Thanks
I always do this with mplayer and x264.
Some guru on here told me to add
Code:
-vf dsize=1920:1080:0,scale=0:0,expand=1920:1080
(for 1080p)
or
Code:
-vf dsize=1280:720:0,scale=0:0,expand=1280:720
(for 720p)
to my mplayer args...

So the full mplayer line looks like this:
Code:
mkfifo stream.y4m; /usr/local/bin/mplayer -vo yuv4mpeg:file=stream.y4m \
-nosound -vf dsize=1920:1080:0,scale=0:0,expand=1920:1080 <inputfile>
In a separate window (detaching by adding & in the same terminal did not work for me, at least in MacOS X) in the same directory where the stream.y4m resides I start x264:
Code:
x264 -r 3 --crf <19-21> --threads 0 --level="4.1" --sar 1:1 --partitions all --aud \
--mixed-refs --bframes 3 --b-pyramid --direct auto --direct-8x8 1 --8x8dct --analyse all \
--subme 6 --me umh --b-rdo --bime --weightb --trellis 1 --no-ssim --no-psnr --progress \
-o <output.mkv/264> stream.y4m; rm stream.y4m
Note: This uses CRF for encoding, as it's sufficient for me and much faster than 2 pass. If you want CBR 2pass you need to replace the --crf with "-B <Bitrate> --pass 1" for the first pass and "-B <Bitrate> --pass 2 --stats x264_2pass.log" for the second pass!

that mkfifo saves you a fewhundred GBytes of diskspace, since it generates a file that is kept at 0 bytes since it simulates a FIFO, meaning that mplayer writes into it while x264 reads from it, and mplayer is only allowed to write again after x264 has read from it.

The end result is an uncropped 1080p video that plays on the PS3 and that, because it's full frame, can also be burned as AVCHD. ;-) Beware of the fps though, as AVCHD does not allow for 25fps (for 1080p it's 23,9 and 24 fps only I think)...
From what I remember mplayer can also insert subtitles when decoding the video, try playing with the -sub and -sid options...

Last edited by kaid; 19th September 2008 at 16:45. Reason: mentioned CRF vs 2pass
kaid is offline   Reply With Quote
Old 16th September 2008, 22:20   #4  |  Link
kaid
Registered User
 
Join Date: Jul 2008
Posts: 96
Quote:
Originally Posted by neuron2 View Post
Of course it's possible. Better to use your original source material, though, than to re-encode the H264 stream. Just put the appropriate AddBorders() call in your Avisynth script.
Can Avisynth do that without re-encoding the video? That would be quite an amazing feat, I've been looking for something to "uncrop" H.264 losslessly for ages...
kaid is offline   Reply With Quote
Old 18th September 2008, 22:46   #5  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by kaid View Post
Can Avisynth do that without re-encoding the video? That would be quite an amazing feat, I've been looking for something to "uncrop" H.264 losslessly for ages...
Thanks, Kaid! Your post above was most illuminating. :) I will go and give it a try now!

And yes, 'uncrop' wirhout re-encoding would be perfect.
__________________
Gorgeous, delicious, deculture!

Last edited by asarian; 18th September 2008 at 23:31.
asarian is offline   Reply With Quote
Old 18th September 2008, 23:52   #6  |  Link
linyx
Un-Registered User
 
linyx's Avatar
 
Join Date: Mar 2008
Location: Audio Stream - 0x80
Posts: 341
Quote:
Can Avisynth do that without re-encoding the video? That would be quite an amazing feat, I've been looking for something to "uncrop" H.264 losslessly for ages...
Yes if you simply watch your videos through a player that can accept avs as input. I believe there is a list of supported players on Wikipedia.
linyx is offline   Reply With Quote
Old 19th September 2008, 00:07   #7  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by linyx View Post
Yes if you simply watch your videos through a player that can accept avs as input. I believe there is a list of supported players on Wikipedia.
I wonder why this is so hard? Didn't x264 have a 'lossless' parameter these days? (or so I heard). Sometimes you really need to add borders, or crop first (from the top, for instance), to add extra border-space at the bottom, like for subtitles. So, in those cases, you really can't afford to lose quality on all these multi-pass operations.
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 19th September 2008, 16:48   #8  |  Link
kaid
Registered User
 
Join Date: Jul 2008
Posts: 96
Quote:
Originally Posted by linyx View Post
Yes if you simply watch your videos through a player that can accept avs as input. I believe there is a list of supported players on Wikipedia.
That's software players. They can play any resolution anyway! And why would I want to change my movie into an .avs? I need lossless uncropping for AVCHD, which only allows for 1280x720 or 1920x1080 resolution...
kaid is offline   Reply With Quote
Old 19th September 2008, 16:53   #9  |  Link
kaid
Registered User
 
Join Date: Jul 2008
Posts: 96
Quote:
Originally Posted by asarian View Post
I wonder why this is so hard? Didn't x264 have a 'lossless' parameter these days? (or so I heard). Sometimes you really need to add borders, or crop first (from the top, for instance), to add extra border-space at the bottom, like for subtitles. So, in those cases, you really can't afford to lose quality on all these multi-pass operations.
You mean this?

Quote:
Lossless macroblock coding features including:
A lossless PCM macroblock representation mode in which video data samples are represented directly, allowing perfect representation of specific regions and allowing a strict limit to be placed on the quantity of coded data for each macroblock.
An enhanced lossless macroblock representation mode allowing perfect representation of specific regions while ordinarily using substantially fewer bits than the PCM mode.
How I understand it this means that the source material is represented losslessly, but a bit smaller. It's like WAV vs FLAC! I highly doubt that this is the same as the "passthrough" of macroblocks, which would be a better word for what we're looking for...
In order to do this "lossless passthrough" x264 would have to accept H.264 streams as input to start with, which it doesn't right now! ;-)
kaid is offline   Reply With Quote
Old 19th September 2008, 23:06   #10  |  Link
linyx
Un-Registered User
 
linyx's Avatar
 
Join Date: Mar 2008
Location: Audio Stream - 0x80
Posts: 341
Quote:
And why would I want to change my movie into an .avs? I need lossless uncropping for AVCHD, which only allows for 1280x720 or 1920x1080 resolution...
True that it only works for software players, but it is lossless.
linyx is offline   Reply With Quote
Old 20th September 2008, 19:11   #11  |  Link
bond
Registered User
 
Join Date: Nov 2001
Posts: 9,770
you can crop and add borders losslessly in the h264 stream. every compliant h264 decoder will display the video taking this info into account.

propably h264info can do that

i dont know if such streams will be avchd compliant

edit: sorry, its not possible to add borders that way (only cropping works)
__________________
Between the weak and the strong one it is the freedom which oppresses and the law that liberates (Jean Jacques Rousseau)
I know, that I know nothing (Socrates)

MPEG-4 ASP FAQ | AVC/H.264 FAQ | AAC FAQ | MP4 FAQ | MP4Menu stores DVD Menus in MP4 (guide)
Ogg Theora | Ogg Vorbis
use WM9 today and get Micro$oft controlling the A/V market tomorrow for free

Last edited by bond; 20th September 2008 at 19:45.
bond is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:15.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.