Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Gyan Doshi <ffmpeg@gyani.pro>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg: fix implementation of updated input start time
Date: Fri, 14 Oct 2022 09:52:42 +0530
Message-ID: <0a7a9061-9fd4-e187-799d-6afaa18319ab@gyani.pro> (raw)
In-Reply-To: <166559164999.12287.9666902488178933378@lain.khirnov.net>



On 2022-10-12 09:50 pm, Anton Khirnov wrote:
> Quoting Gyan Doshi (2022-09-27 06:40:56)
>> The current adjustment of input start times just adjusts the tsoffset.
>> And it does so, by resetting the tsoffset to nullify the new start time.
>> This leads to breakage of -copyts, ignoring of user_ts_offset, breaking
>                                                   ^^^^^^^^^^^^^^
>                                                   no such variable

Will correct.
>> of -isync as well as breaking wrap correction.
> Given all these options that are supposed to interact with each other in
> highly nonobvious ways, it would be great to have tests for the use
> cases you're fixing here.

These options don't really interact with each other. They all derive 
from or reference the start time.
Since ctx->start_time can't be changed outside lavf, we need to point to 
an fftools field. Basically, that's it.

>> Fixed by taking cognizance of these parameters, and by correcting start
>> times just before sync offsets are applied.
>> ---
>>   fftools/ffmpeg.c       | 24 +-------------------
>>   fftools/ffmpeg.h       |  5 ++++-
>>   fftools/ffmpeg_demux.c |  4 ++--
>>   fftools/ffmpeg_opt.c   | 50 +++++++++++++++++++++++++++++++++++++-----
>>   4 files changed, 52 insertions(+), 31 deletions(-)
>>
>> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
>> index 0e1477299d..fabb0fb952 100644
>> --- a/fftools/ffmpeg.c
>> +++ b/fftools/ffmpeg.c
>> @@ -1898,7 +1898,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
>>           start_time = 0;
>>           if (copy_ts) {
>>               start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
>> -            start_time += start_at_zero ? 0 : f->ctx->start_time;
>> +            start_time += start_at_zero ? 0 : f->enabled_start_time;
>>           }
>>           if (ist->pts >= f->recording_time + start_time) {
>>               close_output_stream(ost);
>> @@ -3323,28 +3323,6 @@ static int transcode_init(void)
>>                   input_streams[j + ifile->ist_index]->start = av_gettime_relative();
>>       }
>>   
>> -    // Correct starttime based on the enabled streams
>> -    for (i = 0; i < nb_input_files; i++) {
>> -        InputFile       *ifile = input_files[i];
>> -        AVFormatContext    *is = ifile->ctx;
>> -        int64_t new_start_time = INT64_MAX;
>> -
>> -        if (is->start_time == AV_NOPTS_VALUE ||
>> -            !(is->iformat->flags & AVFMT_TS_DISCONT))
>> -            continue;
>> -
>> -        for (int j = 0; j < is->nb_streams; j++) {
>> -            AVStream *st = is->streams[j];
>> -            if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
>> -                continue;
>> -            new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
>> -        }
>> -        if (new_start_time > is->start_time) {
>> -            av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time);
>> -            ifile->ts_offset = -new_start_time;
>> -        }
>> -    }
>> -
> The change would be more readable if you first moved this block into a
> separate function in a separate patch.
Will do.

>
> Also, apply_sync_offsets() and correct_input_start_times() both modify
> ts_offset in complicated ways. IMO it makes more sense to have both
> loops in one function.

I'd prefer a parent container with these two as child functions. I like 
the one purpose per function - cleaner for any future changes.

>>       /* init input streams */
>>       for (i = 0; i < nb_input_streams; i++)
>>           if ((ret = init_input_stream(i, error, sizeof(error))) < 0)
>> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
>> index ede0b2bd96..b93c2427b6 100644
>> --- a/fftools/ffmpeg.h
>> +++ b/fftools/ffmpeg.h
>> @@ -439,7 +439,10 @@ typedef struct InputFile {
>>       AVRational time_base; /* time base of the duration */
>>       int64_t input_ts_offset;
>>       int input_sync_ref;
>> -
>> +    /**
>> +     * Effective format start time based on enabled streams.
>> +     */
>> +    int64_t enabled_start_time;
> Not a big fan of the name. Maybe start_time_effective would be better.
> Or maybe even rename InputFile.start_time into start_time_user and reuse
> the start_time name for the new variable.

I like start_time_effective . Will do.

Regards,
Gyan
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2022-10-14  4:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27  4:40 Gyan Doshi
2022-10-02 19:46 ` Gyan Doshi
2022-10-04  9:11   ` Anton Khirnov
2022-10-12  6:35     ` Gyan Doshi
2022-10-12 16:20 ` Anton Khirnov
2022-10-14  4:22   ` Gyan Doshi [this message]
2022-10-14 13:19 ` Jan Ekström
2022-10-14 13:37   ` Gyan Doshi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a7a9061-9fd4-e187-799d-6afaa18319ab@gyani.pro \
    --to=ffmpeg@gyani.pro \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git