Re: [FFmpeg-devel] [PATCH v2 2/8] ffmpeg: do packet ts rescaling in write_packet()

2017-02-21 Thread Michael Niedermayer
On Wed, Feb 15, 2017 at 10:24:17AM +0100, wm4 wrote:
> From: Anton Khirnov 
> 
> This will be useful in the following commit, after which the muxer
> timebase is not always available when encoding.
> 
> This merges Libav commit 3e265ca. It was previously skipped.
> 
> There is a minor change with setting the mux_timebase field only after
> the muxer's write_header function has been called, because it can
> readjust the timebase.
> 
> Includes a minor merge fix by Mark Thompson, and
> 
> avconv: Move rescale to stream timebase before monotonisation
> 
> also by Mark Thompson .
> 
> Signed-off-by: wm4 
> ---
>  ffmpeg.c | 39 ++-
>  ffmpeg.h |  2 ++
>  2 files changed, 24 insertions(+), 17 deletions(-)

Tests run against master with
cb6f1be864c64cfa1d48a5d3eadbecbc771402e7
9148290d71648b0c4295485e59f6541892041a6b
(taken from your git)


This causes a difference in:
./ffmpeg -i ~/tickets/1242/sample.mkv -vcodec copy  -copyts -acodec copy -sn 
test.ts

Ive looked at the difference and it seems the first timestamp differs
0,  -3780,  0,0, 3056, 0x00f4902c, S=1,1, 
0x00e000e0
vs.
0,  -3754,  0,0, 3056, 0x00f4902c, S=1,1, 
0x00e000e0

3754 is closer to 9/24000/1001
3780 is closer to the first timestamp from the source file

i dont really know what is better

with
./ffmpeg -i ~/tickets/2143/input.mpg -vcodec copy -acodec copy  -ss 7 -t 7 
test.mpg

this causes larger timestamp differences and a shower of warnings like
Non-monotonous DTS in output stream 0:0; previous: 483483, current: 483483; 
changing to 483484. This may result in incorrect timestamps in the output file.

previously no such warnings where generated

with
./ffmpeg -i ~/tickets/2424/aspect_bug.mkv -vcodec copy -acodec copy -t 1 
test.mp4
Again the first timestamps change and here also the printed fps value
changes from 24 to 24.01

theres also a differene with Starship_Troopers.vob which i belive i reported
previously

and this also has different timestamps:
./ffmpeg -i ~/tickets/3547/sat_uplink_signalloss.ts -vcodec copy -acodec copy 
test.asf
interrestingly this is specific to asf output, other formats seem not
to show this

Thats all i could find for the 2 commits with some light analysis.
I Hope it helps

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus


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


[FFmpeg-devel] [PATCH v2 2/8] ffmpeg: do packet ts rescaling in write_packet()

2017-02-15 Thread wm4
From: Anton Khirnov 

This will be useful in the following commit, after which the muxer
timebase is not always available when encoding.

This merges Libav commit 3e265ca. It was previously skipped.

There is a minor change with setting the mux_timebase field only after
the muxer's write_header function has been called, because it can
readjust the timebase.

Includes a minor merge fix by Mark Thompson, and

avconv: Move rescale to stream timebase before monotonisation

also by Mark Thompson .

Signed-off-by: wm4 
---
 ffmpeg.c | 39 ++-
 ffmpeg.h |  2 ++
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 913c18d92b..2876e43b32 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -713,10 +713,12 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost)
 if (pkt->duration > 0)
 av_log(NULL, AV_LOG_WARNING, "Overriding packet duration by 
frame rate, this should not happen\n");
 pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate),
- ost->st->time_base);
+ ost->mux_timebase);
 }
 }
 
+av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base);
+
 if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
 if (pkt->dts != AV_NOPTS_VALUE &&
 pkt->pts != AV_NOPTS_VALUE &&
@@ -907,13 +909,13 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
 
 update_benchmark("encode_audio %d.%d", ost->file_index, ost->index);
 
-av_packet_rescale_ts(, enc->time_base, ost->st->time_base);
+av_packet_rescale_ts(, enc->time_base, ost->mux_timebase);
 
 if (debug_ts) {
 av_log(NULL, AV_LOG_INFO, "encoder -> type:audio "
"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
-   av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, 
>st->time_base),
-   av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, 
>st->time_base));
+   av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, >time_base),
+   av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, 
>time_base));
 }
 
 output_packet(of, , ost);
@@ -993,8 +995,8 @@ static void do_subtitle_out(OutputFile *of,
 av_init_packet();
 pkt.data = subtitle_out;
 pkt.size = subtitle_out_size;
-pkt.pts  = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base);
-pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 
1000 }, ost->st->time_base);
+pkt.pts  = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase);
+pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 
1000 }, ost->mux_timebase);
 if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
 /* XXX: the pts correction is handled here. Maybe handling
it in the codec would be better */
@@ -1187,7 +1189,7 @@ static void do_video_out(OutputFile *of,
 mux_par->field_order = AV_FIELD_PROGRESSIVE;
 pkt.data   = (uint8_t *)in_picture;
 pkt.size   =  sizeof(AVPicture);
-pkt.pts= av_rescale_q(in_picture->pts, enc->time_base, 
ost->st->time_base);
+pkt.pts= av_rescale_q(in_picture->pts, enc->time_base, 
ost->mux_timebase);
 pkt.flags |= AV_PKT_FLAG_KEY;
 
 output_packet(of, , ost);
@@ -1283,13 +1285,13 @@ static void do_video_out(OutputFile *of,
 if (pkt.pts == AV_NOPTS_VALUE && !(enc->codec->capabilities & 
AV_CODEC_CAP_DELAY))
 pkt.pts = ost->sync_opts;
 
-av_packet_rescale_ts(, enc->time_base, ost->st->time_base);
+av_packet_rescale_ts(, enc->time_base, ost->mux_timebase);
 
 if (debug_ts) {
 av_log(NULL, AV_LOG_INFO, "encoder -> type:video "
 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
-av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, 
>st->time_base),
-av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, 
>st->time_base));
+av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, 
>mux_timebase),
+av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, 
>mux_timebase));
 }
 
 frame_size = pkt.size;
@@ -1862,8 +1864,8 @@ static void flush_encoders(void)
 av_packet_unref();
 continue;
 }
-av_packet_rescale_ts(, enc->time_base, ost->st->time_base);
 pkt_size = pkt.size;
+av_packet_rescale_ts(, enc->time_base, ost->mux_timebase);
 output_packet(of, , ost);
 if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && 
vstats_filename) {
 do_video_stats(ost, pkt_size);
@@ -1897,7 +1899,7 @@ static void