View Full Version : Adding borders to H264 stream
asarian
16th September 2008, 19:37
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
Guest
16th September 2008, 21:58
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.
kaid
16th September 2008, 22:19
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
-vf dsize=1920:1080:0,scale=0:0,expand=1920:1080 (for 1080p)
or
-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:
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:
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...
kaid
16th September 2008, 22:20
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...
asarian
18th September 2008, 22:46
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.
linyx
18th September 2008, 23:52
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 (http://en.wikipedia.org/wiki/Avisynth#AviSynth_compatible_programs) of supported players on Wikipedia.
asarian
19th September 2008, 00:07
Yes if you simply watch your videos through a player that can accept avs as input. I believe there is a list (http://en.wikipedia.org/wiki/Avisynth#AviSynth_compatible_programs) 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.
kaid
19th September 2008, 16:48
Yes if you simply watch your videos through a player that can accept avs as input. I believe there is a list (http://en.wikipedia.org/wiki/Avisynth#AviSynth_compatible_programs) 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
19th September 2008, 16:53
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 (http://en.wikipedia.org/wiki/H.264)?
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! ;-)
linyx
19th September 2008, 23:06
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.
bond
20th September 2008, 19:11
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)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.