From 77e208bf58ba7980f9d5aefb7ffb70ba8af5ee5a Mon Sep 17 00:00:00 2001 From: Good Guy Date: Sat, 30 Jan 2016 08:19:49 -0700 Subject: [PATCH] rework ffmpeg seek, bld_script updates --- cinelerra-5.0/bld_scripts/bld_incremental.sh | 2 +- cinelerra-5.0/bld_scripts/bld_package.sh | 2 +- cinelerra-5.0/bld_scripts/bld_prepare.sh | 4 +- cinelerra-5.0/cinelerra/ffmpeg.C | 59 +++++++++++--------- cinelerra-5.0/cinelerra/fileffmpeg.C | 16 ------ cinelerra-5.0/cinelerra/fileffmpeg.h | 2 - 6 files changed, 37 insertions(+), 48 deletions(-) diff --git a/cinelerra-5.0/bld_scripts/bld_incremental.sh b/cinelerra-5.0/bld_scripts/bld_incremental.sh index ad62cd84..e38308d8 100755 --- a/cinelerra-5.0/bld_scripts/bld_incremental.sh +++ b/cinelerra-5.0/bld_scripts/bld_incremental.sh @@ -3,7 +3,7 @@ dir="$1" path="/home" bld="git-repo" -proj="cinelerra" +proj="cinelerra5" base="cinelerra-5.0" if [ ! -d "$path/$dir/$bld/$proj" ]; then diff --git a/cinelerra-5.0/bld_scripts/bld_package.sh b/cinelerra-5.0/bld_scripts/bld_package.sh index 81f027bd..08f21a4e 100755 --- a/cinelerra-5.0/bld_scripts/bld_package.sh +++ b/cinelerra-5.0/bld_scripts/bld_package.sh @@ -10,7 +10,7 @@ fi dir="$1" path="/home" bld="git-repo" -proj="cinelerra" +proj="cinelerra5" base="cinelerra-5.0" centos="centos-7.0-1406" diff --git a/cinelerra-5.0/bld_scripts/bld_prepare.sh b/cinelerra-5.0/bld_scripts/bld_prepare.sh index 9eb54334..a99de900 100755 --- a/cinelerra-5.0/bld_scripts/bld_prepare.sh +++ b/cinelerra-5.0/bld_scripts/bld_prepare.sh @@ -23,7 +23,7 @@ case "$dir" in libpng-devel bzip2-devel zlib-devel kernel-headers \ libavc1394 festival-devel libiec61883-devel flac-devel \ libsndfile-devel libtheora-devel linux-firmware ivtv-firmware \ - libvorbis-devel texinfo xz-devel lzma-devel cmake udftools + libvorbis-devel texinfo xz-devel lzma-devel cmake udftools git yasm=yasm-1.2.0-7.fc21.x86_64.rpm release=http://archives.fedoraproject.org/pub/fedora/linux/releases/21 url=$release/Everything/x86_64/os/Packages/y/$yasm @@ -39,7 +39,7 @@ case "$dir" in openexr-devel libavc1394-devel festival-devel libjpeg8-devel libdv-devel \ libdvdnav-devel libdvdread-devel libiec61883-devel libuuid-devel \ ilmbase-devel fftw3-devel libsndfile-devel libtheora-devel flac-devel \ - cmake patch libnuma-devel lzma-devel udftools + cmake patch libnuma-devel lzma-devel udftools git if [ ! -f /usr/lib64/libtermcap.so ]; then ln -s libtermcap.so.2 /usr/lib64/libtermcap.so fi diff --git a/cinelerra-5.0/cinelerra/ffmpeg.C b/cinelerra-5.0/cinelerra/ffmpeg.C index 120a75d6..aa7a9f1f 100644 --- a/cinelerra-5.0/cinelerra/ffmpeg.C +++ b/cinelerra-5.0/cinelerra/ffmpeg.C @@ -12,6 +12,7 @@ #ifndef INT64_MAX #define INT64_MAX 9223372036854775807LL #endif +#define MAX_RETRY 1000 #include "asset.h" #include "bccmodels.h" @@ -350,7 +351,7 @@ int FFStream::read_packet() int FFStream::decode(AVFrame *frame) { int ret = 0; - int retries = 1000; + int retries = MAX_RETRY; int got_frame = 0; while( ret >= 0 && !flushed && --retries >= 0 && !got_frame ) { @@ -365,7 +366,7 @@ int FFStream::decode(AVFrame *frame) ipkt->data += ret; ipkt->size -= ret; } - retries = 1000; + retries = MAX_RETRY; } if( !got_frame ) { need_packet = 1; @@ -460,33 +461,39 @@ int FFStream::seek(int64_t no, double rate) if( n < 0 ) n = 0; pos = n; plmt = marks[i].pos; - npkts = 1000; + npkts = MAX_RETRY; } } double secs = pos / rate; - int64_t tstmp = secs * st->time_base.den / st->time_base.num; + int64_t pkt_ts, tstmp = secs * st->time_base.den / st->time_base.num; if( nudge != AV_NOPTS_VALUE ) tstmp += nudge; - if( avformat_seek_file(fmt_ctx, st->index, - -INT64_MAX, tstmp, INT64_MAX, AVSEEK_FLAG_ANY) < 0 ) return -1; - avcodec_flush_buffers(st->codec); - need_packet = 0; flushed = 0; - seeked = 1; st_eof(0); - int64_t pkt_ts = AV_NOPTS_VALUE; - int ret = 1, retry = 1000; - + int ret = avformat_seek_file(fmt_ctx, st->index, + -INT64_MAX, tstmp, INT64_MAX, AVSEEK_FLAG_ANY); + if( ret >= 0 ) { + avcodec_flush_buffers(st->codec); + need_packet = 0; flushed = 0; + seeked = 1; st_eof(0); // read up to retry packets, limited to npkts in stream, and not past pkt.pos plmt - while( ret > 0 && npkts > 0 && --retry >= 0 ) { - if( (ret=read_packet()) <= 0 ) break; - if( ipkt->stream_index != st->index ) continue; - if( (pkt_ts=ipkt->dts) == AV_NOPTS_VALUE ) pkt_ts = ipkt->pts; - if( pkt_ts != AV_NOPTS_VALUE && pkt_ts >= tstmp ) break; - if( plmt >= 0 && ipkt->pos >= plmt ) break; - --npkts; + for( int retry=MAX_RETRY; ret>=0 && --retry>=0; ) { + if( read_packet() <= 0 || ( plmt >= 0 && ipkt->pos > plmt ) ) { + ret = -1; break; + } + if( ipkt->stream_index != st->index ) continue; + if( --npkts <= 0 ) break; + if( (pkt_ts=ipkt->dts) == AV_NOPTS_VALUE && + (pkt_ts=ipkt->pts) == AV_NOPTS_VALUE ) continue; + if( pkt_ts >= tstmp ) break; + } } - - if( ret <= 0 || retry < 0 ) return -1; + if( ret < 0 ) { +//printf("** seek fail %ld, %ld\n", pos, tstmp); + seeked = need_packet = 0; + st_eof(flushed=1); + return -1; + } +//printf("seeked pos = %ld, %ld\n", pos, tstmp); seek_pos = curr_pos = pos; - return npkts > 0 ? 1 : 0; + return 0; } FFAudioStream::FFAudioStream(FFMPEG *ffmpeg, AVStream *strm, int idx, int fidx) @@ -628,7 +635,7 @@ int FFAudioStream::load(int64_t pos, int len) if( mbsz < len ) mbsz = len; int64_t end_pos = pos + len; int ret = 0; - for( int i=0; ret>=0 && !flushed && curr_pos=0 && !flushed && curr_pos 0 ) { load_history(&frame->extended_data[0], frame->nb_samples); @@ -742,7 +749,7 @@ int FFVideoStream::load(VFrame *vframe, int64_t pos) fprintf(stderr, "FFVideoStream::load: av_frame_alloc failed\n"); return -1; } - for( int i=0; ret>=0 && !flushed && curr_pos<=pos && i<1000; ++i ) { + for( int i=0; ret>=0 && !flushed && curr_pos<=pos && i 0 ) ++curr_pos; } @@ -1254,9 +1261,9 @@ int FFMPEG::read_options(FILE *fp, const char *options, AVDictionary *&opts) if( !ret ) { if( !strcmp(key, "duration") ) opt_duration = strtod(val, 0); - if( !strcmp(key, "video_filter") ) + else if( !strcmp(key, "video_filter") ) opt_video_filter = cstrdup(val); - if( !strcmp(key, "audio_filter") ) + else if( !strcmp(key, "audio_filter") ) opt_audio_filter = cstrdup(val); else if( !strcmp(key, "loglevel") ) set_loglevel(val); diff --git a/cinelerra-5.0/cinelerra/fileffmpeg.C b/cinelerra-5.0/cinelerra/fileffmpeg.C index b5b459ef..1972a9ec 100644 --- a/cinelerra-5.0/cinelerra/fileffmpeg.C +++ b/cinelerra-5.0/cinelerra/fileffmpeg.C @@ -247,22 +247,6 @@ int FileFFMPEG::close_file() } -int FileFFMPEG::set_video_position(int64_t pos) -{ - if( !ff || pos < 0 || pos >= asset->video_length ) - return 1; - return 0; -} - - -int FileFFMPEG::set_audio_position(int64_t pos) -{ - if( !ff || pos < 0 || pos >= asset->audio_length ) - return 1; - return 0; -} - - int FileFFMPEG::write_samples(double **buffer, int64_t len) { if( !ff || len < 0 ) return -1; diff --git a/cinelerra-5.0/cinelerra/fileffmpeg.h b/cinelerra-5.0/cinelerra/fileffmpeg.h index ed95ee94..fe068d25 100644 --- a/cinelerra-5.0/cinelerra/fileffmpeg.h +++ b/cinelerra-5.0/cinelerra/fileffmpeg.h @@ -52,8 +52,6 @@ public: int open_file(int rd,int wr); int get_index(char *index_filename); int close_file(void); - int set_video_position(int64_t pos); - int set_audio_position(int64_t pos); int write_samples(double **buffer,int64_t len); int write_frames(VFrame ***frames,int len); int read_samples(double *buffer,int64_t len); -- 2.26.2