Re: [FFmpeg-devel] [PATCH 1/2] Set subtitle track dimensions for mov_text to display the subtitles properly

2015-06-11 Thread Philip Langdale
On Fri, 12 Jun 2015 00:11:24 +0530
Niklesh Lalwani niklesh.lalw...@iitb.ac.in wrote:

 Ok so it goes like this.
 
 We first find out the height and width of the video stream from the
 header box. The dimensions of the text track (subtitle track) is then
 set (in pixels). Here, we have used the width equal to the width of
 the video, and height equal to 1/10 of the video height.
 The write matrix specifies the coordinate origin and the translation
 values from the origin, ie, where to place the subtitle track. Here,
 we have set tx = 0; and ty = 9/10 of the video track height.
 There is also a text box inside this subtitle area, inside which the
 text is rendered. For now, this is set equal to the the subtitle track
 dimensions.
 
 Philip, please correct me if I am wrong.

Nicolas was asking about the general mechanism, I think.

So, the subtitle track has dimensions, just like the video track, and
for a given set of dimensions, it can be placed at a position within
the video track's dimensions. In Nikleh's example, it's the same width,
and 1/10 of the height, and placed 9/10'th down, so as to occupy the
bottom 1/10 of the display area.

Within the subtitle area, specific subtitles occupy text boxes that can
be smaller than the full area. In our simple example, all subtitles are
in the same box that occupies the full area.

--phil
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] Set subtitle track dimensions for mov_text to display the subtitles properly

2015-06-11 Thread Nicolas George
Le tridi 23 prairial, an CCXXIII, Niklesh Lalwani a écrit :
 From: Niklesh niklesh.lalw...@iitb.ac.in
 
 This patch mostly replicates the concept patch posted by Philip 
 https://ffmpeg.org/pipermail/ffmpeg-devel/2013-March/140299.html. This sets 
 the proper dimensions for the subtitle tracks, by making use of the height 
 and width of the video stream. The patch is exlained in detail in the link.
 
 Signed-off-by: Niklesh niklesh.lalw...@iitb.ac.in
 ---
  libavformat/movenc.c | 38 ++
  libavformat/movenc.h |  4 
  2 files changed, 38 insertions(+), 4 deletions(-)

I said it in the original thread and I say it again now: this is not the
proper place, it should happen in the encoder and the surrounding
applications.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] Set subtitle track dimensions for mov_text to display the subtitles properly

2015-06-11 Thread Philip Langdale

On 2015-06-11 00:42, Nicolas George wrote:

Le tridi 23 prairial, an CCXXIII, Niklesh Lalwani a écrit :

From: Niklesh niklesh.lalw...@iitb.ac.in

This patch mostly replicates the concept patch posted by Philip 
https://ffmpeg.org/pipermail/ffmpeg-devel/2013-March/140299.html. This 
sets the proper dimensions for the subtitle tracks, by making use of 
the height and width of the video stream. The patch is exlained in 
detail in the link.


Signed-off-by: Niklesh niklesh.lalw...@iitb.ac.in
---
 libavformat/movenc.c | 38 ++
 libavformat/movenc.h |  4 
 2 files changed, 38 insertions(+), 4 deletions(-)


I said it in the original thread and I say it again now: this is not 
the

proper place, it should happen in the encoder and the surrounding
applications.


Yeah. I sent this to Niklesh to unblock his other work, but we need a 
proper

approach to setting the dimensions and this isn't it.

--phil
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] Set subtitle track dimensions for mov_text to display the subtitles properly

2015-06-11 Thread Nicolas George
Le tridi 23 prairial, an CCXXIII, Philip Langdale a écrit :
 Yeah. I sent this to Niklesh to unblock his other work, but we need a proper
 approach to setting the dimensions and this isn't it.

Can you (or Niklesh) describe exactly the factors that guide the geometry of
the text on screen? IIRC, in the original thread, there was mention of a
matrix on top of the video resolution.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] Set subtitle track dimensions for mov_text to display the subtitles properly

2015-06-11 Thread Niklesh Lalwani
Ok so it goes like this.

We first find out the height and width of the video stream from the header
box. The dimensions of the text track (subtitle track) is then set (in
pixels). Here, we have used the width equal to the width of the video, and
height equal to 1/10 of the video height.
The write matrix specifies the coordinate origin and the translation values
from the origin, ie, where to place the subtitle track. Here, we have set
tx = 0; and ty = 9/10 of the video track height.
There is also a text box inside this subtitle area, inside which the text
is rendered. For now, this is set equal to the the subtitle track
dimensions.

Philip, please correct me if I am wrong.

Thanks,

Niklesh

On Thu, Jun 11, 2015 at 11:09 PM, Nicolas George geo...@nsup.org wrote:

 Le tridi 23 prairial, an CCXXIII, Philip Langdale a écrit :
  Yeah. I sent this to Niklesh to unblock his other work, but we need a
 proper
  approach to setting the dimensions and this isn't it.

 Can you (or Niklesh) describe exactly the factors that guide the geometry
 of
 the text on screen? IIRC, in the original thread, there was mention of a
 matrix on top of the video resolution.

 Regards,

 --
   Nicolas George

 ___
 ffmpeg-devel mailing list
 ffmpeg-devel@ffmpeg.org
 http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] Set subtitle track dimensions for mov_text to display the subtitles properly

2015-06-10 Thread Niklesh Lalwani
From: Niklesh niklesh.lalw...@iitb.ac.in

This patch mostly replicates the concept patch posted by Philip 
https://ffmpeg.org/pipermail/ffmpeg-devel/2013-March/140299.html. This sets the 
proper dimensions for the subtitle tracks, by making use of the height and 
width of the video stream. The patch is exlained in detail in the link.

Signed-off-by: Niklesh niklesh.lalw...@iitb.ac.in
---
 libavformat/movenc.c | 38 ++
 libavformat/movenc.h |  4 
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index dc9570b..c55219e 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1505,8 +1505,20 @@ static int mov_write_subtitle_tag(AVIOContext *pb, 
MOVTrack *track)
 
 if (track-enc-codec_id == AV_CODEC_ID_DVD_SUBTITLE)
 mov_write_esds_tag(pb, track);
-else if (track-enc-extradata_size)
+else if (track-enc-extradata_size) {
+if (track-enc-extradata_size = 18) {
+// Rewrite text box dimensions to match video stream.
+uint8_t *ed = track-enc-extradata;
+uint16_t width = track-video_width;
+uint16_t height = track-video_height;
+height /= 10;
+ed[14] = height  8;
+ed[15] = height  0xFF;
+ed[16] = width  8;
+ed[17] = width  0xFF;
+   }
 avio_write(pb, track-enc-extradata, track-enc-extradata_size);
+}
 
 return update_size(pb, pos);
 }
@@ -2335,7 +2347,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 
 avio_wb32(pb, 0); /* reserved */
 avio_wb32(pb, 0); /* reserved */
-avio_wb16(pb, 0); /* layer */
+avio_wb16(pb, -1); /* layer */
 avio_wb16(pb, group); /* alternate group) */
 /* Volume, only for audio */
 if (track-enc-codec_type == AVMEDIA_TYPE_AUDIO)
@@ -2352,6 +2364,8 @@ static int mov_write_tkhd_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 if (display_matrix) {
 for (i = 0; i  9; i++)
 avio_wb32(pb, display_matrix[i]);
+} else if (track-enc-codec_type == AVMEDIA_TYPE_SUBTITLE) {
+write_matrix(pb, 1, 0, 0, 1, 0, (track-video_height*9)/10);
 } else if (rotation == 90) {
 write_matrix(pb,  0,  1, -1,  0, track-enc-height, 0);
 } else if (rotation == 180) {
@@ -2362,8 +2376,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 write_matrix(pb,  1,  0,  0,  1, 0, 0);
 }
 /* Track width and height, for visual only */
-if (st  (track-enc-codec_type == AVMEDIA_TYPE_VIDEO ||
-   track-enc-codec_type == AVMEDIA_TYPE_SUBTITLE)) {
+if (st  (track-enc-codec_type == AVMEDIA_TYPE_VIDEO)) {
 if (track-mode == MODE_MOV) {
 avio_wb32(pb, track-enc-width  16);
 avio_wb32(pb, track-height  16);
@@ -2374,6 +2387,9 @@ static int mov_write_tkhd_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 avio_wb32(pb, sample_aspect_ratio * track-enc-width * 0x1);
 avio_wb32(pb, track-height * 0x1);
 }
+} else if (st  track-enc-codec_type == AVMEDIA_TYPE_SUBTITLE) {
+avio_wb32(pb, track-video_width * 0x1);
+avio_wb32(pb, (track-video_height * 0x1) / 10);
 } else {
 avio_wb32(pb, 0);
 avio_wb32(pb, 0);
@@ -5216,6 +5232,20 @@ static int mov_write_header(AVFormatContext *s)
 }
 }
 
+for (i = 0; i  mov-nb_streams; i++) {
+MOVTrack *track = mov-tracks[i];
+if (track-enc-codec_type == AVMEDIA_TYPE_SUBTITLE) {
+int j;
+for (j = 0; j  mov-nb_streams; j++) {
+if (mov-tracks[j].enc-codec_type == AVMEDIA_TYPE_VIDEO) {
+track-video_width = mov-tracks[j].enc-width;
+track-video_height = mov-tracks[j].enc-height;
+break;
+}
+}
+}
+}
+
 enable_tracks(s);
 
 
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 744d14e..c89a59e 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -148,6 +148,10 @@ typedef struct MOVTrack {
 int slices;
 } vc1_info;
 
+// For subtitle tracks.
+uint16_t video_width;
+uint16_t video_height;
+
 void   *eac3_priv;
 } MOVTrack;
 
-- 
1.9.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel