[FFmpeg-devel] [PATCH] Add -t option to ffplay
Stefano Sabatini
stefano.sabatini-lala
Sat Mar 27 00:00:51 CET 2010
On date Wednesday 2010-03-24 16:58:59 +0100, Robert Kr?ger encoded:
>
> On 24.03.2010, at 16:37, Michael Niedermayer wrote:
>
> > On Wed, Mar 24, 2010 at 04:34:16PM +0100, Robert Kr?ger wrote:
> >>
> >> On 24.03.2010, at 15:43, Michael Niedermayer wrote:
> >>
> >>> On Wed, Mar 24, 2010 at 10:10:46AM +0100, Robert Kr?ger wrote:
> >>>>
> >>>> This patch adds a -t option (a la ffmpeg) to ffplay to allow
> >>>> specifying a max duration to play. Together with -ss and -loop
> >>>> a useful tool for reviewing specific parts of video footage (at
> >>>> least that's my use case).
> >>>>
> >>>>
> >>>> Regards,
> >>>>
> >>>> Robert
> >>>>
> >>>>
> >>>
> >>> breaks gcc 2.95
> >>>
> >>
> >> which aspect of the statement. A hint would be appreciated.
> >
> > mixing statements and declarations
> > declarations must be at the begin of blocks (pre C99)
> >
>
> thanks. attached patch got rid of respective warnings (which I should have noticed).
>
> Regards,
>
> Robert
>
> Index: ffplay.c
> ===================================================================
> --- ffplay.c (revision 22648)
> +++ ffplay.c (working copy)
> @@ -244,6 +244,7 @@
> static int show_status = 1;
> static int av_sync_type = AV_SYNC_AUDIO_MASTER;
> static int64_t start_time = AV_NOPTS_VALUE;
> +static int64_t duration = AV_NOPTS_VALUE;
> static int debug = 0;
> static int debug_mv = 0;
> static int step = 0;
> @@ -2302,6 +2303,8 @@
> AVPacket pkt1, *pkt = &pkt1;
> AVFormatParameters params, *ap = ¶ms;
> int eof=0;
> + int64_t effective_start_time = 0;
> + int pkt_past_play_range = 0;
>
> ic = avformat_alloc_context();
>
> @@ -2473,6 +2476,8 @@
> SDL_Delay(10);
> continue;
> }
> + if(start_time != AV_NOPTS_VALUE)
> + effective_start_time = start_time;
> if(url_feof(ic->pb) || eof) {
> if(is->video_stream >= 0){
> av_init_packet(pkt);
> @@ -2484,7 +2489,7 @@
> SDL_Delay(10);
> if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){
> if(loop!=1 && (!loop || --loop)){
> - stream_seek(cur_stream, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0);
> + stream_seek(cur_stream, effective_start_time, 0, 0);
> }else if(autoexit){
> ret=AVERROR_EOF;
> goto fail;
> @@ -2501,11 +2506,16 @@
> SDL_Delay(100); /* wait for user event */
> continue;
> }
> - if (pkt->stream_index == is->audio_stream) {
> + /* check if packet is in play range specified by user, then queue, otherwise discard */
> + pkt_past_play_range = duration != AV_NOPTS_VALUE &&
> + (pkt->pts - ic->streams[pkt->stream_index]->start_time) *
> + av_q2d(ic->streams[pkt->stream_index]->time_base) - (double)effective_start_time/1000000
> + > ((double)duration/1000000);
> + if (!pkt_past_play_range && pkt->stream_index == is->audio_stream) {
> packet_queue_put(&is->audioq, pkt);
> - } else if (pkt->stream_index == is->video_stream) {
> + } else if (!pkt_past_play_range && pkt->stream_index == is->video_stream) {
> packet_queue_put(&is->videoq, pkt);
> - } else if (pkt->stream_index == is->subtitle_stream) {
> + } else if (!pkt_past_play_range && pkt->stream_index == is->subtitle_stream) {
> packet_queue_put(&is->subtitleq, pkt);
> } else {
> av_free_packet(pkt);
> @@ -2913,6 +2923,12 @@
> return 0;
> }
>
> +static int opt_duration(const char *opt, const char *arg)
> +{
> + duration = parse_time_or_die(opt, arg, 1);
> + return 0;
> +}
> +
> static int opt_debug(const char *opt, const char *arg)
> {
> av_log_set_level(99);
> @@ -2947,6 +2963,7 @@
> { "vst", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_stream[CODEC_TYPE_VIDEO]}, "select desired video stream", "stream_number" },
> { "sst", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_stream[CODEC_TYPE_SUBTITLE]}, "select desired subtitle stream", "stream_number" },
> { "ss", HAS_ARG | OPT_FUNC2, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" },
> + { "t", HAS_ARG | OPT_FUNC2, {(void*)&opt_duration}, "play \"duration\" seconds of audio/video", "duration" },
> { "bytes", OPT_INT | HAS_ARG, {(void*)&seek_by_bytes}, "seek by bytes 0=off 1=on -1=auto", "val" },
> { "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" },
> { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
Missing manpage docs.
Regards.
--
FFmpeg = Funny and Formidable Mystic Purposeless Elitarian Genius
More information about the ffmpeg-devel
mailing list