diff mbox

[FFmpeg-devel] fftools/ffmpeg: properly initialize output stream field order

Message ID 1524751587-32477-1-git-send-email-t.rapp@noa-archive.com
State Accepted
Commit a150b2e3a099fd539ecc6664050fd20617ce223c
Headers show

Commit Message

Tobias Rapp April 26, 2018, 2:06 p.m. UTC
Fixes stream field order written by avformat_write_header when "top"
option is specified on the command-line.

Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com>
---
 fftools/ffmpeg.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Derek Buitenhuis April 26, 2018, 2:11 p.m. UTC | #1
On 4/26/2018 3:06 PM, Tobias Rapp wrote:
> +        if (ost->top_field_first == 0) {
> +            enc_ctx->field_order = AV_FIELD_BB;
> +        } else if (ost->top_field_first == 1) {
> +            enc_ctx->field_order = AV_FIELD_TT;
> +        }

This doesn't look correct; ost->top_field_first is only
valid if ost->interlaced_frame is set. Wouldn't this
incorrectly set field_order on progressive streams,
which should be set to AV_FIELD_PROGRESSIVE?

- Derek
Tobias Rapp April 26, 2018, 2:49 p.m. UTC | #2
On 26.04.2018 16:11, Derek Buitenhuis wrote:
> On 4/26/2018 3:06 PM, Tobias Rapp wrote:
>> +        if (ost->top_field_first == 0) {
>> +            enc_ctx->field_order = AV_FIELD_BB;
>> +        } else if (ost->top_field_first == 1) {
>> +            enc_ctx->field_order = AV_FIELD_TT;
>> +        }
> 
> This doesn't look correct; ost->top_field_first is only
> valid if ost->interlaced_frame is set. Wouldn't this
> incorrectly set field_order on progressive streams,
> which should be set to AV_FIELD_PROGRESSIVE?

"ost" is of type OutputStream here, which only has top_field_first with 
values auto=-1/bff=0/tff=1. AVFrame has the 
interlaced_frame/top_field_first pair you mentioned, while 
AVCodecContext has field_order.

Regards,
Tobias
Derek Buitenhuis April 26, 2018, 2:58 p.m. UTC | #3
On 4/26/2018 3:49 PM, Tobias Rapp wrote:
> "ost" is of type OutputStream here, which only has top_field_first with 
> values auto=-1/bff=0/tff=1. AVFrame has the 
> interlaced_frame/top_field_first pair you mentioned, while 
> AVCodecContext has field_order.

Ah, I misunderstood the type and values of ost. Confusing naming...

Seems OK then, I suppose.

- Derek
Michael Niedermayer April 27, 2018, 4:37 p.m. UTC | #4
On Thu, Apr 26, 2018 at 04:06:27PM +0200, Tobias Rapp wrote:
> Fixes stream field order written by avformat_write_header when "top"
> option is specified on the command-line.
> 
> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com>
> ---
>  fftools/ffmpeg.c | 6 ++++++
>  1 file changed, 6 insertions(+)

possibly correct

thanks

[...]
Tobias Rapp May 2, 2018, 7:12 a.m. UTC | #5
On 26.04.2018 16:06, Tobias Rapp wrote:
> Fixes stream field order written by avformat_write_header when "top"
> option is specified on the command-line.
> 
> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com>
> ---
>   fftools/ffmpeg.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> [...]

Pushed, thanks to both of you for the review.

Regards,
Tobias
diff mbox

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 4dbe721..a28786a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3379,6 +3379,12 @@  static int init_output_stream_encode(OutputStream *ost)
             enc_ctx->bits_per_raw_sample = frame_bits_per_raw_sample;
         }
 
+        if (ost->top_field_first == 0) {
+            enc_ctx->field_order = AV_FIELD_BB;
+        } else if (ost->top_field_first == 1) {
+            enc_ctx->field_order = AV_FIELD_TT;
+        }
+
         if (ost->forced_keyframes) {
             if (!strncmp(ost->forced_keyframes, "expr:", 5)) {
                 ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5,