--- FFmpeg-n4.4.4/.gitattributes
+++ /dev/null
@@ -1,2 +0,0 @@
-*.pnm -diff -text
-tests/ref/fate/sub-scc eol=crlf
--- FFmpeg-n4.4.4/.gitignore
+++ /dev/null
@@ -1,39 +0,0 @@
-*.a
-*.o
-*.o.*
-*.d
-*.def
-*.dll
-*.dylib
-*.exe
-*.exp
-*.gcda
-*.gcno
-*.h.c
-*.ilk
-*.lib
-*.pc
-*.pdb
-*.so
-*.so.*
-*.swp
-*.ver
-*.version
-*.ptx
-*.ptx.c
-*_g
-\#*
-.\#*
-/.config
-/.version
-/ffmpeg
-/ffplay
-/ffprobe
-/config.asm
-/config.h
-/coverage.info
-/avversion.h
-/lcov/
-/src
-/mapfile
-/tools/python/__pycache__/
--- FFmpeg-n4.4.4/.mailmap
+++ /dev/null
@@ -1,25 +0,0 @@
-<james.darnley@gmail.com> <jdarnley@obe.tv>
-<jeebjp@gmail.com> <jan.ekstrom@aminocom.com>
-<sw@jkqxz.net> <mrt@jkqxz.net>
-<u@pkh.me> <cboesch@gopro.com>
-<zhilizhao@tencent.com> <quinkblack@foxmail.com>
-<zhilizhao@tencent.com> <wantlamy@gmail.com>
-<modmaker@google.com> <modmaker-at-google.com@ffmpeg.org>
-<stebbins@jetheaddev.com> <jstebbins@jetheaddev.com>
-<barryjzhao@tencent.com> <mypopydev@gmail.com>
-<barryjzhao@tencent.com> <jun.zhao@intel.com>
-<josh@itanimul.li> <joshdk@obe.tv>
-<michael@niedermayer.cc> <michaelni@gmx.at>
-<linjie.justin.fu@gmail.com> <linjie.fu@intel.com>
-<linjie.justin.fu@gmail.com> <fulinjie@zju.edu.cn>
-<ceffmpeg@gmail.com> <cehoyos@ag.or.at>
-<ceffmpeg@gmail.com> <cehoyos@rainbow.studorg.tuwien.ac.at>
-<ffmpeg@gyani.pro> <gyandoshi@gmail.com>
-<atomnuker@gmail.com> <rpehlivanov@obe.tv>
-<lizhong1008@gmail.com> <zhong.li@intel.com>
-<lizhong1008@gmail.com> <zhongli_dev@126.com>
-<andreas.rheinhardt@gmail.com> <andreas.rheinhardt@googlemail.com>
-rcombs <rcombs@rcombs.me> <rodger.combs@gmail.com>
-<thilo.borgmann@mail.de> <thilo.borgmann@googlemail.com>
-<liuqi05@kuaishou.com> <lq@chinaffmpeg.org>
-<ruiling.song83@gmail.com> <ruiling.song@intel.com>
--- FFmpeg-n4.4.4/.travis.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-language: c
-sudo: false
-os:
-  - linux
-  - osx
-addons:
-  apt:
-    packages:
-      - nasm
-      - diffutils
-compiler:
-  - clang
-  - gcc
-matrix:
-    exclude:
-        - os: osx
-          compiler: gcc
-cache:
-  directories:
-    - ffmpeg-samples
-before_install:
-  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi
-install:
-  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install nasm; fi
-script:
-  - mkdir -p ffmpeg-samples
-  - ./configure --samples=ffmpeg-samples --cc=$CC
-  - make -j 8
-  - make fate-rsync
-  - make check -j 8
--- FFmpeg-n4.4.4/CREDITS
+++ Ascendffmpeg/CREDITS
@@ -1,6 +1,6 @@
-See the Git history of the project (https://git.ffmpeg.org/ffmpeg) to
+See the Git history of the project (git://source.ffmpeg.org/ffmpeg) to
 get the names of people who have contributed to FFmpeg.
 
 To check the log, you can type the command "git log" in the FFmpeg
 source directory, or browse the online repository at
-https://git.ffmpeg.org/ffmpeg
+http://source.ffmpeg.org.
--- FFmpeg-n4.4.4/Changelog
+++ Ascendffmpeg/Changelog
@@ -1,267 +1,6 @@
 Entries are sorted chronologically from oldest to youngest within each release,
 releases are sorted from youngest to oldest.
 
-version 4.4.4:
-- avcodec/tests/snowenc: Fix 2nd test
-- avcodec/tests/snowenc: return a failure if DWT/IDWT mismatches
-- avcodec/snowenc: Fix visual weight calculation
-- avcodec/tests/snowenc: unbreak DWT tests
-- avcodec/vp3: Add missing check for av_malloc
-- avformat/nutdec: Add check for avformat_new_stream
-- avcodec/mpeg12dec: Check input size
-- avcodec/escape124: Fix some return codes
-- avcodec/escape124: fix signdness of end of input check
-- Use https for repository links
-- avcodec/rpzaenc: stop accessing out of bounds frame
-- avcodec/motionpixels: Mask pixels to valid values
-- avcodec/xpmdec: Check size before allocation to avoid truncation
-- avcodec/bink: Avoid undefined out of array end pointers in binkb_decode_plane()
-- avcodec/bink: Fix off by 1 error in ref end
-- avcodec/utils: Ensure linesize for SVQ3
-- avcodec/utils: allocate a line more for VC1 and WMV3
-- avcodec/videodsp_template: Adjust pointers to avoid undefined pointer things
-- avcodec/pngdec: Check deloco index more exactly
-- avcodec/ffv1dec: Check that num h/v slices is supported
-- avformat/mov: Check samplesize and offset to avoid integer overflow
-- avcodec/pictordec: Remove mid exit branch
-- avcodec/eac3dec: avoid float noise in fixed mode addition to overflow
-- avcodec/utils: use 32pixel alignment for bink
-- avcodec/scpr3: Check bx
-- avcodec/012v: Order operations for odd size handling
-- avcodec/eatgq: : Check index increments in tgq_decode_block()
-- avcodec/scpr: Test bx before use
-- avformat/mxfdec: Use 64bit in remainder
-- avcodec/sunrast: Fix maplength check
-- avcodec/wavpack: Avoid undefined shift in get_tail()
-- avcodec/wavpack: Check for end of input in wv_unpack_dsd_high()
-- avformat/id3v2: Check taglen in read_uslt()
-- avcodec/tiff: Ignore tile_count
-- avcodec/ffv1dec: restructure slice coordinate reading a bit
-- avcodec/mlpdec: Check max matrix instead of max channel in noise check
-- swscale/input: Use more unsigned intermediates
-- avcodec/alsdec: The minimal block is at least 7 bits
-- avformat/replaygain: avoid undefined / negative abs
-- swscale/output: Bias 16bps output calculations to improve non overflowing range
-- avcodec/speedhq: Check buf_size to be big enough for DC
-- avcodec/ffv1dec: Fail earlier if prior context is corrupted
-- avcodec/nvenc: fix b-frame DTS behavior with fractional framerates
-- avfilter/vf_untile: swap the chroma shift values used for plane offsets
-- avcodec/nvenc: fix vbv buffer size in cq mode
-- avcodec/mjpegenc: take into account component count when writing the SOF header size
-- swscale: aarch64: Fix yuv2rgb with negative stride
-
-version 4.4.3:
-- avformat/vividas: Check packet size
-- configure: link to libatomic when it's present
-- avcodec/dstdec: Check for overflow in build_filter()
-- avformat/spdifdec: Use 64bit to compute bit rate
-- avformat/rpl: Use 64bit for duration computation
-- avformat/xwma: Use av_rescale() for duration computation
-- avformat/sdsdec: Use av_rescale() to avoid intermediate overflow in duration calculation
-- avformat/sbgdec: Check ts_int in genrate_intervals
-- avformat/rmdec: check tag_size
-- avformat/nutdec: Check fields
-- avformat/flvdec: Use 64bit for sum_flv_tag_size
-- avformat/jacosubdec: Fix overflow in get_shift()
-- avformat/dxa: avoid bpc overflows
-- avformat/cafdec: Check that nb_frasmes fits within 64bit
-- avformat/asfdec_o: Limit packet offset
-- avformat/ape: Check frames size
-- avformat/icodec: Check nb_pal
-- avformat/aiffdec: Use 64bit for block_duration use
-- avformat/aiffdec: Check block_duration
-- avformat/mxfdec: only probe max run in
-- avformat/mxfdec: Check run_in is within 65536
-- avcodec/mjpegdec: Check for unsupported bayer case
-- avcodec/apedec: Fix integer overflow in filter_3800()
-- avcodec/tta: Check 24bit scaling for overflow
-- avcodec/mobiclip: Check quantizer for overflow
-- avcodec/exr: Check preview psize
-- avcodec/tiff: Fix loop detection
-- libavformat/hls: Free keys
-- avcodec/fmvc: Move frame allocation to a later stage
-- avfilter/vf_showinfo: remove backspaces
-- avcodec/speedhq: Check width
-- avcodec/bink: disallow odd positioned scaled blocks
-- avformat/asfdec_o: limit recursion depth in asf_read_unknown()
-- doc/git-howto.texi: Document commit signing
-- libavcodec/8bps: Check that line lengths fit within the buffer
-- avcodec/midivid: Perform lzss_uncompress() before ff_reget_buffer()
-- libavformat/iff: Check for overflow in body_end calculation
-- avformat/avidec: Prevent entity expansion attacks
-- avcodec/h263dec: Sanity check against minimal I/P frame size
-- avcodec/hevcdec: Check s->ref in the md5 path similar to hwaccel
-- avcodec/mpegaudiodec_template: use unsigned shift in handle_crc()
-- avformat/subviewerdec: Make read_ts() more flexible
-- avcodec/mjpegdec: bayer and rct are incompatible
-- MAINTAINERS: Add ED25519 key for signing my commits in the future
-- avcodec/hevc_filter: copy_CTB() only within width&height
-- avcodec/tiff: Check tile_length and tile_width
-- avcodec/mss4: Check image size with av_image_check_size2()
-- avformat/flvdec: Check for EOF in index reading
-- avformat/nutdec: Check get_packetheader() in mainheader
-- avformat/asfdec_f: Use 64bit for packet start time
-- avcodec/exr: Check x/ysize
-- tools/target_dec_fuzzer: Adjust threshold for MMVIDEO
-- avcodec/lagarith: Check dst/src in zero run code
-- avcodec/h264dec: Skip late SEI
-- avcodec/sbrdsp_fixed: Fix integer overflows in sbr_qmf_deint_neg_c()
-- avfilter/vf_signature: Fix integer overflow in filter_frame()
-- avformat/rtsp: break on unknown protocols
-- avcodec/hevcdsp_template: stay within tables in sao_band_filter()
-- avcodec/tiff: Check pixel format types for dng
-- avcodec/qpeldsp: copy less for the mc0x cases
-- avformat/aaxdec: Check for empty segments
-- avcodec/ffv1dec: Limit golomb rice coded slices to width 8M
-- avformat/iff: simplify duration calculation
-- avcodec/wnv1: Check for width =1
-- avcodec/ffv1dec_template: fix indention
-- avformat/sctp: close socket on errors
-- avcodec/aasc: Fix indention
-- avcodec/qdrw: adjust max colors to array size
-- avcodec/alacdsp: Make intermediates unsigned
-- avformat/aiffdec: cleanup size handling for extreem cases
-- avformat/matroskadec: avoid integer overflows in SAR computation
-- avcodec/jpeglsdec: fix end check for xfrm
-- avcodec/cdgraphics: limit scrolling to the line
-- avformat/hls: Limit start_seq_no to one bit less
-- avformat/aiffdec: avoid integer overflow in get_meta()
-- avformat/ape: more bits in size for less overflows
-- avformat/aviobuf: Check buf_size in ffio_ensure_seekback()
-- avformat/bfi: Check offsets better
-- avformat/asfdec_f: Check packet_frag_timestamp
-- avcodec/texturedspenc: Fix indexing in color distribution determination
-- avformat/act: Check ff_get_wav_header() for failure
-- avcodec/libxavs2: Improve r redundancy in occured
-- avformat/libzmq: Improve r redundancy in occured
-- avfilter/vsrc_mandelbrot: Check for malloc failure
-- avfilter/vf_frei0r: Copy to frame allocated according to frei0r requirements
-- avfilter/video: Add ff_default_get_video_buffer2() to set specific alignment
-- avformat/genh: Check sample rate
-- configure: bump year
-- lavc/videotoolbox: do not pass AVCodecContext to decoder output callback
-- lavc/pthread_frame: always transfer stashed hwaccel state
-- avcodec/arm/sbcenc: avoid callee preserved vfp registers
-- avfilter/vf_scale: overwrite the width and height expressions with the original values
-- lavc/pthread_frame: avoid leaving stale hwaccel state in worker threads
-- configure: extend SDL check to accept all 2.x versions
-- lavf/tls_mbedtls: add support for mbedtls version 3
-
-version 4.4.2:
-- fate: update reference files after the recent dash manifest muxer changes
-- avformat/webmdashenc: fix on-demand profile string
-- Update for FFmpeg 4.4.2
-- avcodec/exr: Avoid signed overflow in displayWindow
-- avcodec/diracdec: avoid signed integer overflow in global mv
-- avcodec/takdsp: Fix integer overflow in decorrelate_sf()
-- avcodec/apedec: fix a integer overflow in long_filter_high_3800()
-- avfilter/vf_subtitles: pass storage size to libass
-- avformat/aqtitledec: Skip unrepresentable durations
-- avformat/cafdec: Do not store empty keys in read_info_chunk()
-- avformat/mxfdec: Do not clear array in mxf_read_strong_ref_array() before writing
-- avformat/mxfdec: Check for avio_read() failure in mxf_read_strong_ref_array()
-- avformat/mxfdec: Check count in mxf_read_strong_ref_array()
-- avformat/hls: Check target_duration
-- avcodec/pixlet: Avoid signed integer overflow in scaling in filterfn()
-- avformat/matroskadec: Check pre_ns
-- avcodec/sonic: Use unsigned for predictor_k to avoid undefined behavior
-- avcodec/libuavs3d: Check ff_set_dimensions() for failure
-- avcodec/mjpegbdec: Set buf_size
-- avformat/matroskadec: Use rounded down duration in get_cue_desc() check
-- avcodec/argo: Check packet size
-- avcodec/g729_parser: Check channels
-- avformat/avidec: Check height
-- avformat/rmdec: Better duplicate tags check
-- avformat/mov: Disallow empty sidx
-- avformat/argo_asf: Fix order of operations in error check in argo_asf_write_trailer()
-- avformat/matroskadec: Check duration
-- avformat/mov: Corner case encryption error cleanup in mov_read_senc()
-- avcodec/jpeglsdec: Fix if( code style
-- avcodec/jpeglsdec: Check get_ur_golomb_jpegls() for error
-- avcodec/motion_est: fix indention of ff_get_best_fcode()
-- avcodec/motion_est: Fix xy indexing on range violation in ff_get_best_fcode()
-- avformat/hls: Use unsigned for iv computation
-- avcodec/jpeglsdec: Increase range for N in ls_get_code_runterm() by using unsigned
-- avformat/matroskadec: Check desc_bytes
-- avformat/utils: Fix invalid NULL pointer operation in ff_parse_key_value()
-- avformat/matroskadec: Fix infinite loop with bz decompression
-- avformat/mov: Check size before subtraction
-- avcodec/cfhd: Avoid signed integer overflow in coeff
-- avcodec/apedec: Fix integer overflows in predictor_update_3930()
-- avcodec/apedec: fix integer overflow in 8bit samples
-- avformat/flvdec: timestamps cannot use the full int64 range
-- avcodec/tiff: Remove messing with jpeg context
-- avcodec/tiff: Use ff_set_dimensions() for setting up mjpeg context dimensions
-- avcodec/tiff: Pass max_pixels to mjpeg context
-- avcodec/vqavideo: reset accounting on error
-- avcodec/alacdsp: fix integer overflow in decorrelate_stereo()
-- avformat/4xm: Check for duplicate track ids
-- avformat/4xm: Consider max_streams on reallocating tracks array
-- avformat/mov: Check next offset in mov_read_dref()
-- avformat/vivo: Favor setting fps from explicit fractions
-- avformat/vivo: Do not use the general expression evaluator for parsing a floating point value
-- avformat/mxfdec: Check for duplicate mxf_read_index_entry_array()
-- avcodec/apedec: Change avg to uint32_t
-- avformat/mxfdec: Check component_depth in mxf_get_color_range()
-- avformat/mov: Disallow duplicate smdm
-- avformat/mov: Check for EOF in mov_read_glbl()
-- avcodec/vp3: Check version in all cases when VP4 code is not built
-- avformat/mov: Check channels for mov_parse_stsd_audio()
-- avformat/avidec: Check read_odml_index() for failure
-- avformat/aiffdec: Use av_rescale() for bitrate
-- avformat/aiffdec: sanity check block_align
-- avformat/aiffdec: Check sample_rate
-- avcodec/libdav1d: free the Dav1dData packet on dav1d_send_data() failure
-- avcodec/zmbvenc: Fix memleak upon init error
-- avcodec/dnxhdenc: Fix segfault when using too many slice threads
-- avcodec/wma(dec|enc): Fix memleaks upon allocation error
-- avfilter/avfilter: Actually error out on init error
-- avcodec/opus_silk: Remove wrong size information in function declaration
-- avformat/omadec: Don't output uninitialized values
-- avformat/jacosubenc: Fix writing extradata
-- avformat/cafenc: Fix memleak when trailer is never written
-- avformat/cafenc: Don't segfault upon allocation error
-- avformat/cafenc: Fix potential integer overflow
-- avformat/movenc: Limit ism_lookahead to a sane value
-- avutil/utils: Remove racy check from avutil_version()
-- avformat/sccdec: Don't use uninitialized data, fix crash, simplify logic
-- avformat/subtitles: Honour ff_subtitles_read_line() documentation
-- avformat/tee: Fix leak of FIFO-options dictionary
-- avformat/tee: Fix leak of strings
-- avcodec/rasc: Fix potential use of uninitialized value
-- avfilter/vf_w3fdif: Fix segfault on allocation error
-- avfilter/af_surround: Fix memleaks upon allocation error
-- avfilter/af_vibrato: Fix segfault upon allocation error
-- avfilter/aeval: Fix leak of expressions upon reallocation error
-- avdevice/xv: Increase array size
-- avfilter/asrc_flite: Fix use-after-frees
-- avfilter/asrc_flite: Don't segfault when using list_voices option
-- Revert "avfilter/vf_idet: reduce noisyness if the filter has been auto inserted"
-- avformat/matroskadec: Don't unnecessarily reduce aspect ratio
-- avcodec/h263: Fix global-buffer-overflow with noout flag2 set
-- avcodec/vaapi_encode: Fix segfault upon closing uninitialized encoder
-- avcodec/movtextenc: Fix infinite loop due to variable truncation
-- avcodec/libopenh264dec: Increase array sizes, fix stack-buffer overread
-- avcodec/libkvazaar: Increase array size
-- avformat/aadec: Don't use the same loop counter in inner and outer loop
-- avformat/moflex: Don't use uninitialized timebase for data stream
-- lavf/udp: do not return an uninitialized value from udp_open()
-- avcodec/nvenc: zero-initialize NV_ENC_REGISTER_RESOURCE struct
-- configure: Add missing libshine->mpegaudioheader dependency
-- avcodec/Makefile: Add missing entry for ADPCM_IMA_AMV_ENCODER
-- avcodec/Makefile: Only compile nvenc.o if needed
-- avcodec/av1_vaapi: improve decode quality
-- avcodec/av1_vaapi: enable segmentation features
-- avcodec/av1_vaapi: setting 2 output surface for film grain
-- avcodec/vaapi: increase av1 decode pool size
-- avcodec/dxva2_av1: fix global motion params
-- avcodec/av1_vaapi: add gm params valid check
-- avcodec/av1dec: support setup shear process
-- avcodec/av1: extend some definitions in spec section 3
-- cbs_av1: fix incorrect data type
-- avcodec/libdav1d: let libdav1d choose optimal max frame delay
-- avcodec/libdav1d: pass auto threads value to libdav1d
-
 version 4.4.1:
 - avcodec/flac_parser: Consider AV_INPUT_BUFFER_PADDING_SIZE
 - avcodec/ttadsp: Fix integer overflows in tta_filter_process_c()
--- FFmpeg-n4.4.4/MAINTAINERS
+++ Ascendffmpeg/MAINTAINERS
@@ -615,7 +615,6 @@
 Loren Merritt                 ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 56DE
 Lynne                         FE50 139C 6805 72CA FD52 1F8D A2FE A5F0 3F03 4464
 Michael Niedermayer           9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB
-                              DD1E C9E8 DE08 5C62 9B3E 1846 B18E 8928 B394 8D64
 Nicolas George                24CE 01CE 9ACC 5CEB 74D8 8D9D B063 D997 36E5 4C93
 Nikolay Aleksandrov           8978 1D8C FB71 588E 4B27 EAA8 C4F0 B5FC E011 13B1
 Panagiotis Issaris            6571 13A3 33D9 3726 F728 AA98 F643 B12E ECF3 E029
--- FFmpeg-n4.4.4/README.md
+++ Ascendffmpeg/README.md
@@ -1,46 +1,141 @@
-FFmpeg README
-=============
+# FFmpeg-Ascend
 
-FFmpeg is a collection of libraries and tools to process multimedia content
-such as audio, video, subtitles and related metadata.
+## 介绍
 
-## Libraries
+MxVison ascend 硬件平台内置了视频相关的硬件加速解码器,
+为了用户的易用性,MxVision 提供了 FFmepg-Ascend 解决方案。
 
-* `libavcodec` provides implementation of a wider range of codecs.
-* `libavformat` implements streaming protocols, container formats and basic I/O access.
-* `libavutil` includes hashers, decompressors and miscellaneous utility functions.
-* `libavfilter` provides a mean to alter decoded Audio and Video through chain of filters.
-* `libavdevice` provides an abstraction to access capture and playback devices.
-* `libswresample` implements audio mixing and resampling routines.
-* `libswscale` implements color conversion and scaling routines.
+该样例的处理流程为:
 
-## Tools
+```
+准备芯片及环境 > 安装 CANN 版本包 > 拉取 FFmpeg-Ascend 代码 > 编译 > 执行
+```
 
-* [ffmpeg](https://ffmpeg.org/ffmpeg.html) is a command line toolbox to
-  manipulate, convert and stream multimedia content.
-* [ffplay](https://ffmpeg.org/ffplay.html) is a minimalistic multimedia player.
-* [ffprobe](https://ffmpeg.org/ffprobe.html) is a simple analysis tool to inspect
-  multimedia content.
-* Additional small tools such as `aviocat`, `ismindex` and `qt-faststart`.
+## 支持的产品
+Atlas 300I Pro和Atlas 300V Pro
 
-## Documentation
+## 支持的 ACL 版本
 
-The offline documentation is available in the **doc/** directory.
+5.1.RC2
+*注意:目前只支持 HiMpi 接口即 310P 昇腾 AI芯片。
 
-The online documentation is available in the main [website](https://ffmpeg.org)
-and in the [wiki](https://trac.ffmpeg.org).
+查询 ACL 版本号的方法是,在 Atlas 产品环境下,运行以下命令:
+```bash
+npu-smi info
+```
 
-### Examples
+## 支持的功能
+|功能|mpeg4|h264/h265|多路|
+|:----:|:----:|:----:|:----:|
+|硬件解码|√|√|√|
+|硬件编码|√|√|√|
+|硬件转码|√|√|√|
+|硬件缩放|√|√|√|
 
-Coding examples are available in the **doc/examples** directory.
+## 安装 CANN 版本包
+详情请参考: https://support.huawei.com/enterprise/zh/doc/EDOC1100234042/f1fad1e0
 
-## License
+## FFmpeg-Ascend目录结构
 
-FFmpeg codebase is mainly LGPL-licensed with optional components licensed under
-GPL. Please refer to the LICENSE file for detailed information.
+FFmpeg-Ascend 目录主要文件:
+.
+|-- configure (FFmpeg 编译入口)
+|
+|-- README.md (FFmpeg-Ascend 使用手册)
+|
+|-- ffbuild (编译相关文件)
+|
+|-- fftools (FFmpeg 相关命令行工具)
+|
+|-- libavcodec (FFmpeg 编解码器)
+|
+|-- libavutil (FFmpeg 相关工具,包含硬件加速相关流程)
 
-## Contributing
+## 依赖条件
 
-Patches should be submitted to the ffmpeg-devel mailing list using
-`git format-patch` or `git send-email`. Github pull requests should be
-avoided because they are not part of our review process and will be ignored.
+设置环境变量:
+* `ASCEND_HOME`     Ascend 安装的路径,一般为 `/usr/local/Ascend`
+* `FFMPEG_LIB_PATH` FFmpeg 编译安装的 lib 文件路径(一般为 FFmpeg 安装目录下的 lib 目录, 由安装时的 --prefix 编译选项来指定)。
+* `LD_LIBRARY_PATH` 指定 ffmpeg 程序运行时依赖的动态库查找路径。
+
+```bash
+export ASCEND_HOME=/usr/local/Ascend
+export LD_LIBRARY_PATH=${FFMPEG_LIB_PATH}:${ASCEND_HOME}/ascend-toolkit/latest/acllib/lib64:$LD_LIBRARY_PATH
+```
+
+## 编译
+
+编写编译脚本
+```bash
+vi run.sh
+```
+
+`run.sh` 内编译选项: 
+* `prefix` : FFmpeg 及相关组件安装目录
+* `enable-shared` : FFmpeg 允许生成 so 文件
+* `extra-cflags` : 添加第三方头文件
+* `extra-libs` : 添加第三方 so 文件
+* `enable-ascend` : 允许使用 ascend 进行硬件加速
+```bash
+./configure \
+    --prefix=./ascend \
+    --enable-shared \
+    --extra-cflags="-I${ASCEND_HOME}/ascend-toolkit/latest/acllib/include" \
+    --extra-libs="-lacl_dvpp_mpi -lascendcl" \
+    --enable-ascend \
+    && make -j && make install
+```
+
+脚本添加可执行权限
+```bash
+chmod +x run.sh
+```
+
+运行脚本
+```bash
+./run.sh
+```
+
+
+注意:若是运行失败,则可能是 `./configure` 没有可执行权限
+```bash
+chmod +x ./configure
+chmod +x ./ffbuild/*.sh
+```
+
+## 运行
+当前目录或者 FFmpeg 安装目录下均会生成 `ffmpeg` 可执行文件,均可以使用。
+相关指令参数:
+
+* `-hwaccel`    -   指定采用 ascend 来进行硬件加速, 用来做硬件相关初始化工作。
+
+解码相关参数(注意:解码相关参数需要在 `-i` 参数前设置):
+* `-c:v`        -   指定解码器为 h264_ascend (解码 h265 格式可以使用 h265_ascend)。
+* `-device_id`  -   指定硬件设备 id 为 0。取值范围取决于芯片个数,默认为 0。 `npu-smi info` 命令可以查看芯片个数
+* `-channel_id` -   指定解码通道 id [0-255], 默认为0, 若是指定的通道已被占用, 则自动寻找并申请新的通道。
+* `-resize`     -   指定缩放大小, 输入格式为: {width}x{height}。宽高:[128x128-4096x4096], 宽高相乘不能超过 4096*2304。宽要与 16 对齐,高要与 2 对齐。 
+* `-i`          -   指定输入文件(支持h264和h265及rtsp视频流, 其他视频格式不做保证)。
+
+编码相关参数(注意:编码相关参数需要在 `-i` 参数后设置):
+* `-c:v`        -   指定编码器为 h264_ascend (编码成 h265 格式可以使用 h265_ascend)。
+* `-device_id`  -   指定硬件设备 id 为 0。取值范围取决于芯片个数,默认为 0。 `npu-smi info` 命令可以查看芯片个数。
+* `-channel_id` -   指定编码通道 id [0-127], 默认为 0, 若是指定的通道已被占用, 则自动寻找并申请新的通道。
+* `-profile`    -   指定视频编码的画质级别(0: baseline, 1: main, 2: high, 默认为 1。 H265 编码器只支持 main)。
+* `-rc_mode`    -   指定视频编码器的速率控制模式(0: CBR, 1: VBR, 默认为 0)。
+* `-gop`        -   指定关键帧间隔, [1, 65536], 默认为 30。
+* `-frame_rate` -   指定帧率, [1, 240], 默认为25。
+* `-max_bit_rate` - 限制码流的最大比特率, [2, 614400], 默认为 20000。
+* `-movement_scene` - 指定视频场景(0:静态场景(监控视频等), 1:动态场景(直播,游戏等)), 默认为 1。
+
+```bash
+./ffmpeg -hwaccel ascend -c:v h264_ascend -i test.264 -c:v h264_ascend out.264
+```
+
+```bash
+./ffmpeg -hwaccel ascend -c:v h264_ascend -device_id 0 -channel_id 0 -resize 1024x1000 -i test.264 -c:v h264_ascend -device_id 0 -channel_id 0 -profile 2 -rc_mode 0 -gop 30 -frame_rate 25 -max_bit_rate 20000 out.264
+```
+
+```bash
+./ffmpeg -hwaccel ascend -c:v h264_ascend -i test.264 out.yuv
+./ffmpeg -hwaccel ascend -s 1920x1080 -pix_fmt nv12 -i out.yuv -c:v h264_ascend out.264
+```
\ No newline at end of file
--- FFmpeg-n4.4.4/RELEASE
+++ Ascendffmpeg/RELEASE
@@ -1 +1 @@
-4.4.4
+4.4.1
--- FFmpeg-n4.4.4/configure
+++ Ascendffmpeg/configure
@@ -349,6 +349,7 @@
   --disable-vaapi          disable Video Acceleration API (mainly Unix/Intel) code [autodetect]
   --disable-vdpau          disable Nvidia Video Decode and Presentation API for Unix code [autodetect]
   --disable-videotoolbox   disable VideoToolbox code [autodetect]
+  --enable-ascend          enable MxVision Ascend interface accelerate [no]
 
 Toolchain options:
   --arch=ARCH              select architecture [$arch]
@@ -1748,6 +1749,7 @@
     libvo_amrwbenc
     mbedtls
     rkmpp
+    acl_dvpp_mpi
 "
 
 EXTERNAL_LIBRARY_GPLV3_LIST="
@@ -1848,6 +1850,8 @@
     videotoolbox
     v4l2_m2m
     xvmc
+    ascend
+    ascendcl
 "
 
 # catchall list of things that require external libs to link
@@ -3074,6 +3078,8 @@
 h263_v4l2m2m_encoder_deps="v4l2_m2m h263_v4l2_m2m"
 h264_amf_encoder_deps="amf"
 h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
+h264_ascend_decoder_deps="ascendcl"
+h264_ascend_decoder_select="h264_mp4toannexb_bsf"
 h264_cuvid_decoder_deps="cuvid"
 h264_cuvid_decoder_select="h264_mp4toannexb_bsf"
 h264_mediacodec_decoder_deps="mediacodec"
@@ -3268,7 +3274,7 @@
 librav1e_encoder_select="extract_extradata_bsf"
 librsvg_decoder_deps="librsvg"
 libshine_encoder_deps="libshine"
-libshine_encoder_select="audio_frame_queue mpegaudioheader"
+libshine_encoder_select="audio_frame_queue"
 libspeex_decoder_deps="libspeex"
 libspeex_encoder_deps="libspeex"
 libspeex_encoder_select="audio_frame_queue"
@@ -3706,23 +3712,23 @@
 
 # libraries, in any order
 avcodec_deps="avutil"
-avcodec_suggest="libm stdatomic"
+avcodec_suggest="libm"
 avcodec_select="null_bsf"
 avdevice_deps="avformat avcodec avutil"
-avdevice_suggest="libm stdatomic"
+avdevice_suggest="libm"
 avfilter_deps="avutil"
-avfilter_suggest="libm stdatomic"
+avfilter_suggest="libm"
 avformat_deps="avcodec avutil"
-avformat_suggest="libm network zlib stdatomic"
+avformat_suggest="libm network zlib"
 avresample_deps="avutil"
 avresample_suggest="libm"
-avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi vulkan videotoolbox corefoundation corevideo coremedia bcrypt stdatomic"
+avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi vulkan videotoolbox corefoundation corevideo coremedia bcrypt"
 postproc_deps="avutil gpl"
-postproc_suggest="libm stdatomic"
+postproc_suggest="libm"
 swresample_deps="avutil"
-swresample_suggest="libm libsoxr stdatomic"
+swresample_suggest="libm libsoxr"
 swscale_deps="avutil"
-swscale_suggest="libm stdatomic"
+swscale_suggest="libm"
 
 avcodec_extralibs="pthreads_extralibs iconv_extralibs dxva2_extralibs"
 avfilter_extralibs="pthreads_extralibs"
@@ -6186,14 +6192,7 @@
 # it seems there are versions of clang in some distros that try to use the
 # gcc headers, which explodes for stdatomic
 # so we also check that atomics actually work here
-#
-# some configurations also require linking to libatomic, so try
-# both with -latomic and without
-for LATOMIC in "-latomic" ""; do
-    check_builtin stdatomic stdatomic.h                                                 \
-        "atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(&foo, 0); foo += bar"  \
-        $LATOMIC && eval stdatomic_extralibs="\$LATOMIC" && break
-done
+check_builtin stdatomic stdatomic.h "atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(&foo, 0); foo += bar"
 
 check_lib advapi32 "windows.h"            RegCloseKey          -ladvapi32
 check_lib bcrypt   "windows.h bcrypt.h"   BCryptGenRandom      -lbcrypt &&
@@ -6562,7 +6561,7 @@
 
 if enabled sdl2; then
     SDL2_CONFIG="${cross_prefix}sdl2-config"
-    test_pkg_config sdl2 "sdl2 >= 2.0.1 sdl2 < 3.0.0" SDL_events.h SDL_PollEvent
+    test_pkg_config sdl2 "sdl2 >= 2.0.1 sdl2 < 2.1.0" SDL_events.h SDL_PollEvent
     if disabled sdl2 && "${SDL2_CONFIG}" --version > /dev/null 2>&1; then
         sdl2_cflags=$("${SDL2_CONFIG}" --cflags)
         sdl2_extralibs=$("${SDL2_CONFIG}" --libs)
@@ -7591,7 +7590,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
 #define FFMPEG_LICENSE "$(c_escape $license)"
-#define CONFIG_THIS_YEAR 2023
+#define CONFIG_THIS_YEAR 2021
 #define FFMPEG_DATADIR "$(eval c_escape $datadir)"
 #define AVCONV_DATADIR "$(eval c_escape $datadir)"
 #define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})"
--- FFmpeg-n4.4.4/doc/Doxyfile
+++ Ascendffmpeg/doc/Doxyfile
@@ -38,7 +38,7 @@
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER         = 4.4.4
+PROJECT_NUMBER         = 4.4.1
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
--- FFmpeg-n4.4.4/doc/authors.texi
+++ Ascendffmpeg/doc/authors.texi
@@ -3,9 +3,9 @@
 The FFmpeg developers.
 
 For details about the authorship, see the Git history of the project
-(https://git.ffmpeg.org/ffmpeg), e.g. by typing the command
+(git://source.ffmpeg.org/ffmpeg), e.g. by typing the command
 @command{git log} in the FFmpeg source directory, or browsing the
-online repository at @url{https://git.ffmpeg.org/ffmpeg}.
+online repository at @url{http://source.ffmpeg.org}.
 
 Maintainers for the specific components are listed in the file
 @file{MAINTAINERS} in the source code tree.
--- FFmpeg-n4.4.4/doc/git-howto.texi
+++ Ascendffmpeg/doc/git-howto.texi
@@ -53,7 +53,7 @@
 @section Cloning the source tree
 
 @example
-git clone https://git.ffmpeg.org/ffmpeg.git <target>
+git clone git://source.ffmpeg.org/ffmpeg <target>
 @end example
 
 This will put the FFmpeg sources into the directory @var{<target>}.
@@ -187,20 +187,13 @@
 git add [-i|-p|-A] <filenames/dirnames>
 @end example
 
-Make sure you have told Git your name, email address and GPG key
+Make sure you have told Git your name and email address
 
 @example
 git config --global user.name "My Name"
 git config --global user.email my@@email.invalid
-git config --global user.signingkey ABCDEF0123245
 @end example
 
-Enable signing all commits or use -S
-
-@example
-git config --global commit.gpgsign true
-@end example
-
 Use @option{--global} to set the global configuration for all your Git checkouts.
 
 Git will select the changes to the files for commit. Optionally you can use
@@ -399,19 +392,6 @@
 
 where @var{$SHA1} is the commit hash from the @command{git log} output.
 
-
-@chapter gpg key generation
-
-If you have no gpg key yet, we recommend that you create a ed25519 based key as it
-is small, fast and secure. Especially it results in small signatures in git.
-
-@example
-gpg --default-new-key-algo "ed25519/cert,sign+cv25519/encr" --quick-generate-key "human@@server.com"
-@end example
-
-When generating a key, make sure the email specified matches the email used in git as some sites like
-github consider mismatches a reason to declare such commits unverified. After generating a key you
-can add it to the MAINTAINER file and upload it to a keyserver.
 
 @chapter Pre-push checklist
 
--- FFmpeg-n4.4.4/fftools/ffmpeg_hw.c
+++ Ascendffmpeg/fftools/ffmpeg_hw.c
@@ -339,8 +339,15 @@
         } else if (ist->hwaccel_id == HWACCEL_GENERIC) {
             type = ist->hwaccel_device_type;
             dev = hw_device_get_by_type(type);
-            if (!dev)
-                err = hw_device_init_from_type(type, NULL, &dev);
+            if (!dev) {
+                char* device_id = "device_id";
+                AVDictionaryEntry* opt = av_dict_get(ist->decoder_opts, device_id, NULL, 0);
+                if (opt) {
+                    err = hw_device_init_from_type(type, opt->value, &dev);
+                } else {
+                    err = hw_device_init_from_type(type, NULL, &dev);
+                }
+            }
         } else {
             dev = hw_device_match_by_codec(ist->dec);
             if (!dev) {
--- FFmpeg-n4.4.4/libavcodec/012v.c
+++ Ascendffmpeg/libavcodec/012v.c
@@ -131,8 +131,8 @@
             u = x/2 + (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
             v = x/2 + (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
             memcpy(y, y_temp, sizeof(*y) * (width - x));
-            memcpy(u, u_temp, sizeof(*u) * ((width - x + 1) / 2));
-            memcpy(v, v_temp, sizeof(*v) * ((width - x + 1) / 2));
+            memcpy(u, u_temp, sizeof(*u) * (width - x + 1) / 2);
+            memcpy(v, v_temp, sizeof(*v) * (width - x + 1) / 2);
         }
 
         line_end += stride;
--- FFmpeg-n4.4.4/libavcodec/8bps.c
+++ Ascendffmpeg/libavcodec/8bps.c
@@ -70,9 +70,6 @@
     unsigned char *planemap = c->planemap;
     int ret;
 
-    if (buf_size < planes * height *2)
-        return AVERROR_INVALIDDATA;
-
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
--- FFmpeg-n4.4.4/libavcodec/Makefile
+++ Ascendffmpeg/libavcodec/Makefile
@@ -25,6 +25,8 @@
           videotoolbox.h                                                \
           vorbis_parser.h                                               \
           xvmc.h                                                        \
+          ascend_dec.h                                                  \
+          ascend_enc.h                                                  \
 
 OBJS = ac3_parser.o                                                     \
        adts_parser.o                                                    \
@@ -132,6 +134,7 @@
                                           motion_est.o ratecontrol.o    \
                                           mpegvideoencdsp.o
 OBJS-$(CONFIG_MSS34DSP)                += mss34dsp.o
+OBJS-$(CONFIG_NVENC)                   += nvenc.o
 OBJS-$(CONFIG_PIXBLOCKDSP)             += pixblockdsp.o
 OBJS-$(CONFIG_QPELDSP)                 += qpeldsp.o
 OBJS-$(CONFIG_QSV)                     += qsv.o
@@ -369,14 +372,16 @@
                                           h264_mb.o h264_picture.o \
                                           h264_refs.o h264_sei.o \
                                           h264_slice.o h264data.o
+OBJS-$(CONFIG_H264_ASCEND_DECODER)     += ascend_dec.o
+OBJS-$(CONFIG_H264_ASCEND_ENCODER)     += ascend_enc.o
 OBJS-$(CONFIG_H264_AMF_ENCODER)        += amfenc_h264.o
 OBJS-$(CONFIG_H264_CUVID_DECODER)      += cuviddec.o
 OBJS-$(CONFIG_H264_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_H264_MF_ENCODER)         += mfenc.o mf_utils.o
 OBJS-$(CONFIG_H264_MMAL_DECODER)       += mmaldec.o
-OBJS-$(CONFIG_H264_NVENC_ENCODER)      += nvenc.o nvenc_h264.o
-OBJS-$(CONFIG_NVENC_ENCODER)           += nvenc.o nvenc_h264.o
-OBJS-$(CONFIG_NVENC_H264_ENCODER)      += nvenc.o nvenc_h264.o
+OBJS-$(CONFIG_H264_NVENC_ENCODER)      += nvenc_h264.o
+OBJS-$(CONFIG_NVENC_ENCODER)           += nvenc_h264.o
+OBJS-$(CONFIG_NVENC_H264_ENCODER)      += nvenc_h264.o
 OBJS-$(CONFIG_H264_OMX_ENCODER)        += omx.o
 OBJS-$(CONFIG_H264_QSV_DECODER)        += qsvdec.o
 OBJS-$(CONFIG_H264_QSV_ENCODER)        += qsvenc_h264.o
@@ -392,12 +397,14 @@
 OBJS-$(CONFIG_HEVC_DECODER)            += hevcdec.o hevc_mvs.o \
                                           hevc_cabac.o hevc_refs.o hevcpred.o    \
                                           hevcdsp.o hevc_filter.o hevc_data.o
+OBJS-$(CONFIG_H265_ASCEND_DECODER)     += ascend_dec.o
+OBJS-$(CONFIG_H265_ASCEND_ENCODER)     += ascend_enc.o
 OBJS-$(CONFIG_HEVC_AMF_ENCODER)        += amfenc_hevc.o
 OBJS-$(CONFIG_HEVC_CUVID_DECODER)      += cuviddec.o
 OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_HEVC_MF_ENCODER)         += mfenc.o mf_utils.o
-OBJS-$(CONFIG_HEVC_NVENC_ENCODER)      += nvenc.o nvenc_hevc.o
-OBJS-$(CONFIG_NVENC_HEVC_ENCODER)      += nvenc.o nvenc_hevc.o
+OBJS-$(CONFIG_HEVC_NVENC_ENCODER)      += nvenc_hevc.o
+OBJS-$(CONFIG_NVENC_HEVC_ENCODER)      += nvenc_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_DECODER)        += qsvdec.o
 OBJS-$(CONFIG_HEVC_QSV_ENCODER)        += qsvenc_hevc.o hevc_ps_enc.o       \
                                           hevc_data.o
@@ -874,7 +881,6 @@
 OBJS-$(CONFIG_ADPCM_G726LE_DECODER)       += g726.o
 OBJS-$(CONFIG_ADPCM_G726LE_ENCODER)       += g726.o
 OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)      += adpcm.o adpcm_data.o
-OBJS-$(CONFIG_ADPCM_IMA_AMV_ENCODER)      += adpcmenc.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_ALP_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_ALP_ENCODER)      += adpcmenc.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)      += adpcm.o adpcm_data.o
@@ -1271,6 +1277,12 @@
 else
 $(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DCONFIG_SMALL=0
 endif
+
+#ifdef CONFIG_ASCEND
+CFLAGS += -DENABLE_DVPP_INTERFACE=1
+#else
+#$(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DENABLE_DVPP_INTERFACE=0
+#endif
 
 GEN_HEADERS = cbrt_tables.h cbrt_fixed_tables.h aacps_tables.h aacps_fixed_tables.h \
               dv_tables.h     \
--- FFmpeg-n4.4.4/libavcodec/aasc.c
+++ Ascendffmpeg/libavcodec/aasc.c
@@ -104,25 +104,25 @@
         ff_msrle_decode(avctx, s->frame, 8, &s->gb);
         break;
     case MKTAG('A', 'A', 'S', 'C'):
-        switch (compr) {
-        case 0:
-            stride = (avctx->width * psize + psize) & ~psize;
-            if (buf_size < stride * avctx->height)
-                return AVERROR_INVALIDDATA;
-            for (i = avctx->height - 1; i >= 0; i--) {
-                memcpy(s->frame->data[0] + i * s->frame->linesize[0], buf, avctx->width * psize);
-                buf += stride;
-                buf_size -= stride;
-            }
-            break;
-        case 1:
-            bytestream2_init(&s->gb, buf, buf_size);
-            ff_msrle_decode(avctx, s->frame, 8, &s->gb);
-            break;
-        default:
-            av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
+    switch (compr) {
+    case 0:
+        stride = (avctx->width * psize + psize) & ~psize;
+        if (buf_size < stride * avctx->height)
             return AVERROR_INVALIDDATA;
+        for (i = avctx->height - 1; i >= 0; i--) {
+            memcpy(s->frame->data[0] + i * s->frame->linesize[0], buf, avctx->width * psize);
+            buf += stride;
+            buf_size -= stride;
         }
+        break;
+    case 1:
+        bytestream2_init(&s->gb, buf, buf_size);
+        ff_msrle_decode(avctx, s->frame, 8, &s->gb);
+        break;
+    default:
+        av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
+        return AVERROR_INVALIDDATA;
+    }
         break;
     default:
         av_log(avctx, AV_LOG_ERROR, "Unknown FourCC: %X\n", avctx->codec_tag);
--- FFmpeg-n4.4.4/libavcodec/ac3.h
+++ Ascendffmpeg/libavcodec/ac3.h
@@ -74,7 +74,6 @@
 #define AC3_DYNAMIC_RANGE1      0
 
 typedef int                     INTFLOAT;
-typedef unsigned int            UINTFLOAT;
 typedef int16_t                 SHORTFLOAT;
 
 #else /* USE_FIXED */
@@ -94,7 +93,6 @@
 #define AC3_DYNAMIC_RANGE1      1.0f
 
 typedef float                   INTFLOAT;
-typedef float                   UINTFLOAT;
 typedef float                   SHORTFLOAT;
 
 #endif /* USE_FIXED */
--- FFmpeg-n4.4.4/libavcodec/alacdsp.c
+++ Ascendffmpeg/libavcodec/alacdsp.c
@@ -29,12 +29,12 @@
     int i;
 
     for (i = 0; i < nb_samples; i++) {
-        uint32_t a, b;
+        int32_t a, b;
 
         a = buffer[0][i];
         b = buffer[1][i];
 
-        a -= (int)(b * decorr_left_weight) >> decorr_shift;
+        a -= (b * decorr_left_weight) >> decorr_shift;
         b += a;
 
         buffer[0][i] = b;
--- FFmpeg-n4.4.4/libavcodec/allcodecs.c
+++ Ascendffmpeg/libavcodec/allcodecs.c
@@ -787,6 +787,10 @@
 extern AVCodec ff_av1_qsv_decoder;
 extern AVCodec ff_libopenh264_encoder;
 extern AVCodec ff_libopenh264_decoder;
+extern AVCodec ff_h264_ascend_decoder;
+extern AVCodec ff_h265_ascend_decoder;
+extern AVCodec ff_h264_ascend_encoder;
+extern AVCodec ff_h265_ascend_encoder;
 extern AVCodec ff_h264_amf_encoder;
 extern AVCodec ff_h264_cuvid_decoder;
 extern AVCodec ff_h264_mf_encoder;
--- FFmpeg-n4.4.4/libavcodec/alsdec.c
+++ Ascendffmpeg/libavcodec/alsdec.c
@@ -1017,7 +1017,7 @@
 
     *bd->shift_lsbs = 0;
 
-    if (get_bits_left(gb) < 7)
+    if (get_bits_left(gb) < 1)
         return AVERROR_INVALIDDATA;
 
     // read block type flag and read the samples accordingly
--- FFmpeg-n4.4.4/libavcodec/apedec.c
+++ Ascendffmpeg/libavcodec/apedec.c
@@ -102,7 +102,7 @@
     int16_t *historybuffer; ///< filter memory
     int16_t *delay;         ///< filtered values
 
-    uint32_t avg;
+    int avg;
 } APEFilter;
 
 typedef struct APERice {
@@ -930,7 +930,7 @@
     p->coeffsB[filter][0] += (((d3 >> 29) & 4) - 2) * sign;
     p->coeffsB[filter][1] -= (((d4 >> 30) & 2) - 1) * sign;
 
-    p->filterB[filter] = p->lastA[filter] + (unsigned)(predictionB >> shift);
+    p->filterB[filter] = p->lastA[filter] + (predictionB >> shift);
     p->filterA[filter] = p->filterB[filter] + (unsigned)((int)(p->filterA[filter] * 31U) >> 5);
 
     return p->filterA[filter];
@@ -955,7 +955,7 @@
             dotprod += delay[j] * (unsigned)coeffs[j];
             coeffs[j] += ((delay[j] >> 31) | 1) * sign;
         }
-        buffer[i] -= (unsigned)(dotprod >> shift);
+        buffer[i] -= dotprod >> shift;
         for (j = 0; j < order - 1; j++)
             delay[j] = delay[j + 1];
         delay[order - 1] = buffer[i];
@@ -1088,13 +1088,13 @@
                                                   const int delayA)
 {
     int32_t predictionA, sign;
-    uint32_t d0, d1, d2, d3;
+    int32_t d0, d1, d2, d3;
 
     p->buf[delayA]     = p->lastA[filter];
     d0 = p->buf[delayA    ];
-    d1 = p->buf[delayA    ] - (unsigned)p->buf[delayA - 1];
-    d2 = p->buf[delayA - 1] - (unsigned)p->buf[delayA - 2];
-    d3 = p->buf[delayA - 2] - (unsigned)p->buf[delayA - 3];
+    d1 = p->buf[delayA    ] - p->buf[delayA - 1];
+    d2 = p->buf[delayA - 1] - p->buf[delayA - 2];
+    d3 = p->buf[delayA - 2] - p->buf[delayA - 3];
 
     predictionA = d0 * p->coeffsA[filter][0] +
                   d1 * p->coeffsA[filter][1] +
@@ -1105,10 +1105,10 @@
     p->filterA[filter] = p->lastA[filter] + ((int)(p->filterA[filter] * 31U) >> 5);
 
     sign = APESIGN(decoded);
-    p->coeffsA[filter][0] += (((int32_t)d0 < 0) * 2 - 1) * sign;
-    p->coeffsA[filter][1] += (((int32_t)d1 < 0) * 2 - 1) * sign;
-    p->coeffsA[filter][2] += (((int32_t)d2 < 0) * 2 - 1) * sign;
-    p->coeffsA[filter][3] += (((int32_t)d3 < 0) * 2 - 1) * sign;
+    p->coeffsA[filter][0] += ((d0 < 0) * 2 - 1) * sign;
+    p->coeffsA[filter][1] += ((d1 < 0) * 2 - 1) * sign;
+    p->coeffsA[filter][2] += ((d2 < 0) * 2 - 1) * sign;
+    p->coeffsA[filter][3] += ((d3 < 0) * 2 - 1) * sign;
 
     return p->filterA[filter];
 }
@@ -1587,7 +1587,7 @@
         for (ch = 0; ch < s->channels; ch++) {
             sample8 = (uint8_t *)frame->data[ch];
             for (i = 0; i < blockstodecode; i++)
-                *sample8++ = (s->decoded[ch][i] + 0x80U) & 0xff;
+                *sample8++ = (s->decoded[ch][i] + 0x80) & 0xff;
         }
         break;
     case 16:
--- FFmpeg-n4.4.4/libavcodec/argo.c
+++ Ascendffmpeg/libavcodec/argo.c
@@ -608,9 +608,6 @@
     uint32_t chunk;
     int ret;
 
-    if (avpkt->size < 4)
-        return AVERROR_INVALIDDATA;
-
     bytestream2_init(gb, avpkt->data, avpkt->size);
 
     if ((ret = ff_reget_buffer(avctx, frame, 0)) < 0)
--- FFmpeg-n4.4.4/libavcodec/arm/sbcdsp_neon.S
+++ Ascendffmpeg/libavcodec/arm/sbcdsp_neon.S
@@ -38,49 +38,49 @@
         /* TODO: merge even and odd cases (or even merge all four calls to this
          * function) in order to have only aligned reads from 'in' array
          * and reduce number of load instructions */
-        vld1.16         {d16, d17}, [r0, :64]!
-        vld1.16         {d20, d21}, [r2, :128]!
+        vld1.16         {d4, d5}, [r0, :64]!
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmull.s16       q0, d16, d20
-        vld1.16         {d18, d19}, [r0, :64]!
-        vmull.s16       q1, d17, d21
-        vld1.16         {d22, d23}, [r2, :128]!
+        vmull.s16       q0, d4, d8
+        vld1.16         {d6,  d7}, [r0, :64]!
+        vmull.s16       q1, d5, d9
+        vld1.16         {d10, d11}, [r2, :128]!
 
-        vmlal.s16       q0, d18, d22
-        vld1.16         {d16, d17}, [r0, :64]!
-        vmlal.s16       q1, d19, d23
-        vld1.16         {d20, d21}, [r2, :128]!
+        vmlal.s16       q0, d6, d10
+        vld1.16         {d4, d5}, [r0, :64]!
+        vmlal.s16       q1, d7, d11
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmlal.s16       q0, d16, d20
-        vld1.16         {d18, d19}, [r0, :64]!
-        vmlal.s16       q1, d17, d21
-        vld1.16         {d22, d23}, [r2, :128]!
+        vmlal.s16       q0, d4, d8
+        vld1.16         {d6,  d7}, [r0, :64]!
+        vmlal.s16       q1, d5, d9
+        vld1.16         {d10, d11}, [r2, :128]!
 
-        vmlal.s16       q0, d18, d22
-        vld1.16         {d16, d17}, [r0, :64]!
-        vmlal.s16       q1, d19, d23
-        vld1.16         {d20, d21}, [r2, :128]!
+        vmlal.s16       q0, d6, d10
+        vld1.16         {d4, d5}, [r0, :64]!
+        vmlal.s16       q1, d7, d11
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmlal.s16       q0, d16, d20
-        vmlal.s16       q1, d17, d21
+        vmlal.s16       q0, d4, d8
+        vmlal.s16       q1, d5, d9
 
         vpadd.s32       d0, d0, d1
         vpadd.s32       d1, d2, d3
 
         vrshrn.s32      d0, q0, SBC_PROTO_FIXED_SCALE
 
-        vld1.16         {d16, d17, d18, d19}, [r2, :128]!
+        vld1.16         {d2, d3, d4, d5}, [r2, :128]!
 
         vdup.i32        d1, d0[1]  /* TODO: can be eliminated */
         vdup.i32        d0, d0[0]  /* TODO: can be eliminated */
 
-        vmull.s16       q10, d16, d0
-        vmull.s16       q11, d17, d0
-        vmlal.s16       q10, d18, d1
-        vmlal.s16       q11, d19, d1
+        vmull.s16       q3, d2, d0
+        vmull.s16       q4, d3, d0
+        vmlal.s16       q3, d4, d1
+        vmlal.s16       q4, d5, d1
 
-        vpadd.s32       d0, d20, d21 /* TODO: can be eliminated */
-        vpadd.s32       d1, d22, d23 /* TODO: can be eliminated */
+        vpadd.s32       d0, d6, d7 /* TODO: can be eliminated */
+        vpadd.s32       d1, d8, d9 /* TODO: can be eliminated */
 
         vst1.32         {d0, d1}, [r1, :128]
 
@@ -91,57 +91,57 @@
         /* TODO: merge even and odd cases (or even merge all four calls to this
          * function) in order to have only aligned reads from 'in' array
          * and reduce number of load instructions */
-        vld1.16         {d16, d17}, [r0, :64]!
-        vld1.16         {d20, d21}, [r2, :128]!
+        vld1.16         {d4, d5}, [r0, :64]!
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmull.s16       q12, d16, d20
-        vld1.16         {d18, d19}, [r0, :64]!
-        vmull.s16       q13, d17, d21
-        vld1.16         {d22, d23}, [r2, :128]!
-        vmull.s16       q14, d18, d22
-        vld1.16         {d16, d17}, [r0, :64]!
-        vmull.s16       q15, d19, d23
-        vld1.16         {d20, d21}, [r2, :128]!
+        vmull.s16       q6, d4, d8
+        vld1.16         {d6,  d7}, [r0, :64]!
+        vmull.s16       q7, d5, d9
+        vld1.16         {d10, d11}, [r2, :128]!
+        vmull.s16       q8, d6, d10
+        vld1.16         {d4, d5}, [r0, :64]!
+        vmull.s16       q9, d7, d11
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmlal.s16       q12, d16, d20
-        vld1.16         {d18, d19}, [r0, :64]!
-        vmlal.s16       q13, d17, d21
-        vld1.16         {d22, d23}, [r2, :128]!
-        vmlal.s16       q14, d18, d22
-        vld1.16         {d16, d17}, [r0, :64]!
-        vmlal.s16       q15, d19, d23
-        vld1.16         {d20, d21}, [r2, :128]!
+        vmlal.s16       q6, d4, d8
+        vld1.16         {d6,  d7}, [r0, :64]!
+        vmlal.s16       q7, d5, d9
+        vld1.16         {d10, d11}, [r2, :128]!
+        vmlal.s16       q8, d6, d10
+        vld1.16         {d4, d5}, [r0, :64]!
+        vmlal.s16       q9, d7, d11
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmlal.s16       q12, d16, d20
-        vld1.16         {d18, d19}, [r0, :64]!
-        vmlal.s16       q13, d17, d21
-        vld1.16         {d22, d23}, [r2, :128]!
-        vmlal.s16       q14, d18, d22
-        vld1.16         {d16, d17}, [r0, :64]!
-        vmlal.s16       q15, d19, d23
-        vld1.16         {d20, d21}, [r2, :128]!
+        vmlal.s16       q6, d4, d8
+        vld1.16         {d6,  d7}, [r0, :64]!
+        vmlal.s16       q7, d5, d9
+        vld1.16         {d10, d11}, [r2, :128]!
+        vmlal.s16       q8, d6, d10
+        vld1.16         {d4, d5}, [r0, :64]!
+        vmlal.s16       q9, d7, d11
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmlal.s16       q12, d16, d20
-        vld1.16         {d18, d19}, [r0, :64]!
-        vmlal.s16       q13, d17, d21
-        vld1.16         {d22, d23}, [r2, :128]!
-        vmlal.s16       q14, d18, d22
-        vld1.16         {d16, d17}, [r0, :64]!
-        vmlal.s16       q15, d19, d23
-        vld1.16         {d20, d21}, [r2, :128]!
+        vmlal.s16       q6, d4, d8
+        vld1.16         {d6,  d7}, [r0, :64]!
+        vmlal.s16       q7, d5, d9
+        vld1.16         {d10, d11}, [r2, :128]!
+        vmlal.s16       q8, d6, d10
+        vld1.16         {d4, d5}, [r0, :64]!
+        vmlal.s16       q9, d7, d11
+        vld1.16         {d8, d9}, [r2, :128]!
 
-        vmlal.s16       q12, d16, d20
-        vld1.16         {d18, d19}, [r0, :64]!
-        vmlal.s16       q13, d17, d21
-        vld1.16         {d22, d23}, [r2, :128]!
+        vmlal.s16       q6, d4, d8
+        vld1.16         {d6,  d7}, [r0, :64]!
+        vmlal.s16       q7, d5, d9
+        vld1.16         {d10, d11}, [r2, :128]!
 
-        vmlal.s16       q14, d18, d22
-        vmlal.s16       q15, d19, d23
+        vmlal.s16       q8, d6, d10
+        vmlal.s16       q9, d7, d11
 
-        vpadd.s32       d0, d24, d25
-        vpadd.s32       d1, d26, d27
-        vpadd.s32       d2, d28, d29
-        vpadd.s32       d3, d30, d31
+        vpadd.s32       d0, d12, d13
+        vpadd.s32       d1, d14, d15
+        vpadd.s32       d2, d16, d17
+        vpadd.s32       d3, d18, d19
 
         vrshr.s32       q0, q0, SBC_PROTO_FIXED_SCALE
         vrshr.s32       q1, q1, SBC_PROTO_FIXED_SCALE
@@ -153,38 +153,38 @@
         vdup.i32        d1, d0[1]  /* TODO: can be eliminated */
         vdup.i32        d0, d0[0]  /* TODO: can be eliminated */
 
-        vld1.16         {d16, d17}, [r2, :128]!
-        vmull.s16       q12, d16, d0
-        vld1.16         {d18, d19}, [r2, :128]!
-        vmull.s16       q13, d17, d0
-        vmull.s16       q14, d18, d0
-        vmull.s16       q15, d19, d0
+        vld1.16         {d4, d5}, [r2, :128]!
+        vmull.s16       q6, d4, d0
+        vld1.16         {d6, d7}, [r2, :128]!
+        vmull.s16       q7, d5, d0
+        vmull.s16       q8, d6, d0
+        vmull.s16       q9, d7, d0
 
-        vld1.16         {d16, d17}, [r2, :128]!
-        vmlal.s16       q12, d16, d1
-        vld1.16         {d18, d19}, [r2, :128]!
-        vmlal.s16       q13, d17, d1
-        vmlal.s16       q14, d18, d1
-        vmlal.s16       q15, d19, d1
+        vld1.16         {d4, d5}, [r2, :128]!
+        vmlal.s16       q6, d4, d1
+        vld1.16         {d6, d7}, [r2, :128]!
+        vmlal.s16       q7, d5, d1
+        vmlal.s16       q8, d6, d1
+        vmlal.s16       q9, d7, d1
 
-        vld1.16         {d16, d17}, [r2, :128]!
-        vmlal.s16       q12, d16, d2
-        vld1.16         {d18, d19}, [r2, :128]!
-        vmlal.s16       q13, d17, d2
-        vmlal.s16       q14, d18, d2
-        vmlal.s16       q15, d19, d2
+        vld1.16         {d4, d5}, [r2, :128]!
+        vmlal.s16       q6, d4, d2
+        vld1.16         {d6, d7}, [r2, :128]!
+        vmlal.s16       q7, d5, d2
+        vmlal.s16       q8, d6, d2
+        vmlal.s16       q9, d7, d2
 
-        vld1.16         {d16, d17}, [r2, :128]!
-        vmlal.s16       q12, d16, d3
-        vld1.16         {d18, d19}, [r2, :128]!
-        vmlal.s16       q13, d17, d3
-        vmlal.s16       q14, d18, d3
-        vmlal.s16       q15, d19, d3
+        vld1.16         {d4, d5}, [r2, :128]!
+        vmlal.s16       q6, d4, d3
+        vld1.16         {d6, d7}, [r2, :128]!
+        vmlal.s16       q7, d5, d3
+        vmlal.s16       q8, d6, d3
+        vmlal.s16       q9, d7, d3
 
-        vpadd.s32       d0, d24, d25 /* TODO: can be eliminated */
-        vpadd.s32       d1, d26, d27 /* TODO: can be eliminated */
-        vpadd.s32       d2, d28, d29 /* TODO: can be eliminated */
-        vpadd.s32       d3, d30, d31 /* TODO: can be eliminated */
+        vpadd.s32       d0, d12, d13 /* TODO: can be eliminated */
+        vpadd.s32       d1, d14, d15 /* TODO: can be eliminated */
+        vpadd.s32       d2, d16, d17 /* TODO: can be eliminated */
+        vpadd.s32       d3, d18, d19 /* TODO: can be eliminated */
 
         vst1.32         {d0, d1, d2, d3}, [r1, :128]
 
--- /dev/null
+++ Ascendffmpeg/libavcodec/ascend_dec.c
@@ -0,0 +1,886 @@
+/*
+ * Copyright(c) 2020. Huawei Technologies Co.,Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except int compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#include <semaphore.h>
+#include <stdatomic.h>
+#include "ascend_dec.h"
+
+static void *get_frame(void *arg)
+{
+    ASCENDContext_t *ctx = (ASCENDContext_t*)arg;
+    int ret = 0;
+    int eos_flag = 0;
+    ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Set context failed, ret is %d.\n", ret);
+        return ((void*) (-1));
+    }
+
+    hi_video_frame_info frame;
+    hi_vdec_stream stream;
+    hi_vdec_supplement_info stSupplement;
+
+    av_log(NULL, AV_LOG_INFO, "Thread start.\n");
+
+    while (ctx->thread_run_flag) {
+        ret = hi_mpi_vdec_get_frame(ctx->channel_id, &frame, &stSupplement, &stream, VDEC_GET_TIME_OUT);
+        if (ret != 0) {
+            if (ctx->decoder_flushing && ret == HI_ERR_VDEC_BUF_EMPTY) {
+                eos_flag = 1;
+                av_log(ctx, AV_LOG_DEBUG, "Decoder flushing or stream eos.\n");
+            } else {
+                av_log(ctx, AV_LOG_DEBUG, "HiMpi get frame failed, ret is %d.\n", ret);
+                continue;
+            }
+        }
+
+        size_t decResult = frame.v_frame.frame_flag;
+        if (eos_flag) {
+            // eos
+            FrameInfo_t frame_info;
+            memset(&frame_info, 0, sizeof(FrameInfo_t));
+            frame_info.event_type = EVENT_EOS;
+
+            ff_mutex_lock(&ctx->queue_mutex);
+            av_fifo_generic_write(ctx->frame_queue, &frame_info, sizeof(FrameInfo_t), NULL);
+            ff_mutex_unlock(&ctx->queue_mutex);
+            sem_post(&ctx->eos_sema);
+            av_log(ctx, AV_LOG_DEBUG, "Decode got eos.\n");
+            break;
+        }
+
+        hi_mpi_dvpp_free(stream.addr);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "HiMpi free stream failed, ret is %d.\n", ret);
+        }
+        if (decResult != 0 && frame.v_frame.virt_addr[0] != NULL) {
+            hi_mpi_dvpp_free(frame.v_frame.virt_addr[0]);
+        }
+        
+        if (decResult != 0 || frame.v_frame.virt_addr[0] == NULL || stream.need_display == HI_FALSE) {
+            ret = hi_mpi_vdec_release_frame(ctx->channel_id, &frame);
+            if (ret != 0) {
+                av_log(ctx, AV_LOG_ERROR, "HiMpi release frame failed, ret is %d.", ret);
+                return ((void*) (-1));
+            }
+            continue;
+        }
+        FrameInfo_t frame_info;
+        frame_info.ascend_ctx = ctx;
+        get_vdec_frame_info(&frame_info, frame);
+
+        ff_mutex_lock(&ctx->queue_mutex);
+        av_fifo_generic_read(ctx->dts_queue, &frame_info.dts, sizeof(int64_t), NULL);
+        av_fifo_generic_write(ctx->frame_queue, &frame_info, sizeof(FrameInfo_t), NULL);
+        ff_mutex_unlock(&ctx->queue_mutex);
+
+        ret = hi_mpi_vdec_release_frame(ctx->channel_id, &frame);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "HiMpi release frame failed, ret is %d.\n", ret);
+            return ((void*) (-1));
+        }
+
+        ctx->total_out_frame_count++;
+    }
+    return NULL;
+}
+
+static inline int decode_params_checking(AVCodecContext* avctx)
+{
+    switch (avctx->codec->id) {
+        case AV_CODEC_ID_H264:
+        case AV_CODEC_ID_H265:
+            if (avctx->width < 128 || avctx->height < 128 ||
+                avctx->width > 4096 || avctx->height > 4096) {
+                av_log(avctx, AV_LOG_ERROR,
+                    "H264 decoder only support resolution: 128x128 ~ 4096x4096, now: %dx%d.\n",
+                    avctx->width, avctx->height);
+                return -1;
+            }
+            break;
+    
+        default:
+            break;
+    }
+
+    return 0;
+}
+
+static av_cold int ff_himpi_decode_end(AVCodecContext *avctx)
+{
+    ASCENDContext_t *ctx = (ASCENDContext_t*)avctx->priv_data;
+    int ret = 0;
+    int semvalue = 0;
+    struct timespec ts;
+    if (ctx == NULL || avctx->priv_data == NULL) {
+        av_log(ctx, AV_LOG_ERROR, "HiMpi decode end error, AVCodecContext is NULL.\n");
+        return AVERROR_BUG;
+    }
+
+    ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Set Context failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    clock_gettime(CLOCK_REALTIME, &ts);
+    ts.tv_sec += 3;
+    if (sem_timedwait(&(ctx->eos_sema), &ts) == -1) {
+        semvalue = -1;
+        sem_getvalue(&ctx->eos_sema, &semvalue);
+        av_log(ctx, AV_LOG_ERROR, "Decode sem_timewait = -1, semvalue = %d.\n", semvalue);
+    }
+
+    if (ctx->hi_mpi_init_flag) {
+        ret = hi_mpi_vdec_stop_recv_stream(ctx->channel_id);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "HiMpi stop receive stream failed, ret is %d.\n", ret);
+            return ret;
+        }
+
+        ret = hi_mpi_vdec_destroy_chn(ctx->channel_id);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "HiMpi destroy channel failed, ret is %d.\n", ret);
+            return ret;
+        }
+
+        ret = hi_mpi_sys_exit();
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "HiMpi sys exit failed, ret is %d.\n", ret);
+            return ret;
+        }
+    }
+
+    ctx->hi_mpi_init_flag = 0;
+    ctx->decode_run_flag = 0;
+
+    if (ctx->thread_run_flag) {
+        ctx->thread_run_flag = 0;
+        pthread_join(ctx->thread_id, NULL);
+    }
+
+    sem_destroy(&ctx->eos_sema);
+
+    if (ctx->frame_queue) {
+        av_fifo_freep(&ctx->frame_queue);
+        ctx->frame_queue = NULL;
+    }
+
+    ff_mutex_destroy(&ctx->queue_mutex);
+    if (ctx->bsf) {
+        av_bsf_free(&ctx->bsf);
+        ctx->bsf = NULL;
+    }
+
+    av_buffer_unref(&ctx->hw_frame_ref);
+    av_buffer_unref(&ctx->hw_device_ref);
+
+    av_log(avctx, AV_LOG_INFO, "Decode hw send packet count is: %llu.\n", ctx->total_out_frame_count);
+    av_log(avctx, AV_LOG_INFO, "Decode hw out frame count is: %llu.\n", ctx->total_packet_count);
+
+    return 0;
+}
+
+static int malloc_and_send_frame(AVCodecContext *avctx, const AVPacket *avpkt)
+{
+    ASCENDContext_t *ctx = (ASCENDContext_t*)avctx->priv_data;
+    int ret = 0;
+    if (ctx->first_packet) {
+        if (avctx->extradata_size) {
+            uint8_t* streamBuffer = NULL;
+            ret = hi_mpi_dvpp_malloc(ctx->device_id, &streamBuffer, avctx->extradata_size);
+            if (ret != 0) {
+                av_log(avctx, AV_LOG_ERROR, "HiMpi malloc first packet failed, ret is %d.\n", ret);
+                return ret;
+            }
+            ret = aclrtMemcpy(streamBuffer, avctx->extradata_size, avctx->extradata, avctx->extradata_size,
+                              ACL_MEMCPY_HOST_TO_DEVICE);
+            if (ret != 0) {
+                av_log(avctx, AV_LOG_ERROR, "Mem copy H2D first packet failed, ret is %d.\n", ret);
+                return ret;
+            }
+
+            hi_vdec_stream stream;
+            stream.pts = avpkt->pts;
+            stream.addr = streamBuffer;
+            stream.len = avctx->extradata_size;
+            stream.end_of_frame = HI_TRUE;
+            stream.end_of_stream = HI_FALSE;
+            stream.need_display = HI_FALSE;
+
+            hi_vdec_pic_info pic_info;
+            pic_info.vir_addr = 0;
+            pic_info.buffer_size = 0;
+            pic_info.pixel_format = HI_PIXEL_FORMAT_YUV_SEMIPLANAR_420;
+            ret = hi_mpi_vdec_send_stream(ctx->channel_id, &stream, &pic_info, VDEC_TIME_OUT);
+            if (ret != 0) {
+                av_log(avctx, AV_LOG_ERROR, "HiMpi vdec send first packet failed, ret is %d.\n", ret);
+                return ret;
+            }
+        }
+        ctx->first_packet = 0;
+    }
+
+    uint8_t* streamBuffer = NULL;
+    ret = hi_mpi_dvpp_malloc(ctx->device_id, &streamBuffer, avpkt->size);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi malloc packet failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    ret = aclrtMemcpy(streamBuffer, avpkt->size, avpkt->data, avpkt->size,
+                      ACL_MEMCPY_HOST_TO_DEVICE);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "Mem copy H2D first packet failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    // create stream info
+    hi_vdec_stream stream;
+    stream.pts = avpkt->pts;
+    stream.addr = streamBuffer;
+    stream.len = avpkt->size;
+    stream.end_of_frame = HI_TRUE;
+    stream.end_of_stream = HI_FALSE;
+    stream.need_display = HI_TRUE;
+
+    ff_mutex_lock(&ctx->queue_mutex);
+    av_fifo_generic_write(ctx->dts_queue, &avpkt->dts, sizeof(int64_t), NULL);
+    ff_mutex_unlock(&ctx->queue_mutex);
+
+    // create frame info
+    hi_vdec_pic_info pic_info;
+    pic_info.width = ctx->resize_width;         // Output image width,  supports resize, set 0 means no resize.
+    pic_info.height = ctx->resize_height;        // Output image height, supports resize, set 0 means no resize.
+    pic_info.width_stride = FFALIGN(ctx->vdec_width, VDEC_WIDTH_ALIGN);
+    pic_info.height_stride = FFALIGN(ctx->vdec_height, VDEC_HEIGHT_ALIGN);
+    if (ctx->resize_str && ctx->resize_width != 0 && ctx->resize_height != 0) {
+        pic_info.width_stride = FFALIGN(ctx->resize_width, VDEC_WIDTH_ALIGN);
+        pic_info.height_stride = FFALIGN(ctx->resize_height, VDEC_HEIGHT_ALIGN);
+    }
+    uint32_t size = pic_info.width_stride * pic_info.height_stride * YUV_BGR_CONVERT_3 / YUV_BGR_CONVERT_2;
+        
+    pic_info.buffer_size = size;
+    pic_info.pixel_format = HI_PIXEL_FORMAT_YUV_SEMIPLANAR_420;
+    void *picBuffer = NULL;
+    
+    ret = hi_mpi_dvpp_malloc(ctx->device_id, &picBuffer, size);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi malloc failed, ret is %d.\n", ret);
+        return ret;
+    }
+    pic_info.vir_addr = (uint64_t)picBuffer;
+
+    do {
+        ret = hi_mpi_vdec_send_stream(ctx->channel_id, &stream, &pic_info, VDEC_TIME_OUT);
+        if ((unsigned int)ret == HI_ERR_VDEC_BUF_FULL) {
+            usleep(VDEC_SLEEP_TIME);
+        }
+    } while ((unsigned int)ret == HI_ERR_VDEC_BUF_FULL);
+
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi send stream failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    ctx->frame_id++;
+    ctx->total_packet_count++;
+    return 0;
+}
+
+static int hi_mpi_decode(AVCodecContext *avctx, const AVPacket *avpkt)
+{
+    ASCENDContext_t *ctx = (ASCENDContext_t*) avctx->priv_data;
+    int ret = 0;
+    AVPacket packet = { 0 };
+    AVPacket bsf_packet = { 0 };
+
+    if (avpkt && avpkt->size && ctx->bsf) {
+        ret = av_packet_ref(&packet, avpkt);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "av_packet_ref failed, ret(%d).\n", ret);
+            return ret;
+        }
+        ret = av_bsf_send_packet(ctx->bsf, &packet);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "av_bsf_send_packet failed, ret(%d).\n", ret);
+            av_packet_unref(&packet);
+            return ret;
+        }
+        ret = av_bsf_receive_packet(ctx->bsf, &bsf_packet);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "av_bsf_receive_packet failed, ret(%d).\n", ret);
+            return ret;
+        }
+        avpkt = &bsf_packet;
+    }
+    av_packet_unref(&packet);
+
+    if (avpkt && avpkt->size) {
+        ret = malloc_and_send_frame(avctx, avpkt);
+        if (ret != 0) {
+            av_packet_unref(avpkt);
+            return AVERROR(EINVAL);
+        }
+    } else {
+        if (!ctx->decoder_flushing) {
+            hi_vdec_stream stream;
+            stream.addr = NULL;
+            stream.len = 0;
+            stream.end_of_frame = HI_FALSE;
+            stream.end_of_stream = HI_TRUE; // Stream end flag to flushing all data.
+            stream.need_display = HI_TRUE;
+
+            hi_vdec_pic_info pic_info;
+            pic_info.vir_addr = 0;
+            pic_info.buffer_size = 0;
+            pic_info.pixel_format = HI_PIXEL_FORMAT_YUV_SEMIPLANAR_420;
+            ret = hi_mpi_vdec_send_stream(ctx->channel_id, &stream, &pic_info, -1);
+            if (ret != 0) {
+                av_packet_unref(avpkt);
+                av_log(avctx, AV_LOG_ERROR, "Send last stream failed, ret is %d", ret);
+                return ret;
+            }
+            ctx->decoder_flushing = 1;
+        }
+    }
+    av_packet_unref(avpkt);
+    return 0;
+}
+
+static int himpi_get_frame(AVCodecContext *avctx, AVFrame *frame)
+{
+    ASCENDContext_t *ctx = (ASCENDContext_t*)avctx->priv_data;
+    int ret = 0;
+    if (!ctx->frame_queue) {
+        return AVERROR(EAGAIN);
+    }
+
+    FrameInfo_t frame_info;
+    ff_mutex_lock(&ctx->queue_mutex);
+    if (av_fifo_size(ctx->frame_queue) != 0) {
+        av_fifo_generic_read(ctx->frame_queue, &frame_info, sizeof(FrameInfo_t), NULL);
+    } else {
+        ff_mutex_unlock(&ctx->queue_mutex);
+        return AVERROR(EAGAIN);
+    }
+    ff_mutex_unlock(&ctx->queue_mutex);
+
+    if (frame_info.event_type == EVENT_EOS) {
+        return AVERROR_EOF;
+    }
+
+    if (avctx->pix_fmt == AV_PIX_FMT_ASCEND) {
+        ret = av_hwframe_get_buffer(ctx->hw_frame_ref, frame, 0);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "av_hwframe_get_buffer failed, ret is %d.\n", ret);
+            return AVERROR(EINVAL);
+        }
+        ret = ff_decode_frame_props(avctx, frame);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "ff_decode_frame_props failed, ret is %d.\n", ret);
+            return AVERROR(EINVAL);
+        }
+    } else {
+        ret = ff_get_buffer(avctx, frame, 0);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Decode ff_get_buffer failed, ret is %d.\n", ret);
+            return AVERROR(EINVAL);
+        }
+    }
+
+    frame->pkt_pos      = -1;
+    frame->pkt_duration = 0;
+    frame->pkt_size     = -1;
+    frame->pts          = frame_info.pts;
+    frame->pkt_pts      = frame->pts;
+    frame->pkt_dts      = frame_info.dts;
+    frame->width        = frame_info.width_stride;
+    frame->height       = frame_info.height_stride;
+
+    switch (frame_info.format) {
+        case HI_PIXEL_FORMAT_YUV_SEMIPLANAR_420:
+            if (avctx->pix_fmt == AV_PIX_FMT_ASCEND) {
+                uint32_t offset = 0;
+                for (int i = 0; i < 2; i++) {
+                    size_t dstBytes = frame->width * frame->height * (i ? 1.0 / 2 : 1);
+                    ret = aclrtMemcpy(frame->data[i], dstBytes, frame_info.data + offset, dstBytes,
+                                      ACL_MEMCPY_DEVICE_TO_DEVICE);
+                    if (ret != 0) {
+                        av_log(avctx, AV_LOG_ERROR, "Mem copy D2D failed, ret is %d.\n", ret);
+                        hi_mpi_dvpp_free(frame_info.data);
+                        return ret;
+                    }
+                    offset += dstBytes;
+                }
+            } else {
+                uint32_t offset = 0;
+                for (int i = 0; i < 2; i++) {
+                    size_t dstBytes = frame->width * frame->height * (i ? 1.0 / 2 : 1);
+                    ret = aclrtMemcpy(frame->data[i], dstBytes, frame_info.data + offset, dstBytes,
+                                      ACL_MEMCPY_DEVICE_TO_HOST);
+                    if (ret != 0) {
+                        av_log(avctx, AV_LOG_ERROR, "Mem copy D2H failed, ret is %d.\n", ret);
+                        hi_mpi_dvpp_free(frame_info.data);
+                        return ret;
+                    }
+                    offset += dstBytes;
+                }
+            }
+            ret = hi_mpi_dvpp_free(frame_info.data);
+            if (ret != 0) {
+                av_log(avctx, AV_LOG_ERROR, "HiMpi free data failed, ret is %d.\n", ret);
+            }
+            break;
+        
+        default:
+            hi_mpi_dvpp_free(frame_info.data);
+            av_log(avctx, AV_LOG_ERROR, "Unsupport pixfmt: %d.\n", (int)frame_info.format);
+            break;
+    }
+
+    
+    return 0;
+}
+
+static int ff_himpi_receive_frame(AVCodecContext *avctx, AVFrame *frame)
+{
+    ASCENDContext_t *ctx = (ASCENDContext_t*)avctx->priv_data;
+    AVPacket pkt = { 0 };
+    int send_ret = -1;
+    int get_ret = -1;
+    int ret = 0;
+
+    if (avctx == NULL || avctx->priv_data == NULL) {
+        av_log(avctx, AV_LOG_ERROR, "ff_himpi_receive_frame error, AVCodecContext is NULL.\n");
+        return AVERROR_BUG;
+    }
+    if (!ctx->hi_mpi_init_flag || !ctx->thread_run_flag || !ctx->decode_run_flag) {
+        av_log(avctx, AV_LOG_ERROR, "ff_himpi_receive_frame error, AVCodecContext is NULL.\n");
+        return AVERROR_BUG;
+    }
+
+    if (ctx->eos_received) {
+        return AVERROR_EOF;
+    }
+
+    ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Set context failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    while (ctx->decode_run_flag) {
+        if (!ctx->decoder_flushing) {
+            send_ret = ff_decode_get_packet(avctx, &pkt);
+            if (send_ret < 0 && send_ret != AVERROR_EOF) {
+                return send_ret;
+            }
+            send_ret = hi_mpi_decode(avctx, &pkt);
+            av_packet_unref(&pkt);
+            if (send_ret < 0 && send_ret != AVERROR_EOF) {
+                av_log(ctx, AV_LOG_ERROR, "Send packet failed, ret is %d.\n", send_ret);
+                return send_ret;
+            }
+        }
+
+        get_ret = himpi_get_frame(avctx, frame);
+        if (get_ret != 0 && get_ret != AVERROR_EOF) {
+            if (get_ret != AVERROR(EAGAIN)) {
+                return get_ret;
+            }
+            if (ctx->decoder_flushing) {
+                av_usleep(2000);
+            }
+        } else {
+            if (get_ret == AVERROR_EOF) {
+                ctx->eos_received = 1;
+            }
+            return get_ret;
+        }
+    }
+
+    av_log(avctx, AV_LOG_ERROR, "Decode stop, error.\n");
+    return AVERROR_BUG;
+
+}
+
+static av_cold int ff_himpi_decode_init(AVCodecContext *avctx)
+{
+    ASCENDContext_t *ctx = (ASCENDContext_t*)avctx->priv_data;
+    AVASCENDDeviceContext *hw_device_ctx;
+    AVHWFramesContext *hw_frame_ctx;
+    const AVBitStreamFilter *bsf;
+    int ret = 0;
+
+    if (avctx == NULL || avctx->priv_data == NULL) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi decoder init failed, AVCodecContext is NULL.\n");
+        return AVERROR_BUG;
+    }
+
+    if (ctx->hi_mpi_init_flag == 1) {
+        av_log(avctx, AV_LOG_ERROR, "Error, himpi decode double init. \n");
+        return AVERROR_BUG;
+    }
+
+    enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_ASCEND, AV_PIX_FMT_NV12, AV_PIX_FMT_NONE };
+    avctx->pix_fmt = ff_get_format(avctx, pix_fmts);
+    if (avctx->pix_fmt < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Error, ff_get_format failed with format id: %d.\n", avctx->pix_fmt);
+        return AVERROR_BUG;
+    }
+
+    ctx->avctx = avctx;
+
+    if (ctx->resize_str) {
+        ret = av_parse_video_size(&ctx->resize_width, &ctx->resize_height, ctx->resize_str);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Invalid resize param: %s, which should be {width}x{height}.\n",
+                   ctx->resize_str);
+            return AVERROR_BUG;
+        }
+
+        if (ctx->resize_width != FFALIGN(ctx->resize_width, VDEC_WIDTH_ALIGN) ||
+            ctx->resize_height != FFALIGN(ctx->resize_height, VDEC_HEIGHT_ALIGN)) {
+            av_log(avctx, AV_LOG_ERROR, "Invalid resize param: %s, which should be stride by %d and %d.\n",
+                   ctx->resize_str, VDEC_WIDTH_ALIGN, VDEC_HEIGHT_ALIGN);
+            return AVERROR_BUG;
+        }
+
+        if (ctx->resize_width < 128 || ctx->resize_height < 128 ||
+            ctx->resize_width > 4096 || ctx->resize_height > 4096) {
+                av_log(avctx, AV_LOG_ERROR, "Invalid resize param: %s, which should be in [128x128 ~ 4096x4096].\n",
+                       ctx->resize_str, VDEC_WIDTH_ALIGN, VDEC_HEIGHT_ALIGN);
+                return AVERROR_BUG; 
+            }
+        avctx->coded_width = ctx->resize_width;
+        avctx->coded_height = ctx->resize_height;
+    }
+
+    if (!ctx->resize_str || (ctx->resize_height == avctx->height && ctx->resize_width == avctx->width)) {
+        ctx->vdec_width = FFALIGN(avctx->width, VDEC_WIDTH_ALIGN);
+        ctx->vdec_height = FFALIGN(avctx->height, VDEC_HEIGHT_ALIGN);
+        ctx->resize_width = ctx->resize_height = 0;
+    } else {
+        av_log(avctx, AV_LOG_INFO, "Vdec resize: %dx%d.\n", ctx->resize_width, ctx->resize_height);
+    }
+
+    ctx->vdec_width = avctx->width;
+    ctx->vdec_height = avctx->height;
+    
+    if (decode_params_checking(avctx) != 0) {
+        return AVERROR(EINVAL);
+    }
+    av_log(avctx, AV_LOG_DEBUG, "Vdec width: %d.\n", ctx->vdec_width);
+    av_log(avctx, AV_LOG_DEBUG, "Vdec height: %d.\n", ctx->vdec_height);
+
+    if (avctx->hw_frames_ctx) {
+        av_buffer_unref(&ctx->hw_frame_ref);
+        ctx->hw_frame_ref = av_buffer_ref(avctx->hw_frames_ctx);
+        if (!ctx->hw_frame_ref) {
+            ret = AVERROR(EINVAL);
+            goto error;
+        }
+
+        hw_frame_ctx = (AVHWFramesContext*)ctx->hw_frame_ref->data;
+        if (!hw_frame_ctx->pool ||
+            (ctx->vdec_width != hw_frame_ctx->width && ctx->resize_width != hw_frame_ctx->width)) {
+            if (hw_frame_ctx->pool) {
+                av_buffer_pool_uninit(&hw_frame_ctx->pool);
+            }
+            hw_frame_ctx->width     = ctx->resize_width == 0 ? ctx->vdec_width : ctx->resize_width;
+            hw_frame_ctx->height    = ctx->resize_height == 0 ? ctx->vdec_height : ctx->resize_height;
+            hw_frame_ctx->initial_pool_size = 2;
+            hw_frame_ctx->format    = AV_PIX_FMT_ASCEND;
+            hw_frame_ctx->sw_format = avctx->sw_pix_fmt;
+
+            ret = av_hwframe_ctx_init(ctx->hw_frame_ref);
+            if (ret < 0) {
+                av_log(avctx, AV_LOG_ERROR, "HWFrame contex init failed.\n");
+                return AVERROR(ENAVAIL);
+            }
+        }
+        ctx->hw_device_ref = av_buffer_ref(hw_frame_ctx->device_ref);
+        if (!ctx->hw_device_ref) {
+            av_log(avctx, AV_LOG_ERROR, "Get hw_device_ref failed.\n");
+            ret = AVERROR(EINVAL);
+            goto error;
+        }
+    } else {
+        if (avctx->hw_device_ctx) {
+            ctx->hw_device_ref = av_buffer_ref(avctx->hw_device_ctx);
+            if (!ctx->hw_device_ref) {
+                av_log(avctx, AV_LOG_ERROR, "ref hwdevice failed.\n");
+                ret = AVERROR(EINVAL);
+                goto error;
+            }
+        } else {
+            char dev_idx[sizeof(int)];
+            sprintf(dev_idx, "%d", ctx->device_id);
+            av_log(avctx, AV_LOG_INFO, "dev_idx: %s.\n", dev_idx);
+            ret = av_hwdevice_ctx_create(&ctx->hw_device_ref, AV_HWDEVICE_TYPE_ASCEND, dev_idx, NULL, 0);
+            if (ret < 0) {
+                av_log(avctx, AV_LOG_ERROR, "hwdevice contex create failed.\n");
+                goto error;
+            }
+        }
+        ctx->hw_frame_ref = av_hwframe_ctx_alloc(ctx->hw_device_ref);
+        if (!ctx->hw_frame_ref) {
+            av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_alloc failed, ret is %d.\n", ret);
+            ret = AVERROR(EINVAL);
+            goto error;
+        }
+        hw_frame_ctx = (AVHWFramesContext*)ctx->hw_frame_ref->data;
+        if (!hw_frame_ctx->pool) {
+            hw_frame_ctx->width         = ctx->resize_width == 0 ? ctx->vdec_width : ctx->resize_width;
+            hw_frame_ctx->height        = ctx->resize_height == 0 ? ctx->vdec_height : ctx->resize_height;
+            hw_frame_ctx->initial_pool_size = 2;
+            hw_frame_ctx->format        = AV_PIX_FMT_ASCEND;
+            hw_frame_ctx->sw_format     = avctx->sw_pix_fmt;
+            ret = av_hwframe_ctx_init(ctx->hw_frame_ref);
+            if (ret < 0) {
+                av_log(avctx, AV_LOG_ERROR, "hwframe ctx init error, ret is %d.\n", ret);
+                return AVERROR(EINVAL);
+            }
+        }
+    }
+    hw_device_ctx = ((AVHWDeviceContext*)ctx->hw_device_ref->data)->hwctx;
+    ctx->hw_device_ctx          = hw_device_ctx;
+    ctx->hw_frames_ctx          = hw_frame_ctx;
+    ctx->ascend_ctx             = ctx->hw_device_ctx->ascend_ctx;
+
+    ctx->device_id              = ctx->ascend_ctx->device_id;
+    ctx->frame_id               = 0;
+    ctx->eos_received           = 0;
+    ctx->total_out_frame_count  = 0;
+    ctx->total_packet_count     = 0;
+    ctx->decoder_flushing       = 0;
+    ctx->first_packet           = 1;
+
+    ff_mutex_init(&ctx->queue_mutex, NULL);
+
+    switch (avctx->codec->id)
+    {
+        case AV_CODEC_ID_H264:
+            ctx->codec_type = HI_PT_H264;
+            break;
+        case AV_CODEC_ID_H265:
+            ctx->codec_type = HI_PT_H265;
+            break;
+        default:
+            av_log(avctx, AV_LOG_ERROR, "Invalid codec type, %d.\n", avctx->codec->id);
+            return AVERROR_BUG;
+    }
+    ctx->bsf = NULL;
+    if (avctx->codec->id == AV_CODEC_ID_H264 || avctx->codec->id == AV_CODEC_ID_H265) {
+        if (avctx->codec->id == AV_CODEC_ID_H264)
+            bsf = av_bsf_get_by_name("h264_mp4toannexb");
+        else if (avctx->codec->id == AV_CODEC_ID_H265)
+            bsf = av_bsf_get_by_name("hevc_mp4toannexb");
+        if (!bsf) {
+            ret = AVERROR_BSF_NOT_FOUND;
+            goto error;
+        }
+        ret = av_bsf_alloc(bsf, &ctx->bsf);
+        if (ret < 0)
+            goto error;
+        
+        ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
+        if (ret < 0) {
+            av_bsf_free(&ctx->bsf);
+            goto error;
+        }
+        ret = av_bsf_init(ctx->bsf);
+        if (ret < 0) {
+            av_bsf_free(&ctx->bsf);
+            goto error;
+        }
+    } else {
+        av_log(avctx, AV_LOG_ERROR, "Invalid codec id, %d.\n", avctx->codec->id);
+        return AVERROR_BUG;
+    }
+
+    ctx->frame_queue = av_fifo_alloc(1000 * sizeof(FrameInfo_t));
+    if (!ctx->frame_queue) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to alloc frame fifo queue.\n");
+        goto error;
+    }
+
+    ctx->dts_queue = av_fifo_alloc(1000 * sizeof(int64_t));
+    if (!ctx->dts_queue) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to alloc dts fifo queue.\n");
+        goto error;
+    }
+
+    ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "Set context failed, ret is %d.\n", ret);
+        goto error;
+    }
+
+    ret = hi_mpi_sys_init();
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi sys init failed, ret is %d.\n", ret);
+        goto error;
+    }
+
+    ctx->chn_attr_.type         = ctx->codec_type;
+    ctx->chn_attr_.mode         = HI_VDEC_SEND_MODE_FRAME;
+    ctx->chn_attr_.pic_width    = ctx->vdec_width;
+    ctx->chn_attr_.pic_height   = ctx->vdec_height;
+
+    // Stream buffer size, Recommended value is width * height * 3 / 2
+    ctx->chn_attr_.stream_buf_size = ctx->vdec_width * ctx->vdec_height * YUV_BGR_CONVERT_3 / YUV_BGR_CONVERT_2;
+    ctx->chn_attr_.frame_buf_cnt = REF_FRAME_NUM + DISPLAY_FRAME_NUM + 1;
+
+    // Create buf attribute
+    ctx->buf_attr_.width        = ctx->chn_attr_.pic_width;
+    ctx->buf_attr_.height       = ctx->chn_attr_.pic_height;
+    ctx->buf_attr_.align        = 0;
+    ctx->buf_attr_.bit_width    = HI_DATA_BIT_WIDTH_8;
+    ctx->buf_attr_.pixel_format = HI_PIXEL_FORMAT_YUV_SEMIPLANAR_420;
+    ctx->buf_attr_.compress_mode = HI_COMPRESS_MODE_NONE;
+
+    ctx->chn_attr_.frame_buf_size = hi_vdec_get_pic_buf_size(ctx->chn_attr_.type, &ctx->buf_attr_);
+
+    // Configure video decoder channel attribute
+    ctx->chn_attr_.video_attr.ref_frame_num     = REF_FRAME_NUM;
+    ctx->chn_attr_.video_attr.temporal_mvp_en   = HI_TRUE;
+    ctx->chn_attr_.video_attr.tmv_buf_size      = hi_vdec_get_tmv_buf_size(ctx->chn_attr_.type,
+                                                                           ctx->chn_attr_.pic_width,
+                                                                           ctx->chn_attr_.pic_height);
+
+    av_log(avctx, AV_LOG_INFO, "Channel Id is: %d.\n", ctx->channel_id);
+    ret = hi_mpi_vdec_create_chn(ctx->channel_id, &ctx->chn_attr_);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi create vdec channel failed, ret is %d.\n", ret);
+        goto error;
+    }
+
+    // reset channel param.
+    ret = hi_mpi_vdec_get_chn_param(ctx->channel_id, &ctx->chn_param_);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi vdec get channel param failed, ret is %d.\n", ret);
+        goto error;
+    }
+
+    ctx->chn_param_.video_param.dec_mode        = HI_VIDEO_DEC_MODE_IPB;
+    ctx->chn_param_.video_param.compress_mode   = HI_COMPRESS_MODE_HFBC;
+    ctx->chn_param_.video_param.video_format    = HI_VIDEO_FORMAT_TILE_64x16;
+    ctx->chn_param_.display_frame_num           = DISPLAY_FRAME_NUM;
+    ctx->chn_param_.video_param.out_order       = HI_VIDEO_OUT_ORDER_DISPLAY;
+
+    ret = hi_mpi_vdec_set_chn_param(ctx->channel_id, &ctx->chn_param_);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi vdec set channel param failed, ret is %d.\n", ret);
+        goto error;
+    }
+
+    ret = hi_mpi_vdec_start_recv_stream(ctx->channel_id);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "HiMpi vdec start receive stream failed, ret is %d.\n", ret);
+        goto error;
+    }
+    ctx->hi_mpi_init_flag = 1;
+    ctx->decode_run_flag = 1;
+
+    // create callback thread
+    ctx->thread_run_flag = 1;
+    ret = pthread_create(&ctx->thread_id, NULL, get_frame, (void *)ctx);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "pthread_create callback thread failed, ret is %d.\n", ret);
+        goto error;
+    }
+
+    avctx->pkt_timebase.num = 1;
+    avctx->pkt_timebase.den = 90000;
+    if (!avctx->pkt_timebase.num || !avctx->pkt_timebase.den) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid pkt_timebase.\n");
+    }
+    
+    sem_init(&ctx->eos_sema, 0, 0);
+    return 0;
+
+error:
+    sem_post(&ctx->eos_sema);
+    ff_himpi_decode_end(avctx);
+    return ret;
+}
+
+static void ff_himpi_flush(AVCodecContext *avctx) {
+    ff_himpi_decode_end(avctx);
+    ff_himpi_decode_init(avctx);
+}
+
+#define OFFSET(x) offsetof(ASCENDContext_t, x)
+#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+    { "device_id",      "Use to choose the ascend chip.",                   OFFSET(device_id), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 8, VD},
+    { "channel_id",     "Set channelId of decoder.",                        OFFSET(channel_id), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 255, VD},
+    { "resize",         "Resize (width)x(height).",                         OFFSET(resize_str), AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, VD},
+    { NULL }
+};
+
+static const AVCodecHWConfigInternal* ascend_hw_configs[] = {
+    &(const AVCodecHWConfigInternal) {
+        .public = {
+            .pix_fmt        = AV_PIX_FMT_ASCEND,
+            .methods        = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX | AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX | \
+                              AV_CODEC_HW_CONFIG_METHOD_INTERNAL,
+            .device_type    = AV_HWDEVICE_TYPE_ASCEND
+        },
+        .hwaccel = NULL,
+    },
+    NULL
+};
+
+#define ASCEND_DEC_CODEC(x, X) \
+    static const AVClass x##_ascend_class = { \
+        .class_name = #x "_ascend_dec", \
+        .item_name = av_default_item_name, \
+        .option = options, \
+        .version = LIBAVUTIL_VERSION_INT, \
+    }; \
+    AVCodec ff_##x##_ascend_decoder = { \
+        .name       = #x "_ascend", \
+        .long_name  = NULL_IF_CONFIG_SMALL("Ascend HiMpi " #X " decoder"), \
+        .type       = AVMEDIA_TYPE_VIDEO, \
+        .id         = AV_CODEC_ID_##X, \
+        .priv_data_size = sizeof(ASCENDContext_t), \
+        .priv_class     = &x##_ascend_class, \
+        .init           = ff_himpi_decode_init, \
+        .close          = ff_himpi_decode_end, \
+        .receive_frame  = ff_himpi_receive_frame, \
+        .flush          = ff_himpi_flush, \
+        .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
+        .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_ASCEND, \
+                                                        AV_PIX_FMT_NV12, \
+                                                        AV_PIX_FMT_NONE }, \
+        .hw_configs     = ascend_hw_configs, \
+        .wrapper_name   = "ascenddec", \
+    };
+
+#if CONFIG_H264_ASCEND_DECODER
+ASCEND_DEC_CODEC(h264, H264)
+#endif
+
+#if CONFIG_H265_ASCEND_DECODER
+ASCEND_DEC_CODEC(h265, H265)
+#endif
\ No newline at end of file
--- /dev/null
+++ Ascendffmpeg/libavcodec/ascend_dec.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright(c) 2020. Huawei Technologies Co.,Ltd. All rights reserved. 
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except int compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FFMPEG_ASCEND_ASCEND_DEC_H
+#define FFMPEG_ASCEND_ASCEND_DEC_H
+
+#include "libavutil/parseutils.h"
+#include "libavutil/buffer.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_ascend.h"
+#include "libavutil/fifo.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+#include "libavutil/time.h"
+#include "libavutil/common.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/thread.h"
+#include "libavutil/version.h"
+#include "config.h"
+#include "avcodec.h"
+#include "decode.h"
+#include "hwaccels.h"
+#include "hwconfig.h"
+#include "internal.h"
+#include "libavutil/avutil.h"
+
+#include "acl/dvpp/hi_dvpp.h"
+
+#define VDEC_WIDTH_ALIGN 16
+#define VDEC_HEIGHT_ALIGN 2
+
+#define REF_FRAME_NUM 8
+#define DISPLAY_FRAME_NUM 2
+#define VDEC_TIME_OUT 1000
+#define VDEC_GET_TIME_OUT 100
+#define VDEC_SLEEP_TIME 1000
+
+#define YUV_BGR_CONVERT_3 3
+#define YUV_BGR_CONVERT_2 2
+
+typedef enum {
+    EVENT_NEW_FRAME = 0,
+    EVENT_EOS = 1,
+} eventType_t;
+
+typedef struct FrameInfo {
+    void *ascend_ctx;
+    eventType_t event_type;
+    uint8_t *data;
+    uint32_t data_size;
+    hi_pixel_format format;
+    int64_t pts;
+    int64_t dts;
+    uint32_t width_stride;
+    uint32_t height_stride;
+} FrameInfo_t;
+
+typedef struct ASCENDContext {
+    AVClass* av_class;
+    int device_id;
+    int channel_id;
+
+    pthread_t thread_id;
+    volatile int thread_run_flag;
+    volatile int hi_mpi_init_flag;
+
+    /*
+    struct {
+        int x;
+        int y;
+        int w;
+        int h;
+    } crop;
+    struct {
+        int width;
+        int height;
+    } resize;
+    */
+
+    char *output_pixfmt;
+    sem_t eos_sema;
+
+    AVBufferRef *hw_device_ref;
+    AVBufferRef *hw_frame_ref;
+    AVBSFContext *bsf;
+    AVCodecContext *avctx;
+    AVFifoBuffer *frame_queue;
+    AVFifoBuffer *dts_queue;
+    AVASCENDDeviceContext *hw_device_ctx;
+    AVHWFramesContext *hw_frames_ctx;
+    AscendContext *ascend_ctx;
+
+    hi_vdec_chn_attr chn_attr_;
+    hi_pic_buf_attr buf_attr_;
+    hi_vdec_chn_param chn_param_;
+
+    AVMutex queue_mutex;
+
+    int max_width;
+    int max_height;
+    int vdec_width;
+    int vdec_height;
+    int stride_align;
+    char* resize_str;
+    int resize_width;
+    int resize_height;
+    hi_payload_type codec_type;
+
+    volatile int frame_id;
+    int first_packet;
+    volatile int first_seq;
+    volatile int eos_received;
+    volatile int decoder_flushing;
+    volatile int decode_run_flag;
+    unsigned long long total_packet_count;
+    unsigned long long total_out_frame_count;
+
+    hi_vdec_stream stream;
+    hi_vdec_pic_info pic_info;
+} ASCENDContext_t;
+
+static inline void get_vdec_frame_info(FrameInfo_t* frame_info, hi_video_frame_info frame)
+{
+    uint32_t width_stride = frame.v_frame.width_stride[0];
+    uint32_t height_stride = frame.v_frame.height_stride[0];
+    frame_info->width_stride = width_stride;
+    frame_info->height_stride = height_stride;
+    frame_info->data_size = width_stride * height_stride * YUV_BGR_CONVERT_3 / YUV_BGR_CONVERT_2;
+    frame_info->format = frame.v_frame.pixel_format;
+    frame_info->pts = frame.v_frame.pts;
+    frame_info->data = frame.v_frame.virt_addr[0];
+}
+
+#endif // FFMPEG_ASCEND_ASCEND_DEC_H
\ No newline at end of file
--- /dev/null
+++ Ascendffmpeg/libavcodec/ascend_enc.c
@@ -0,0 +1,937 @@
+/*
+ * Copyright(c) 2020. Huawei Technologies Co.,Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except int compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "ascend_enc.h"
+
+static void CloseEpoll(int32_t epollFd)
+{
+    int ret = hi_mpi_sys_close_epoll(epollFd);
+    if (ret != 0) {
+        av_log(NULL, AV_LOG_ERROR, "Call hi_mpi_sys_close_epoll failed, ret is %d.\n", ret);
+    }
+}
+
+static int get_stream_loop(ASCENDEncContext_t *ctx, int32_t epollFd)
+{
+    int i = 0;
+    int eos_flag = 0;
+    while (ctx->thread_run_flag) {
+        if (ctx->eos_post_flag == 1 && (ctx->frame_send_sum <= i)) {
+            // eos
+            StreamInfo_t stream_info;
+            memset(&stream_info, 0, sizeof(StreamInfo_t));
+            stream_info.event_type = EVENT_EOS;
+            
+            ff_mutex_lock(&ctx->queue_mutex);
+            av_fifo_generic_write(ctx->frame_queue, &stream_info, sizeof(StreamInfo_t), NULL);
+            ff_mutex_unlock(&ctx->queue_mutex);
+            sem_post(&ctx->eos_sema);
+            av_log(ctx, AV_LOG_DEBUG, "Encoder got eos.\n");
+            break;
+        }
+
+        int32_t eventCount = 0;
+        hi_dvpp_epoll_event events[HI_DVPP_EPOLL_EVENT];
+        int ret = hi_mpi_sys_wait_epoll(epollFd, events, HI_MPI_SYS_WAIT_EPOLL_MAX_EVENTS,
+                                        HI_DVPP_EPOLL_EVENT_NUM, &eventCount);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_sys_wait_epoll failed, ret is %d.\n", ret);
+            return -1;
+        }
+
+        hi_venc_chn_status stat;
+        ret = hi_mpi_venc_query_status(ctx->channel_id, &stat);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_query_status failed, ret is %d.\n", ret);
+            return -1;
+        }
+
+        hi_venc_stream stream;
+        stream.pack_cnt = stat.cur_packs;
+
+        hi_venc_pack pack[MAX_PACK_COUNT];
+        stream.pack = pack;
+        if (stream.pack == NULL) {
+            return -1;
+        }
+
+        ret = hi_mpi_venc_get_stream(ctx->channel_id, &stream, WAIT_GET_TILL_TIMEOUT);
+        if (ret != 0) {
+            if (ctx->encoder_flushing && ret == HI_ERR_VENC_BUF_EMPTY) {
+                eos_flag = 1;
+                av_log(ctx, AV_LOG_DEBUG, "Encoder_flushing or stream eos.\n");
+            } else {
+                av_log(ctx, AV_LOG_DEBUG, "Call hi_mpi_venc_get_stream failed, ret is %d.\n", ret);
+                continue;
+            }
+        }
+
+        if (eos_flag) {
+            //eos
+            StreamInfo_t stream_info;
+            memset(&stream_info, 0, sizeof(StreamInfo_t));
+            stream_info.event_type = EVENT_EOS;
+
+            ff_mutex_lock(&ctx->queue_mutex);
+            av_fifo_generic_write(ctx->frame_queue, &stream_info, sizeof(StreamInfo_t), NULL);
+            ff_mutex_unlock(&ctx->queue_mutex);
+            sem_post(&ctx->eos_sema);
+            av_log(ctx, AV_LOG_DEBUG, "Encoder got eos.\n");
+            break;
+        }
+
+        // Create stream.
+        uint32_t streamSize = stream.pack[0].len - stream.pack[0].offset;
+
+        // Make sure stream size is bigger than 0'
+        if (stream.pack[0].len <= stream.pack[0].offset) {
+            av_log(ctx, AV_LOG_ERROR, "StreamSize(%d) is invalid, it has to be bigger than 0.\n",
+                   stream.pack[0].len - stream.pack[0].offset);
+            return -1;
+        }
+
+        // Make sure sream size is less than 2 Gigabytes
+        if (streamSize > MAX_MEMORY_SIZE) {
+            av_log(ctx, AV_LOG_ERROR, "StreamSize(%d) is invalid, it has to be less than 2G.\n", streamSize);
+            return -1;
+        }
+
+        StreamInfo_t stream_info;
+        stream_info.ascend_ctx = ctx;
+        get_venc_stream_info(&stream_info, stream);
+        uint8_t* data_frame = NULL;
+
+        ff_mutex_lock(&ctx->queue_mutex);
+        av_fifo_generic_read(ctx->dataptr_queue, &data_frame, sizeof(uint8_t*), NULL);
+        av_fifo_generic_write(ctx->frame_queue, &stream_info, sizeof(StreamInfo_t), NULL);
+        ff_mutex_unlock(&ctx->queue_mutex);
+
+        ret = hi_mpi_venc_release_stream(ctx->channel_id, &stream);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_release_stream failed, ret is %d.\n", ret);
+            return -1;
+        }
+
+        ret = hi_mpi_dvpp_free(data_frame);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_WARNING, "Call hi_mpi_dvpp_free failed, ret is %d.\n", ret);
+        }
+
+        i++;
+        av_log(ctx, AV_LOG_DEBUG, "Finish getting the %d th frame.\n", i);
+    }
+    av_log(ctx, AV_LOG_DEBUG, "Encode thread get eos signal.\n");
+    return 0;
+}
+
+static void *venc_get_stream(void *arg)
+{
+    ASCENDEncContext_t *ctx = (ASCENDEncContext_t*)arg;
+
+    // Set Device
+    av_log(NULL, AV_LOG_INFO, "Encode thread start.\n");
+    int eos_flag = 0;
+    int ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Set context failed at line(%d) in func(%s), ret is %d.\n", __LINE__, __func__, ret);
+        return ((void*) (-1));
+    }
+
+    // init 
+    int32_t epollFd = 0;
+    int32_t fd = hi_mpi_venc_get_fd(ctx->channel_id);
+    ret = hi_mpi_sys_create_epoll(HI_SYS_CREATE_EPOLL_SIZE, &epollFd);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_sys_create_epoll failed, ret is %d.\n", ret);
+        return ((void*) (-1));
+    }
+    hi_dvpp_epoll_event event;
+    event.events = HI_DVPP_EPOLL_IN;
+    event.data = (void*)(uint64_t)(fd);
+    ret = hi_mpi_sys_ctl_epoll(epollFd, HI_DVPP_EPOLL_CTL_ADD, fd, &event);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_sys_ctl_epoll add failed, ret is %d.\n", ret);
+        CloseEpoll(epollFd);
+        return ((void*) (-1));
+    }
+
+    // start reveive loop
+    ret = get_stream_loop(ctx, epollFd);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call get_stream_loop failed, ret is %d.\n", ret);
+        CloseEpoll(epollFd);
+        return ((void*) (-1));
+    }
+
+    ret = hi_mpi_sys_ctl_epoll(epollFd, HI_DVPP_EPOLL_CTL_DEL, fd, NULL);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_sys_ctl_epoll del failed, ret is %d.\n", ret);
+        CloseEpoll(epollFd);
+        return ((void*) (-1));
+    }
+
+    CloseEpoll(epollFd);
+
+    return NULL;
+}
+
+static inline int encode_params_checking(AVCodecContext* avctx)
+{
+    switch (avctx->codec->id) {
+        case AV_CODEC_ID_H264:
+            if (avctx->width * avctx->height > 4096 * 2304) {
+                av_log(avctx, AV_LOG_ERROR,
+                       "ASCEND encoder H264 input max pixel num should be less than 4096x2304"
+                       ", now: %dx%d.\n", avctx->width, avctx->height);
+                return -1;
+            }
+        case AV_CODEC_ID_H265:
+            if (avctx->width < 128 || avctx->width > 4096 || avctx->height < 128 || avctx->height > 4096) {
+                av_log(avctx, AV_LOG_ERROR,
+                       "ASCEND encoder only support size: 128x128~4096x4096, now: %dx%d.\n",
+                       avctx->width, avctx->height);
+                return -1;
+            }
+            break;
+        default:
+            break;
+    }
+    return 0;
+}
+
+static inline int set_venc_mod_param(AVCodecContext *avctx)
+{
+    hi_venc_mod_param mod_param;
+
+    switch (avctx->codec->id) {
+        case AV_CODEC_ID_H264:
+            mod_param.mod_type = HI_VENC_MOD_H264;
+            break;
+        case AV_CODEC_ID_H265:
+            mod_param.mod_type = HI_VENC_MOD_H265;
+            break;
+        default:
+            av_log(avctx, AV_LOG_ERROR, "Ascend encoder only support h264 or h265.\n");
+            return AVERROR_BUG;
+            break;
+    }
+
+    int ret = hi_mpi_venc_get_mod_param(&mod_param);
+    if (ret != 0) {
+        av_log(avctx, AV_LOG_ERROR, "Call hi_mpi_venc_get_mod_param failed, ret is: %d.\n", ret);
+        return ret;
+    }
+
+    switch (avctx->codec->id) {
+        case AV_CODEC_ID_H264:
+            mod_param.h264_mod_param.one_stream_buf = 1;
+            break;
+        case AV_CODEC_ID_H265:
+            mod_param.h265_mod_param.one_stream_buf = 1;
+            break;
+        default:
+            av_log(avctx, AV_LOG_ERROR, "Ascend encoder only support h264 or h265.\n");
+            return AVERROR_BUG;
+            break;
+    }
+
+    ret = hi_mpi_venc_set_mod_param(&mod_param);
+    if (ret != 0 && (unsigned int)ret != HI_ERR_VENC_NOT_PERM) {
+        av_log(avctx, AV_LOG_ERROR, "Call hi_mpi_venc_set_mod_param failed, ret is %d.\n", ret);
+        return ret;
+    } else if ((unsigned int)ret == HI_ERR_VENC_NOT_PERM) {
+        av_log(avctx, AV_LOG_WARNING, "Venc channel already exists, using default mod param.\n");
+    }
+
+    return 0;
+}
+
+static inline int create_venc_channel_by_order(ASCENDEncContext_t *ctx)
+{
+    int chnId = 0;
+    int ret;
+    while(1) {
+        ret = hi_mpi_venc_create_chn(chnId, &ctx->chn_attr_);
+        if (ret == 0) {
+            ctx->channel_id = chnId;
+            av_log(ctx, AV_LOG_WARNING, "The specified channel is occupied now, another channle will be arranged.\n");
+            av_log(ctx, AV_LOG_INFO, "Create venc channels success, channel id is %d.\n", ctx->channel_id);
+            break;
+        } else if ((unsigned int)ret == HI_ERR_VENC_EXIST) {
+            chnId++;
+            if (chnId > MAX_HIMPI_VENC_CHN_NUM) {
+                av_log(ctx, AV_LOG_ERROR, "All venc channels were occupied, create venc channel failed.\n");
+                return -1;
+            }
+        } else {
+            av_log(ctx, AV_LOG_ERROR, "Failed to create venc channel, ret is %d.\n", ret);
+            return ret;
+        }
+    }
+    return 0;
+}
+
+static inline int create_venc_channel(ASCENDEncContext_t *ctx)
+{
+    ctx->chn_attr_.venc_attr.max_pic_width = MAX_VENC_WIDTH;
+    ctx->chn_attr_.venc_attr.max_pic_height = MAX_VENC_HEIGHT;
+    ctx->chn_attr_.venc_attr.pic_width = ctx->coded_width;
+    ctx->chn_attr_.venc_attr.pic_height = ctx->coded_height;
+    if (ctx->is_movement_scene == 1) {
+        ctx->chn_attr_.venc_attr.buf_size = FFALIGN(MAX_VENC_WIDTH * MAX_VENC_HEIGHT * BUF_SIZE_TIMES, BUF_SIZE_STRIDE);
+    } else {
+        ctx->chn_attr_.venc_attr.buf_size = MAX_VENC_WIDTH * MAX_VENC_HEIGHT * YUV_BGR_SIZE_CONVERT_3 / YUV_BGR_SIZE_CONVERT_2;
+    }
+
+    ctx->chn_attr_.venc_attr.is_by_frame = HI_TRUE;
+    int stats_time = (ctx->is_movement_scene != 0) ? (int)(1.0 * ctx->gop / ctx->frame_rate + 0.5) : HI_VENC_CHN_ATTR_STATS_TIME;
+
+    if (ctx->avctx->codec->id == AV_CODEC_ID_H264) {
+        ctx->chn_attr_.venc_attr.type = HI_PT_H264;
+        ctx->chn_attr_.venc_attr.profile = ctx->profile;
+
+        if (ctx->rc_mode == 1) {
+            // VBR
+            ctx->chn_attr_.rc_attr.rc_mode = HI_VENC_RC_MODE_H264_VBR;
+            ctx->chn_attr_.rc_attr.h264_vbr.gop = ctx->gop;
+            ctx->chn_attr_.rc_attr.h264_vbr.stats_time = stats_time;
+            ctx->chn_attr_.rc_attr.h264_vbr.src_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h264_vbr.dst_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h264_vbr.max_bit_rate = ctx->max_bit_rate;
+        } else {
+            // CBR
+            ctx->chn_attr_.rc_attr.rc_mode = HI_VENC_RC_MODE_H264_CBR;
+            ctx->chn_attr_.rc_attr.h264_cbr.gop = ctx->gop;
+            ctx->chn_attr_.rc_attr.h264_cbr.stats_time = stats_time;
+            ctx->chn_attr_.rc_attr.h264_cbr.src_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h264_cbr.dst_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h264_cbr.bit_rate = ctx->max_bit_rate;
+        }
+    } else if (ctx->avctx->codec->id == AV_CODEC_ID_H265) {
+        ctx->chn_attr_.venc_attr.type = HI_PT_H265;
+        if (ctx->profile != 1) {
+            av_log(ctx, AV_LOG_ERROR, "'profile' param only support value is 1 when ascend encoder is h265, please check.\n");
+            return AVERROR(EINVAL);
+        }
+        ctx->chn_attr_.venc_attr.profile = HI_VENC_H265_MAIN_LEVEL;
+
+        if (ctx->rc_mode == 1) {
+            // VBR
+            ctx->chn_attr_.rc_attr.rc_mode = HI_VENC_RC_MODE_H265_VBR;
+            ctx->chn_attr_.rc_attr.h265_vbr.gop = ctx->gop;
+            ctx->chn_attr_.rc_attr.h265_vbr.stats_time = stats_time;
+            ctx->chn_attr_.rc_attr.h265_vbr.src_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h265_vbr.dst_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h265_vbr.max_bit_rate = ctx->max_bit_rate;
+        } else {
+            // CBR
+            ctx->chn_attr_.rc_attr.rc_mode = HI_VENC_RC_MODE_H265_CBR;
+            ctx->chn_attr_.rc_attr.h265_cbr.gop = ctx->gop;
+            ctx->chn_attr_.rc_attr.h265_cbr.stats_time = stats_time;
+            ctx->chn_attr_.rc_attr.h265_cbr.src_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h265_cbr.dst_frame_rate = ctx->frame_rate;
+            ctx->chn_attr_.rc_attr.h265_cbr.bit_rate = ctx->max_bit_rate;
+        }
+    } else {
+        av_log(ctx, AV_LOG_ERROR, "Ascend encoder only support h264 or h265.\n");
+        return AVERROR_BUG;
+    }
+
+    ctx->chn_attr_.gop_attr.gop_mode = HI_VENC_GOP_MODE_NORMAL_P;
+    ctx->chn_attr_.gop_attr.normal_p.ip_qp_delta = HI_ODD_NUM_3;
+
+    int ret = hi_mpi_venc_create_chn(ctx->channel_id, &ctx->chn_attr_);
+    if (ret == 0) {
+        av_log(ctx, AV_LOG_INFO, "Create venc channels success. Channel id is %d.\n", ctx->channel_id);
+    } else if ((unsigned int)ret == HI_ERR_VENC_EXIST) {
+        ret = create_venc_channel_by_order(ctx);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Failed to create venc channel, ret is %d.\n", ret);
+            return ret;
+        }
+    } else {
+        av_log(ctx, AV_LOG_ERROR, "Failed to create venc channel, ret is %d.\n", ret);
+        return ret;
+    }
+
+    hi_venc_scene_mode scene_mode = HI_VENC_SCENE_0;
+    if (ctx->avctx->codec_id == AV_CODEC_ID_H265 && ctx->is_movement_scene != 0) {
+        scene_mode = HI_VENC_SCENE_1;
+    }
+    ret = hi_mpi_venc_set_scene_mode(ctx->channel_id, scene_mode);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_set_scene_mode failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    return 0;
+}
+
+static inline int set_venc_rc_param(ASCENDEncContext_t *ctx)
+{
+    int ret;
+    hi_s32 i = 0;
+    hi_u32 u32Thrd_ori[16] = {0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255};
+    hi_venc_rc_param rcParam;
+    ret = hi_mpi_venc_get_rc_param(ctx->channel_id, &rcParam);
+    if (ret != HI_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_get_rc_param [%u] failed with ret 0x%x.\n", ctx->channel_id, ret);
+        return ret;
+    }
+    for (i = 0; i < 16; i++) {
+        hi_u32 value = u32Thrd_ori[i];
+        rcParam.threshold_i[i] = value;
+        rcParam.threshold_p[i] = value;
+        rcParam.threshold_b[i] = value;
+    }
+
+    rcParam.direction = 8;
+    rcParam.row_qp_delta = 0;
+
+    ret = hi_mpi_venc_set_rc_param(ctx->channel_id, &rcParam);
+    if (ret != HI_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_set_rc_param [%u] failed with ret 0x%x.\n", ctx->channel_id, ret);
+        return ret;
+    }
+
+    return 0;
+}
+
+static av_cold int ff_himpi_enc_init(AVCodecContext *avctx)
+{
+    ASCENDEncContext_t *ctx = (ASCENDEncContext_t*)avctx->priv_data;
+    AVASCENDDeviceContext *device_hwctx;
+    AVHWFramesContext *hwframe_ctx;
+    int ret = -1;
+    int bitstream_buf_size = 0;
+    char device_id[sizeof(int)];
+
+    if (avctx == NULL || ctx == NULL) {
+        av_log(avctx, AV_LOG_ERROR, "Early error in ff_himpi_enc_init.\n");
+        return AVERROR_BUG;
+    }
+
+    if (ctx->hi_mpi_init_flag == 1) {
+        av_log(avctx, AV_LOG_ERROR, "Error, himpi encoder double init.\n");
+        return AVERROR_BUG;
+    }
+
+    if (encode_params_checking(avctx) != 0) {
+        return AVERROR(EINVAL);
+    }
+
+    ctx->avctx = avctx;
+    ctx->coded_width = FFALIGN(avctx->coded_width, VENC_WIDTH_ALIGN);
+    ctx->coded_height = FFALIGN(avctx->coded_height, VENC_HEIGHT_ALIGN);
+    sprintf(device_id, "%d", ctx->device_id);
+    av_log(ctx, AV_LOG_INFO, "Device id is: %s.\n", device_id);
+
+    if (avctx->pix_fmt == AV_PIX_FMT_ASCEND) {
+        if (avctx->hw_frames_ctx) {
+            av_buffer_unref(&ctx->hw_frame_ref);
+            ctx->hw_frame_ref = av_buffer_ref(avctx->hw_frames_ctx);
+            if (!ctx->hw_frame_ref) {
+                return AVERROR(EINVAL);
+            }
+            hwframe_ctx = (AVHWFramesContext*)ctx->hw_frame_ref->data;
+            ctx->hw_device_ref = av_buffer_ref(hwframe_ctx->device_ref);
+            if (!ctx->hw_device_ref) {
+                return AVERROR(EINVAL);
+            }
+
+            device_hwctx            = hwframe_ctx->device_ctx->hwctx;
+            ctx->hw_frame_ctx       = hwframe_ctx;
+            ctx->hw_device_ctx      = device_hwctx;
+            ctx->ascend_ctx         = ctx->hw_device_ctx->ascend_ctx;
+        } else {
+            if (avctx->hw_device_ctx) {
+                ctx->hw_device_ref = av_buffer_ref(avctx->hw_device_ctx);
+                if (!ctx->hw_device_ref) {
+                    return AVERROR(EINVAL);
+                }
+            } else {
+                ret = av_hwdevice_ctx_create(&ctx->hw_device_ref, AV_HWDEVICE_TYPE_ASCEND, device_id, NULL, 0);
+                if (ret < 0) {
+                    return AVERROR(EINVAL);
+                }
+            }
+            ctx->hw_frame_ref = av_hwframe_ctx_alloc(ctx->hw_device_ref);
+            if (!ctx->hw_frame_ref) {
+                av_log(avctx, AV_LOG_ERROR, "Failed in av_hwframe_ctx_alloc.\n");
+                return AVERROR(EINVAL);
+            }
+            hwframe_ctx = (AVHWFramesContext*)ctx->hw_frame_ref->data;
+            device_hwctx = hwframe_ctx->device_ctx->hwctx;
+            ctx->hw_frame_ctx = hwframe_ctx;
+            ctx->hw_device_ctx = device_hwctx;
+            ctx->ascend_ctx = ctx->hw_device_ctx->ascend_ctx;
+
+            if (!hwframe_ctx->pool) {
+                hwframe_ctx->format = AV_PIX_FMT_ASCEND;
+                hwframe_ctx->sw_format = avctx->sw_pix_fmt;
+                hwframe_ctx->width = ctx->coded_width;
+                hwframe_ctx->height = ctx->coded_height;
+                if ((ret = av_hwframe_ctx_init(ctx->hw_frame_ref)) < 0) {
+                    av_log(avctx, AV_LOG_ERROR, "Failed in av_hwframe_ctx_init.\n");
+                    return AVERROR(EINVAL);
+                }
+            }
+        }
+        ctx->in_sw_pixfmt = avctx->sw_pix_fmt;
+    } else {
+        av_buffer_unref(&ctx->hw_device_ref);
+        ret = av_hwdevice_ctx_create(&ctx->hw_device_ref, AV_HWDEVICE_TYPE_ASCEND, device_id, NULL, 0);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Failed in av_hwdevice_ctx_create.\n");
+            return AVERROR(EINVAL);
+        }
+        ctx->hw_device_ctx = ((AVHWDeviceContext*)ctx->hw_device_ref->data)->hwctx;
+        ctx->ascend_ctx = ctx->hw_device_ctx->ascend_ctx;
+        ctx->in_sw_pixfmt = avctx->pix_fmt;
+    }
+
+    bitstream_buf_size = ctx->coded_width * ctx->coded_height;
+    switch (ctx->in_sw_pixfmt) {
+        case AV_PIX_FMT_NV12:
+        case AV_PIX_FMT_YUV420P:
+        case AV_PIX_FMT_YUVJ420P:
+            bitstream_buf_size += (bitstream_buf_size >> 1);
+            break;
+        
+        default:
+            break;
+    }
+
+    ctx->eos_post_flag = 0;
+    ctx->eos_received = 0;
+    ctx->codec_abort_flag = 0;
+    sem_init(&(ctx->eos_sema), 0, 0);
+    ff_mutex_init(&ctx->queue_mutex, NULL);
+    ctx->frame_queue = av_fifo_alloc(1000 * sizeof(StreamInfo_t));
+    if (!ctx->frame_queue) {
+        sem_post(&(ctx->eos_sema));
+        av_log(avctx, AV_LOG_FATAL, "Failed to alloc memory for async fifo.\n");
+        return AVERROR(EINVAL);
+    }
+    ctx->dataptr_queue = av_fifo_alloc(1000 * sizeof(uint8_t*));
+    if (!ctx->dataptr_queue) {
+        sem_post(&(ctx->eos_sema));
+        av_log(avctx, AV_LOG_FATAL, "Failed to alloc memory for async fifo.\n");
+        return AVERROR(EINVAL);
+    }
+
+    ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Set context failed at line(%d) in func(%s), ret is %d", __LINE__, __func__, ret);
+        return ret;
+    }
+
+    ret = hi_mpi_sys_init();
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_sys_init failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    ret = set_venc_mod_param(avctx);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call set_venc_mod_param failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    ret = create_venc_channel(ctx);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call create_venc_channel failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    ret = set_venc_rc_param(ctx);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call set_venc_rc_param failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    // start receive stream
+    ctx->hi_mpi_init_flag = 1;
+    ctx->thread_run_flag = 1;
+    ctx->encode_run_flag = 1;
+    
+    ret = pthread_create(&ctx->thread_id, NULL, venc_get_stream, (void*)ctx);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Create receive stream thread failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    avctx->pkt_timebase.num = 1;
+    avctx->pkt_timebase.den = 90000;
+    if (!avctx->pkt_timebase.num || !avctx->pkt_timebase.den) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid pkt_timebase.\n");
+    }
+
+    av_log(avctx, AV_LOG_DEBUG, "Ascend encoder init successfully.\n");
+    return 0;
+}
+
+static int hi_mpi_encode(ASCENDEncContext_t *ctx, const AVFrame *frame)
+{
+    av_log(ctx, AV_LOG_DEBUG, "Send frame size: %ux%u, pts:%ld, frame type:%d.\n",
+           frame->width, frame->height, frame->pts, frame->pict_type);
+    
+    hi_venc_start_param recvParam;
+    recvParam.recv_pic_num = -1;
+    int ret = hi_mpi_venc_start_chn(ctx->channel_id, &recvParam);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_start_chn failed, ret is %d.\n", ret);
+        return ret;
+    }
+
+    if (frame && frame->width && frame->height) {
+        uint8_t* streamBuffer = NULL;
+        uint32_t dataSize = frame->width * frame->height * YUV_BGR_SIZE_CONVERT_3 / YUV_BGR_SIZE_CONVERT_2;
+        ret = hi_mpi_dvpp_malloc(ctx->device_id, &streamBuffer, dataSize);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_dvpp_malloc failed, ret is %d.\n", ret);
+            return ret;
+        }
+
+        uint32_t offset = 0;
+        for (int i = 0; i < FF_ARRAY_ELEMS(frame->data) && frame->data[i]; i++) {
+            size_t dstBytes = frame->width * frame->height * (i ? 1.0 / 2 : 1);
+            ret = aclrtMemcpy(streamBuffer + offset, dataSize, frame->data[i], dstBytes, ACL_MEMCPY_HOST_TO_DEVICE);
+            if (ret != 0) {
+                hi_mpi_dvpp_free(streamBuffer);
+                av_log(ctx, AV_LOG_ERROR, "Ascend memory H2D(host: %ld, dev: %d) failed, ret is %d.\n",
+                       dstBytes, dataSize, ret);
+                return ret;
+            }
+            offset += dstBytes;
+        }
+
+        hi_video_frame_info himpi_frame;
+        himpi_frame.mod_id = HI_ID_VENC;
+        himpi_frame.v_frame.width = frame->width;
+        himpi_frame.v_frame.height = frame->height;
+        himpi_frame.v_frame.field = HI_VIDEO_FIELD_FRAME;
+        himpi_frame.v_frame.pixel_format = HI_PIXEL_FORMAT_YUV_SEMIPLANAR_420;
+        himpi_frame.v_frame.video_format = HI_VIDEO_FORMAT_LINEAR;
+        himpi_frame.v_frame.compress_mode = HI_COMPRESS_MODE_NONE;
+        himpi_frame.v_frame.dynamic_range = HI_DYNAMIC_RANGE_SDR8;
+        himpi_frame.v_frame.color_gamut = HI_COLOR_GAMUT_BT709;
+        himpi_frame.v_frame.width_stride[0] = FFALIGN(frame->width, VENC_WIDTH_ALIGN);
+
+        himpi_frame.v_frame.width_stride[1] = FFALIGN(frame->width, VENC_WIDTH_ALIGN);
+        himpi_frame.v_frame.height_stride[0] = FFALIGN(frame->height, VENC_HEIGHT_ALIGN);
+        himpi_frame.v_frame.height_stride[1] = FFALIGN(frame->height, VENC_HEIGHT_ALIGN);
+        himpi_frame.v_frame.virt_addr[0] = streamBuffer;
+        himpi_frame.v_frame.virt_addr[1] = (hi_void *)((uintptr_t)himpi_frame.v_frame.virt_addr[0] +
+                                                        frame->width * frame->height);
+        himpi_frame.v_frame.frame_flag = 0;
+        himpi_frame.v_frame.time_ref = 2 * ctx->frame_send_sum;
+        himpi_frame.v_frame.pts = frame->pts;
+
+        // push frame buffer addr to fifo
+        ff_mutex_lock(&ctx->queue_mutex);
+        av_fifo_generic_write(ctx->dataptr_queue, &streamBuffer, sizeof(uint8_t*), NULL);
+        ff_mutex_unlock(&ctx->queue_mutex);
+
+        ret = hi_mpi_venc_send_frame(ctx->channel_id, &himpi_frame, VENC_SEND_STREAM_TIMEOUT);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_send_stream failed, ret is %d.\n", ret);
+            return ret;
+        }
+
+        ctx->frame_send_sum++;
+    } else {
+        if (!ctx->encoder_flushing) {
+            ctx->encoder_flushing = 1;
+        }
+    }
+
+    return 0;
+}
+
+static int hi_mpi_get_pkt(AVCodecContext *avctx, AVPacket *avpkt)
+{
+    ASCENDEncContext_t *ctx = (ASCENDEncContext_t*)avctx->priv_data;
+    int ret = 0;
+    if (!ctx->frame_queue || !ctx->dataptr_queue) {
+        return AVERROR(EAGAIN);
+    }
+
+    StreamInfo_t stream_info;
+    ff_mutex_lock(&ctx->queue_mutex);
+    if (av_fifo_size(ctx->frame_queue) != 0) {
+        av_fifo_generic_read(ctx->frame_queue, &stream_info, sizeof(stream_info), NULL);
+    } else {
+        ff_mutex_unlock(&ctx->queue_mutex);
+        return AVERROR(EAGAIN);
+    }
+    ff_mutex_unlock(&ctx->queue_mutex);
+    if (stream_info.event_type == EVENT_EOS) {
+        return AVERROR_EOF;
+    }
+
+    ret = ff_get_encode_buffer(avctx, avpkt, stream_info.data_size, stream_info.data_size);
+    if (ret < 0) {
+        av_log(avctx, AV_LOG_ERROR, "FFmpeg get frame buffer failed, ret is %d.\n", ret);
+        return AVERROR(EINVAL);
+    }
+
+    ret = aclrtMemcpy(avpkt->data, avpkt->size, stream_info.data, stream_info.data_size,
+                      ACL_MEMCPY_DEVICE_TO_HOST);
+    if (ret != 0) {
+        hi_mpi_dvpp_free(stream_info.data);
+        av_log(ctx, AV_LOG_ERROR, "Ascend memory D2H(dev: %d, host: %d) failed, ret is %d.\n",
+               avpkt->size, stream_info.data_size, ret);
+        return ret;
+    }
+
+    avpkt->pts = stream_info.pts;
+    avpkt->size = stream_info.data_size;
+
+    hi_mpi_dvpp_free(stream_info.data);
+
+    return 0;
+}
+
+static int ff_himpi_enc_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
+{
+    int ret = -1;
+    int send_ret = -1;
+    int get_ret = -1;
+    ASCENDEncContext_t *ctx = (ASCENDEncContext_t*)avctx->priv_data;
+    AVFrame frame = {0};
+
+    if (avctx == NULL || ctx == NULL || avpkt == NULL || !ctx->hi_mpi_init_flag) {
+        av_log(avctx, AV_LOG_ERROR, "Early error in func: ff_himpi_enc_receive_packet");
+        return AVERROR_EXTERNAL;
+    }
+
+    if (ctx->eos_received) {
+        return AVERROR_EOF;
+    }
+
+    if (ctx->codec_abort_flag) {
+        av_log(avctx, AV_LOG_FATAL, "Encoder got abort flag before send frame.\n");
+        return AVERROR_EXTERNAL;
+    }
+
+    ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Set context failed at line(%d) in func(%s), ret is %d", __LINE__, __func__, ret);
+        return ret;
+    }
+
+    while(ctx->encode_run_flag) {
+        if (!ctx->encoder_flushing) {
+            send_ret = ff_encode_get_frame(avctx, &frame);
+            if (send_ret < 0 && send_ret != AVERROR_EOF) {
+                return send_ret;
+            } else if (send_ret == AVERROR_EOF) {
+                ctx->eos_post_flag = 1;
+                ctx->encoder_flushing = 1;
+                continue;
+            }
+
+            send_ret = hi_mpi_encode(ctx, &frame);
+            av_frame_unref(&frame);
+            if (send_ret < 0 && send_ret != AVERROR_EOF) {
+                av_log(avctx, AV_LOG_ERROR, "Encoder send frame failed, ret is %d.\n", send_ret);
+                return send_ret;
+            }
+        }
+
+        get_ret = hi_mpi_get_pkt(avctx, avpkt);
+        if (get_ret != 0 && get_ret != AVERROR_EOF) {
+            if (get_ret != AVERROR(EAGAIN)) {
+                return get_ret;
+            }
+            if (ctx->encoder_flushing) {
+                av_usleep(2000);
+            }
+        } else {
+            if (get_ret == AVERROR_EOF) {
+                ctx->eos_received = 1;
+            }
+            return get_ret;
+        }
+    }
+    av_log(avctx, AV_LOG_ERROR, "Encode stop, error.\n");
+    return 0;
+}
+
+static av_cold int ff_himpi_enc_close(AVCodecContext *avctx)
+{
+    ASCENDEncContext_t *ctx = (ASCENDEncContext_t*)avctx->priv_data;
+    int ret = -1;
+    int semvalue = -1;
+    struct timespec ts;
+
+    if (avctx == NULL || ctx == NULL) {
+        av_log(NULL, AV_LOG_ERROR, "Early error in ff_himpi_enc_close.\n");
+        return AVERROR(EINVAL);
+    }
+
+    if (ctx->ascend_ctx == NULL || ctx->ascend_ctx->context == NULL) {
+        av_log(NULL, AV_LOG_ERROR, "Early error in ff_himpi_enc_close.\n");
+        return AVERROR(EINVAL);
+    }
+
+    ret = aclrtSetCurrentContext(ctx->ascend_ctx->context);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "Set context failed at line(%d) in func(%s), ret is %d", __LINE__, __func__, ret);
+        return ret;
+    }
+
+    clock_gettime(CLOCK_REALTIME, &ts);
+    ts.tv_sec += 3;
+    if (sem_timedwait(&(ctx->eos_sema), &ts) == -1) {
+        sem_getvalue(&ctx->eos_sema, &semvalue);
+        av_log(ctx, AV_LOG_ERROR, "Enc sem_timewait = -1, time out, semvalue = %d ...\n", semvalue);
+    }
+
+    if (ctx->hi_mpi_init_flag) {
+        ret = hi_mpi_venc_stop_chn(ctx->channel_id);
+        if (ret == HI_ERR_VENC_UNEXIST) {
+            av_log(ctx, AV_LOG_WARNING, "Venc channel not exist, no need to stop it.\n", ret);
+        } else if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_stop_chn failed, ret is %d.\n", ret);
+            return ret;
+        }
+
+        ret = hi_mpi_venc_destroy_chn(ctx->channel_id);
+        if (ret == HI_ERR_VENC_UNEXIST) {
+            av_log(ctx, AV_LOG_WARNING, "Venc channel not exist, no need to destroy it.\n", ret);
+        } else if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_venc_destroy_chn failed, ret is %d.\n", ret);
+            return ret;
+        }
+
+        ret = hi_mpi_sys_exit();
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Call hi_mpi_sys_exit failed, ret is %d.\n", ret);
+            return ret;
+        }
+
+        ctx->hi_mpi_init_flag = 0;
+    }
+
+    if (ctx->thread_run_flag) {
+        ctx->thread_run_flag = 0;
+        pthread_join(ctx->thread_id, NULL);
+    }
+
+    ctx->encode_run_flag = 0;
+    
+    sem_destroy(&(ctx->eos_sema));
+
+    ff_mutex_lock(&ctx->queue_mutex);
+    if (ctx->frame_queue) {
+        av_fifo_freep(&ctx->frame_queue);
+        ctx->frame_queue = NULL;
+    }
+    if (ctx->dataptr_queue) {
+        av_fifo_freep(&ctx->dataptr_queue);
+        ctx->dataptr_queue = NULL;
+    }
+
+    ff_mutex_unlock(&ctx->queue_mutex);
+    ff_mutex_destroy(&ctx->queue_mutex);
+
+    if (avctx->extradata) {
+        av_free(avctx->extradata);
+        avctx->extradata = NULL;
+    }
+
+    if (ctx->hw_frame_ref) {
+        av_buffer_unref(&ctx->hw_frame_ref);
+    }
+
+    if (ctx->hw_device_ref) {
+        av_buffer_unref(&ctx->hw_device_ref);
+    }
+
+    av_log(avctx, AV_LOG_DEBUG, "Encode closed.\n");
+
+    return 0;
+}
+
+
+
+
+
+
+#define OFFSET(x) offsetof(ASCENDEncContext_t, x)
+#ifndef VE
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+#endif
+
+static const AVOption options[] = {
+    { "device_id",      "Use to choose the ascend chip.",                   OFFSET(device_id), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 8, VE},
+    { "channel_id",     "Set channelId of encoder.",                        OFFSET(channel_id), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 127, VE},
+    { "profile",        "0: baseline, 1:main, 2: high. H265 file only support main level.",  OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = 1}, 0, 2, VE},
+    { "rc_mode",        "0: CBR mode, 1: VBR mode.",                        OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 1, VE},
+    { "gop",            "Set gop of encoder.",                              OFFSET(gop), AV_OPT_TYPE_INT, { .i64 = 30}, 1, 65536, VE},
+    { "frame_rate",     "Set input stream frame_rate.",                     OFFSET(frame_rate), AV_OPT_TYPE_INT, { .i64 = 25}, 1, 240, VE},
+    { "max_bit_rate",   "Set max_bite_rate of VBR or average_bit_rate of CBR.", OFFSET(max_bit_rate), AV_OPT_TYPE_INT, { .i64 = 20000}, 2, 614400, VE},
+    { "movement_scene", "0: static scene, 1: movement scene.",              OFFSET(is_movement_scene), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 1, VE},
+    { NULL }
+};
+
+static const AVCodecHWConfigInternal* ascend_hw_configs[] = {
+    &(const AVCodecHWConfigInternal) {
+        .public = {
+            .pix_fmt        = AV_PIX_FMT_ASCEND,
+            .methods        = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX | AV_CODEC_HW_CONFIG_METHOD_INTERNAL,
+            .device_type    = AV_HWDEVICE_TYPE_ASCEND
+        },
+        .hwaccel = NULL,
+    },
+    NULL
+};
+
+#define ASCEND_ENC_CODEC(x, X) \
+    static const AVClass x##_ascend_class = { \
+        .class_name = #x "_ascend_enc", \
+        .item_name = av_default_item_name, \
+        .option = options, \
+        .version = LIBAVUTIL_VERSION_INT, \
+    }; \
+    AVCodec ff_##x##_ascend_encoder = { \
+        .name       = #x "_ascend", \
+        .long_name  = NULL_IF_CONFIG_SMALL("Ascend HiMpi " #X " encoder"), \
+        .type       = AVMEDIA_TYPE_VIDEO, \
+        .id         = AV_CODEC_ID_##X, \
+        .priv_data_size = sizeof(ASCENDEncContext_t), \
+        .priv_class     = &x##_ascend_class, \
+        .init           = ff_himpi_enc_init, \
+        .close          = ff_himpi_enc_close, \
+        .receive_packet = ff_himpi_enc_receive_packet, \
+        .capabilities   = AV_CODEC_CAP_DELAY, \
+        .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP, \
+        .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
+                                                        AV_PIX_FMT_ASCEND, \
+                                                        AV_PIX_FMT_NONE }, \
+        .hw_configs     = ascend_hw_configs, \
+        .wrapper_name   = "ascendenc", \
+    };
+
+#if CONFIG_H264_ASCEND_ENCODER
+ASCEND_ENC_CODEC(h264, H264)
+#endif
+#if CONFIG_H265_ASCEND_ENCODER
+ASCEND_ENC_CODEC(h265, H265)
+#endif
\ No newline at end of file
--- /dev/null
+++ Ascendffmpeg/libavcodec/ascend_enc.h
@@ -0,0 +1,153 @@
+/*
+ * Copyright(c) 2020. Huawei Technologies Co.,Ltd. All rights reserved. 
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except int compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef FFMPEG_ASCEND_ASCEND_ENC_H
+#define FFMPEG_ASCEND_ASCEND_ENC_H
+
+#include <stdint.h>
+#include <unistd.h>
+#include <time.h>
+#include <semaphore.h>
+#include <stdatomic.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <libavutil/hwcontext_ascend.h>
+#include <libavutil/hwcontext.h>
+#include <libavutil/buffer.h>
+#include <libavutil/mathematics.h>
+#include <libavutil/fifo.h>
+#include <libavutil/log.h>
+#include <libavutil/opt.h>
+#include <libavutil/time.h>
+#include <libavutil/common.h>
+#include <libavutil/pixdesc.h>
+#include <libavutil/thread.h>
+#include <libavutil/version.h>
+#include "config.h"
+#include "avcodec.h"
+#include "encode.h"
+#include "hwaccels.h"
+#include "hwconfig.h"
+#include "internal.h"
+#include "libavutil/avutil.h"
+
+#include "acl/dvpp/hi_dvpp.h"
+
+// send
+#define VENC_WIDTH_ALIGN 16
+#define VENC_HEIGHT_ALIGN 2
+#define MAX_VENC_WIDTH 4096
+#define MAX_VENC_HEIGHT 4096
+#define YUV_BGR_SIZE_CONVERT_2 2
+#define YUV_BGR_SIZE_CONVERT_3 3
+#define BUF_SIZE_STRIDE 64
+#define BUF_SIZE_TIMES 10
+#define HI_VENC_CHN_ATTR_STATS_TIME 1
+#define HI_VENC_H264_BASELINE_LEVEL 0
+#define HI_VENC_H264_MAIN_LEVEL 1
+#define HI_VENC_H264_HIGH_LEVEL 2
+#define HI_VENC_H265_MAIN_LEVEL 0
+#define HI_ODD_NUM_3 3
+#define TIMESTAMP_QUEUE_SIZE 100
+#define MAX_HIMPI_VENC_CHN_NUM 127
+#define FIRST_FRAME_START_QP 32
+#define THRESHOLD_OF_ENCODE_RATE_VECTOR_LEN 16
+#define THRESHOLD_OF_ENCODE_RATE 255
+#define VENC_SEND_STREAM_TIMEOUT 1000
+
+//receive
+#define HI_SYS_CREATE_EPOLL_SIZE 10
+#define HI_MPI_SYS_WAIT_EPOLL_MAX_EVENTS 3
+#define HI_DVPP_EPOLL_EVENT 1024
+#define HI_DVPP_EPOLL_EVENT_NUM 1000
+#define WAIT_TILL_TIMEOUT 1000
+#define WAIT_GET_TILL_TIMEOUT 100
+#define MAX_MEMORY_SIZE 2147483648
+#define MAX_PACK_COUNT 100
+
+typedef enum {
+    EVENT_NEW_FRAME = 0,
+    EVENT_EOS = 1,
+} eventType_t;
+
+typedef struct StreamInfo {
+    void *ascend_ctx;
+    eventType_t event_type;
+    uint8_t* data;
+    uint32_t data_size;
+    int64_t pts;
+    hi_venc_data_type data_type;
+    uint32_t len;
+    int is_frame_end;
+} StreamInfo_t;
+
+typedef struct ASCENDEncContext {
+    AVClass                         *av_class;
+    AVCodecContext                  *avctx;
+    int                             device_id;
+    int                             channel_id;
+    pthread_t                       thread_id;
+    int                             encoder_flushing;
+    int                             codec_abort_flag;
+    volatile int                    thread_run_flag;
+    volatile int                    encode_run_flag;
+    volatile int                    eos_post_flag;
+    volatile int                    eos_received;
+    volatile int                    hi_mpi_init_flag;
+    volatile int                    frame_send_sum;
+
+    hi_venc_chn_attr                chn_attr_;
+    int                             profile;
+    int                             rc_mode;
+    int                             gop;
+    int                             frame_rate;
+    int                             max_bit_rate;
+    int                             is_movement_scene;
+
+    int                             coded_width;
+    int                             coded_height;
+    sem_t                           eos_sema;
+
+    AVFifoBuffer                    *frame_queue;
+    AVFifoBuffer                    *dataptr_queue;
+    AVMutex                         queue_mutex;
+
+    AVBufferRef                     *hw_frame_ref;
+    AVBufferRef                     *hw_device_ref;
+
+    AscendContext                   *ascend_ctx;
+    AVASCENDDeviceContext           *hw_device_ctx;
+    AVHWFramesContext               *hw_frame_ctx;
+    enum AVPixelFormat              in_sw_pixfmt;
+
+} ASCENDEncContext_t;
+
+static inline void get_venc_stream_info(StreamInfo_t *stream_info, hi_venc_stream stream)
+{
+    stream_info->data         = stream.pack[0].addr + stream.pack[0].offset;
+    stream_info->pts          = stream.pack[0].pts;
+    stream_info->len          = stream.pack[0].len;
+    stream_info->is_frame_end = stream.pack[0].is_frame_end;
+    stream_info->data_type    = stream.pack[0].data_type;
+    stream_info->data_size    = stream.pack[0].len - stream.pack[0].offset;
+}
+
+#endif // FFMPEG_ASCEND_ASCEND_ENC_H
\ No newline at end of file
--- FFmpeg-n4.4.4/libavcodec/av1.h
+++ Ascendffmpeg/libavcodec/av1.h
@@ -114,13 +114,6 @@
     AV1_WARP_MODEL_TRANSLATION = 1,
     AV1_WARP_MODEL_ROTZOOM     = 2,
     AV1_WARP_MODEL_AFFINE      = 3,
-    AV1_WARP_PARAM_REDUCE_BITS = 6,
-
-    AV1_DIV_LUT_BITS      = 8,
-    AV1_DIV_LUT_PREC_BITS = 14,
-    AV1_DIV_LUT_NUM       = 257,
-
-    AV1_MAX_LOOP_FILTER = 63,
 };
 
 
--- FFmpeg-n4.4.4/libavcodec/av1dec.c
+++ Ascendffmpeg/libavcodec/av1dec.c
@@ -28,34 +28,6 @@
 #include "internal.h"
 #include "profiles.h"
 
-/**< same with Div_Lut defined in spec 7.11.3.7 */
-static const uint16_t div_lut[AV1_DIV_LUT_NUM] = {
-  16384, 16320, 16257, 16194, 16132, 16070, 16009, 15948, 15888, 15828, 15768,
-  15709, 15650, 15592, 15534, 15477, 15420, 15364, 15308, 15252, 15197, 15142,
-  15087, 15033, 14980, 14926, 14873, 14821, 14769, 14717, 14665, 14614, 14564,
-  14513, 14463, 14413, 14364, 14315, 14266, 14218, 14170, 14122, 14075, 14028,
-  13981, 13935, 13888, 13843, 13797, 13752, 13707, 13662, 13618, 13574, 13530,
-  13487, 13443, 13400, 13358, 13315, 13273, 13231, 13190, 13148, 13107, 13066,
-  13026, 12985, 12945, 12906, 12866, 12827, 12788, 12749, 12710, 12672, 12633,
-  12596, 12558, 12520, 12483, 12446, 12409, 12373, 12336, 12300, 12264, 12228,
-  12193, 12157, 12122, 12087, 12053, 12018, 11984, 11950, 11916, 11882, 11848,
-  11815, 11782, 11749, 11716, 11683, 11651, 11619, 11586, 11555, 11523, 11491,
-  11460, 11429, 11398, 11367, 11336, 11305, 11275, 11245, 11215, 11185, 11155,
-  11125, 11096, 11067, 11038, 11009, 10980, 10951, 10923, 10894, 10866, 10838,
-  10810, 10782, 10755, 10727, 10700, 10673, 10645, 10618, 10592, 10565, 10538,
-  10512, 10486, 10460, 10434, 10408, 10382, 10356, 10331, 10305, 10280, 10255,
-  10230, 10205, 10180, 10156, 10131, 10107, 10082, 10058, 10034, 10010, 9986,
-  9963,  9939,  9916,  9892,  9869,  9846,  9823,  9800,  9777,  9754,  9732,
-  9709,  9687,  9664,  9642,  9620,  9598,  9576,  9554,  9533,  9511,  9489,
-  9468,  9447,  9425,  9404,  9383,  9362,  9341,  9321,  9300,  9279,  9259,
-  9239,  9218,  9198,  9178,  9158,  9138,  9118,  9098,  9079,  9059,  9039,
-  9020,  9001,  8981,  8962,  8943,  8924,  8905,  8886,  8867,  8849,  8830,
-  8812,  8793,  8775,  8756,  8738,  8720,  8702,  8684,  8666,  8648,  8630,
-  8613,  8595,  8577,  8560,  8542,  8525,  8508,  8490,  8473,  8456,  8439,
-  8422,  8405,  8389,  8372,  8355,  8339,  8322,  8306,  8289,  8273,  8257,
-  8240,  8224,  8208,  8192
-};
-
 static uint32_t inverse_recenter(int r, uint32_t v)
 {
     if (v > 2 * r)
@@ -125,71 +97,7 @@
                                        -mx, mx + 1, r) << prec_diff) + round;
 }
 
-static uint64_t round_two(uint64_t x, uint16_t n)
-{
-    if (n == 0)
-        return x;
-    return ((x + ((uint64_t)1 << (n - 1))) >> n);
-}
-
-static int64_t round_two_signed(int64_t x, uint16_t n)
-{
-    return ((x<0) ? -((int64_t)round_two(-x, n)) : (int64_t)round_two(x, n));
-}
-
 /**
- * Resolve divisor process.
- * see spec 7.11.3.7
- */
-static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
-{
-    int32_t e, f;
-
-    *shift = av_log2(d);
-    e = d - (1 << (*shift));
-    if (*shift > AV1_DIV_LUT_BITS)
-        f = round_two(e, *shift - AV1_DIV_LUT_BITS);
-    else
-        f = e << (AV1_DIV_LUT_BITS - (*shift));
-
-    *shift += AV1_DIV_LUT_PREC_BITS;
-
-    return div_lut[f];
-}
-
-/**
- * check if global motion params is valid.
- * see spec 7.11.3.6
- */
-static uint8_t get_shear_params_valid(AV1DecContext *s, int idx)
-{
-    int16_t alpha, beta, gamma, delta, divf, divs;
-    int64_t v, w;
-    int32_t *param = &s->cur_frame.gm_params[idx][0];
-    if (param[2] < 0)
-        return 0;
-
-    alpha = av_clip_int16(param[2] - (1 << AV1_WARPEDMODEL_PREC_BITS));
-    beta  = av_clip_int16(param[3]);
-    divf  = resolve_divisor(abs(param[2]), &divs);
-    v     = (int64_t)param[4] * (1 << AV1_WARPEDMODEL_PREC_BITS);
-    w     = (int64_t)param[3] * param[4];
-    gamma = av_clip_int16((int)round_two_signed((v * divf), divs));
-    delta = av_clip_int16(param[5] - (int)round_two_signed((w * divf), divs) - (1 << AV1_WARPEDMODEL_PREC_BITS));
-
-    alpha = round_two_signed(alpha, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
-    beta  = round_two_signed(beta,  AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
-    gamma = round_two_signed(gamma, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
-    delta = round_two_signed(delta, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
-
-    if ((4 * abs(alpha) + 7 * abs(beta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS) ||
-        (4 * abs(gamma) + 4 * abs(delta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS))
-        return 0;
-
-    return 1;
-}
-
-/**
 * update gm type/params, since cbs already implemented part of this funcation,
 * so we don't need to full implement spec.
 */
@@ -236,9 +144,6 @@
             read_global_param(s, type, ref, 0);
             read_global_param(s, type, ref, 1);
         }
-        if (type <= AV1_WARP_MODEL_AFFINE) {
-            s->cur_frame.gm_invalid[ref] = !get_shear_params_valid(s, ref);
-        }
     }
 }
 
@@ -604,9 +509,6 @@
 
     dst->spatial_id = src->spatial_id;
     dst->temporal_id = src->temporal_id;
-    memcpy(dst->gm_invalid,
-           src->gm_invalid,
-           AV1_NUM_REF_FRAMES * sizeof(uint8_t));
     memcpy(dst->gm_type,
            src->gm_type,
            AV1_NUM_REF_FRAMES * sizeof(uint8_t));
--- FFmpeg-n4.4.4/libavcodec/av1dec.h
+++ Ascendffmpeg/libavcodec/av1dec.h
@@ -42,7 +42,6 @@
     int temporal_id;
     int spatial_id;
 
-    uint8_t gm_invalid[AV1_NUM_REF_FRAMES];
     uint8_t gm_type[AV1_NUM_REF_FRAMES];
     int32_t gm_params[AV1_NUM_REF_FRAMES][6];
 
--- FFmpeg-n4.4.4/libavcodec/bink.c
+++ Ascendffmpeg/libavcodec/bink.c
@@ -869,7 +869,7 @@
 
     binkb_init_bundles(c);
     ref_start = frame->data[plane_idx];
-    ref_end   = frame->data[plane_idx] + ((bh - 1) * frame->linesize[plane_idx] + bw - 1) * 8;
+    ref_end   = frame->data[plane_idx] + (bh * frame->linesize[plane_idx] + bw) * 8;
 
     for (i = 0; i < 64; i++)
         coordmap[i] = (i & 7) + (i >> 3) * stride;
@@ -925,7 +925,7 @@
                 xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
                 yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias;
                 ref = dst + xoff + yoff * stride;
-                if (ref < ref_start || ref > ref_end) {
+                if (ref < ref_start || ref + 8*stride > ref_end) {
                     av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
                 } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
                     c->put_pixels_tab(dst, ref, stride, 8);
@@ -941,7 +941,7 @@
                 xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
                 yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias;
                 ref = dst + xoff + yoff * stride;
-                if (ref < ref_start || ref > ref_end) {
+                if (ref < ref_start || ref + 8 * stride > ref_end) {
                     av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
                 } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
                     c->put_pixels_tab(dst, ref, stride, 8);
@@ -973,7 +973,7 @@
                 xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
                 yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias;
                 ref = dst + xoff + yoff * stride;
-                if (ref < ref_start || ref > ref_end) {
+                if (ref < ref_start || ref + 8 * stride > ref_end) {
                     av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
                 } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
                     c->put_pixels_tab(dst, ref, stride, 8);
@@ -1086,7 +1086,7 @@
         for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
             blk = get_value(c, BINK_SRC_BLOCK_TYPES);
             // 16x16 block type on odd line means part of the already decoded block, so skip it
-            if (((by & 1) || (bx & 1)) && blk == SCALED_BLOCK) {
+            if ((by & 1) && blk == SCALED_BLOCK) {
                 bx++;
                 dst  += 8;
                 prev += 8;
--- FFmpeg-n4.4.4/libavcodec/cbs_av1_syntax_template.c
+++ Ascendffmpeg/libavcodec/cbs_av1_syntax_template.c
@@ -355,7 +355,7 @@
         AV1_REF_FRAME_ALTREF2, AV1_REF_FRAME_ALTREF
     };
     int8_t ref_frame_idx[AV1_REFS_PER_FRAME], used_frame[AV1_NUM_REF_FRAMES];
-    int16_t shifted_order_hints[AV1_NUM_REF_FRAMES];
+    int8_t shifted_order_hints[AV1_NUM_REF_FRAMES];
     int cur_frame_hint, latest_order_hint, earliest_order_hint, ref;
     int i, j;
 
--- FFmpeg-n4.4.4/libavcodec/cdgraphics.c
+++ Ascendffmpeg/libavcodec/cdgraphics.c
@@ -239,7 +239,7 @@
     for (y = FFMAX(0, vinc); y < FFMIN(CDG_FULL_HEIGHT + vinc, CDG_FULL_HEIGHT); y++)
         memcpy(out + FFMAX(0, hinc) + stride * y,
                in + FFMAX(0, hinc) - hinc + (y - vinc) * stride,
-               FFABS(stride) - FFABS(hinc));
+               FFMIN(stride + hinc, stride));
 
     if (vinc > 0)
         cdg_fill_wrapper(0, 0, out,
--- FFmpeg-n4.4.4/libavcodec/cfhd.c
+++ Ascendffmpeg/libavcodec/cfhd.c
@@ -838,7 +838,7 @@
                             const uint16_t q = s->quantisation;
 
                             for (i = 0; i < run; i++) {
-                                *coeff_data |= coeff * 256U;
+                                *coeff_data |= coeff * 256;
                                 *coeff_data++ *= q;
                             }
                         } else {
@@ -869,7 +869,7 @@
                             const uint16_t q = s->quantisation;
 
                             for (i = 0; i < run; i++) {
-                                *coeff_data |= coeff * 256U;
+                                *coeff_data |= coeff * 256;
                                 *coeff_data++ *= q;
                             }
                         } else {
--- FFmpeg-n4.4.4/libavcodec/diracdec.c
+++ Ascendffmpeg/libavcodec/diracdec.c
@@ -1432,8 +1432,8 @@
     int *c      = s->globalmc[ref].perspective;
 
     int64_t m   = (1<<ep) - (c[0]*(int64_t)x + c[1]*(int64_t)y);
-    int64_t mx  = m * (uint64_t)((A[0][0] * (int64_t)x + A[0][1]*(int64_t)y) + (1LL<<ez) * b[0]);
-    int64_t my  = m * (uint64_t)((A[1][0] * (int64_t)x + A[1][1]*(int64_t)y) + (1LL<<ez) * b[1]);
+    int64_t mx  = m * (int64_t)((A[0][0] * (int64_t)x + A[0][1]*(int64_t)y) + (1LL<<ez) * b[0]);
+    int64_t my  = m * (int64_t)((A[1][0] * (int64_t)x + A[1][1]*(int64_t)y) + (1LL<<ez) * b[1]);
 
     block->u.mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep);
     block->u.mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep);
--- FFmpeg-n4.4.4/libavcodec/dnxhdenc.c
+++ Ascendffmpeg/libavcodec/dnxhdenc.c
@@ -1353,7 +1353,7 @@
     av_freep(&ctx->qmatrix_c16);
     av_freep(&ctx->qmatrix_l16);
 
-    if (ctx->thread[1]) {
+    if (avctx->active_thread_type == FF_THREAD_SLICE) {
         for (i = 1; i < avctx->thread_count; i++)
             av_freep(&ctx->thread[i]);
     }
--- FFmpeg-n4.4.4/libavcodec/dstdec.c
+++ Ascendffmpeg/libavcodec/dstdec.c
@@ -215,7 +215,7 @@
     return (ff_reverse[c & 127] >> 1) + 1;
 }
 
-static int build_filter(int16_t table[DST_MAX_ELEMENTS][16][256], const Table *fsets)
+static void build_filter(int16_t table[DST_MAX_ELEMENTS][16][256], const Table *fsets)
 {
     int i, j, k, l;
 
@@ -226,17 +226,14 @@
             int total = av_clip(length - j * 8, 0, 8);
 
             for (k = 0; k < 256; k++) {
-                int64_t v = 0;
+                int v = 0;
 
                 for (l = 0; l < total; l++)
                     v += (((k >> l) & 1) * 2 - 1) * fsets->coeff[i][j * 8 + l];
-                if ((int16_t)v != v)
-                    return AVERROR_INVALIDDATA;
                 table[i][j][k] = v;
             }
         }
     }
-    return 0;
 }
 
 static int decode_frame(AVCodecContext *avctx, void *data,
@@ -332,9 +329,7 @@
         return AVERROR_INVALIDDATA;
     ac_init(ac, gb);
 
-    ret = build_filter(s->filter, &s->fsets);
-    if (ret < 0)
-        return ret;
+    build_filter(s->filter, &s->fsets);
 
     memset(s->status, 0xAA, sizeof(s->status));
     memset(dsd, 0, frame->nb_samples * 4 * channels);
--- FFmpeg-n4.4.4/libavcodec/dxva2_av1.c
+++ Ascendffmpeg/libavcodec/dxva2_av1.c
@@ -139,7 +139,7 @@
         pp->frame_refs[i].Index  = ref_frame->buf[0] ? ref_idx : 0xFF;
 
         /* Global Motion */
-        pp->frame_refs[i].wminvalid = h->cur_frame.gm_invalid[AV1_REF_FRAME_LAST + i];
+        pp->frame_refs[i].wminvalid = (h->cur_frame.gm_type[AV1_REF_FRAME_LAST + i] == AV1_WARP_MODEL_IDENTITY);
         pp->frame_refs[i].wmtype    = h->cur_frame.gm_type[AV1_REF_FRAME_LAST + i];
         for (j = 0; j < 6; ++j) {
              pp->frame_refs[i].wmmat[j] = h->cur_frame.gm_params[AV1_REF_FRAME_LAST + i][j];
--- FFmpeg-n4.4.4/libavcodec/eac3dec.c
+++ Ascendffmpeg/libavcodec/eac3dec.c
@@ -139,11 +139,9 @@
             // spx_noise_blend and spx_signal_blend are both FP.23
             nscale *= 1.0 / (1<<23);
             sscale *= 1.0 / (1<<23);
-            if (nscale < -1.0)
-                nscale = -1.0;
 #endif
             for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
-                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
+                float noise  = nscale * (int32_t)av_lfg_get(&s->dith_state);
                 s->transform_coeffs[ch][bin]   *= sscale;
                 s->transform_coeffs[ch][bin++] += noise;
             }
--- FFmpeg-n4.4.4/libavcodec/eatgq.c
+++ Ascendffmpeg/libavcodec/eatgq.c
@@ -61,7 +61,7 @@
     return 0;
 }
 
-static int tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb)
+static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb)
 {
     uint8_t *perm = s->scantable.permutated;
     int i, j, value;
@@ -69,8 +69,6 @@
     for (i = 1; i < 64;) {
         switch (show_bits(gb, 3)) {
         case 4:
-            if (i >= 63)
-                return AVERROR_INVALIDDATA;
             block[perm[i++]] = 0;
         case 0:
             block[perm[i++]] = 0;
@@ -80,8 +78,6 @@
         case 1:
             skip_bits(gb, 2);
             value = get_bits(gb, 6);
-            if (value > 64 - i)
-                return AVERROR_INVALIDDATA;
             for (j = 0; j < value; j++)
                 block[perm[i++]] = 0;
             break;
@@ -109,7 +105,6 @@
         }
     }
     block[0] += 128 << 4;
-    return 0;
 }
 
 static void tgq_idct_put_mb(TgqContext *s, int16_t (*block)[64], AVFrame *frame,
@@ -169,11 +164,8 @@
         if (ret < 0)
             return ret;
 
-        for (i = 0; i < 6; i++) {
-            int ret = tgq_decode_block(s, s->block[i], &gb);
-            if (ret < 0)
-                return ret;
-        }
+        for (i = 0; i < 6; i++)
+            tgq_decode_block(s, s->block[i], &gb);
         tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y);
         bytestream2_skip(&s->gb, mode);
     } else {
--- FFmpeg-n4.4.4/libavcodec/escape124.c
+++ Ascendffmpeg/libavcodec/escape124.c
@@ -88,6 +88,11 @@
     unsigned i, j;
     CodeBook cb = { 0 };
 
+    if (size >= INT_MAX / 34 || get_bits_left(gb) < size * 34)
+        return cb;
+
+    if (size >= INT_MAX / sizeof(MacroBlock))
+        return cb;
     cb.blocks = av_malloc(size ? size * sizeof(MacroBlock) : 1);
     if (!cb.blocks)
         return cb;
@@ -221,7 +226,7 @@
     // represent a lower bound of the space needed for skipped superblocks. Non
     // skipped SBs need more space.
     if (get_bits_left(&gb) < 64 + s->num_superblocks * 23LL / 4320)
-        return AVERROR_INVALIDDATA;
+        return -1;
 
     frame_flags = get_bits_long(&gb, 32);
     frame_size  = get_bits_long(&gb, 32);
@@ -272,14 +277,9 @@
             }
 
             av_freep(&s->codebooks[i].blocks);
-            if (cb_size >= INT_MAX / 34 || get_bits_left(&gb) < (int)cb_size * 34)
-                return AVERROR_INVALIDDATA;
-
-            if (cb_size >= INT_MAX / sizeof(MacroBlock))
-                return AVERROR_INVALIDDATA;
             s->codebooks[i] = unpack_codebook(&gb, cb_depth, cb_size);
             if (!s->codebooks[i].blocks)
-                return AVERROR(ENOMEM);
+                return -1;
         }
     }
 
--- FFmpeg-n4.4.4/libavcodec/exr.c
+++ Ascendffmpeg/libavcodec/exr.c
@@ -1240,8 +1240,7 @@
         td->ysize = FFMIN(s->tile_attr.ySize, s->ydelta - tile_y * s->tile_attr.ySize);
         td->xsize = FFMIN(s->tile_attr.xSize, s->xdelta - tile_x * s->tile_attr.xSize);
 
-        if (td->xsize * (uint64_t)s->current_channel_offset > INT_MAX ||
-            av_image_check_size2(td->xsize, td->ysize, s->avctx->max_pixels, AV_PIX_FMT_NONE, 0, s->avctx) < 0)
+        if (td->xsize * (uint64_t)s->current_channel_offset > INT_MAX)
             return AVERROR_INVALIDDATA;
 
         td->channel_line_size = td->xsize * s->current_channel_offset;/* uncompress size of one line */
@@ -1265,8 +1264,7 @@
         td->ysize          = FFMIN(s->scan_lines_per_block, s->ymax - line + 1); /* s->ydelta - line ?? */
         td->xsize          = s->xdelta;
 
-        if (td->xsize * (uint64_t)s->current_channel_offset > INT_MAX ||
-            av_image_check_size2(td->xsize, td->ysize, s->avctx->max_pixels, AV_PIX_FMT_NONE, 0, s->avctx) < 0)
+        if (td->xsize * (uint64_t)s->current_channel_offset > INT_MAX)
             return AVERROR_INVALIDDATA;
 
         td->channel_line_size = td->xsize * s->current_channel_offset;/* uncompress size of one line */
@@ -1831,8 +1829,8 @@
             dx = bytestream2_get_le32(gb);
             dy = bytestream2_get_le32(gb);
 
-            s->w = (unsigned)dx - sx + 1;
-            s->h = (unsigned)dy - sy + 1;
+            s->w = dx - sx + 1;
+            s->h = dy - sy + 1;
 
             continue;
         } else if ((var_size = check_header_variable(s, "lineOrder",
@@ -1947,12 +1945,9 @@
                                                      "preview", 16)) >= 0) {
             uint32_t pw = bytestream2_get_le32(gb);
             uint32_t ph = bytestream2_get_le32(gb);
-            uint64_t psize = pw * ph;
-            if (psize > INT64_MAX / 4)
-                return AVERROR_INVALIDDATA;
-            psize *= 4;
+            int64_t psize = 4LL * pw * ph;
 
-            if ((int64_t)psize >= bytestream2_get_bytes_left(gb))
+            if (psize >= bytestream2_get_bytes_left(gb))
                 return AVERROR_INVALIDDATA;
 
             bytestream2_skip(gb, psize);
--- FFmpeg-n4.4.4/libavcodec/ffv1dec.c
+++ Ascendffmpeg/libavcodec/ffv1dec.c
@@ -166,35 +166,25 @@
     RangeCoder *c = &fs->c;
     uint8_t state[CONTEXT_SIZE];
     unsigned ps, i, context_count;
-    int sx, sy, sw, sh;
-
     memset(state, 128, sizeof(state));
-    sx = get_symbol(c, state, 0);
-    sy = get_symbol(c, state, 0);
-    sw = get_symbol(c, state, 0) + 1U;
-    sh = get_symbol(c, state, 0) + 1U;
 
     av_assert0(f->version > 2);
 
+    fs->slice_x      =  get_symbol(c, state, 0)      * f->width ;
+    fs->slice_y      =  get_symbol(c, state, 0)      * f->height;
+    fs->slice_width  = (get_symbol(c, state, 0) + 1) * f->width  + fs->slice_x;
+    fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y;
 
-    if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
-        return AVERROR_INVALIDDATA;
-    if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
-        return AVERROR_INVALIDDATA;
+    fs->slice_x /= f->num_h_slices;
+    fs->slice_y /= f->num_v_slices;
+    fs->slice_width  = fs->slice_width /f->num_h_slices - fs->slice_x;
+    fs->slice_height = fs->slice_height/f->num_v_slices - fs->slice_y;
+    if ((unsigned)fs->slice_width > f->width || (unsigned)fs->slice_height > f->height)
+        return -1;
+    if (    (unsigned)fs->slice_x + (uint64_t)fs->slice_width  > f->width
+         || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)
+        return -1;
 
-    fs->slice_x      =  sx       * (int64_t)f->width  / f->num_h_slices;
-    fs->slice_y      =  sy       * (int64_t)f->height / f->num_v_slices;
-    fs->slice_width  = (sx + sw) * (int64_t)f->width  / f->num_h_slices - fs->slice_x;
-    fs->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - fs->slice_y;
-
-    av_assert0((unsigned)fs->slice_width  <= f->width &&
-                (unsigned)fs->slice_height <= f->height);
-    av_assert0 (   (unsigned)fs->slice_x + (uint64_t)fs->slice_width  <= f->width
-                && (unsigned)fs->slice_y + (uint64_t)fs->slice_height <= f->height);
-
-    if (fs->ac == AC_GOLOMB_RICE && fs->slice_width >= (1<<23))
-        return AVERROR_INVALIDDATA;
-
     for (i = 0; i < f->plane_count; i++) {
         PlaneContext * const p = &fs->plane[i];
         int idx = get_symbol(c, state, 0);
@@ -308,11 +298,8 @@
     }
     if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)
         return ret;
-    if (f->cur->key_frame || fs->slice_reset_contexts) {
+    if (f->cur->key_frame || fs->slice_reset_contexts)
         ff_ffv1_clear_slice_state(f, fs);
-    } else if (fs->slice_damaged) {
-        return AVERROR_INVALIDDATA;
-    }
 
     width  = fs->slice_width;
     height = fs->slice_height;
@@ -475,11 +462,6 @@
         return AVERROR_INVALIDDATA;
     }
 
-    if (f->num_h_slices > MAX_SLICES / f->num_v_slices) {
-        av_log(f->avctx, AV_LOG_ERROR, "slice count unsupported\n");
-        return AVERROR_PATCHWELCOME;
-    }
-
     f->quant_table_count = get_symbol(c, state, 0);
     if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) {
         av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count);
@@ -782,25 +764,21 @@
         fs->slice_damaged = 0;
 
         if (f->version == 2) {
-            int sx = get_symbol(c, state, 0);
-            int sy = get_symbol(c, state, 0);
-            int sw = get_symbol(c, state, 0) + 1U;
-            int sh = get_symbol(c, state, 0) + 1U;
+            fs->slice_x      =  get_symbol(c, state, 0)      * f->width ;
+            fs->slice_y      =  get_symbol(c, state, 0)      * f->height;
+            fs->slice_width  = (get_symbol(c, state, 0) + 1) * f->width  + fs->slice_x;
+            fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y;
 
-            if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
+            fs->slice_x     /= f->num_h_slices;
+            fs->slice_y     /= f->num_v_slices;
+            fs->slice_width  = fs->slice_width  / f->num_h_slices - fs->slice_x;
+            fs->slice_height = fs->slice_height / f->num_v_slices - fs->slice_y;
+            if ((unsigned)fs->slice_width  > f->width ||
+                (unsigned)fs->slice_height > f->height)
                 return AVERROR_INVALIDDATA;
-            if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
+            if (   (unsigned)fs->slice_x + (uint64_t)fs->slice_width  > f->width
+                || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)
                 return AVERROR_INVALIDDATA;
-
-            fs->slice_x      =  sx       * (int64_t)f->width  / f->num_h_slices;
-            fs->slice_y      =  sy       * (int64_t)f->height / f->num_v_slices;
-            fs->slice_width  = (sx + sw) * (int64_t)f->width  / f->num_h_slices - fs->slice_x;
-            fs->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - fs->slice_y;
-
-            av_assert0((unsigned)fs->slice_width  <= f->width &&
-                       (unsigned)fs->slice_height <= f->height);
-            av_assert0 (   (unsigned)fs->slice_x + (uint64_t)fs->slice_width  <= f->width
-                        && (unsigned)fs->slice_y + (uint64_t)fs->slice_height <= f->height);
         }
 
         for (i = 0; i < f->plane_count; i++) {
--- FFmpeg-n4.4.4/libavcodec/ffv1dec_template.c
+++ Ascendffmpeg/libavcodec/ffv1dec_template.c
@@ -93,11 +93,11 @@
                         run_count--;
                     }
                 } else {
-                    while (run_count > 1 && w-x > 1) {
-                        sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
-                        x++;
-                        run_count--;
-                    }
+                while (run_count > 1 && w-x > 1) {
+                    sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
+                    x++;
+                    run_count--;
+                }
                 }
                 run_count--;
                 if (run_count < 0) {
--- FFmpeg-n4.4.4/libavcodec/fmvc.c
+++ Ascendffmpeg/libavcodec/fmvc.c
@@ -401,17 +401,20 @@
     PutByteContext *pb = &s->pb;
     AVFrame *frame = data;
     int ret, y, x;
-    int key_frame;
 
     if (avpkt->size < 8)
         return AVERROR_INVALIDDATA;
 
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+        return ret;
+
     bytestream2_init(gb, avpkt->data, avpkt->size);
     bytestream2_skip(gb, 2);
 
-    key_frame = !!bytestream2_get_le16(gb);
+    frame->key_frame = !!bytestream2_get_le16(gb);
+    frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
-    if (key_frame) {
+    if (frame->key_frame) {
         const uint8_t *src;
         unsigned type, size;
         uint8_t *dst;
@@ -431,12 +434,6 @@
             return AVERROR_PATCHWELCOME;
         }
 
-        if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
-            return ret;
-
-        frame->key_frame = 1;
-        frame->pict_type = AV_PICTURE_TYPE_I;
-
         src = s->buffer;
         dst = frame->data[0] + (avctx->height - 1) * frame->linesize[0];
         for (y = 0; y < avctx->height; y++) {
@@ -516,12 +513,6 @@
             }
             dst = &rect[block_h * s->stride];
         }
-
-        if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
-            return ret;
-
-        frame->key_frame = 0;
-        frame->pict_type = AV_PICTURE_TYPE_P;
 
         ssrc = s->buffer;
         ddst = frame->data[0] + (avctx->height - 1) * frame->linesize[0];
--- FFmpeg-n4.4.4/libavcodec/g729_parser.c
+++ Ascendffmpeg/libavcodec/g729_parser.c
@@ -49,9 +49,6 @@
         s->block_size = (avctx->bit_rate < 8000) ? G729D_6K4_BLOCK_SIZE : G729_8K_BLOCK_SIZE;
         if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)
             s->block_size++;
-        // channels > 2 is invalid, we pass the packet on unchanged
-        if (avctx->channels > 2)
-            s->block_size = 0;
         s->block_size *= avctx->channels;
         s->duration   = avctx->frame_size;
     }
--- FFmpeg-n4.4.4/libavcodec/h263.h
+++ Ascendffmpeg/libavcodec/h263.h
@@ -100,16 +100,15 @@
 
 
 static inline int h263_get_motion_length(int val, int f_code){
-    int bit_size, code, sign;
+    int l, bit_size, code;
 
     if (val == 0) {
         return ff_mvtab[0][1];
     } else {
         bit_size = f_code - 1;
         /* modulo encoding */
-        val  = sign_extend(val, 6 + bit_size);
-        sign = val >> 31;
-        val  = (val ^ sign) - sign; /* val = FFABS(val) */
+        l= INT_BIT - 6 - bit_size;
+        val = (val<<l)>>l;
         val--;
         code = (val >> bit_size) + 1;
 
--- FFmpeg-n4.4.4/libavcodec/h263dec.c
+++ Ascendffmpeg/libavcodec/h263dec.c
@@ -545,8 +545,6 @@
     avctx->has_b_frames = !s->low_delay;
 
     if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
-        if (s->pict_type != AV_PICTURE_TYPE_B && s->mb_num/2 > get_bits_left(&s->gb))
-            return AVERROR_INVALIDDATA;
         if (ff_mpeg4_workaround_bugs(avctx) == 1)
             goto retry;
         if (s->studio_profile != (s->idsp.idct == NULL))
--- FFmpeg-n4.4.4/libavcodec/h264dec.c
+++ Ascendffmpeg/libavcodec/h264dec.c
@@ -654,10 +654,6 @@
             avpriv_request_sample(avctx, "data partitioning");
             break;
         case H264_NAL_SEI:
-            if (h->setup_finished) {
-                avpriv_request_sample(avctx, "Late SEI");
-                break;
-            }
             ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx);
             h->has_recovery_point = h->has_recovery_point || h->sei.recovery_point.recovery_frame_cnt != -1;
             if (avctx->debug & FF_DEBUG_GREEN_MD)
--- FFmpeg-n4.4.4/libavcodec/hevc_filter.c
+++ Ascendffmpeg/libavcodec/hevc_filter.c
@@ -145,21 +145,10 @@
 
     if (((intptr_t)dst | (intptr_t)src | stride_dst | stride_src) & 15) {
         for (i = 0; i < height; i++) {
-            for (j = 0; j < width - 7; j+=8)
+            for (j = 0; j < width; j+=8)
                 AV_COPY64U(dst+j, src+j);
             dst += stride_dst;
             src += stride_src;
-        }
-        if (width&7) {
-            dst += ((width>>3)<<3) - stride_dst * height;
-            src += ((width>>3)<<3) - stride_src * height;
-            width &= 7;
-            for (i = 0; i < height; i++) {
-                for (j = 0; j < width; j++)
-                    dst[j] = src[j];
-                dst += stride_dst;
-                src += stride_src;
-            }
         }
     } else {
         for (i = 0; i < height; i++) {
--- FFmpeg-n4.4.4/libavcodec/hevcdec.c
+++ Ascendffmpeg/libavcodec/hevcdec.c
@@ -3338,7 +3338,7 @@
         }
     } else {
         /* verify the SEI checksum */
-        if (avctx->err_recognition & AV_EF_CRCCHECK && s->ref && s->is_decoded &&
+        if (avctx->err_recognition & AV_EF_CRCCHECK && s->is_decoded &&
             s->sei.picture_hash.is_md5) {
             ret = verify_md5(s, s->ref->frame);
             if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) {
--- FFmpeg-n4.4.4/libavcodec/hevcdsp_template.c
+++ Ascendffmpeg/libavcodec/hevcdsp_template.c
@@ -313,7 +313,7 @@
         offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
     for (y = 0; y < height; y++) {
         for (x = 0; x < width; x++)
-            dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
+            dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
         dst += stride_dst;
         src += stride_src;
     }
--- FFmpeg-n4.4.4/libavcodec/hwaccels.h
+++ Ascendffmpeg/libavcodec/hwaccels.h
@@ -35,6 +35,7 @@
 extern const AVHWAccel ff_h264_vaapi_hwaccel;
 extern const AVHWAccel ff_h264_vdpau_hwaccel;
 extern const AVHWAccel ff_h264_videotoolbox_hwaccel;
+extern const AVHWAccel ff_h264_ascend_hwaccel;
 extern const AVHWAccel ff_hevc_d3d11va_hwaccel;
 extern const AVHWAccel ff_hevc_d3d11va2_hwaccel;
 extern const AVHWAccel ff_hevc_dxva2_hwaccel;
--- FFmpeg-n4.4.4/libavcodec/hwconfig.h
+++ Ascendffmpeg/libavcodec/hwconfig.h
@@ -80,6 +80,8 @@
     HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD,  NONE,         ff_ ## codec ## _d3d11va_hwaccel)
 #define HWACCEL_XVMC(codec) \
     HW_CONFIG_HWACCEL(0, 0, 1, XVMC,         NONE,         ff_ ## codec ## _xvmc_hwaccel)
+#define HWACCEL_ASCEND(codec) \
+    HW_CONFIG_HWACCEL(0, 0, 0, ASCEND,       ASCEND,       ff_ ## codec ## _ascend_hwaccel)
 
 #define HW_CONFIG_ENCODER(device, frames, ad_hoc, format, device_type_) \
     &(const AVCodecHWConfigInternal) { \
--- FFmpeg-n4.4.4/libavcodec/jpeglsdec.c
+++ Ascendffmpeg/libavcodec/jpeglsdec.c
@@ -67,7 +67,7 @@
         s->t3     = get_bits(&s->gb, 16);
         s->reset  = get_bits(&s->gb, 16);
 
-        if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
+        if(s->avctx->debug & FF_DEBUG_PICT_INFO) {
             av_log(s->avctx, AV_LOG_DEBUG, "Coding parameters maxval:%d T1:%d T2:%d T3:%d reset:%d\n",
                    s->maxval, s->t1, s->t2, s->t3, s->reset);
         }
@@ -96,7 +96,7 @@
         else
             maxtab = 65530/wt - 1;
 
-        if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
+        if(s->avctx->debug & FF_DEBUG_PICT_INFO) {
             av_log(s->avctx, AV_LOG_DEBUG, "LSE palette %d tid:%d wt:%d maxtab:%d\n", id, tid, wt, maxtab);
         }
         if (maxtab >= 256) {
@@ -186,7 +186,7 @@
     if (RItype)
         temp += state->N[Q] >> 1;
 
-    for (k = 0; ((unsigned)state->N[Q] << k) < temp; k++)
+    for (k = 0; (state->N[Q] << k) < temp; k++)
         ;
 
 #ifdef JLS_BROKEN
@@ -195,8 +195,6 @@
 #endif
     ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1,
                                state->qbpp);
-    if (ret < 0)
-        return -0x10000;
 
     /* decode mapped error */
     map = 0;
@@ -211,7 +209,7 @@
         ret = ret >> 1;
     }
 
-    if (FFABS(ret) > 0xFFFF)
+    if(FFABS(ret) > 0xFFFF)
         return -0x10000;
     /* update state */
     state->A[Q] += FFABS(ret) - RItype;
@@ -478,19 +476,19 @@
             for (i = 0; i < s->height; i++) {
                 switch(s->xfrm) {
                 case 1:
-                    for (x = off; x + 2 < w; x += 3) {
+                    for (x = off; x < w; x += 3) {
                         src[x  ] += src[x+1] + 128;
                         src[x+2] += src[x+1] + 128;
                     }
                     break;
                 case 2:
-                    for (x = off; x + 2 < w; x += 3) {
+                    for (x = off; x < w; x += 3) {
                         src[x  ] += src[x+1] + 128;
                         src[x+2] += ((src[x  ] + src[x+1])>>1) + 128;
                     }
                     break;
                 case 3:
-                    for (x = off; x + 2 < w; x += 3) {
+                    for (x = off; x < w; x += 3) {
                         int g = src[x+0] - ((src[x+2]+src[x+1])>>2) + 64;
                         src[x+0] = src[x+2] + g + 128;
                         src[x+2] = src[x+1] + g + 128;
@@ -498,7 +496,7 @@
                     }
                     break;
                 case 4:
-                    for (x = off; x + 2 < w; x += 3) {
+                    for (x = off; x < w; x += 3) {
                         int r    = src[x+0] - ((                       359 * (src[x+2]-128) + 490) >> 8);
                         int g    = src[x+0] - (( 88 * (src[x+1]-128) - 183 * (src[x+2]-128) +  30) >> 8);
                         int b    = src[x+0] + ((454 * (src[x+1]-128)                        + 574) >> 8);
--- FFmpeg-n4.4.4/libavcodec/lagarith.c
+++ Ascendffmpeg/libavcodec/lagarith.c
@@ -408,9 +408,6 @@
         if (zero_run) {
             zero_run = 0;
             i += esc_count;
-            if (i >  end - dst ||
-                i >= src_end - src)
-                return AVERROR_INVALIDDATA;
             memcpy(dst, src, i);
             dst += i;
             l->zeros_rem = lag_calc_zero_run(src[i]);
--- FFmpeg-n4.4.4/libavcodec/libdav1d.c
+++ Ascendffmpeg/libavcodec/libdav1d.c
@@ -127,11 +127,7 @@
 {
     Libdav1dContext *dav1d = c->priv_data;
     Dav1dSettings s;
-#if FF_DAV1D_VERSION_AT_LEAST(6,0)
-    int threads = c->thread_count;
-#else
     int threads = (c->thread_count ? c->thread_count : av_cpu_count()) * 3 / 2;
-#endif
     int res;
 
     av_log(c, AV_LOG_INFO, "libdav1d %s\n", dav1d_version());
@@ -157,7 +153,7 @@
         s.n_threads = FFMAX(dav1d->frame_threads, dav1d->tile_threads);
     else
         s.n_threads = FFMIN(threads, DAV1D_MAX_THREADS);
-    s.max_frame_delay = (c->flags & AV_CODEC_FLAG_LOW_DELAY) ? 1 : 0;
+    s.max_frame_delay = (c->flags & AV_CODEC_FLAG_LOW_DELAY) ? 1 : s.n_threads;
     av_log(c, AV_LOG_DEBUG, "Using %d threads, %d max_frame_delay\n",
            s.n_threads, s.max_frame_delay);
 #else
@@ -248,10 +244,8 @@
     if (res < 0) {
         if (res == AVERROR(EINVAL))
             res = AVERROR_INVALIDDATA;
-        if (res != AVERROR(EAGAIN)) {
-            dav1d_data_unref(data);
+        if (res != AVERROR(EAGAIN))
             return res;
-        }
     }
 
     res = dav1d_get_picture(dav1d->c, p);
--- FFmpeg-n4.4.4/libavcodec/libkvazaar.c
+++ Ascendffmpeg/libavcodec/libkvazaar.c
@@ -210,19 +210,13 @@
 
         // Copy pixels from frame to input_pic.
         {
-            uint8_t *dst[4] = {
-                input_pic->data[0],
-                input_pic->data[1],
-                input_pic->data[2],
-                NULL,
-            };
             int dst_linesizes[4] = {
               frame->width,
               frame->width / 2,
               frame->width / 2,
               0
             };
-            av_image_copy(dst, dst_linesizes,
+            av_image_copy(input_pic->data, dst_linesizes,
                           (const uint8_t **)frame->data, frame->linesize,
                           frame->format, frame->width, frame->height);
         }
--- FFmpeg-n4.4.4/libavcodec/libopenh264dec.c
+++ Ascendffmpeg/libavcodec/libopenh264dec.c
@@ -91,8 +91,8 @@
 {
     SVCContext *s = avctx->priv_data;
     SBufferInfo info = { 0 };
-    uint8_t *ptrs[4] = { NULL };
-    int ret, linesize[4];
+    uint8_t* ptrs[3];
+    int ret, linesize[3];
     AVFrame *avframe = data;
     DECODING_STATE state;
 #if OPENH264_VER_AT_LEAST(1, 7)
@@ -140,7 +140,6 @@
 
     linesize[0] = info.UsrData.sSystemBuffer.iStride[0];
     linesize[1] = linesize[2] = info.UsrData.sSystemBuffer.iStride[1];
-    linesize[3] = 0;
     av_image_copy(avframe->data, avframe->linesize, (const uint8_t **) ptrs, linesize, avctx->pix_fmt, avctx->width, avctx->height);
 
     avframe->pts     = info.uiOutYuvTimeStamp;
--- FFmpeg-n4.4.4/libavcodec/libuavs3d.c
+++ Ascendffmpeg/libavcodec/libuavs3d.c
@@ -208,9 +208,7 @@
                 }
                 avctx->has_b_frames  = !seqh->low_delay;
                 avctx->pix_fmt = seqh->bit_depth_internal == 8 ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV420P10LE;
-                ret = ff_set_dimensions(avctx, seqh->horizontal_size, seqh->vertical_size);
-                if (ret < 0)
-                    return ret;
+                ff_set_dimensions(avctx, seqh->horizontal_size, seqh->vertical_size);
                 h->got_seqhdr = 1;
 
                 if (seqh->colour_description) {
--- FFmpeg-n4.4.4/libavcodec/libxavs2.c
+++ Ascendffmpeg/libavcodec/libxavs2.c
@@ -205,7 +205,7 @@
         ret = cae->api->encoder_encode(cae->encoder, &pic, &cae->packet);
 
         if (ret) {
-            av_log(avctx, AV_LOG_ERROR, "Encoding error occurred.\n");
+            av_log(avctx, AV_LOG_ERROR, "Encoding error occured.\n");
             return AVERROR_EXTERNAL;
         }
 
--- FFmpeg-n4.4.4/libavcodec/midivid.c
+++ Ascendffmpeg/libavcodec/midivid.c
@@ -202,7 +202,12 @@
     bytestream2_skip(gb, 8);
     uncompressed = bytestream2_get_le32(gb);
 
-    if (!uncompressed) {
+    if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0)
+        return ret;
+
+    if (uncompressed) {
+        ret = decode_mvdv(s, avctx, frame);
+    } else {
         av_fast_padded_malloc(&s->uncompressed, &s->uncompressed_size, 16LL * (avpkt->size - 12));
         if (!s->uncompressed)
             return AVERROR(ENOMEM);
@@ -211,12 +216,8 @@
         if (ret < 0)
             return ret;
         bytestream2_init(gb, s->uncompressed, ret);
+        ret = decode_mvdv(s, avctx, frame);
     }
-
-    if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0)
-        return ret;
-
-    ret = decode_mvdv(s, avctx, frame);
 
     if (ret < 0)
         return ret;
--- FFmpeg-n4.4.4/libavcodec/mjpegbdec.c
+++ Ascendffmpeg/libavcodec/mjpegbdec.c
@@ -57,7 +57,6 @@
     buf_end = buf + buf_size;
     s->got_picture = 0;
     s->adobe_transform = -1;
-    s->buf_size = buf_size;
 
 read_header:
     /* reset on every SOI */
--- FFmpeg-n4.4.4/libavcodec/mjpegdec.c
+++ Ascendffmpeg/libavcodec/mjpegdec.c
@@ -1082,10 +1082,6 @@
         return AVERROR_INVALIDDATA;
     if (s->v_max != 1 || s->h_max != 1 || !s->lossless)
         return AVERROR_INVALIDDATA;
-    if (s->bayer) {
-        if (s->rct || s->pegasus_rct)
-            return AVERROR_INVALIDDATA;
-    }
 
 
     s->restart_count = s->restart_interval;
@@ -1202,8 +1198,6 @@
                 ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
             }
         } else if (s->bayer) {
-            if (s->bits <= 8)
-                return AVERROR_PATCHWELCOME;
             if (nb_components == 1) {
                 /* Leave decoding to the TIFF/DNG decoder (see comment in ff_mjpeg_decode_sof) */
                 for (mb_x = 0; mb_x < width; mb_x++)
@@ -1938,8 +1932,6 @@
         }
 
         len -= 9;
-        if (s->bayer)
-            goto out;
         if (s->got_picture)
             if (rgb != s->rgb || pegasus_rct != s->pegasus_rct) {
                 av_log(s->avctx, AV_LOG_WARNING, "Mismatching LJIF tag\n");
--- FFmpeg-n4.4.4/libavcodec/mjpegenc_common.c
+++ Ascendffmpeg/libavcodec/mjpegenc_common.c
@@ -247,7 +247,7 @@
     default: av_assert0(0);
     }
 
-    put_bits(pb, 16, 8 + 3 * components);
+    put_bits(pb, 16, 17);
     if (lossless && (  avctx->pix_fmt == AV_PIX_FMT_BGR0
                     || avctx->pix_fmt == AV_PIX_FMT_BGRA
                     || avctx->pix_fmt == AV_PIX_FMT_BGR24))
--- FFmpeg-n4.4.4/libavcodec/mlpdec.c
+++ Ascendffmpeg/libavcodec/mlpdec.c
@@ -521,7 +521,7 @@
 
     /* This should happen for TrueHD streams with >6 channels and MLP's noise
      * type. It is not yet known if this is allowed. */
-    if (max_matrix_channel > MAX_MATRIX_CHANNEL_MLP && !noise_type) {
+    if (max_channel > MAX_MATRIX_CHANNEL_MLP && !noise_type) {
         avpriv_request_sample(m->avctx,
                               "%d channels (more than the "
                               "maximum supported by the decoder)",
--- FFmpeg-n4.4.4/libavcodec/mobiclip.c
+++ Ascendffmpeg/libavcodec/mobiclip.c
@@ -329,7 +329,7 @@
     return 0;
 }
 
-static int setup_qtables(AVCodecContext *avctx, int64_t quantizer)
+static int setup_qtables(AVCodecContext *avctx, int quantizer)
 {
     MobiClipContext *s = avctx->priv_data;
     int qx, qy;
@@ -1256,7 +1256,7 @@
         frame->key_frame = 0;
         s->dct_tab_idx = 0;
 
-        ret = setup_qtables(avctx, s->quantizer + (int64_t)get_se_golomb(gb));
+        ret = setup_qtables(avctx, s->quantizer + get_se_golomb(gb));
         if (ret < 0)
             return ret;
 
--- FFmpeg-n4.4.4/libavcodec/motion_est.c
+++ Ascendffmpeg/libavcodec/motion_est.c
@@ -1614,7 +1614,7 @@
         for(y=0; y<s->mb_height; y++){
             int x;
             int xy= y*s->mb_stride;
-            for(x=0; x<s->mb_width; x++, xy++){
+            for(x=0; x<s->mb_width; x++){
                 if(s->mb_type[xy] & type){
                     int mx= mv_table[xy][0];
                     int my= mv_table[xy][1];
@@ -1622,15 +1622,16 @@
                                      fcode_tab[my + MAX_MV]);
                     int j;
 
-                    if (mx >= range || mx < -range ||
-                        my >= range || my < -range)
-                        continue;
+                        if(mx >= range || mx < -range ||
+                           my >= range || my < -range)
+                            continue;
 
                     for(j=0; j<fcode && j<8; j++){
                         if(s->pict_type==AV_PICTURE_TYPE_B || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy])
                             score[j]-= 170;
                     }
                 }
+                xy++;
             }
         }
 
--- FFmpeg-n4.4.4/libavcodec/motionpixels.c
+++ Ascendffmpeg/libavcodec/motionpixels.c
@@ -184,7 +184,7 @@
     int color;
 
     color = *(uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2];
-    return mp_rgb_yuv_table[color & 0x7FFF];
+    return mp_rgb_yuv_table[color];
 }
 
 static void mp_set_rgb_from_yuv(MotionPixelsContext *mp, int x, int y, const YuvPixel *p)
--- FFmpeg-n4.4.4/libavcodec/movtextenc.c
+++ Ascendffmpeg/libavcodec/movtextenc.c
@@ -85,7 +85,7 @@
     uint8_t box_flags;
     StyleBox d;
     uint16_t text_pos;
-    unsigned byte_count;
+    uint16_t byte_count;
     char **fonts;
     int font_count;
     double font_scale_factor;
@@ -585,9 +585,9 @@
     mov_text_ass_style_set(s, style);
 }
 
-static unsigned utf8_strlen(const char *text, int len)
+static uint16_t utf8_strlen(const char *text, int len)
 {
-    unsigned i = 0, ret = 0;
+    uint16_t i = 0, ret = 0;
     while (i < len) {
         char c = text[i];
         if ((c & 0x80) == 0)
@@ -607,7 +607,7 @@
 
 static void mov_text_text_cb(void *priv, const char *text, int len)
 {
-    unsigned utf8_len = utf8_strlen(text, len);
+    uint16_t utf8_len = utf8_strlen(text, len);
     MovTextContext *s = priv;
     av_bprint_append_data(&s->buffer, text, len);
     // If it's not utf-8, just use the byte length
--- FFmpeg-n4.4.4/libavcodec/mpeg12dec.c
+++ Ascendffmpeg/libavcodec/mpeg12dec.c
@@ -2999,10 +2999,6 @@
     AVFrame * const frame = data;
     int ret;
 
-    // Check for minimal intra MB size (considering mb header, luma & chroma dc VLC, ac EOB VLC)
-    if (avpkt->size*8LL < (avctx->width+15)/16 * ((avctx->height+15)/16) * (2 + 3*4 + 2*2 + 2*6))
-        return AVERROR_INVALIDDATA;
-
     ret = ff_get_buffer(avctx, frame, 0);
     if (ret < 0)
         return ret;
--- FFmpeg-n4.4.4/libavcodec/mpegaudiodec_template.c
+++ Ascendffmpeg/libavcodec/mpegaudiodec_template.c
@@ -372,7 +372,7 @@
         crc_val = av_crc(crc_tab, crc_val, &buf[6], sec_byte_len);
 
         AV_WB32(tmp_buf,
-                ((buf[6 + sec_byte_len] & (0xFF00U >> sec_rem_bits)) << 24) +
+                ((buf[6 + sec_byte_len] & (0xFF00 >> sec_rem_bits)) << 24) +
                 ((s->crc << 16) >> sec_rem_bits));
 
         crc_val = av_crc(crc_tab, crc_val, tmp_buf, 3);
--- FFmpeg-n4.4.4/libavcodec/mss4.c
+++ Ascendffmpeg/libavcodec/mss4.c
@@ -26,7 +26,6 @@
  */
 
 #include "libavutil/thread.h"
-#include "libavutil/imgutils.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
@@ -477,9 +476,6 @@
                width, height);
         return AVERROR_INVALIDDATA;
     }
-    if (av_image_check_size2(width, height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)
-        return AVERROR_INVALIDDATA;
-
     if (quality < 1 || quality > 100) {
         av_log(avctx, AV_LOG_ERROR, "Invalid quality setting %d\n", quality);
         return AVERROR_INVALIDDATA;
--- FFmpeg-n4.4.4/libavcodec/nvenc.c
+++ Ascendffmpeg/libavcodec/nvenc.c
@@ -1025,9 +1025,8 @@
 
         av_log(avctx, AV_LOG_VERBOSE, "CQ(%d) mode enabled.\n", tmp_quality);
 
-        // CQ mode shall discard avg bitrate/vbv buffer size and honor only max bitrate
+        //CQ mode shall discard avg bitrate & honor max bitrate;
         ctx->encode_config.rcParams.averageBitRate = avctx->bit_rate = 0;
-        ctx->encode_config.rcParams.vbvBufferSize = avctx->rc_buffer_size = 0;
         ctx->encode_config.rcParams.maxBitRate = avctx->rc_max_rate;
     }
 }
@@ -1761,7 +1760,7 @@
     NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
 
     AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frame->hw_frames_ctx->data;
-    NV_ENC_REGISTER_RESOURCE reg = { 0 };
+    NV_ENC_REGISTER_RESOURCE reg;
     int i, idx, ret;
 
     for (i = 0; i < ctx->nb_registered_frames; i++) {
@@ -1926,7 +1925,7 @@
     pkt->pts = params->outputTimeStamp;
     pkt->dts = timestamp_queue_dequeue(ctx->timestamp_list);
 
-    pkt->dts -= FFMAX(ctx->encode_config.frameIntervalP - 1, 0) * FFMAX(avctx->ticks_per_frame, 1) * FFMAX(avctx->time_base.num, 1);
+    pkt->dts -= FFMAX(ctx->encode_config.frameIntervalP - 1, 0) * FFMAX(avctx->ticks_per_frame, 1);
 
     return 0;
 }
--- FFmpeg-n4.4.4/libavcodec/opus_silk.c
+++ Ascendffmpeg/libavcodec/opus_silk.c
@@ -198,8 +198,7 @@
     }
 }
 
-static void silk_lsp2poly(const int32_t lsp[/* 2 * half_order - 1 */],
-                          int32_t pol[/* half_order + 1 */], int half_order)
+static void silk_lsp2poly(const int32_t lsp[16], int32_t pol[16], int half_order)
 {
     int i, j;
 
--- FFmpeg-n4.4.4/libavcodec/pictordec.c
+++ Ascendffmpeg/libavcodec/pictordec.c
@@ -245,6 +245,8 @@
                         run = bytestream2_get_le16(&s->g);
                     val = bytestream2_get_byte(&s->g);
                 }
+                if (!bytestream2_get_bytes_left(&s->g))
+                    break;
 
                 if (bits_per_plane == 8) {
                     picmemset_8bpp(s, frame, val, run, &x, &y);
--- FFmpeg-n4.4.4/libavcodec/pixlet.c
+++ Ascendffmpeg/libavcodec/pixlet.c
@@ -405,7 +405,7 @@
                 (int64_t) low [i - 1] * -INT64_C(325392907)  +
                 (int64_t) high[i + 0] *  INT64_C(1518500249) +
                 (int64_t) high[i - 1] *  INT64_C(1518500249);
-        dest[i * 2] = av_clip_int16(((value >> 32) * (uint64_t)scale) >> 32);
+        dest[i * 2] = av_clip_int16(((value >> 32) * scale) >> 32);
     }
 
     for (i = 0; i < hsize; i++) {
@@ -416,7 +416,7 @@
                 (int64_t) high[i + 1] *  INT64_C(303700064)  +
                 (int64_t) high[i + 0] * -INT64_C(3644400640) +
                 (int64_t) high[i - 1] *  INT64_C(303700064);
-        dest[i * 2 + 1] = av_clip_int16(((value >> 32) * (uint64_t)scale) >> 32);
+        dest[i * 2 + 1] = av_clip_int16(((value >> 32) * scale) >> 32);
     }
 }
 
--- FFmpeg-n4.4.4/libavcodec/pngdec.c
+++ Ascendffmpeg/libavcodec/pngdec.c
@@ -322,7 +322,7 @@
 static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
 { \
     int i; \
-    for (i = 0; i < size - 2; i += 3 + alpha) { \
+    for (i = 0; i < size; i += 3 + alpha) { \
         int g = dst [i + 1]; \
         dst[i + 0] += g; \
         dst[i + 2] += g; \
--- FFmpeg-n4.4.4/libavcodec/pthread_frame.c
+++ Ascendffmpeg/libavcodec/pthread_frame.c
@@ -145,12 +145,6 @@
                                     * Set for the first N packets, where N is the number of threads.
                                     * While it is set, ff_thread_en/decode_frame won't return any results.
                                     */
-
-    /* hwaccel state is temporarily stored here in order to transfer its ownership
-     * to the next decoding thread without the need for extra synchronization */
-    const AVHWAccel *stash_hwaccel;
-    void            *stash_hwaccel_context;
-    void            *stash_hwaccel_priv;
 } FrameThreadContext;
 
 #if FF_API_THREAD_SAFE_CALLBACKS
@@ -235,17 +229,9 @@
             ff_thread_finish_setup(avctx);
 
         if (p->hwaccel_serializing) {
-            /* wipe hwaccel state to avoid stale pointers lying around;
-             * the state was transferred to FrameThreadContext in
-             * ff_thread_finish_setup(), so nothing is leaked */
-            avctx->hwaccel                     = NULL;
-            avctx->hwaccel_context             = NULL;
-            avctx->internal->hwaccel_priv_data = NULL;
-
             p->hwaccel_serializing = 0;
             pthread_mutex_unlock(&p->parent->hwaccel_mutex);
         }
-        av_assert0(!avctx->hwaccel);
 
         if (p->async_serializing) {
             p->async_serializing = 0;
@@ -307,10 +293,14 @@
         dst->color_range = src->color_range;
         dst->chroma_sample_location = src->chroma_sample_location;
 
+        dst->hwaccel = src->hwaccel;
+        dst->hwaccel_context = src->hwaccel_context;
+
         dst->channels       = src->channels;
         dst->sample_rate    = src->sample_rate;
         dst->sample_fmt     = src->sample_fmt;
         dst->channel_layout = src->channel_layout;
+        dst->internal->hwaccel_priv_data = src->internal->hwaccel_priv_data;
 
         if (!!dst->hw_frames_ctx != !!src->hw_frames_ctx ||
             (dst->hw_frames_ctx && dst->hw_frames_ctx->data != src->hw_frames_ctx->data)) {
@@ -456,12 +446,6 @@
         }
     }
 
-    /* transfer the stashed hwaccel state, if any */
-    av_assert0(!p->avctx->hwaccel);
-    FFSWAP(const AVHWAccel*, p->avctx->hwaccel,                     fctx->stash_hwaccel);
-    FFSWAP(void*,            p->avctx->hwaccel_context,             fctx->stash_hwaccel_context);
-    FFSWAP(void*,            p->avctx->internal->hwaccel_priv_data, fctx->stash_hwaccel_priv);
-
     av_packet_unref(p->avpkt);
     ret = av_packet_ref(p->avpkt, avpkt);
     if (ret < 0) {
@@ -665,14 +649,6 @@
         async_lock(p->parent);
     }
 
-    /* save hwaccel state for passing to the next thread;
-     * this is done here so that this worker thread can wipe its own hwaccel
-     * state after decoding, without requiring synchronization */
-    av_assert0(!p->parent->stash_hwaccel);
-    p->parent->stash_hwaccel         = avctx->hwaccel;
-    p->parent->stash_hwaccel_context = avctx->hwaccel_context;
-    p->parent->stash_hwaccel_priv    = avctx->internal->hwaccel_priv_data;
-
     pthread_mutex_lock(&p->progress_mutex);
     if(atomic_load(&p->state) == STATE_SETUP_FINISHED){
         av_log(avctx, AV_LOG_WARNING, "Multiple ff_thread_finish_setup() calls\n");
@@ -767,6 +743,13 @@
 
     park_frame_worker_threads(fctx, thread_count);
 
+    if (fctx->prev_thread && avctx->internal->hwaccel_priv_data !=
+                             fctx->prev_thread->avctx->internal->hwaccel_priv_data) {
+        if (update_context_from_thread(avctx, fctx->prev_thread->avctx, 1) < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to update user thread.\n");
+        }
+    }
+
     if (fctx->prev_thread && fctx->prev_thread != fctx->threads)
         if (update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0) < 0) {
             av_log(avctx, AV_LOG_ERROR, "Final thread update failed\n");
@@ -819,13 +802,6 @@
 
     av_freep(&fctx->threads);
     free_pthread(fctx, thread_ctx_offsets);
-
-    /* if we have stashed hwaccel state, move it to the user-facing context,
-     * so it will be freed in avcodec_close() */
-    av_assert0(!avctx->hwaccel);
-    FFSWAP(const AVHWAccel*, avctx->hwaccel,                     fctx->stash_hwaccel);
-    FFSWAP(void*,            avctx->hwaccel_context,             fctx->stash_hwaccel_context);
-    FFSWAP(void*,            avctx->internal->hwaccel_priv_data, fctx->stash_hwaccel_priv);
 
     av_freep(&avctx->internal->thread_ctx);
 
--- FFmpeg-n4.4.4/libavcodec/qdrw.c
+++ Ascendffmpeg/libavcodec/qdrw.c
@@ -369,7 +369,7 @@
             bytestream2_skip(&gbc, 18);
             colors = bytestream2_get_be16(&gbc);
 
-            if (colors < 0 || colors > 255) {
+            if (colors < 0 || colors > 256) {
                 av_log(avctx, AV_LOG_ERROR,
                        "Error color count - %i(0x%X)\n", colors, colors);
                 return AVERROR_INVALIDDATA;
--- FFmpeg-n4.4.4/libavcodec/qpeldsp.c
+++ Ascendffmpeg/libavcodec/qpeldsp.c
@@ -198,7 +198,7 @@
     uint8_t full[16 * 9];                                                     \
     uint8_t half[64];                                                         \
                                                                               \
-    copy_block8(full, src, 16, stride, 9);                                    \
+    copy_block9(full, src, 16, stride, 9);                                    \
     put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
     OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);                \
 }                                                                             \
@@ -208,7 +208,7 @@
 {                                                                             \
     uint8_t full[16 * 9];                                                     \
                                                                               \
-    copy_block8(full, src, 16, stride, 9);                                    \
+    copy_block9(full, src, 16, stride, 9);                                    \
     OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);                   \
 }                                                                             \
                                                                               \
@@ -218,7 +218,7 @@
     uint8_t full[16 * 9];                                                     \
     uint8_t half[64];                                                         \
                                                                               \
-    copy_block8(full, src, 16, stride, 9);                                    \
+    copy_block9(full, src, 16, stride, 9);                                    \
     put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
     OPNAME ## pixels8_l2_8(dst, full + 16, half, stride, 16, 8, 8);           \
 }                                                                             \
@@ -458,7 +458,7 @@
     uint8_t full[24 * 17];                                                    \
     uint8_t half[256];                                                        \
                                                                               \
-    copy_block16(full, src, 24, stride, 17);                                  \
+    copy_block17(full, src, 24, stride, 17);                                  \
     put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
     OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);             \
 }                                                                             \
@@ -468,7 +468,7 @@
 {                                                                             \
     uint8_t full[24 * 17];                                                    \
                                                                               \
-    copy_block16(full, src, 24, stride, 17);                                  \
+    copy_block17(full, src, 24, stride, 17);                                  \
     OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);                  \
 }                                                                             \
                                                                               \
@@ -478,7 +478,7 @@
     uint8_t full[24 * 17];                                                    \
     uint8_t half[256];                                                        \
                                                                               \
-    copy_block16(full, src, 24, stride, 17);                                  \
+    copy_block17(full, src, 24, stride, 17);                                  \
     put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
     OPNAME ## pixels16_l2_8(dst, full + 24, half, stride, 24, 16, 16);        \
 }                                                                             \
--- FFmpeg-n4.4.4/libavcodec/rasc.c
+++ Ascendffmpeg/libavcodec/rasc.c
@@ -722,7 +722,6 @@
             break;
         default:
             bytestream2_skip(gb, size);
-            ret = 0;
         }
 
         if (ret < 0)
--- FFmpeg-n4.4.4/libavcodec/rpzaenc.c
+++ Ascendffmpeg/libavcodec/rpzaenc.c
@@ -204,7 +204,7 @@
 
     // loop thru and compare pixels
     for (y = 0; y < bi->block_height; y++) {
-        for (x = 0; x < bi->block_width; x++) {
+        for (x = 0; x < bi->block_width; x++){
             // TODO:  optimize
             min_r = FFMIN(R(block_ptr[x]), min_r);
             min_g = FFMIN(G(block_ptr[x]), min_g);
@@ -276,7 +276,7 @@
         return -1;
 
     for (i = 0; i < bi->block_height; i++) {
-        for (j = 0; j < bi->block_width; j++) {
+        for (j = 0; j < bi->block_width; j++){
             x = GET_CHAN(block_ptr[j], xchannel);
             y = GET_CHAN(block_ptr[j], ychannel);
             sumx += x;
@@ -323,7 +323,7 @@
     int max_err = 0;
 
     for (i = 0; i < bi->block_height; i++) {
-        for (j = 0; j < bi->block_width; j++) {
+        for (j = 0; j < bi->block_width; j++){
             int x_inc, lin_y, lin_x;
             x = GET_CHAN(block_ptr[j], xchannel);
             y = GET_CHAN(block_ptr[j], ychannel);
@@ -418,9 +418,7 @@
                                        uint16_t *dest_pixels,
                                        const BlockInfo *bi, int block_counter)
 {
-    const int y_size = FFMIN(4, bi->image_height - bi->row * 4);
-
-    for (int y = 0; y < y_size; y++) {
+    for (int y = 0; y < 4; y++) {
         memcpy(dest_pixels, src_pixels, 8);
         dest_pixels += bi->rowstride;
         src_pixels += bi->rowstride;
@@ -730,25 +728,19 @@
 
             if (err > s->sixteen_color_thresh) { // DO SIXTEEN COLOR BLOCK
                 uint16_t *row_ptr;
-                int y_size, rgb555;
+                int rgb555;
 
                 block_offset = get_block_info(&bi, block_counter);
 
                 row_ptr = &src_pixels[block_offset];
-                y_size = FFMIN(4, bi.image_height - bi.row * 4);
 
-                for (int y = 0; y < y_size; y++) {
-                    for (int x = 0; x < 4; x++) {
+                for (int y = 0; y < 4; y++) {
+                    for (int x = 0; x < 4; x++){
                         rgb555 = row_ptr[x] & ~0x8000;
 
                         put_bits(&s->pb, 16, rgb555);
                     }
                     row_ptr += bi.rowstride;
-                }
-
-                for (int y = y_size; y < 4; y++) {
-                    for (int x = 0; x < 4; x++)
-                        put_bits(&s->pb, 16, 0);
                 }
 
                 block_counter++;
--- FFmpeg-n4.4.4/libavcodec/sbrdsp_fixed.c
+++ Ascendffmpeg/libavcodec/sbrdsp_fixed.c
@@ -114,8 +114,8 @@
 {
     int i;
     for (i = 0; i < 32; i++) {
-        v[     i] = (int)(0x10U + src[63 - 2*i    ]) >> 5;
-        v[63 - i] = (int)(0x10U - src[63 - 2*i - 1]) >> 5;
+        v[     i] = ( src[63 - 2*i    ] + 0x10) >> 5;
+        v[63 - i] = (-src[63 - 2*i - 1] + 0x10) >> 5;
     }
 }
 
--- FFmpeg-n4.4.4/libavcodec/scpr.c
+++ Ascendffmpeg/libavcodec/scpr.c
@@ -459,9 +459,6 @@
                 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
                 uint32_t r, g, b, clr, ptype = 0;
 
-                if (bx >= avctx->width)
-                    return AVERROR_INVALIDDATA;
-
                 for (; by < y * 16 + sy2 && by < avctx->height;) {
                     ret = decode_value(s, s->op_model[ptype], 6, 1000, &ptype);
                     if (ret < 0)
--- FFmpeg-n4.4.4/libavcodec/scpr3.c
+++ Ascendffmpeg/libavcodec/scpr3.c
@@ -1168,9 +1168,6 @@
                 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
                 uint32_t clr, ptype = 0, r, g, b;
 
-                if (bx >= avctx->width)
-                    return AVERROR_INVALIDDATA;
-
                 for (; by < y * 16 + sy2 && by < avctx->height;) {
                     ret = decode_value3(s, 5, &s->op_model3[ptype].cntsum,
                                         s->op_model3[ptype].freqs[0],
--- FFmpeg-n4.4.4/libavcodec/snowenc.c
+++ Ascendffmpeg/libavcodec/snowenc.c
@@ -1544,10 +1544,10 @@
     int level, orientation, x, y;
 
     for(level=0; level<s->spatial_decomposition_count; level++){
-        int64_t error=0;
         for(orientation=level ? 1 : 0; orientation<4; orientation++){
             SubBand *b= &p->band[level][orientation];
             IDWTELEM *ibuf= b->ibuf;
+            int64_t error=0;
 
             memset(s->spatial_idwt_buffer, 0, sizeof(*s->spatial_idwt_buffer)*width*height);
             ibuf[b->width/2 + b->height/2*b->stride]= 256*16;
@@ -1558,13 +1558,9 @@
                     error += d*d;
                 }
             }
-            if (orientation == 2)
-                error /= 2;
+
             b->qlog= (int)(QROOT * log2(352256.0/sqrt(error)) + 0.5);
-            if (orientation != 1)
-                error = 0;
         }
-        p->band[level][1].qlog = p->band[level][2].qlog;
     }
 }
 
--- FFmpeg-n4.4.4/libavcodec/sonic.c
+++ Ascendffmpeg/libavcodec/sonic.c
@@ -1004,7 +1004,7 @@
 
     // dequantize
     for (i = 0; i < s->num_taps; i++)
-        s->predictor_k[i] *= (unsigned) s->tap_quant[i];
+        s->predictor_k[i] *= s->tap_quant[i];
 
     if (s->lossless)
         quant = 1;
--- FFmpeg-n4.4.4/libavcodec/speedhq.c
+++ Ascendffmpeg/libavcodec/speedhq.c
@@ -498,9 +498,7 @@
     uint32_t second_field_offset;
     int ret;
 
-    if (buf_size < 4 || avctx->width < 8 || avctx->width % 8 != 0)
-        return AVERROR_INVALIDDATA;
-    if (buf_size < avctx->width*avctx->height / 64 / 4)
+    if (buf_size < 4 || avctx->width < 8)
         return AVERROR_INVALIDDATA;
 
     quality = buf[0];
--- FFmpeg-n4.4.4/libavcodec/sunrast.c
+++ Ascendffmpeg/libavcodec/sunrast.c
@@ -19,7 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/imgutils.h"
@@ -76,12 +75,6 @@
         return AVERROR_PATCHWELCOME;
     }
 
-    if (maplength > 768) {
-        av_log(avctx, AV_LOG_WARNING, "invalid colormap length\n");
-        return AVERROR_INVALIDDATA;
-    }
-
-    // This also checks depth to be valid
     switch (depth) {
         case 1:
             avctx->pix_fmt = maplength ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_MONOWHITE;
@@ -103,23 +96,15 @@
             return AVERROR_INVALIDDATA;
     }
 
-    // This checks w and h to be valid in the sense that bytes of a padded bitmap are addressable with 32bit int
     ret = ff_set_dimensions(avctx, w, h);
     if (ret < 0)
         return ret;
 
-    // ensured by ff_set_dimensions()
-    av_assert0(w <= (INT32_MAX - 7) / depth);
-
     /* scanlines are aligned on 16 bit boundaries */
     len  = (depth * w + 7) >> 3;
     alen = len + (len & 1);
 
-    // ensured by ff_set_dimensions()
-    av_assert0(h  <= INT32_MAX / (3 * len));
-
-    // maplength is limited to 768 and the right term is limited to INT32_MAX / 256 so the add needs no check
-    if (buf_end - buf < (uint64_t)maplength + (len * h) * 3 / 256)
+    if (buf_end - buf < maplength + (len * h) * 3 / 256)
         return AVERROR_INVALIDDATA;
 
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
@@ -133,7 +118,7 @@
     } else if (maplength) {
         unsigned int len = maplength / 3;
 
-        if (maplength % 3) {
+        if (maplength % 3 || maplength > 768) {
             av_log(avctx, AV_LOG_WARNING, "invalid colormap length\n");
             return AVERROR_INVALIDDATA;
         }
--- FFmpeg-n4.4.4/libavcodec/takdsp.c
+++ Ascendffmpeg/libavcodec/takdsp.c
@@ -65,7 +65,7 @@
     for (i = 0; i < length; i++) {
         int32_t a = p1[i];
         int32_t b = p2[i];
-        b         = (unsigned)((int)(dfactor * (unsigned)(b >> dshift) + 128) >> 8) << dshift;
+        b         = (unsigned)(dfactor * (b >> dshift) + 128 >> 8) << dshift;
         p1[i]     = b - a;
     }
 }
--- FFmpeg-n4.4.4/libavcodec/tests/snowenc.c
+++ Ascendffmpeg/libavcodec/tests/snowenc.c
@@ -31,13 +31,11 @@
 #define width  256
 #define height 256
     int buffer[2][width*height];
-    short obuffer[width*height];
     SnowContext s;
     int i;
     AVLFG prng;
     s.spatial_decomposition_count=6;
     s.spatial_decomposition_type=1;
-    int ret = 0;
 
     s.temp_dwt_buffer  = av_mallocz_array(width, sizeof(DWTELEM));
     s.temp_idwt_buffer = av_mallocz_array(width, sizeof(IDWTELEM));
@@ -51,34 +49,24 @@
 
     printf("testing 5/3 DWT\n");
     for(i=0; i<width*height; i++)
-        buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 19000 - 9000;
+        buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
 
     ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-    for(i=0; i<width*height; i++)
-        obuffer[i] = buffer[0][i];
-    ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+    ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
 
     for(i=0; i<width*height; i++)
-        if(buffer[1][i]!= obuffer[i]) {
-            printf("fsck: %4dx%4dx %12d %7d\n",i%width, i/width, buffer[1][i], obuffer[i]);
-            ret = 1;
-        }
+        if(buffer[0][i]!= buffer[1][i]) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
 
     printf("testing 9/7 DWT\n");
     s.spatial_decomposition_type=0;
     for(i=0; i<width*height; i++)
-        buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 11000 - 5000;
+        buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
 
     ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-    for(i=0; i<width*height; i++)
-        obuffer[i] = buffer[0][i];
-    ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+    ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
 
     for(i=0; i<width*height; i++)
-        if(FFABS(buffer[1][i] - obuffer[i])>20) {
-            printf("fsck: %4dx%4d %12d %7d\n",i%width, i/width, buffer[1][i], obuffer[i]);
-            ret = 1;
-        }
+        if(FFABS(buffer[0][i] - buffer[1][i])>20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
 
     {
     int level, orientation, x, y;
@@ -93,18 +81,18 @@
                 int w= width  >> (s.spatial_decomposition_count-level);
                 int h= height >> (s.spatial_decomposition_count-level);
                 int stride= width  << (s.spatial_decomposition_count-level);
-                IDWTELEM *buf= obuffer;
+                DWTELEM *buf= buffer[0];
                 int64_t error=0;
 
                 if(orientation&1) buf+=w;
                 if(orientation>1) buf+=stride>>1;
 
-                memset(obuffer, 0, sizeof(short)*width*height);
-                buf[w/2 + h/2*stride]= 8*256;
-                ff_spatial_idwt(obuffer, s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+                memset(buffer[0], 0, sizeof(int)*width*height);
+                buf[w/2 + h/2*stride]= 256*256;
+                ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
                 for(y=0; y<height; y++){
                     for(x=0; x<width; x++){
-                        int64_t d= obuffer[x + y*width];
+                        int64_t d= buffer[0][x + y*width];
                         error += d*d;
                         if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
                     }
@@ -155,5 +143,5 @@
         }
 
     }
-    return ret;
+    return 0;
 }
--- FFmpeg-n4.4.4/libavcodec/texturedspenc.c
+++ Ascendffmpeg/libavcodec/texturedspenc.c
@@ -255,11 +255,11 @@
 
         muv = minv = maxv = bp[0];
         for (y = 0; y < 4; y++) {
-            for (x = 0; x < 4; x++) {
+            for (x = 4; x < 4; x += 4) {
                 muv += bp[x * 4 + y * stride];
-                if (bp[x * 4 + y * stride] < minv)
+                if (bp[x] < minv)
                     minv = bp[x * 4 + y * stride];
-                else if (bp[x * 4 + y * stride] > maxv)
+                else if (bp[x] > maxv)
                     maxv = bp[x * 4 + y * stride];
             }
         }
--- FFmpeg-n4.4.4/libavcodec/tiff.c
+++ Ascendffmpeg/libavcodec/tiff.c
@@ -100,6 +100,7 @@
     int is_tiled;
     int tile_byte_counts_offset, tile_offsets_offset;
     int tile_width, tile_length;
+    int tile_count;
 
     int is_jpeg;
 
@@ -734,6 +735,19 @@
     return 0;
 }
 
+static int dng_decode_strip(AVCodecContext *avctx, AVFrame *frame)
+{
+    TiffContext *s = avctx->priv_data;
+
+    s->jpgframe->width  = s->width;
+    s->jpgframe->height = s->height;
+
+    s->avctx_mjpeg->width = s->width;
+    s->avctx_mjpeg->height = s->height;
+
+    return dng_decode_jpeg(avctx, frame, s->stripsize, 0, 0, s->width, s->height);
+}
+
 static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int stride,
                              const uint8_t *src, int size, int strip_start, int lines)
 {
@@ -772,7 +786,6 @@
     if (s->is_bayer) {
         av_assert0(width == (s->bpp * s->width + 7) >> 3);
     }
-    av_assert0(!(s->is_bayer && is_yuv));
     if (p->format == AV_PIX_FMT_GRAY12) {
         av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, width);
         if (s->yuv_line == NULL) {
@@ -856,9 +869,7 @@
             av_log(s->avctx, AV_LOG_ERROR, "More than one DNG JPEG strips unsupported\n");
             return AVERROR_PATCHWELCOME;
         }
-        if (!s->is_bayer)
-            return AVERROR_PATCHWELCOME;
-        if ((ret = dng_decode_jpeg(s->avctx, p, s->stripsize, 0, 0, s->width, s->height)) < 0)
+        if ((ret = dng_decode_strip(s->avctx, p)) < 0)
             return ret;
         return 0;
     }
@@ -976,9 +987,12 @@
     int pos_x = 0, pos_y = 0;
     int ret;
 
-    if (s->tile_width <= 0 || s->tile_length <= 0)
-        return AVERROR_INVALIDDATA;
+    s->jpgframe->width  = s->tile_width;
+    s->jpgframe->height = s->tile_length;
 
+    s->avctx_mjpeg->width = s->tile_width;
+    s->avctx_mjpeg->height = s->tile_length;
+
     has_width_leftover = (s->width % s->tile_width != 0);
     has_height_leftover = (s->height % s->tile_length != 0);
 
@@ -987,7 +1001,7 @@
     tile_count_y = (s->height + s->tile_length - 1) / s->tile_length;
 
     /* Iterate over the number of tiles */
-    for (tile_idx = 0; tile_idx < tile_count_x * tile_count_y; tile_idx++) {
+    for (tile_idx = 0; tile_idx < s->tile_count; tile_idx++) {
         tile_x = tile_idx % tile_count_x;
         tile_y = tile_idx / tile_count_x;
 
@@ -1407,6 +1421,7 @@
         break;
     case TIFF_TILE_OFFSETS:
         s->tile_offsets_offset = off;
+        s->tile_count = count;
         s->is_tiled = 1;
         break;
     case TIFF_TILE_BYTE_COUNTS:
@@ -1762,7 +1777,7 @@
     TiffContext *const s = avctx->priv_data;
     AVFrame *const p = data;
     ThreadFrame frame = { .f = data };
-    unsigned off, last_off = 0;
+    unsigned off, last_off;
     int le, ret, plane, planes;
     int i, j, entries, stride;
     unsigned soff, ssize;
@@ -1827,6 +1842,7 @@
     /** whether we should process this multi-page IFD's next page */
     retry_for_page = s->get_page && s->cur_page + 1 < s->get_page;  // get_page is 1-indexed
 
+    last_off = off;
     if (retry_for_page) {
         // set offset to the next IFD
         off = ff_tget_long(&s->gb, le);
@@ -1844,7 +1860,6 @@
             avpriv_request_sample(s->avctx, "non increasing IFD offset");
             return AVERROR_INVALIDDATA;
         }
-        last_off = off;
         if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
             av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
             return AVERROR_INVALIDDATA;
@@ -1901,7 +1916,7 @@
         return AVERROR_INVALIDDATA;
     }
 
-    has_tile_bits  = s->is_tiled || s->tile_byte_counts_offset || s->tile_offsets_offset || s->tile_width || s->tile_length;
+    has_tile_bits  = s->is_tiled || s->tile_byte_counts_offset || s->tile_offsets_offset || s->tile_width || s->tile_length || s->tile_count;
     has_strip_bits = s->strippos || s->strips || s->stripoff || s->rps || s->sot || s->sstype || s->stripsize || s->stripsizesoff;
 
     if (has_tile_bits && has_strip_bits) {
@@ -2154,7 +2169,6 @@
     s->avctx_mjpeg->flags2 = avctx->flags2;
     s->avctx_mjpeg->dct_algo = avctx->dct_algo;
     s->avctx_mjpeg->idct_algo = avctx->idct_algo;
-    s->avctx_mjpeg->max_pixels = avctx->max_pixels;
     ret = avcodec_open2(s->avctx_mjpeg, codec, NULL);
     if (ret < 0) {
         return ret;
--- FFmpeg-n4.4.4/libavcodec/tta.c
+++ Ascendffmpeg/libavcodec/tta.c
@@ -371,15 +371,8 @@
     case 3: {
         // shift samples for 24-bit sample format
         int32_t *samples = (int32_t *)frame->data[0];
-        int overflow = 0;
-
-        for (i = 0; i < framelen * s->channels; i++) {
-            int scaled = *samples * 256U;
-            overflow += (scaled >> 8 != *samples);
-            *samples++ = scaled;
-        }
-        if (overflow)
-            av_log(avctx, AV_LOG_WARNING, "%d overflows occurred on 24bit upscale\n", overflow);
+        for (i = 0; i < framelen * s->channels; i++)
+            *samples++ *= 256;
         // reset decode buffer
         s->decode_buffer = NULL;
         break;
--- FFmpeg-n4.4.4/libavcodec/utils.c
+++ Ascendffmpeg/libavcodec/utils.c
@@ -236,8 +236,6 @@
     case AV_PIX_FMT_GBRAP16BE:
         w_align = 16; //FIXME assume 16 pixel per macroblock
         h_align = 16 * 2; // interlaced needs 2 macroblocks height
-        if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
-            w_align = 16*2;
         break;
     case AV_PIX_FMT_YUV411P:
     case AV_PIX_FMT_YUVJ411P:
@@ -316,7 +314,6 @@
     *width  = FFALIGN(*width, w_align);
     *height = FFALIGN(*height, h_align);
     if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
-        s->codec_id == AV_CODEC_ID_VC1  || s->codec_id == AV_CODEC_ID_WMV3 ||
         s->codec_id == AV_CODEC_ID_VP5  || s->codec_id == AV_CODEC_ID_VP6 ||
         s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
     ) {
@@ -328,9 +325,6 @@
         // it requires a temporary area large enough to hold a 21x21 block,
         // increasing witdth ensure that the temporary area is large enough,
         // the next rounded up width is 32
-        *width = FFMAX(*width, 32);
-    }
-    if (s->codec_id == AV_CODEC_ID_SVQ3) {
         *width = FFMAX(*width, 32);
     }
 
--- FFmpeg-n4.4.4/libavcodec/vaapi_av1.c
+++ Ascendffmpeg/libavcodec/vaapi_av1.c
@@ -21,28 +21,8 @@
 #include "libavutil/pixdesc.h"
 #include "hwconfig.h"
 #include "vaapi_decode.h"
-#include "internal.h"
 #include "av1dec.h"
 
-typedef struct VAAPIAV1FrameRef {
-    ThreadFrame frame;
-    int valid;
-} VAAPIAV1FrameRef;
-
-typedef struct VAAPIAV1DecContext {
-    VAAPIDecodeContext base;
-
-    /**
-     * For film grain case, VAAPI generate 2 output for each frame,
-     * current_frame will not apply film grain, and will be used for
-     * references for next frames. Maintain the reference list without
-     * applying film grain here. And current_display_picture will be
-     * used to apply film grain and push to downstream.
-    */
-    VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES];
-    ThreadFrame tmp_frame;
-} VAAPIAV1DecContext;
-
 static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf)
 {
     if (vf)
@@ -69,48 +49,6 @@
     return bit_depth == 8 ? 0 : bit_depth == 10 ? 1 : 2;
 }
 
-static int vaapi_av1_decode_init(AVCodecContext *avctx)
-{
-    VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
-
-    ctx->tmp_frame.f = av_frame_alloc();
-    if (!ctx->tmp_frame.f) {
-        av_log(avctx, AV_LOG_ERROR,
-               "Failed to allocate frame.\n");
-        return AVERROR(ENOMEM);
-    }
-
-    for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) {
-        ctx->ref_tab[i].frame.f = av_frame_alloc();
-        if (!ctx->ref_tab[i].frame.f) {
-            av_log(avctx, AV_LOG_ERROR,
-                   "Failed to allocate reference table frame %d.\n", i);
-            return AVERROR(ENOMEM);
-        }
-        ctx->ref_tab[i].valid = 0;
-    }
-
-    return ff_vaapi_decode_init(avctx);
-}
-
-static int vaapi_av1_decode_uninit(AVCodecContext *avctx)
-{
-    VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
-
-    if (ctx->tmp_frame.f->buf[0])
-        ff_thread_release_buffer(avctx, &ctx->tmp_frame);
-    av_frame_free(&ctx->tmp_frame.f);
-
-    for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) {
-        if (ctx->ref_tab[i].frame.f->buf[0])
-            ff_thread_release_buffer(avctx, &ctx->ref_tab[i].frame);
-        av_frame_free(&ctx->ref_tab[i].frame.f);
-    }
-
-    return ff_vaapi_decode_uninit(avctx);
-}
-
-
 static int vaapi_av1_start_frame(AVCodecContext *avctx,
                                  av_unused const uint8_t *buffer,
                                  av_unused uint32_t size)
@@ -120,62 +58,40 @@
     const AV1RawFrameHeader *frame_header = s->raw_frame_header;
     const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
     VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
-    VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
     VADecPictureParameterBufferAV1 pic_param;
     int8_t bit_depth_idx;
     int err = 0;
     int apply_grain = !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain;
     uint8_t remap_lr_type[4] = {AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ};
-    uint8_t segmentation_feature_signed[AV1_SEG_LVL_MAX] = {1, 1, 1, 1, 1, 0, 0, 0};
-    uint8_t segmentation_feature_max[AV1_SEG_LVL_MAX] = {255, AV1_MAX_LOOP_FILTER,
-        AV1_MAX_LOOP_FILTER, AV1_MAX_LOOP_FILTER, AV1_MAX_LOOP_FILTER, 7 , 0 , 0 };
 
+    pic->output_surface = vaapi_av1_surface_id(&s->cur_frame);
+
     bit_depth_idx = vaapi_av1_get_bit_depth_idx(avctx);
     if (bit_depth_idx < 0)
         goto fail;
 
-    if (apply_grain) {
-        if (ctx->tmp_frame.f->buf[0])
-            ff_thread_release_buffer(avctx, &ctx->tmp_frame);
-        err = ff_thread_get_buffer(avctx, &ctx->tmp_frame, AV_GET_BUFFER_FLAG_REF);
-        if (err < 0)
-            goto fail;
-        pic->output_surface = ff_vaapi_get_surface_id(ctx->tmp_frame.f);
-    } else {
-        pic->output_surface = vaapi_av1_surface_id(&s->cur_frame);
-    }
-
     memset(&pic_param, 0, sizeof(VADecPictureParameterBufferAV1));
     pic_param = (VADecPictureParameterBufferAV1) {
-        .profile                    = seq->seq_profile,
-        .order_hint_bits_minus_1    = seq->order_hint_bits_minus_1,
-        .bit_depth_idx              = bit_depth_idx,
-        .matrix_coefficients        = seq->color_config.matrix_coefficients,
-        .current_frame              = pic->output_surface,
-        .current_display_picture    = vaapi_av1_surface_id(&s->cur_frame),
-        .frame_width_minus1         = frame_header->frame_width_minus_1,
-        .frame_height_minus1        = frame_header->frame_height_minus_1,
-        .primary_ref_frame          = frame_header->primary_ref_frame,
-        .order_hint                 = frame_header->order_hint,
-        .tile_cols                  = frame_header->tile_cols,
-        .tile_rows                  = frame_header->tile_rows,
-        .context_update_tile_id     = frame_header->context_update_tile_id,
-        .superres_scale_denominator = frame_header->use_superres ?
-                                        frame_header->coded_denom + AV1_SUPERRES_DENOM_MIN :
-                                        AV1_SUPERRES_NUM,
-        .interp_filter              = frame_header->interpolation_filter,
-        .filter_level[0]            = frame_header->loop_filter_level[0],
-        .filter_level[1]            = frame_header->loop_filter_level[1],
-        .filter_level_u             = frame_header->loop_filter_level[2],
-        .filter_level_v             = frame_header->loop_filter_level[3],
-        .base_qindex                = frame_header->base_q_idx,
-        .y_dc_delta_q               = frame_header->delta_q_y_dc,
-        .u_dc_delta_q               = frame_header->delta_q_u_dc,
-        .u_ac_delta_q               = frame_header->delta_q_u_ac,
-        .v_dc_delta_q               = frame_header->delta_q_v_dc,
-        .v_ac_delta_q               = frame_header->delta_q_v_ac,
-        .cdef_damping_minus_3       = frame_header->cdef_damping_minus_3,
-        .cdef_bits                  = frame_header->cdef_bits,
+        .profile                 = seq->seq_profile,
+        .order_hint_bits_minus_1 = seq->order_hint_bits_minus_1,
+        .bit_depth_idx           = bit_depth_idx,
+        .current_frame           = pic->output_surface,
+        .current_display_picture = pic->output_surface,
+        .frame_width_minus1      = frame_header->frame_width_minus_1,
+        .frame_height_minus1     = frame_header->frame_height_minus_1,
+        .primary_ref_frame       = frame_header->primary_ref_frame,
+        .order_hint              = frame_header->order_hint,
+        .tile_cols               = frame_header->tile_cols,
+        .tile_rows               = frame_header->tile_rows,
+        .context_update_tile_id  = frame_header->context_update_tile_id,
+        .interp_filter           = frame_header->interpolation_filter,
+        .filter_level[0]         = frame_header->loop_filter_level[0],
+        .filter_level[1]         = frame_header->loop_filter_level[1],
+        .filter_level_u          = frame_header->loop_filter_level[2],
+        .filter_level_v          = frame_header->loop_filter_level[3],
+        .base_qindex             = frame_header->base_q_idx,
+        .cdef_damping_minus_3    = frame_header->cdef_damping_minus_3,
+        .cdef_bits               = frame_header->cdef_bits,
         .seq_info_fields.fields = {
             .still_picture              = seq->still_picture,
             .use_128x128_superblock     = seq->use_128x128_superblock,
@@ -246,15 +162,12 @@
             .mode_ref_delta_update  = frame_header->loop_filter_delta_update,
         },
         .mode_control_fields.bits = {
-            .delta_q_present_flag  = frame_header->delta_q_present,
-            .log2_delta_q_res      = frame_header->delta_q_res,
-            .delta_lf_present_flag = frame_header->delta_lf_present,
-            .log2_delta_lf_res     = frame_header->delta_lf_res,
-            .delta_lf_multi        = frame_header->delta_lf_multi,
-            .tx_mode               = frame_header->tx_mode,
-            .reference_select      = frame_header->reference_select,
-            .reduced_tx_set_used   = frame_header->reduced_tx_set,
-            .skip_mode_present     = frame_header->skip_mode_present,
+            .delta_q_present_flag = frame_header->delta_q_present,
+            .log2_delta_q_res     = frame_header->delta_q_res,
+            .tx_mode              = frame_header->tx_mode,
+            .reference_select     = frame_header->reference_select,
+            .reduced_tx_set_used  = frame_header->reduced_tx_set,
+            .skip_mode_present    = frame_header->skip_mode_present,
         },
         .loop_restoration_fields.bits = {
             .yframe_restoration_type  = remap_lr_type[frame_header->lr_type[0]],
@@ -265,9 +178,6 @@
         },
         .qmatrix_fields.bits = {
             .using_qmatrix = frame_header->using_qmatrix,
-            .qm_y          = frame_header->qm_y,
-            .qm_u          = frame_header->qm_u,
-            .qm_v          = frame_header->qm_v,
         }
     };
 
@@ -275,9 +185,7 @@
         if (pic_param.pic_info_fields.bits.frame_type == AV1_FRAME_KEY)
             pic_param.ref_frame_map[i] = VA_INVALID_ID;
         else
-            pic_param.ref_frame_map[i] = ctx->ref_tab[i].valid ?
-                                         ff_vaapi_get_surface_id(ctx->ref_tab[i].frame.f) :
-                                         vaapi_av1_surface_id(&s->ref[i]);
+            pic_param.ref_frame_map[i] = vaapi_av1_surface_id(&s->ref[i]);
     }
     for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
         pic_param.ref_frame_idx[i] = frame_header->ref_frame_idx[i];
@@ -305,22 +213,10 @@
             frame_header->height_in_sbs_minus_1[i];
     }
     for (int i = AV1_REF_FRAME_LAST; i <= AV1_REF_FRAME_ALTREF; i++) {
-        pic_param.wm[i - 1].invalid = s->cur_frame.gm_invalid[i];
-        pic_param.wm[i - 1].wmtype  = s->cur_frame.gm_type[i];
+        pic_param.wm[i - 1].wmtype = s->cur_frame.gm_type[i];
         for (int j = 0; j < 6; j++)
             pic_param.wm[i - 1].wmmat[j] = s->cur_frame.gm_params[i][j];
     }
-    for (int i = 0; i < AV1_MAX_SEGMENTS; i++) {
-        for (int j = 0; j < AV1_SEG_LVL_MAX; j++) {
-            pic_param.seg_info.feature_mask[i] |= (frame_header->feature_enabled[i][j] << j);
-            if (segmentation_feature_signed[j])
-                pic_param.seg_info.feature_data[i][j] = av_clip(frame_header->feature_value[i][j],
-                    -segmentation_feature_max[j], segmentation_feature_max[j]);
-            else
-                pic_param.seg_info.feature_data[i][j] = av_clip(frame_header->feature_value[i][j],
-                    0, segmentation_feature_max[j]);
-        }
-    }
     if (apply_grain) {
         for (int i = 0; i < film_grain->num_y_points; i++) {
             pic_param.film_grain_info.point_y_value[i] =
@@ -367,34 +263,8 @@
 static int vaapi_av1_end_frame(AVCodecContext *avctx)
 {
     const AV1DecContext *s = avctx->priv_data;
-    const AV1RawFrameHeader *header = s->raw_frame_header;
-    const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
     VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
-    VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
-
-    int apply_grain = !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain;
-    int ret;
-    ret = ff_vaapi_decode_issue(avctx, pic);
-    if (ret < 0)
-        return ret;
-
-    for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
-        if (header->refresh_frame_flags & (1 << i)) {
-            if (ctx->ref_tab[i].frame.f->buf[0])
-                ff_thread_release_buffer(avctx, &ctx->ref_tab[i].frame);
-
-            if (apply_grain) {
-                ret = ff_thread_ref_frame(&ctx->ref_tab[i].frame, &ctx->tmp_frame);
-                if (ret < 0)
-                    return ret;
-                ctx->ref_tab[i].valid = 1;
-            } else {
-                ctx->ref_tab[i].valid = 0;
-            }
-        }
-    }
-
-    return 0;
+    return ff_vaapi_decode_issue(avctx, pic);
 }
 
 static int vaapi_av1_decode_slice(AVCodecContext *avctx,
@@ -441,9 +311,9 @@
     .end_frame            = vaapi_av1_end_frame,
     .decode_slice         = vaapi_av1_decode_slice,
     .frame_priv_data_size = sizeof(VAAPIDecodePicture),
-    .init                 = vaapi_av1_decode_init,
-    .uninit               = vaapi_av1_decode_uninit,
+    .init                 = ff_vaapi_decode_init,
+    .uninit               = ff_vaapi_decode_uninit,
     .frame_params         = ff_vaapi_common_frame_params,
-    .priv_data_size       = sizeof(VAAPIAV1DecContext),
+    .priv_data_size       = sizeof(VAAPIDecodeContext),
     .caps_internal        = HWACCEL_CAP_ASYNC_SAFE,
 };
--- FFmpeg-n4.4.4/libavcodec/vaapi_decode.c
+++ Ascendffmpeg/libavcodec/vaapi_decode.c
@@ -577,10 +577,10 @@
         switch (avctx->codec_id) {
         case AV_CODEC_ID_H264:
         case AV_CODEC_ID_HEVC:
-        case AV_CODEC_ID_AV1:
             frames->initial_pool_size += 16;
             break;
         case AV_CODEC_ID_VP9:
+        case AV_CODEC_ID_AV1:
             frames->initial_pool_size += 8;
             break;
         case AV_CODEC_ID_VP8:
--- FFmpeg-n4.4.4/libavcodec/vaapi_encode.c
+++ Ascendffmpeg/libavcodec/vaapi_encode.c
@@ -2366,11 +2366,6 @@
     VAStatus vas;
     int err;
 
-    ctx->va_config  = VA_INVALID_ID;
-    ctx->va_context = VA_INVALID_ID;
-
-    /* If you add something that can fail above this av_frame_alloc(),
-     * modify ff_vaapi_encode_close() accordingly. */
     ctx->frame = av_frame_alloc();
     if (!ctx->frame) {
         return AVERROR(ENOMEM);
@@ -2382,6 +2377,9 @@
         return AVERROR(EINVAL);
     }
 
+    ctx->va_config  = VA_INVALID_ID;
+    ctx->va_context = VA_INVALID_ID;
+
     ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
     if (!ctx->input_frames_ref) {
         err = AVERROR(ENOMEM);
@@ -2532,11 +2530,6 @@
 {
     VAAPIEncodeContext *ctx = avctx->priv_data;
     VAAPIEncodePicture *pic, *next;
-
-    /* We check ctx->frame to know whether ff_vaapi_encode_init()
-     * has been called and va_config/va_context initialized. */
-    if (!ctx->frame)
-        return 0;
 
     for (pic = ctx->pic_start; pic; pic = next) {
         next = pic->next;
--- FFmpeg-n4.4.4/libavcodec/videodsp_template.c
+++ Ascendffmpeg/libavcodec/videodsp_template.c
@@ -60,7 +60,7 @@
     av_assert2(start_x < end_x && block_w);
 
     w    = end_x - start_x;
-    src += start_y * src_linesize + start_x * (ptrdiff_t)sizeof(pixel);
+    src += start_y * src_linesize + start_x * sizeof(pixel);
     buf += start_x * sizeof(pixel);
 
     // top
@@ -83,7 +83,7 @@
         buf += buf_linesize;
     }
 
-    buf -= block_h * buf_linesize + start_x * (ptrdiff_t)sizeof(pixel);
+    buf -= block_h * buf_linesize + start_x * sizeof(pixel);
     while (block_h--) {
         pixel *bufp = (pixel *) buf;
 
--- FFmpeg-n4.4.4/libavcodec/videotoolbox.c
+++ Ascendffmpeg/libavcodec/videotoolbox.c
@@ -608,7 +608,8 @@
                                           CMTime pts,
                                           CMTime duration)
 {
-    VTContext *vtctx = opaque;
+    AVCodecContext *avctx = opaque;
+    VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 
     if (vtctx->frame) {
         CVPixelBufferRelease(vtctx->frame);
@@ -616,8 +617,7 @@
     }
 
     if (!image_buffer) {
-        av_log(vtctx->logctx,  AV_LOG_DEBUG,
-               "vt decoder cb: output image buffer is null: %i\n", status);
+        av_log(avctx, AV_LOG_DEBUG, "vt decoder cb: output image buffer is null\n");
         return;
     }
 
@@ -828,7 +828,7 @@
                                                      videotoolbox->cv_pix_fmt_type);
 
     decoder_cb.decompressionOutputCallback = videotoolbox_decoder_callback;
-    decoder_cb.decompressionOutputRefCon   = avctx->internal->hwaccel_priv_data;
+    decoder_cb.decompressionOutputRefCon   = avctx;
 
     status = VTDecompressionSessionCreate(NULL,                      // allocator
                                           videotoolbox->cm_fmt_desc, // videoFormatDescription
@@ -1039,8 +1039,6 @@
     VTContext *vtctx = avctx->internal->hwaccel_priv_data;
     AVHWFramesContext *hw_frames;
     int err;
-
-    vtctx->logctx = avctx;
 
     // Old API - do nothing.
     if (avctx->hwaccel_context)
--- FFmpeg-n4.4.4/libavcodec/vp3.c
+++ Ascendffmpeg/libavcodec/vp3.c
@@ -2683,27 +2683,15 @@
     if ((ret = ff_thread_get_buffer(avctx, &s->current_frame, AV_GET_BUFFER_FLAG_REF)) < 0)
         goto error;
 
-    if (!s->edge_emu_buffer) {
+    if (!s->edge_emu_buffer)
         s->edge_emu_buffer = av_malloc(9 * FFABS(s->current_frame.f->linesize[0]));
-        if (!s->edge_emu_buffer) {
-            ret = AVERROR(ENOMEM);
-            goto error;
-        }
-    }
 
     if (s->keyframe) {
         if (!s->theora) {
             skip_bits(&gb, 4); /* width code */
             skip_bits(&gb, 4); /* height code */
             if (s->version) {
-                int version = get_bits(&gb, 5);
-#if !CONFIG_VP4_DECODER
-                if (version >= 2) {
-                    av_log(avctx, AV_LOG_ERROR, "This build does not support decoding VP4.\n");
-                    return AVERROR_DECODER_NOT_FOUND;
-                }
-#endif
-                s->version = version;
+                s->version = get_bits(&gb, 5);
                 if (avctx->frame_number == 0)
                     av_log(s->avctx, AV_LOG_DEBUG,
                            "VP version: %d\n", s->version);
--- FFmpeg-n4.4.4/libavcodec/vqavideo.c
+++ Ascendffmpeg/libavcodec/vqavideo.c
@@ -588,14 +588,13 @@
         if (s->partial_countdown <= 0) {
             bytestream2_init(&s->gb, s->next_codebook_buffer, s->next_codebook_buffer_index);
             /* decompress codebook */
-            res = decode_format80(s, s->next_codebook_buffer_index,
-                                  s->codebook, s->codebook_size, 0);
+            if ((res = decode_format80(s, s->next_codebook_buffer_index,
+                                       s->codebook, s->codebook_size, 0)) < 0)
+                return res;
 
             /* reset accounting */
             s->next_codebook_buffer_index = 0;
             s->partial_countdown = s->partial_count;
-            if (res < 0)
-                return res;
         }
     }
 
--- FFmpeg-n4.4.4/libavcodec/vt_internal.h
+++ Ascendffmpeg/libavcodec/vt_internal.h
@@ -42,8 +42,6 @@
     // Current H264 parameters (used to trigger decoder restart on SPS changes).
     uint8_t                     sps[3];
     bool                        reconfig_needed;
-
-    void *logctx;
 } VTContext;
 
 int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame);
--- FFmpeg-n4.4.4/libavcodec/wavpack.c
+++ Ascendffmpeg/libavcodec/wavpack.c
@@ -128,7 +128,7 @@
     e   = (1 << (p + 1)) - k - 1;
     res = get_bitsz(gb, p);
     if (res >= e)
-        res = res * 2U - e + get_bits1(gb);
+        res = (res << 1) - e + get_bits1(gb);
     return res;
 }
 
@@ -498,8 +498,6 @@
                 sp[0].fltr0 = 0;
             }
 
-            if (DSD_BYTE_READY(high, low) && !bytestream2_get_bytes_left(&s->gbyte))
-                return AVERROR_INVALIDDATA;
             while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
                 value = (value << 8) | bytestream2_get_byte(&s->gbyte);
                 high = (high << 8) | 0xff;
@@ -535,8 +533,6 @@
                 sp[1].fltr0 = 0;
             }
 
-            if (DSD_BYTE_READY(high, low) && !bytestream2_get_bytes_left(&s->gbyte))
-                return AVERROR_INVALIDDATA;
             while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
                 value = (value << 8) | bytestream2_get_byte(&s->gbyte);
                 high = (high << 8) | 0xff;
--- FFmpeg-n4.4.4/libavcodec/wmadec.c
+++ Ascendffmpeg/libavcodec/wmadec.c
@@ -980,7 +980,6 @@
     .capabilities   = AV_CODEC_CAP_DR1,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
 #if CONFIG_WMAV2_DECODER
@@ -997,6 +996,5 @@
     .capabilities   = AV_CODEC_CAP_DR1,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
--- FFmpeg-n4.4.4/libavcodec/wmaenc.c
+++ Ascendffmpeg/libavcodec/wmaenc.c
@@ -436,7 +436,6 @@
     .close          = ff_wma_end,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
 #if CONFIG_WMAV2_ENCODER
@@ -451,6 +450,5 @@
     .close          = ff_wma_end,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
--- FFmpeg-n4.4.4/libavcodec/wnv1.c
+++ Ascendffmpeg/libavcodec/wnv1.c
@@ -126,9 +126,6 @@
 {
     static AVOnce init_static_once = AV_ONCE_INIT;
 
-    if (avctx->width <= 1)
-        return AVERROR_INVALIDDATA;
-
     avctx->pix_fmt = AV_PIX_FMT_YUV422P;
 
     ff_thread_once(&init_static_once, wnv1_init_static);
--- FFmpeg-n4.4.4/libavcodec/xpmdec.c
+++ Ascendffmpeg/libavcodec/xpmdec.c
@@ -355,9 +355,6 @@
         return AVERROR_INVALIDDATA;
     }
 
-    if (size > SIZE_MAX / 4)
-        return AVERROR(ENOMEM);
-
     size *= 4;
 
     ptr += mod_strcspn(ptr, ",") + 1;
--- FFmpeg-n4.4.4/libavcodec/zmbvenc.c
+++ Ascendffmpeg/libavcodec/zmbvenc.c
@@ -73,7 +73,6 @@
     int keyint, curfrm;
     int bypp;
     enum ZmbvFormat fmt;
-    int zlib_init_ok;
     z_stream zstream;
 
     int score_tab[ZMBV_BLOCK * ZMBV_BLOCK * 4 + 1];
@@ -311,9 +310,8 @@
     av_freep(&c->comp_buf);
     av_freep(&c->work_buf);
 
+    deflateEnd(&c->zstream);
     av_freep(&c->prev_buf);
-    if (c->zlib_init_ok)
-        deflateEnd(&c->zstream);
 
     return 0;
 }
@@ -383,6 +381,8 @@
         return AVERROR(EINVAL);
     }
 
+    // Needed if zlib unused or init aborted before deflateInit
+    memset(&c->zstream, 0, sizeof(z_stream));
     c->comp_size = avctx->width * c->bypp * avctx->height + 1024 +
         ((avctx->width + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * ((avctx->height + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * 2 + 4;
     if (!(c->work_buf = av_malloc(c->comp_size))) {
@@ -424,7 +424,6 @@
         av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
         return -1;
     }
-    c->zlib_init_ok = 1;
 
     return 0;
 }
@@ -446,5 +445,4 @@
 #endif //ZMBV_ENABLE_24BPP
                                                      AV_PIX_FMT_BGR0,
                                                      AV_PIX_FMT_NONE },
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
--- FFmpeg-n4.4.4/libavdevice/xv.c
+++ Ascendffmpeg/libavdevice/xv.c
@@ -296,7 +296,7 @@
 {
     XVContext *xv = s->priv_data;
     XvImage *img = xv->yuv_image;
-    uint8_t *data[4] = {
+    uint8_t *data[3] = {
         img->data + img->offsets[0],
         img->data + img->offsets[1],
         img->data + img->offsets[2]
--- FFmpeg-n4.4.4/libavfilter/aeval.c
+++ Ascendffmpeg/libavfilter/aeval.c
@@ -124,10 +124,11 @@
     }
 
 #define ADD_EXPRESSION(expr_) do {                                      \
-        ret = av_dynarray_add_nofree(&eval->expr,                       \
-                                     &eval->nb_channels, NULL);         \
-        if (ret < 0)                                                    \
+        if (!av_dynarray2_add((void **)&eval->expr, &eval->nb_channels, \
+                              sizeof(*eval->expr), NULL)) {             \
+            ret = AVERROR(ENOMEM);                                      \
             goto end;                                                   \
+        }                                                               \
         eval->expr[eval->nb_channels-1] = NULL;                         \
         ret = av_expr_parse(&eval->expr[eval->nb_channels - 1], expr_,  \
                             var_names, func1_names, func1,              \
--- FFmpeg-n4.4.4/libavfilter/af_surround.c
+++ Ascendffmpeg/libavfilter/af_surround.c
@@ -203,13 +203,13 @@
     s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft));
     if (!s->rdft)
         return AVERROR(ENOMEM);
-    s->nb_in_channels = inlink->channels;
 
     for (ch = 0; ch < inlink->channels; ch++) {
         s->rdft[ch]  = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
         if (!s->rdft[ch])
             return AVERROR(ENOMEM);
     }
+    s->nb_in_channels = inlink->channels;
     s->input_levels = av_malloc_array(s->nb_in_channels, sizeof(*s->input_levels));
     if (!s->input_levels)
         return AVERROR(ENOMEM);
@@ -266,13 +266,13 @@
     s->irdft = av_calloc(outlink->channels, sizeof(*s->irdft));
     if (!s->irdft)
         return AVERROR(ENOMEM);
-    s->nb_out_channels = outlink->channels;
 
     for (ch = 0; ch < outlink->channels; ch++) {
         s->irdft[ch] = av_rdft_init(ff_log2(s->buf_size), IDFT_C2R);
         if (!s->irdft[ch])
             return AVERROR(ENOMEM);
     }
+    s->nb_out_channels = outlink->channels;
     s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
     if (!s->output_levels)
         return AVERROR(ENOMEM);
--- FFmpeg-n4.4.4/libavfilter/af_vibrato.c
+++ Ascendffmpeg/libavfilter/af_vibrato.c
@@ -157,11 +157,11 @@
     int c;
     AVFilterContext *ctx = inlink->dst;
     VibratoContext *s = ctx->priv;
+    s->channels = inlink->channels;
 
     s->buf = av_calloc(inlink->channels, sizeof(*s->buf));
     if (!s->buf)
         return AVERROR(ENOMEM);
-    s->channels = inlink->channels;
     s->buf_size = lrint(inlink->sample_rate * 0.005 + 0.5);
     for (c = 0; c < s->channels; c++) {
         s->buf[c] = av_malloc_array(s->buf_size, sizeof(*s->buf[c]));
--- FFmpeg-n4.4.4/libavfilter/asrc_flite.c
+++ Ascendffmpeg/libavfilter/asrc_flite.c
@@ -196,12 +196,10 @@
 {
     FliteContext *flite = ctx->priv;
 
-    if (flite->voice_entry) {
-        if (!--flite->voice_entry->usage_count) {
-            flite->voice_entry->unregister_fn(flite->voice);
-            flite->voice_entry->voice = NULL;
-        }
-    }
+    if (!--flite->voice_entry->usage_count)
+        flite->voice_entry->unregister_fn(flite->voice);
+    flite->voice = NULL;
+    flite->voice_entry = NULL;
     delete_wave(flite->wave);
     flite->wave = NULL;
 }
--- FFmpeg-n4.4.4/libavfilter/avfilter.c
+++ Ascendffmpeg/libavfilter/avfilter.c
@@ -925,8 +925,6 @@
         ret = ctx->filter->init(ctx);
     else if (ctx->filter->init_dict)
         ret = ctx->filter->init_dict(ctx, options);
-    if (ret < 0)
-        return ret;
 
     if (ctx->enable_str) {
         ret = set_enable_expr(ctx, ctx->enable_str);
@@ -934,7 +932,7 @@
             return ret;
     }
 
-    return 0;
+    return ret;
 }
 
 int avfilter_init_str(AVFilterContext *filter, const char *args)
--- FFmpeg-n4.4.4/libavfilter/vf_frei0r.c
+++ Ascendffmpeg/libavfilter/vf_frei0r.c
@@ -353,20 +353,14 @@
 {
     Frei0rContext *s = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
-    AVFrame *out = ff_default_get_video_buffer2(outlink, outlink->w, outlink->h, 16);
-    if (!out)
-        goto fail;
+    AVFrame *out;
 
-    av_frame_copy_props(out, in);
-
-    if (in->linesize[0] != out->linesize[0]) {
-        AVFrame *in2 = ff_default_get_video_buffer2(outlink, outlink->w, outlink->h, 16);
-        if (!in2)
-            goto fail;
-        av_frame_copy(in2, in);
+    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+    if (!out) {
         av_frame_free(&in);
-        in = in2;
+        return AVERROR(ENOMEM);
     }
+    av_frame_copy_props(out, in);
 
     s->update(s->instance, in->pts * av_q2d(inlink->time_base) * 1000,
                    (const uint32_t *)in->data[0],
@@ -375,10 +369,6 @@
     av_frame_free(&in);
 
     return ff_filter_frame(outlink, out);
-fail:
-    av_frame_free(&in);
-    av_frame_free(&out);
-    return AVERROR(ENOMEM);
 }
 
 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
@@ -477,7 +467,7 @@
 static int source_request_frame(AVFilterLink *outlink)
 {
     Frei0rContext *s = outlink->src->priv;
-    AVFrame *frame = ff_default_get_video_buffer2(outlink, outlink->w, outlink->h, 16);
+    AVFrame *frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 
     if (!frame)
         return AVERROR(ENOMEM);
--- FFmpeg-n4.4.4/libavfilter/vf_idet.c
+++ Ascendffmpeg/libavfilter/vf_idet.c
@@ -336,19 +336,20 @@
 static av_cold void uninit(AVFilterContext *ctx)
 {
     IDETContext *idet = ctx->priv;
+    int level = strncmp(ctx->name, "auto-inserted", 13) ? AV_LOG_INFO : AV_LOG_DEBUG;
 
-    av_log(ctx, AV_LOG_INFO, "Repeated Fields: Neither:%6"PRId64" Top:%6"PRId64" Bottom:%6"PRId64"\n",
+    av_log(ctx, level, "Repeated Fields: Neither:%6"PRId64" Top:%6"PRId64" Bottom:%6"PRId64"\n",
            idet->total_repeats[REPEAT_NONE],
            idet->total_repeats[REPEAT_TOP],
            idet->total_repeats[REPEAT_BOTTOM]
         );
-    av_log(ctx, AV_LOG_INFO, "Single frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
+    av_log(ctx, level, "Single frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
            idet->total_prestat[TFF],
            idet->total_prestat[BFF],
            idet->total_prestat[PROGRESSIVE],
            idet->total_prestat[UNDETERMINED]
         );
-    av_log(ctx, AV_LOG_INFO, "Multi frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
+    av_log(ctx, level, "Multi frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
            idet->total_poststat[TFF],
            idet->total_poststat[BFF],
            idet->total_poststat[PROGRESSIVE],
--- FFmpeg-n4.4.4/libavfilter/vf_scale.c
+++ Ascendffmpeg/libavfilter/vf_scale.c
@@ -493,19 +493,19 @@
     if ((ret = scale_eval_dimensions(ctx)) < 0)
         goto fail;
 
-    outlink->w = scale->w;
-    outlink->h = scale->h;
-
-    ff_scale_adjust_dimensions(inlink, &outlink->w, &outlink->h,
+    ff_scale_adjust_dimensions(inlink, &scale->w, &scale->h,
                                scale->force_original_aspect_ratio,
                                scale->force_divisible_by);
 
-    if (outlink->w > INT_MAX ||
-        outlink->h > INT_MAX ||
-        (outlink->h * inlink->w) > INT_MAX ||
-        (outlink->w * inlink->h) > INT_MAX)
+    if (scale->w > INT_MAX ||
+        scale->h > INT_MAX ||
+        (scale->h * inlink->w) > INT_MAX ||
+        (scale->w * inlink->h) > INT_MAX)
         av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
 
+    outlink->w = scale->w;
+    outlink->h = scale->h;
+
     /* TODO: make algorithm configurable */
 
     scale->input_is_pal = desc->flags & AV_PIX_FMT_FLAG_PAL;
@@ -684,9 +684,9 @@
             goto scale;
 
         if (scale->eval_mode == EVAL_MODE_INIT) {
-            snprintf(buf, sizeof(buf) - 1, "%d", scale->w);
+            snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
             av_opt_set(scale, "w", buf, 0);
-            snprintf(buf, sizeof(buf) - 1, "%d", scale->h);
+            snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
             av_opt_set(scale, "h", buf, 0);
 
             ret = scale_parse_expr(ctx, NULL, &scale->w_pexpr, "width", scale->w_expr);
--- FFmpeg-n4.4.4/libavfilter/vf_showinfo.c
+++ Ascendffmpeg/libavfilter/vf_showinfo.c
@@ -454,15 +454,12 @@
             av_log(ctx, AV_LOG_INFO, " %08"PRIX32, plane_checksum[plane]);
         av_log(ctx, AV_LOG_INFO, "] mean:[");
         for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
-            av_log(ctx, AV_LOG_INFO, "%s%"PRId64,
-                   plane ? " ":"",
-                   (sum[plane] + pixelcount[plane]/2) / pixelcount[plane]);
-        av_log(ctx, AV_LOG_INFO, "] stdev:[");
+            av_log(ctx, AV_LOG_INFO, "%"PRId64" ", (sum[plane] + pixelcount[plane]/2) / pixelcount[plane]);
+        av_log(ctx, AV_LOG_INFO, "\b] stdev:[");
         for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
-            av_log(ctx, AV_LOG_INFO, "%s%3.1f",
-                   plane ? " ":"",
+            av_log(ctx, AV_LOG_INFO, "%3.1f ",
                    sqrt((sum2[plane] - sum[plane]*(double)sum[plane]/pixelcount[plane])/pixelcount[plane]));
-        av_log(ctx, AV_LOG_INFO, "]");
+        av_log(ctx, AV_LOG_INFO, "\b]");
     }
     av_log(ctx, AV_LOG_INFO, "\n");
 
--- FFmpeg-n4.4.4/libavfilter/vf_signature.c
+++ Ascendffmpeg/libavfilter/vf_signature.c
@@ -224,7 +224,7 @@
     dw1 = inlink->w / 32;
     if (inlink->w % 32)
         dw2 = dw1 + 1;
-    denom = (sc->divide) ? dh1 * (int64_t)dh2 * dw1 * dw2 : 1;
+    denom = (sc->divide) ? dh1 * dh2 * dw1 * dw2 : 1;
 
     for (i = 0; i < 32; i++) {
         rowcount = 0;
@@ -250,7 +250,7 @@
         }
     }
 
-    denom = (sc->divide) ? 1 : dh1 * (int64_t)dh2 * dw1 * dw2;
+    denom = (sc->divide) ? 1 : dh1 * dh2 * dw1 * dw2;
 
     for (i = 0; i < ELEMENT_COUNT; i++) {
         const ElemCat* elemcat = elements[i];
--- FFmpeg-n4.4.4/libavfilter/vf_subtitles.c
+++ Ascendffmpeg/libavfilter/vf_subtitles.c
@@ -145,16 +145,9 @@
     ff_draw_init(&ass->draw, inlink->format, ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
 
     ass_set_frame_size  (ass->renderer, inlink->w, inlink->h);
-    if (ass->original_w && ass->original_h) {
+    if (ass->original_w && ass->original_h)
         ass_set_aspect_ratio(ass->renderer, (double)inlink->w / inlink->h,
                              (double)ass->original_w / ass->original_h);
-#if LIBASS_VERSION > 0x01010000
-        ass_set_storage_size(ass->renderer, ass->original_w, ass->original_h);
-    } else {
-        ass_set_storage_size(ass->renderer, inlink->w, inlink->h);
-#endif
-    }
-
     if (ass->shaping != -1)
         ass_set_shaper(ass->renderer, ass->shaping);
 
--- FFmpeg-n4.4.4/libavfilter/vf_untile.c
+++ Ascendffmpeg/libavfilter/vf_untile.c
@@ -139,8 +139,8 @@
         if (!(s->desc->flags & AV_PIX_FMT_FLAG_PAL || s->desc->flags & FF_PSEUDOPAL)) {
             for (i = 1; i < 3; i ++) {
                 if (out->data[i]) {
-                    out->data[i] += (y >> s->desc->log2_chroma_h) * out->linesize[i];
-                    out->data[i] += (x >> s->desc->log2_chroma_w) * s->max_step[i];
+                    out->data[i] += (y >> s->desc->log2_chroma_w) * out->linesize[i];
+                    out->data[i] += (x >> s->desc->log2_chroma_h) * s->max_step[i];
                 }
             }
         }
--- FFmpeg-n4.4.4/libavfilter/vf_w3fdif.c
+++ Ascendffmpeg/libavfilter/vf_w3fdif.c
@@ -283,7 +283,7 @@
     AVFilterContext *ctx = inlink->dst;
     W3FDIFContext *s = ctx->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
-    int ret, i, depth, nb_threads;
+    int ret, i, depth;
 
     if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
         return ret;
@@ -297,11 +297,10 @@
     }
 
     s->nb_planes = av_pix_fmt_count_planes(inlink->format);
-    nb_threads = ff_filter_get_nb_threads(ctx);
-    s->work_line = av_calloc(nb_threads, sizeof(*s->work_line));
+    s->nb_threads = ff_filter_get_nb_threads(ctx);
+    s->work_line = av_calloc(s->nb_threads, sizeof(*s->work_line));
     if (!s->work_line)
         return AVERROR(ENOMEM);
-    s->nb_threads = nb_threads;
 
     for (i = 0; i < s->nb_threads; i++) {
         s->work_line[i] = av_calloc(FFALIGN(s->linesize[0], 32), sizeof(*s->work_line[0]));
--- FFmpeg-n4.4.4/libavfilter/video.c
+++ Ascendffmpeg/libavfilter/video.c
@@ -41,7 +41,7 @@
     return ff_get_video_buffer(link->dst->outputs[0], w, h);
 }
 
-AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align)
+AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
 {
     AVFrame *frame = NULL;
     int pool_width = 0;
@@ -94,11 +94,6 @@
     frame->sample_aspect_ratio = link->sample_aspect_ratio;
 
     return frame;
-}
-
-AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
-{
-    return ff_default_get_video_buffer2(link, w, h, av_cpu_max_align());
 }
 
 AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
--- FFmpeg-n4.4.4/libavfilter/video.h
+++ Ascendffmpeg/libavfilter/video.h
@@ -24,7 +24,6 @@
 #include "avfilter.h"
 
 AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h);
-AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align);
 AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h);
 
 /**
--- FFmpeg-n4.4.4/libavfilter/vsrc_mandelbrot.c
+++ Ascendffmpeg/libavfilter/vsrc_mandelbrot.c
@@ -134,9 +134,6 @@
     s-> next_cache= av_malloc_array(s->cache_allocated, sizeof(*s-> next_cache));
     s-> zyklus    = av_malloc_array(s->maxiter + 16, sizeof(*s->zyklus));
 
-    if (!s->point_cache || !s->next_cache || !s->zyklus)
-        return AVERROR(ENOMEM);
-
     return 0;
 }
 
--- FFmpeg-n4.4.4/libavformat/4xm.c
+++ Ascendffmpeg/libavformat/4xm.c
@@ -137,8 +137,7 @@
         return AVERROR_INVALIDDATA;
 
     track = AV_RL32(buf + 8);
-    if ((unsigned)track >= UINT_MAX / sizeof(AudioTrack) - 1 ||
-        track >= s->max_streams) {
+    if ((unsigned)track >= UINT_MAX / sizeof(AudioTrack) - 1) {
         av_log(s, AV_LOG_ERROR, "current_track too large\n");
         return AVERROR_INVALIDDATA;
     }
@@ -149,9 +148,6 @@
         memset(&fourxm->tracks[fourxm->track_count], 0,
                sizeof(AudioTrack) * (track + 1 - fourxm->track_count));
         fourxm->track_count = track + 1;
-    } else {
-        if (fourxm->tracks[track].bits)
-            return AVERROR_INVALIDDATA;
     }
     fourxm->tracks[track].adpcm       = AV_RL32(buf + 12);
     fourxm->tracks[track].channels    = AV_RL32(buf + 36);
--- FFmpeg-n4.4.4/libavformat/aadec.c
+++ Ascendffmpeg/libavformat/aadec.c
@@ -130,8 +130,8 @@
                 AV_WB32(&header_key[idx * 4], header_key_part[idx]); // convert each part to BE!
             }
             av_log(s, AV_LOG_DEBUG, "Processed HeaderKey is ");
-            for (int j = 0; j < 16; j++)
-                av_log(s, AV_LOG_DEBUG, "%02x", header_key[j]);
+            for (i = 0; i < 16; i++)
+                av_log(s, AV_LOG_DEBUG, "%02x", header_key[i]);
             av_log(s, AV_LOG_DEBUG, "\n");
         } else {
             av_dict_set(&s->metadata, key, val, 0);
--- FFmpeg-n4.4.4/libavformat/aaxdec.c
+++ Ascendffmpeg/libavformat/aaxdec.c
@@ -262,8 +262,6 @@
 
                 start = avio_rb32(pb);
                 size  = avio_rb32(pb);
-                if (!size)
-                    return AVERROR_INVALIDDATA;
                 a->segments[r].start = start + a->data_offset;
                 a->segments[r].end   = a->segments[r].start + size;
             } else {
--- FFmpeg-n4.4.4/libavformat/act.c
+++ Ascendffmpeg/libavformat/act.c
@@ -66,7 +66,6 @@
     AVIOContext *pb = s->pb;
     int size;
     AVStream* st;
-    int ret;
 
     int min,sec,msec;
 
@@ -76,9 +75,7 @@
 
     avio_skip(pb, 16);
     size=avio_rl32(pb);
-    ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
-    if (ret < 0)
-        return ret;
+    ff_get_wav_header(s, pb, st->codecpar, size, 0);
 
     /*
       8000Hz (Fine-rec) file format has 10 bytes long
--- FFmpeg-n4.4.4/libavformat/aiffdec.c
+++ Ascendffmpeg/libavformat/aiffdec.c
@@ -53,9 +53,9 @@
 }
 
 /* returns the size of the found tag */
-static int64_t get_tag(AVIOContext *pb, uint32_t * tag)
+static int get_tag(AVIOContext *pb, uint32_t * tag)
 {
-    int64_t size;
+    int size;
 
     if (avio_feof(pb))
         return AVERROR(EIO);
@@ -63,17 +63,17 @@
     *tag = avio_rl32(pb);
     size = avio_rb32(pb);
 
+    if (size < 0)
+        size = 0x7fffffff;
+
     return size;
 }
 
 /* Metadata string read */
-static void get_meta(AVFormatContext *s, const char *key, int64_t size)
+static void get_meta(AVFormatContext *s, const char *key, int size)
 {
-    uint8_t *str = NULL;
+    uint8_t *str = av_malloc(size+1);
 
-    if (size < SIZE_MAX)
-        str = av_malloc(size+1);
-
     if (str) {
         int res = avio_read(s->pb, str, size);
         if (res < 0){
@@ -89,7 +89,7 @@
 }
 
 /* Returns the number of sound data frames or negative on error */
-static int get_aiff_header(AVFormatContext *s, int64_t size,
+static int get_aiff_header(AVFormatContext *s, int size,
                                     unsigned version)
 {
     AVIOContext *pb        = s->pb;
@@ -100,6 +100,9 @@
     int sample_rate;
     unsigned int num_frames;
 
+    if (size == INT_MAX)
+        return AVERROR_INVALIDDATA;
+
     if (size & 1)
         size++;
     par->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -117,9 +120,6 @@
         sample_rate = val << exp;
     else
         sample_rate = (val + (1ULL<<(-exp-1))) >> -exp;
-    if (sample_rate <= 0)
-        return AVERROR_INVALIDDATA;
-
     par->sample_rate = sample_rate;
     if (size < 18)
         return AVERROR_INVALIDDATA;
@@ -182,10 +182,8 @@
         par->block_align = (av_get_bits_per_sample(par->codec_id) * par->channels) >> 3;
 
     if (aiff->block_duration) {
-        par->bit_rate = av_rescale(par->sample_rate, par->block_align * 8LL,
-                                   aiff->block_duration);
-        if (par->bit_rate < 0)
-            par->bit_rate = 0;
+        par->bit_rate = (int64_t)par->sample_rate * (par->block_align << 3) /
+                        aiff->block_duration;
     }
 
     /* Chunk is over */
@@ -210,8 +208,7 @@
 /* aiff input */
 static int aiff_read_header(AVFormatContext *s)
 {
-    int ret;
-    int64_t filesize, size;
+    int ret, size, filesize;
     int64_t offset = 0, position;
     uint32_t tag;
     unsigned version = AIFF_C_VERSION1;
@@ -222,7 +219,7 @@
 
     /* check FORM header */
     filesize = get_tag(pb, &tag);
-    if (filesize < 4 || tag != MKTAG('F', 'O', 'R', 'M'))
+    if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))
         return AVERROR_INVALIDDATA;
 
     /* AIFF data type */
@@ -249,7 +246,10 @@
         if (size < 0)
             return size;
 
-        filesize -= size + 8;
+        if (size >= 0x7fffffff - 8)
+            filesize = 0;
+        else
+            filesize -= size + 8;
 
         switch (tag) {
         case MKTAG('C', 'O', 'M', 'M'):     /* Common chunk */
@@ -365,12 +365,10 @@
     if (!st->codecpar->block_align && st->codecpar->codec_id == AV_CODEC_ID_QCELP) {
         av_log(s, AV_LOG_WARNING, "qcelp without wave chunk, assuming full rate\n");
         st->codecpar->block_align = 35;
-    } else if (st->codecpar->block_align <= 0) {
+    } else if (!st->codecpar->block_align) {
         av_log(s, AV_LOG_ERROR, "could not find COMM tag or invalid block_align value\n");
         return -1;
     }
-    if (aiff->block_duration < 0)
-        return AVERROR_INVALIDDATA;
 
     /* Now positioned, get the sound data start and end */
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
@@ -425,7 +423,7 @@
         pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
     /* Only one stream in an AIFF file */
     pkt->stream_index = 0;
-    pkt->duration     = (res / st->codecpar->block_align) * (int64_t) aiff->block_duration;
+    pkt->duration     = (res / st->codecpar->block_align) * aiff->block_duration;
     return 0;
 }
 
--- FFmpeg-n4.4.4/libavformat/ape.c
+++ Ascendffmpeg/libavformat/ape.c
@@ -42,8 +42,8 @@
 
 typedef struct APEFrame {
     int64_t pos;
-    int64_t size;
     int nblocks;
+    int size;
     int skip;
     int64_t pts;
 } APEFrame;
@@ -130,7 +130,7 @@
 
     av_log(s, AV_LOG_DEBUG, "\nFrames\n\n");
     for (i = 0; i < ape_ctx->totalframes; i++)
-        av_log(s, AV_LOG_DEBUG, "%8d   %8"PRId64" %8"PRId64" (%d samples)\n", i,
+        av_log(s, AV_LOG_DEBUG, "%8d   %8"PRId64" %8d (%d samples)\n", i,
                ape_ctx->frames[i].pos, ape_ctx->frames[i].size,
                ape_ctx->frames[i].nblocks);
 
@@ -148,8 +148,7 @@
     AVStream *st;
     uint32_t tag;
     int i, ret;
-    int total_blocks;
-    int64_t final_size = 0;
+    int total_blocks, final_size = 0;
     int64_t pts, file_size;
 
     /* Skip any leading junk such as id3v2 tags */
@@ -301,8 +300,6 @@
             ape->frames[i].pos  -= ape->frames[i].skip;
             ape->frames[i].size += ape->frames[i].skip;
         }
-        if (ape->frames[i].size > INT_MAX - 3)
-            return AVERROR_INVALIDDATA;
         ape->frames[i].size = (ape->frames[i].size + 3) & ~3;
     }
     if (ape->fileversion < 3810) {
@@ -400,7 +397,7 @@
 
     if (ape->frames[ape->currentframe].size <= 0 ||
         ape->frames[ape->currentframe].size > INT_MAX - extra_size) {
-        av_log(s, AV_LOG_ERROR, "invalid packet size: %8"PRId64"\n",
+        av_log(s, AV_LOG_ERROR, "invalid packet size: %d\n",
                ape->frames[ape->currentframe].size);
         ape->currentframe++;
         return AVERROR(EIO);
--- FFmpeg-n4.4.4/libavformat/aqtitledec.c
+++ Ascendffmpeg/libavformat/aqtitledec.c
@@ -74,8 +74,7 @@
             new_event = 1;
             pos = avio_tell(s->pb);
             if (sub) {
-                if (frame >= sub->pts && (uint64_t)frame - sub->pts < INT64_MAX)
-                    sub->duration = frame - sub->pts;
+                sub->duration = frame - sub->pts;
                 sub = NULL;
             }
         } else if (*line) {
--- FFmpeg-n4.4.4/libavformat/argo_asf.c
+++ Ascendffmpeg/libavformat/argo_asf.c
@@ -422,7 +422,7 @@
     ArgoASFMuxContext *ctx = s->priv_data;
     int64_t ret;
 
-    if ((ret = avio_seek(s->pb, ASF_FILE_HEADER_SIZE, SEEK_SET)) < 0)
+    if ((ret = avio_seek(s->pb, ASF_FILE_HEADER_SIZE, SEEK_SET) < 0))
         return ret;
 
     avio_wl32(s->pb, (uint32_t)ctx->nb_blocks);
--- FFmpeg-n4.4.4/libavformat/asfdec_f.c
+++ Ascendffmpeg/libavformat/asfdec_f.c
@@ -104,7 +104,7 @@
     int ts_is_pts;
     int packet_multi_size;
     int packet_time_delta;
-    int64_t packet_time_start;
+    int packet_time_start;
     int64_t packet_pos;
 
     int stream_index;
@@ -1321,12 +1321,10 @@
             if ((ret = av_new_packet(&asf_st->pkt, asf_st->packet_obj_size)) < 0)
                 return ret;
             asf_st->seq              = asf->packet_seq;
-            if (asf->packet_frag_timestamp != AV_NOPTS_VALUE) {
-                if (asf->ts_is_pts) {
-                    asf_st->pkt.pts          = asf->packet_frag_timestamp - asf->hdr.preroll;
-                } else
-                    asf_st->pkt.dts          = asf->packet_frag_timestamp - asf->hdr.preroll;
-            }
+            if (asf->ts_is_pts) {
+                asf_st->pkt.pts          = asf->packet_frag_timestamp - asf->hdr.preroll;
+            } else
+                asf_st->pkt.dts          = asf->packet_frag_timestamp - asf->hdr.preroll;
             asf_st->pkt.stream_index = asf->stream_index;
             asf_st->pkt.pos          = asf_st->packet_pos = asf->packet_pos;
             asf_st->pkt_clean        = 0;
--- FFmpeg-n4.4.4/libavformat/asfdec_o.c
+++ Ascendffmpeg/libavformat/asfdec_o.c
@@ -113,7 +113,6 @@
     int64_t data_offset;
     int64_t first_packet_offset; // packet offset
     int64_t unknown_offset;   // for top level header objects or subobjects without specified behavior
-    int in_asf_read_unknown;
 
     // ASF file must not contain more than 128 streams according to the specification
     ASFStream *asf_st[ASF_MAX_STREAMS];
@@ -178,7 +177,7 @@
     uint64_t size   = avio_rl64(pb);
     int ret;
 
-    if (size > INT64_MAX || asf->in_asf_read_unknown > 5)
+    if (size > INT64_MAX)
         return AVERROR_INVALIDDATA;
 
     if (asf->is_header)
@@ -187,11 +186,8 @@
     if (!g->is_subobject) {
         if (!(ret = strcmp(g->name, "Header Extension")))
             avio_skip(pb, 22); // skip reserved fields and Data Size
-        asf->in_asf_read_unknown ++;
-        ret = detect_unknown_subobject(s, asf->unknown_offset,
-                                            asf->unknown_size);
-        asf->in_asf_read_unknown --;
-        if (ret < 0)
+        if ((ret = detect_unknown_subobject(s, asf->unknown_offset,
+                                            asf->unknown_size)) < 0)
             return ret;
     } else {
         if (size < 24) {
@@ -1354,8 +1350,6 @@
     unsigned char error_flags, len_flags, pay_flags;
 
     asf->packet_offset = avio_tell(pb);
-    if (asf->packet_offset > INT64_MAX/2)
-        asf->packet_offset = 0;
     error_flags = avio_r8(pb); // read Error Correction Flags
     if (error_flags & ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT) {
         if (!(error_flags & ASF_ERROR_CORRECTION_LENGTH_TYPE)) {
--- FFmpeg-n4.4.4/libavformat/avidec.c
+++ Ascendffmpeg/libavformat/avidec.c
@@ -79,8 +79,6 @@
     int stream_index;
     DVDemuxContext *dv_demux;
     int odml_depth;
-    int64_t odml_read;
-    int64_t odml_max_pos;
     int use_odml;
 #define MAX_ODML_DEPTH 1000
     int64_t dts_max;
@@ -200,7 +198,7 @@
     st  = s->streams[stream_id];
     ast = st->priv_data;
 
-    if (index_sub_type || entries_in_use < 0)
+    if (index_sub_type)
         return AVERROR_INVALIDDATA;
 
     avio_rl32(pb);
@@ -221,18 +219,11 @@
     }
 
     for (i = 0; i < entries_in_use; i++) {
-        avi->odml_max_pos = FFMAX(avi->odml_max_pos, avio_tell(pb));
-
-        // If we read more than there are bytes then we must have been reading something twice
-        if (avi->odml_read > avi->odml_max_pos)
-            return AVERROR_INVALIDDATA;
-
         if (index_type) {
             int64_t pos = avio_rl32(pb) + base - 8;
             int len     = avio_rl32(pb);
             int key     = len >= 0;
             len &= 0x7FFFFFFF;
-            avi->odml_read += 8;
 
             av_log(s, AV_LOG_TRACE, "pos:%"PRId64", len:%X\n", pos, len);
 
@@ -250,9 +241,6 @@
         } else {
             int64_t offset, pos;
             int duration;
-            int ret;
-            avi->odml_read += 16;
-
             offset = avio_rl64(pb);
             avio_rl32(pb);       /* size */
             duration = avio_rl32(pb);
@@ -270,7 +258,7 @@
             if (avio_seek(pb, offset + 8, SEEK_SET) < 0)
                 return -1;
             avi->odml_depth++;
-            ret = read_odml_index(s, frame_num);
+            read_odml_index(s, frame_num);
             avi->odml_depth--;
             frame_num += duration;
 
@@ -278,8 +266,7 @@
                 av_log(s, AV_LOG_ERROR, "Failed to restore position after reading index\n");
                 return -1;
             }
-            if (ret < 0)
-                return ret;
+
         }
     }
     avi->index_loaded = 2;
@@ -869,8 +856,6 @@
                             memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9,
                                    "BottomUp", 9);
                     }
-                    if (st->codecpar->height == INT_MIN)
-                        return AVERROR_INVALIDDATA;
                     st->codecpar->height = FFABS(st->codecpar->height);
 
 //                    avio_skip(pb, size - 5 * 4);
--- FFmpeg-n4.4.4/libavformat/aviobuf.c
+++ Ascendffmpeg/libavformat/aviobuf.c
@@ -1005,9 +1005,6 @@
     if (buf_size <= s->buf_end - s->buf_ptr)
         return 0;
 
-    if (buf_size > INT_MAX - max_buffer_size)
-        return AVERROR(EINVAL);
-
     buf_size += max_buffer_size - 1;
 
     if (buf_size + s->buf_ptr - s->buffer <= s->buffer_size || s->seekable || !s->read_packet)
--- FFmpeg-n4.4.4/libavformat/bfi.c
+++ Ascendffmpeg/libavformat/bfi.c
@@ -140,12 +140,12 @@
         audio_offset    = avio_rl32(pb);
         avio_rl32(pb);
         video_offset    = avio_rl32(pb);
-        if (audio_offset < 0 || video_offset < audio_offset || chunk_size < video_offset) {
+        audio_size      = video_offset - audio_offset;
+        bfi->video_size = chunk_size - video_offset;
+        if (audio_size < 0 || bfi->video_size < 0) {
             av_log(s, AV_LOG_ERROR, "Invalid audio/video offsets or chunk size\n");
             return AVERROR_INVALIDDATA;
         }
-        audio_size      = video_offset - audio_offset;
-        bfi->video_size = chunk_size - video_offset;
 
         //Tossing an audio packet at the audio decoder.
         ret = av_get_packet(pb, pkt, audio_size);
--- FFmpeg-n4.4.4/libavformat/cafdec.c
+++ Ascendffmpeg/libavformat/cafdec.c
@@ -241,8 +241,6 @@
         char value[1024];
         avio_get_str(pb, INT_MAX, key, sizeof(key));
         avio_get_str(pb, INT_MAX, value, sizeof(value));
-        if (!*key)
-            continue;
         av_dict_set(&s->metadata, key, value, 0);
     }
 }
@@ -342,7 +340,7 @@
 
 found_data:
     if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
-        if (caf->data_size > 0 && caf->data_size / caf->bytes_per_packet < INT64_MAX / caf->frames_per_packet)
+        if (caf->data_size > 0)
             st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
     } else if (st->nb_index_entries && st->duration > 0) {
         if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) {
--- FFmpeg-n4.4.4/libavformat/cafenc.c
+++ Ascendffmpeg/libavformat/cafenc.c
@@ -28,6 +28,7 @@
 
 typedef struct {
     int64_t data;
+    uint8_t *pkt_sizes;
     int size_buffer_size;
     int size_entries_used;
     int packets;
@@ -208,29 +209,30 @@
 static int caf_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     CAFContext *caf = s->priv_data;
-    AVStream *const st = s->streams[0];
 
-    if (!st->codecpar->block_align) {
-        uint8_t *pkt_sizes;
-        int i, alloc_size = caf->size_entries_used + 5U;
-        if (alloc_size < 0)
-            return AVERROR(ERANGE);
-
-        pkt_sizes = av_fast_realloc(st->priv_data,
-                                    &caf->size_buffer_size,
-                                    alloc_size);
-        if (!pkt_sizes)
+    avio_write(s->pb, pkt->data, pkt->size);
+    if (!s->streams[0]->codecpar->block_align) {
+        void *pkt_sizes = caf->pkt_sizes;
+        int i, alloc_size = caf->size_entries_used + 5;
+        if (alloc_size < 0) {
+            caf->pkt_sizes = NULL;
+        } else {
+            caf->pkt_sizes = av_fast_realloc(caf->pkt_sizes,
+                                             &caf->size_buffer_size,
+                                             alloc_size);
+        }
+        if (!caf->pkt_sizes) {
+            av_free(pkt_sizes);
             return AVERROR(ENOMEM);
-        st->priv_data = pkt_sizes;
+        }
         for (i = 4; i > 0; i--) {
             unsigned top = pkt->size >> i * 7;
             if (top)
-                pkt_sizes[caf->size_entries_used++] = 128 | top;
+                caf->pkt_sizes[caf->size_entries_used++] = 128 | top;
         }
-        pkt_sizes[caf->size_entries_used++] = pkt->size & 127;
+        caf->pkt_sizes[caf->size_entries_used++] = pkt->size & 127;
         caf->packets++;
     }
-    avio_write(s->pb, pkt->data, pkt->size);
     return 0;
 }
 
@@ -238,8 +240,7 @@
 {
     CAFContext *caf = s->priv_data;
     AVIOContext *pb = s->pb;
-    AVStream *st = s->streams[0];
-    AVCodecParameters *par = st->codecpar;
+    AVCodecParameters *par = s->streams[0]->codecpar;
 
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
         int64_t file_size = avio_tell(pb);
@@ -249,14 +250,16 @@
         avio_seek(pb, file_size, SEEK_SET);
         if (!par->block_align) {
             ffio_wfourcc(pb, "pakt");
-            avio_wb64(pb, caf->size_entries_used + 24U);
+            avio_wb64(pb, caf->size_entries_used + 24);
             avio_wb64(pb, caf->packets); ///< mNumberPackets
             avio_wb64(pb, caf->packets * samples_per_packet(par->codec_id, par->channels, par->block_align)); ///< mNumberValidFrames
             avio_wb32(pb, 0); ///< mPrimingFrames
             avio_wb32(pb, 0); ///< mRemainderFrames
-            avio_write(pb, st->priv_data, caf->size_entries_used);
+            avio_write(pb, caf->pkt_sizes, caf->size_entries_used);
+            caf->size_buffer_size = 0;
         }
     }
+    av_freep(&caf->pkt_sizes);
     return 0;
 }
 
--- FFmpeg-n4.4.4/libavformat/dxa.c
+++ Ascendffmpeg/libavformat/dxa.c
@@ -118,12 +118,9 @@
             if(tag == MKTAG('d', 'a', 't', 'a')) break;
             avio_skip(pb, fsize);
         }
-        c->bpc = (fsize + (int64_t)c->frames - 1) / c->frames;
-        if(ast->codecpar->block_align) {
-            if (c->bpc > INT_MAX - ast->codecpar->block_align + 1)
-                return AVERROR_INVALIDDATA;
+        c->bpc = (fsize + c->frames - 1) / c->frames;
+        if(ast->codecpar->block_align)
             c->bpc = ((c->bpc + ast->codecpar->block_align - 1) / ast->codecpar->block_align) * ast->codecpar->block_align;
-        }
         c->bytes_left = fsize;
         c->wavpos = avio_tell(pb);
         avio_seek(pb, c->vidpos, SEEK_SET);
--- FFmpeg-n4.4.4/libavformat/flvdec.c
+++ Ascendffmpeg/libavformat/flvdec.c
@@ -64,7 +64,7 @@
     uint8_t resync_buffer[2*RESYNC_BUFFER_SIZE];
 
     int broken_sizes;
-    int64_t sum_flv_tag_size;
+    int sum_flv_tag_size;
 
     int last_keyframe_stream_index;
     int keyframe_count;
@@ -459,10 +459,6 @@
             d = av_int2double(avio_rb64(ioc));
             if (isnan(d) || d < INT64_MIN || d > INT64_MAX)
                 goto invalid;
-            if (current_array == &times && (d <= INT64_MIN / 1000 || d >= INT64_MAX / 1000))
-                goto invalid;
-            if (avio_feof(ioc))
-                goto invalid;
             current_array[0][i] = d;
         }
         if (times && filepositions) {
@@ -1033,7 +1029,7 @@
     type = (avio_r8(s->pb) & 0x1F);
     orig_size =
     size = avio_rb24(s->pb);
-    flv->sum_flv_tag_size += size + 11LL;
+    flv->sum_flv_tag_size += size + 11;
     dts  = avio_rb24(s->pb);
     dts |= (unsigned)avio_r8(s->pb) << 24;
     av_log(s, AV_LOG_TRACE, "type:%d, size:%d, last:%d, dts:%"PRId64" pos:%"PRId64"\n", type, size, last, dts, avio_tell(s->pb));
@@ -1335,7 +1331,7 @@
             !avio_feof(s->pb) &&
             (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
             !flv->broken_sizes) {
-            av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %"PRId64"\n", last, orig_size + 11, flv->sum_flv_tag_size);
+            av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %d\n", last, orig_size + 11, flv->sum_flv_tag_size);
             avio_seek(s->pb, pos + 1, SEEK_SET);
             ret = resync(s);
             av_packet_unref(pkt);
--- FFmpeg-n4.4.4/libavformat/genh.c
+++ Ascendffmpeg/libavformat/genh.c
@@ -67,9 +67,6 @@
         return AVERROR_INVALIDDATA;
     st->codecpar->block_align = align * st->codecpar->channels;
     st->codecpar->sample_rate = avio_rl32(s->pb);
-    if (st->codecpar->sample_rate < 0)
-        return AVERROR_INVALIDDATA;
-
     avio_skip(s->pb, 4);
     st->duration = avio_rl32(s->pb);
 
--- FFmpeg-n4.4.4/libavformat/hls.c
+++ Ascendffmpeg/libavformat/hls.c
@@ -236,7 +236,6 @@
 {
     int i;
     for (i = 0; i < pls->n_init_sections; i++) {
-        av_freep(&pls->init_sections[i]->key);
         av_freep(&pls->init_sections[i]->url);
         av_freep(&pls->init_sections[i]);
     }
@@ -811,26 +810,20 @@
                                &info);
             new_rendition(c, &info, url);
         } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
-            int64_t t;
             ret = ensure_playlist(c, &pls, url);
             if (ret < 0)
                 goto fail;
-            t = strtoll(ptr, NULL, 10);
-            if (t < 0 || t >= INT64_MAX / AV_TIME_BASE) {
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
-            }
-            pls->target_duration = t * AV_TIME_BASE;
+            pls->target_duration = strtoll(ptr, NULL, 10) * AV_TIME_BASE;
         } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
             uint64_t seq_no;
             ret = ensure_playlist(c, &pls, url);
             if (ret < 0)
                 goto fail;
             seq_no = strtoull(ptr, NULL, 10);
-            if (seq_no > INT64_MAX/2) {
+            if (seq_no > INT64_MAX) {
                 av_log(c->ctx, AV_LOG_DEBUG, "MEDIA-SEQUENCE higher than "
-                        "INT64_MAX/2, mask out the highest bit\n");
-                seq_no &= INT64_MAX/2;
+                        "INT64_MAX, mask out the highest bit\n");
+                seq_no &= INT64_MAX;
             }
             pls->start_seq_no = seq_no;
         } else if (av_strstart(line, "#EXT-X-PLAYLIST-TYPE:", &ptr)) {
@@ -910,7 +903,7 @@
                 if (has_iv) {
                     memcpy(seg->iv, iv, sizeof(iv));
                 } else {
-                    uint64_t seq = pls->start_seq_no + (uint64_t)pls->n_segments;
+                    int64_t seq = pls->start_seq_no + pls->n_segments;
                     memset(seg->iv, 0, sizeof(seg->iv));
                     AV_WB64(seg->iv + 8, seq);
                 }
--- FFmpeg-n4.4.4/libavformat/icodec.c
+++ Ascendffmpeg/libavformat/icodec.c
@@ -203,9 +203,6 @@
             AV_WL32(buf + 32, image->nb_pal);
         }
 
-        if (image->nb_pal > INT_MAX / 4 - 14 - 40)
-            return AVERROR_INVALIDDATA;
-
         AV_WL32(buf - 4, 14 + 40 + image->nb_pal * 4);
         AV_WL32(buf + 8, AV_RL32(buf + 8) / 2);
     }
--- FFmpeg-n4.4.4/libavformat/id3v2.c
+++ Ascendffmpeg/libavformat/id3v2.c
@@ -376,10 +376,10 @@
     lang[3] = '\0';
     taglen -= 3;
 
-    if (decode_str(s, pb, encoding, &descriptor, &taglen) < 0 || taglen < 0)
+    if (decode_str(s, pb, encoding, &descriptor, &taglen) < 0)
         goto error;
 
-    if (decode_str(s, pb, encoding, &text, &taglen) < 0 || taglen < 0)
+    if (decode_str(s, pb, encoding, &text, &taglen) < 0)
         goto error;
 
     // FFmpeg does not support hierarchical metadata, so concatenate the keys.
--- FFmpeg-n4.4.4/libavformat/iff.c
+++ Ascendffmpeg/libavformat/iff.c
@@ -385,7 +385,7 @@
                 avio_skip(pb, 1);
             pkt->flags |= AV_PKT_FLAG_KEY;
             pkt->stream_index = 0;
-            pkt->duration = s->streams[0]->codecpar->sample_rate / 75;
+            pkt->duration = 588LL * s->streams[0]->codecpar->sample_rate / 44100;
             pkt->pos = chunk_pos;
 
             chunk_pos = avio_tell(pb);
@@ -398,8 +398,7 @@
         case ID_FRTE:
             if (data_size < 4)
                 return AVERROR_INVALIDDATA;
-            s->streams[0]->duration = avio_rb32(pb) * (uint64_t)s->streams[0]->codecpar->sample_rate / 75;
-
+            s->streams[0]->duration = avio_rb32(pb) * 588LL * s->streams[0]->codecpar->sample_rate / 44100;
             break;
         }
 
@@ -502,9 +501,6 @@
         case ID_DST:
         case ID_MDAT:
             iff->body_pos = avio_tell(pb);
-            if (iff->body_pos < 0 || iff->body_pos + data_size > INT64_MAX)
-                return AVERROR_INVALIDDATA;
-
             iff->body_end = iff->body_pos + data_size;
             iff->body_size = data_size;
             if (chunk_id == ID_DST) {
--- FFmpeg-n4.4.4/libavformat/jacosubdec.c
+++ Ascendffmpeg/libavformat/jacosubdec.c
@@ -152,7 +152,7 @@
     ret = 0;
     switch (n) {
     case 4:
-        ret = sign * (((int64_t)a*3600 + (int64_t)b*60 + c) * timeres + d);
+        ret = sign * (((int64_t)a*3600 + b*60 + c) * timeres + d);
         break;
     case 3:
         ret = sign * ((         (int64_t)a*60 + b) * timeres + c);
--- FFmpeg-n4.4.4/libavformat/jacosubenc.c
+++ Ascendffmpeg/libavformat/jacosubenc.c
@@ -24,7 +24,7 @@
     const AVCodecParameters *par = s->streams[0]->codecpar;
 
     if (par->extradata_size) {
-        avio_write(s->pb, par->extradata, par->extradata_size);
+        avio_write(s->pb, par->extradata, par->extradata_size - 1);
     }
     return 0;
 }
--- FFmpeg-n4.4.4/libavformat/libzmq.c
+++ Ascendffmpeg/libavformat/libzmq.c
@@ -51,7 +51,7 @@
     zmq_pollitem_t items = { .socket = socket, .fd = 0, .events = ev, .revents = 0 };
     ret = zmq_poll(&items, 1, POLLING_TIME);
     if (ret == -1) {
-        av_log(h, AV_LOG_ERROR, "Error occurred during zmq_poll(): %s\n", ZMQ_STRERROR);
+        av_log(h, AV_LOG_ERROR, "Error occured during zmq_poll(): %s\n", ZMQ_STRERROR);
         return AVERROR_EXTERNAL;
     }
     return items.revents & ev ? 0 : AVERROR(EAGAIN);
@@ -90,7 +90,7 @@
     s->context = zmq_ctx_new();
     if (!s->context) {
         /*errno not set on failure during zmq_ctx_new()*/
-        av_log(h, AV_LOG_ERROR, "Error occurred during zmq_ctx_new()\n");
+        av_log(h, AV_LOG_ERROR, "Error occured during zmq_ctx_new()\n");
         return AVERROR_EXTERNAL;
     }
 
@@ -100,13 +100,13 @@
     if (h->flags & AVIO_FLAG_WRITE) {
         s->socket = zmq_socket(s->context, ZMQ_PUB);
         if (!s->socket) {
-            av_log(h, AV_LOG_ERROR, "Error occurred during zmq_socket(): %s\n", ZMQ_STRERROR);
+            av_log(h, AV_LOG_ERROR, "Error occured during zmq_socket(): %s\n", ZMQ_STRERROR);
             goto fail_term;
         }
 
         ret = zmq_bind(s->socket, uri);
         if (ret == -1) {
-            av_log(h, AV_LOG_ERROR, "Error occurred during zmq_bind(): %s\n", ZMQ_STRERROR);
+            av_log(h, AV_LOG_ERROR, "Error occured during zmq_bind(): %s\n", ZMQ_STRERROR);
             goto fail_close;
         }
     }
@@ -115,19 +115,19 @@
     if (h->flags & AVIO_FLAG_READ) {
         s->socket = zmq_socket(s->context, ZMQ_SUB);
         if (!s->socket) {
-            av_log(h, AV_LOG_ERROR, "Error occurred during zmq_socket(): %s\n", ZMQ_STRERROR);
+            av_log(h, AV_LOG_ERROR, "Error occured during zmq_socket(): %s\n", ZMQ_STRERROR);
             goto fail_term;
         }
 
         ret = zmq_setsockopt(s->socket, ZMQ_SUBSCRIBE, "", 0);
         if (ret == -1) {
-            av_log(h, AV_LOG_ERROR, "Error occurred during zmq_setsockopt(): %s\n", ZMQ_STRERROR);
+            av_log(h, AV_LOG_ERROR, "Error occured during zmq_setsockopt(): %s\n", ZMQ_STRERROR);
             goto fail_close;
         }
 
         ret = zmq_connect(s->socket, uri);
         if (ret == -1) {
-            av_log(h, AV_LOG_ERROR, "Error occurred during zmq_connect(): %s\n", ZMQ_STRERROR);
+            av_log(h, AV_LOG_ERROR, "Error occured during zmq_connect(): %s\n", ZMQ_STRERROR);
             goto fail_close;
         }
     }
@@ -150,7 +150,7 @@
         return ret;
     ret = zmq_send(s->socket, buf, size, 0);
     if (ret == -1) {
-        av_log(h, AV_LOG_ERROR, "Error occurred during zmq_send(): %s\n", ZMQ_STRERROR);
+        av_log(h, AV_LOG_ERROR, "Error occured during zmq_send(): %s\n", ZMQ_STRERROR);
         return AVERROR_EXTERNAL;
     }
     return ret; /*number of bytes sent*/
@@ -166,7 +166,7 @@
         return ret;
     ret = zmq_recv(s->socket, buf, size, 0);
     if (ret == -1) {
-        av_log(h, AV_LOG_ERROR, "Error occurred during zmq_recv(): %s\n", ZMQ_STRERROR);
+        av_log(h, AV_LOG_ERROR, "Error occured during zmq_recv(): %s\n", ZMQ_STRERROR);
         return AVERROR_EXTERNAL;
     }
     if (ret > size) {
--- FFmpeg-n4.4.4/libavformat/matroskadec.c
+++ Ascendffmpeg/libavformat/matroskadec.c
@@ -1690,7 +1690,7 @@
     case MATROSKA_TRACK_ENCODING_COMP_ZLIB:
     {
         z_stream zstream = { 0 };
-        if (!pkt_size || inflateInit(&zstream) != Z_OK)
+        if (inflateInit(&zstream) != Z_OK)
             return -1;
         zstream.next_in  = data;
         zstream.avail_in = isize;
@@ -1723,7 +1723,7 @@
     case MATROSKA_TRACK_ENCODING_COMP_BZLIB:
     {
         bz_stream bzstream = { 0 };
-        if (!pkt_size || BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
+        if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
             return -1;
         bzstream.next_in  = data;
         bzstream.avail_in = isize;
@@ -2802,14 +2802,11 @@
                 mkv_stereo_mode_display_mul(track->video.stereo_mode, &display_width_mul, &display_height_mul);
 
             if (track->video.display_unit < MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN) {
-                if (track->video.display_width && track->video.display_height &&
-                    st->codecpar->height  < INT64_MAX / track->video.display_width  / display_width_mul &&
-                    st->codecpar->width   < INT64_MAX / track->video.display_height / display_height_mul)
-                    av_reduce(&st->sample_aspect_ratio.num,
-                              &st->sample_aspect_ratio.den,
-                              st->codecpar->height * track->video.display_width  * display_width_mul,
-                              st->codecpar->width  * track->video.display_height * display_height_mul,
-                              INT_MAX);
+                av_reduce(&st->sample_aspect_ratio.num,
+                          &st->sample_aspect_ratio.den,
+                          st->codecpar->height * track->video.display_width  * display_width_mul,
+                          st->codecpar->width  * track->video.display_height * display_height_mul,
+                          255);
             }
             if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
                 st->need_parsing = AVSTREAM_PARSE_HEADERS;
@@ -2978,8 +2975,6 @@
 
     if (!matroska->time_scale)
         matroska->time_scale = 1000000;
-    if (isnan(matroska->duration))
-        matroska->duration = 0;
     if (matroska->duration)
         matroska->ctx->duration = matroska->duration * matroska->time_scale *
                                   1000 / AV_TIME_BASE;
@@ -3940,9 +3935,7 @@
     int i;
     int nb_index_entries = s->streams[0]->nb_index_entries;
     AVIndexEntry *index_entries = s->streams[0]->index_entries;
-
-    if (ts >= (int64_t)(matroska->duration * matroska->time_scale))
-        return (CueDesc) {-1, -1, -1, -1};
+    if (ts >= matroska->duration * matroska->time_scale) return (CueDesc) {-1, -1, -1, -1};
     for (i = 1; i < nb_index_entries; i++) {
         if (index_entries[i - 1].timestamp * matroska->time_scale <= ts &&
             index_entries[i].timestamp * matroska->time_scale > ts) {
@@ -4131,8 +4124,6 @@
             // prebuffered.
             pre_bytes = desc_end.end_offset - desc_end.start_offset;
             pre_ns = desc_end.end_time_ns - desc_end.start_time_ns;
-            if (pre_ns <= 0)
-                return -1;
             pre_sec = pre_ns / nano_seconds_per_second;
             prebuffer_bytes +=
                 pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec);
@@ -4144,16 +4135,12 @@
             do {
                 int64_t desc_bytes = desc_end.end_offset - desc_beg.start_offset;
                 int64_t desc_ns = desc_end.end_time_ns - desc_beg.start_time_ns;
-                double desc_sec, calc_bits_per_second, percent, mod_bits_per_second;
-                if (desc_bytes <= 0)
-                    return -1;
+                double desc_sec = desc_ns / nano_seconds_per_second;
+                double calc_bits_per_second = (desc_bytes * 8) / desc_sec;
 
-                desc_sec = desc_ns / nano_seconds_per_second;
-                calc_bits_per_second = (desc_bytes * 8) / desc_sec;
-
                 // Drop the bps by the percentage of bytes buffered.
-                percent = (desc_bytes - prebuffer_bytes) / desc_bytes;
-                mod_bits_per_second = calc_bits_per_second * percent;
+                double percent = (desc_bytes - prebuffer_bytes) / desc_bytes;
+                double mod_bits_per_second = calc_bits_per_second * percent;
 
                 if (prebuffer < desc_sec) {
                     double search_sec =
--- FFmpeg-n4.4.4/libavformat/moflex.c
+++ Ascendffmpeg/libavformat/moflex.c
@@ -172,7 +172,7 @@
         unsigned type, ssize, codec_id = 0;
         unsigned codec_type, width = 0, height = 0, sample_rate = 0, channels = 0;
         int stream_index = -1;
-        AVRational tb = av_make_q(0, 1);
+        AVRational fps;
 
         read_var_byte(s, &type);
         read_var_byte(s, &ssize);
@@ -195,7 +195,6 @@
                 return AVERROR_PATCHWELCOME;
             }
             sample_rate = avio_rb24(pb) + 1;
-            tb = av_make_q(1, sample_rate);
             channels = avio_r8(pb) + 1;
             break;
         case 1:
@@ -209,8 +208,8 @@
                 av_log(s, AV_LOG_ERROR, "Unsupported video codec: %d\n", codec_id);
                 return AVERROR_PATCHWELCOME;
             }
-            tb.den = avio_rb16(pb);
-            tb.num = avio_rb16(pb);
+            fps.num = avio_rb16(pb);
+            fps.den = avio_rb16(pb);
             width = avio_rb16(pb);
             height = avio_rb16(pb);
             avio_skip(pb, type == 3 ? 3 : 2);
@@ -238,8 +237,10 @@
             if (!st->priv_data)
                 return AVERROR(ENOMEM);
 
-            if (tb.num)
-                avpriv_set_pts_info(st, 63, tb.num, tb.den);
+            if (sample_rate)
+                avpriv_set_pts_info(st, 63, 1, sample_rate);
+            else
+                avpriv_set_pts_info(st, 63, fps.den, fps.num);
         }
     }
 
--- FFmpeg-n4.4.4/libavformat/mov.c
+++ Ascendffmpeg/libavformat/mov.c
@@ -607,13 +607,11 @@
     for (i = 0; i < entries; i++) {
         MOVDref *dref = &sc->drefs[i];
         uint32_t size = avio_rb32(pb);
-        int64_t next = avio_tell(pb);
+        int64_t next = avio_tell(pb) + size - 4;
 
-        if (size < 12 || next < 0 || next > INT64_MAX - size)
+        if (size < 12)
             return AVERROR_INVALIDDATA;
 
-        next += size - 4;
-
         dref->type = avio_rl32(pb);
         avio_rb32(pb); // version + flags
 
@@ -1944,8 +1942,6 @@
         // wrap a whole fiel atom inside of a glbl atom.
         unsigned size = avio_rb32(pb);
         unsigned type = avio_rl32(pb);
-        if (avio_feof(pb))
-            return AVERROR_INVALIDDATA;
         avio_seek(pb, -8, SEEK_CUR);
         if (type == MKTAG('f','i','e','l') && size == atom.size)
             return mov_read_default(c, pb, atom);
@@ -2555,10 +2551,6 @@
                 av_log(c->fc, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate);
                 return AVERROR_INVALIDDATA;
             }
-            if (st->codecpar->channels < 0) {
-                av_log(c->fc, AV_LOG_ERROR, "Invalid channels %d\n", st->codecpar->channels);
-                return AVERROR_INVALIDDATA;
-            }
         } else if (st->codecpar->codec_type==AVMEDIA_TYPE_SUBTITLE){
             mov_parse_stsd_subtitle(c, pb, st, sc,
                                     size - (avio_tell(pb) - start_pos));
@@ -3963,13 +3955,6 @@
                 if (keyframe)
                     distance = 0;
                 sample_size = sc->stsz_sample_size > 0 ? sc->stsz_sample_size : sc->sample_sizes[current_sample];
-                if (current_offset > INT64_MAX - sample_size) {
-                    av_log(mov->fc, AV_LOG_ERROR, "Current offset %"PRId64" or sample size %u is too large\n",
-                           current_offset,
-                           sample_size);
-                    return;
-                }
-
                 if (sc->pseudo_stream_id == -1 ||
                    sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) {
                     AVIndexEntry *e;
@@ -5131,8 +5116,6 @@
     avio_rb16(pb); // reserved
 
     item_count = avio_rb16(pb);
-    if (item_count == 0)
-        return AVERROR_INVALIDDATA;
 
     for (i = 0; i < item_count; i++) {
         int index;
@@ -5458,9 +5441,6 @@
         av_log(c->fc, AV_LOG_WARNING, "Unsupported Mastering Display Metadata box version %d\n", version);
         return 0;
     }
-    if (sc->mastering)
-        return AVERROR_INVALIDDATA;
-
     avio_skip(pb, 3); /* flags */
 
     sc->mastering = av_mastering_display_metadata_alloc();
@@ -6149,8 +6129,6 @@
         }
         if (pb->eof_reached) {
             av_log(c->fc, AV_LOG_ERROR, "Hit EOF while reading senc\n");
-            if (ret >= 0)
-                av_encryption_info_free(encryption_index->encrypted_samples[i]);
             ret = AVERROR_INVALIDDATA;
         }
 
@@ -7089,8 +7067,6 @@
         if (a.size == 0) {
             a.size = atom.size - total_size + 8;
         }
-        if (a.size < 0)
-            break;
         a.size -= 8;
         if (a.size < 0)
             break;
--- FFmpeg-n4.4.4/libavformat/movenc.c
+++ Ascendffmpeg/libavformat/movenc.c
@@ -91,7 +91,7 @@
     { "frag_duration", "Maximum fragment duration", offsetof(MOVMuxContext, max_fragment_duration), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
     { "min_frag_duration", "Minimum fragment duration", offsetof(MOVMuxContext, min_fragment_duration), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
     { "frag_size", "Maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
-    { "ism_lookahead", "Number of lookahead entries for ISM files", offsetof(MOVMuxContext, ism_lookahead), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 255, AV_OPT_FLAG_ENCODING_PARAM},
+    { "ism_lookahead", "Number of lookahead entries for ISM files", offsetof(MOVMuxContext, ism_lookahead), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
     { "video_track_timescale", "set timescale of all video tracks", offsetof(MOVMuxContext, video_track_timescale), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
     { "brand",    "Override major brand", offsetof(MOVMuxContext, major_brand),   AV_OPT_TYPE_STRING, {.str = NULL}, .flags = AV_OPT_FLAG_ENCODING_PARAM },
     { "use_editlist", "use edit list", offsetof(MOVMuxContext, use_editlist), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
--- FFmpeg-n4.4.4/libavformat/mxfdec.c
+++ Ascendffmpeg/libavformat/mxfdec.c
@@ -60,7 +60,6 @@
 #include "mxf.h"
 
 #define MXF_MAX_CHUNK_SIZE (32 << 20)
-#define RUN_IN_MAX (65535+1)  // S377m-2004 section 5.5 and S377-1-2009 section 6.5, the +1 is to be slightly more tolerant
 
 typedef enum {
     Header,
@@ -876,27 +875,15 @@
 
 static int mxf_read_strong_ref_array(AVIOContext *pb, UID **refs, int *count)
 {
-    int64_t ret;
-    unsigned c = avio_rb32(pb);
-
-    //avio_read() used int
-    if (c > INT_MAX / sizeof(UID))
-        return AVERROR_PATCHWELCOME;
-    *count = c;
-
+    *count = avio_rb32(pb);
     av_free(*refs);
-    *refs = av_malloc_array(*count, sizeof(UID));
+    *refs = av_calloc(*count, sizeof(UID));
     if (!*refs) {
         *count = 0;
         return AVERROR(ENOMEM);
     }
     avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
-    ret = avio_read(pb, (uint8_t *)*refs, *count * sizeof(UID));
-    if (ret != *count * sizeof(UID)) {
-        *count = ret < 0 ? 0   : ret / sizeof(UID);
-        return   ret < 0 ? ret : AVERROR_INVALIDDATA;
-    }
-
+    avio_read(pb, (uint8_t *)*refs, *count * sizeof(UID));
     return 0;
 }
 
@@ -1105,9 +1092,6 @@
 {
     int i, length;
 
-    if (segment->temporal_offset_entries)
-        return AVERROR_INVALIDDATA;
-
     segment->nb_index_entries = avio_rb32(pb);
 
     length = avio_rb32(pb);
@@ -2269,12 +2253,12 @@
         /* CDCI range metadata */
         if (!descriptor->component_depth)
             return AVCOL_RANGE_UNSPECIFIED;
-        if (descriptor->black_ref_level == 0 && descriptor->component_depth < 31 &&
+        if (descriptor->black_ref_level == 0 &&
             descriptor->white_ref_level == ((1<<descriptor->component_depth) - 1) &&
             (descriptor->color_range    == (1<<descriptor->component_depth) ||
              descriptor->color_range    == ((1<<descriptor->component_depth) - 1)))
             return AVCOL_RANGE_JPEG;
-        if (descriptor->component_depth >= 8 && descriptor->component_depth < 31 &&
+        if (descriptor->component_depth >= 8 &&
             descriptor->black_ref_level == (1  <<(descriptor->component_depth - 4)) &&
             descriptor->white_ref_level == (235<<(descriptor->component_depth - 8)) &&
             descriptor->color_range     == ((14<<(descriptor->component_depth - 4)) + 1))
@@ -3358,7 +3342,6 @@
     KLVPacket klv;
     int64_t essence_offset = 0;
     int ret;
-    int64_t run_in;
 
     mxf->last_forward_tell = INT64_MAX;
 
@@ -3369,10 +3352,7 @@
     }
     avio_seek(s->pb, -14, SEEK_CUR);
     mxf->fc = s;
-    run_in = avio_tell(s->pb);
-    if (run_in < 0 || run_in > RUN_IN_MAX)
-        return AVERROR_INVALIDDATA;
-    mxf->run_in = run_in;
+    mxf->run_in = avio_tell(s->pb);
 
     mxf_read_random_index_pack(s);
 
@@ -3516,8 +3496,8 @@
     if ((sample_rate.num / sample_rate.den) == 48000) {
         return av_rescale_q(edit_unit, sample_rate, track->edit_rate);
     } else {
-        int64_t remainder = (sample_rate.num * (int64_t)  time_base.num) %
-                            (  time_base.den * (int64_t)sample_rate.den);
+        int remainder = (sample_rate.num * time_base.num) %
+                        (time_base.den * sample_rate.den);
         if (remainder)
             av_log(mxf->fc, AV_LOG_WARNING,
                    "seeking detected on stream #%d with time base (%d/%d) and "
@@ -3785,7 +3765,7 @@
 
 static int mxf_probe(const AVProbeData *p) {
     const uint8_t *bufp = p->buf;
-    const uint8_t *end = p->buf + FFMIN(p->buf_size, RUN_IN_MAX + 1 + sizeof(mxf_header_partition_pack_key));
+    const uint8_t *end = p->buf + p->buf_size;
 
     if (p->buf_size < sizeof(mxf_header_partition_pack_key))
         return 0;
--- FFmpeg-n4.4.4/libavformat/nutdec.c
+++ Ascendffmpeg/libavformat/nutdec.c
@@ -199,8 +199,6 @@
     int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
 
     length = get_packetheader(nut, bc, 1, MAIN_STARTCODE);
-    if (length == (uint64_t)-1)
-        return AVERROR_INVALIDDATA;
     end = length + avio_tell(bc);
 
     nut->version = ffio_read_varlen(bc);
@@ -244,11 +242,6 @@
     for (i = 0; i < 256;) {
         int tmp_flags  = ffio_read_varlen(bc);
         int tmp_fields = ffio_read_varlen(bc);
-        if (tmp_fields < 0) {
-            av_log(s, AV_LOG_ERROR, "fields %d is invalid\n", tmp_fields);
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
 
         if (tmp_fields > 0)
             tmp_pts = get_s(bc);
@@ -358,12 +351,8 @@
         ret = AVERROR(ENOMEM);
         goto fail;
     }
-    for (i = 0; i < stream_count; i++) {
-        if (!avformat_new_stream(s, NULL)) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
-    }
+    for (i = 0; i < stream_count; i++)
+        avformat_new_stream(s, NULL);
 
     return 0;
 fail:
@@ -811,23 +800,19 @@
     NUTContext *nut = s->priv_data;
     AVIOContext *bc = s->pb;
     int64_t pos;
-    int initialized_stream_count, ret;
+    int initialized_stream_count;
 
     nut->avf = s;
 
     /* main header */
     pos = 0;
-    ret = 0;
     do {
-        if (ret == AVERROR(ENOMEM))
-            return ret;
-
         pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
         if (pos < 0 + 1) {
             av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
             goto fail;
         }
-    } while ((ret = decode_main_header(nut)) < 0);
+    } while (decode_main_header(nut) < 0);
 
     /* stream headers */
     pos = 0;
--- FFmpeg-n4.4.4/libavformat/omadec.c
+++ Ascendffmpeg/libavformat/omadec.c
@@ -494,7 +494,7 @@
         AV_WL16(&edata[6],  jsflag);        // coding mode
         AV_WL16(&edata[8],  jsflag);        // coding mode
         AV_WL16(&edata[10], 1);             // always 1
-        AV_WL16(&edata[12], 0);             // always 0
+        // AV_WL16(&edata[12], 0);          // always 0
 
         avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
         break;
--- FFmpeg-n4.4.4/libavformat/replaygain.c
+++ Ascendffmpeg/libavformat/replaygain.c
@@ -61,7 +61,7 @@
         }
     }
 
-    if (llabs(db) > (INT32_MAX - mb) / 100000)
+    if (abs(db) > (INT32_MAX - mb) / 100000)
         return min;
 
     return db * 100000 + sign * mb;
--- FFmpeg-n4.4.4/libavformat/rmdec.c
+++ Ascendffmpeg/libavformat/rmdec.c
@@ -128,6 +128,10 @@
     uint32_t version;
     int ret;
 
+    // Duplicate tags
+    if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+        return AVERROR_INVALIDDATA;
+
     /* ra type header */
     version = avio_rb16(pb); /* version */
     if (version == 3) {
@@ -327,11 +331,6 @@
     if (codec_data_size == 0)
         return 0;
 
-    // Duplicate tags
-    if (   st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN
-        && st->codecpar->codec_type != AVMEDIA_TYPE_DATA)
-        return AVERROR_INVALIDDATA;
-
     avpriv_set_pts_info(st, 64, 1, 1000);
     codec_pos = avio_tell(pb);
     v = avio_rb32(pb);
@@ -565,8 +564,6 @@
     }
 
     tag_size = avio_rb32(pb);
-    if (tag_size < 0)
-        return AVERROR_INVALIDDATA;
     avio_skip(pb, tag_size - 8);
 
     for(;;) {
--- FFmpeg-n4.4.4/libavformat/rpl.c
+++ Ascendffmpeg/libavformat/rpl.c
@@ -276,7 +276,7 @@
     error |= read_line(pb, line, sizeof(line));  // size of "helpful" sprite
     if (vst) {
         error |= read_line(pb, line, sizeof(line));  // offset to key frame list
-        vst->duration = number_of_chunks * (int64_t)rpl->frames_per_chunk;
+        vst->duration = number_of_chunks * rpl->frames_per_chunk;
     }
 
     // Read the index
--- FFmpeg-n4.4.4/libavformat/rtsp.c
+++ Ascendffmpeg/libavformat/rtsp.c
@@ -952,8 +952,6 @@
                              ";,", &p);
             }
             th->transport = RTSP_TRANSPORT_RAW;
-        } else {
-            break;
         }
         if (!av_strcasecmp(lower_transport, "TCP"))
             th->lower_transport = RTSP_LOWER_TRANSPORT_TCP;
--- FFmpeg-n4.4.4/libavformat/sbgdec.c
+++ Ascendffmpeg/libavformat/sbgdec.c
@@ -1316,8 +1316,6 @@
 
     /* Pseudo event before the first one */
     ev0 = s->events[s->nb_events - 1];
-    if (av_sat_sub64(ev0.ts_int, period) != (uint64_t)ev0.ts_int - period)
-        return AVERROR_INVALIDDATA;
     ev0.ts_int   -= period;
     ev0.ts_trans -= period;
     ev0.ts_next  -= period;
--- FFmpeg-n4.4.4/libavformat/sccdec.c
+++ Ascendffmpeg/libavformat/sccdec.c
@@ -63,7 +63,8 @@
 {
     SCCContext *scc = s->priv_data;
     AVStream *st = avformat_new_stream(s, NULL);
-    AVPacket *sub = NULL;
+    char line2[4096], line[4096];
+    int64_t pos, ts, next_ts = AV_NOPTS_VALUE;
     ptrdiff_t len;
     uint8_t out[4096];
     FFTextReader tr;
@@ -76,27 +77,48 @@
     st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
     st->codecpar->codec_id   = AV_CODEC_ID_EIA_608;
 
-    while (1) {
+    while (!ff_text_eof(&tr) || next_ts == AV_NOPTS_VALUE || line2[0]) {
         char *saveptr = NULL, *lline;
         int hh, mm, ss, fs, i;
-        char line[4096];
-        int64_t pos, ts;
+        AVPacket *sub;
 
-        len = ff_subtitles_read_line(&tr, line, sizeof(line));
-        if (len <= 13) {
-            if (ff_text_eof(&tr))
-                break;
-            continue;
-        }
+        if (next_ts == AV_NOPTS_VALUE) {
+            while (!ff_text_eof(&tr)) {
+                len = ff_subtitles_read_line(&tr, line, sizeof(line));
+                if (len <= 13)
+                    continue;
                 if (!strncmp(line, "Scenarist_SCC V1.0", 18))
                     continue;
-        if (av_sscanf(line, "%d:%d:%d%*[:;]%d", &hh, &mm, &ss, &fs) != 4)
-            continue;
+                if (av_sscanf(line, "%d:%d:%d%*[:;]%d", &hh, &mm, &ss, &fs) == 4)
+                    break;
+            }
 
-        ts = (hh * 3600LL + mm * 60LL + ss) * 1000LL + fs * 33LL;
-        if (sub)
-            sub->duration = ts - sub->pts;
+            ts = (hh * 3600LL + mm * 60LL + ss) * 1000LL + fs * 33LL;
 
+            while (!ff_text_eof(&tr)) {
+                len = ff_subtitles_read_line(&tr, line2, sizeof(line2));
+                if (len <= 13)
+                    continue;
+
+                if (av_sscanf(line2, "%d:%d:%d%*[:;]%d", &hh, &mm, &ss, &fs) == 4)
+                    break;
+            }
+        } else {
+            memmove(line, line2, sizeof(line));
+            line2[0] = 0;
+
+            while (!ff_text_eof(&tr)) {
+                len = ff_subtitles_read_line(&tr, line2, sizeof(line2));
+                if (len <= 13)
+                    continue;
+
+                if (av_sscanf(line2, "%d:%d:%d%*[:;]%d", &hh, &mm, &ss, &fs) == 4)
+                    break;
+            }
+        }
+
+        next_ts = (hh * 3600LL + mm * 60LL + ss) * 1000LL + fs * 33LL;
+
         pos = ff_text_pos(&tr);
         lline = (char *)&line;
         lline += 12;
@@ -146,6 +168,8 @@
 
         sub->pos = pos;
         sub->pts = ts;
+        sub->duration = next_ts - ts;
+        ts = next_ts;
     }
 
     ff_subtitles_queue_finalize(s, &scc->q);
--- FFmpeg-n4.4.4/libavformat/sctp.c
+++ Ascendffmpeg/libavformat/sctp.c
@@ -282,8 +282,6 @@
         goto restart;
     }
 fail1:
-    if (fd >= 0)
-        closesocket(fd);
     ret = AVERROR(EIO);
     freeaddrinfo(ai);
     return ret;
--- FFmpeg-n4.4.4/libavformat/sdsdec.c
+++ Ascendffmpeg/libavformat/sdsdec.c
@@ -112,7 +112,7 @@
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->channels = 1;
     st->codecpar->sample_rate = sample_period ? 1000000000 / sample_period : 16000;
-    st->duration = av_rescale((avio_size(pb) - 21) / 127,  s->size, 4);
+    st->duration = (avio_size(pb) - 21) / (127) * s->size / 4;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
--- FFmpeg-n4.4.4/libavformat/spdifdec.c
+++ Ascendffmpeg/libavformat/spdifdec.c
@@ -226,7 +226,7 @@
     if (!s->bit_rate && s->streams[0]->codecpar->sample_rate)
         /* stream bitrate matches 16-bit stereo PCM bitrate for currently
            supported codecs */
-        s->bit_rate = 2 * 16LL * s->streams[0]->codecpar->sample_rate;
+        s->bit_rate = 2 * 16 * s->streams[0]->codecpar->sample_rate;
 
     return 0;
 }
--- FFmpeg-n4.4.4/libavformat/subtitles.c
+++ Ascendffmpeg/libavformat/subtitles.c
@@ -418,7 +418,6 @@
     size_t cur = 0;
     if (!size)
         return 0;
-    buf[0] = '\0';
     while (cur + 1 < size) {
         unsigned char c = ff_text_r8(tr);
         if (!c)
--- FFmpeg-n4.4.4/libavformat/subviewerdec.c
+++ Ascendffmpeg/libavformat/subviewerdec.c
@@ -51,32 +51,26 @@
     return 0;
 }
 
-static int get_multiplier(int e) {
-    switch (e) {
-    case 1  : return 100;
-    case 2  : return 10;
-    case 3  : return 1;
-    default : return -1;
-    }
-}
-
 static int read_ts(const char *s, int64_t *start, int *duration)
 {
     int64_t end;
     int hh1, mm1, ss1, ms1;
     int hh2, mm2, ss2, ms2;
-    int multiplier1, multiplier2;
-    int ms1p1, ms1p2, ms2p1, ms2p2;
+    int multiplier = 1;
 
-    if (sscanf(s, "%u:%u:%u.%n%u%n,%u:%u:%u.%n%u%n",
-               &hh1, &mm1, &ss1, &ms1p1, &ms1, &ms1p2, &hh2, &mm2, &ss2, &ms2p1, &ms2, &ms2p2) == 8) {
-        multiplier1 = get_multiplier(ms1p2 - ms1p1);
-        multiplier2 = get_multiplier(ms2p2 - ms2p1);
-        if (multiplier1 <= 0 ||multiplier2 <= 0)
-            return -1;
-
-        end    = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2 * multiplier2;
-        *start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1 * multiplier1;
+    if (sscanf(s, "%u:%u:%u.%2u,%u:%u:%u.%2u",
+               &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) {
+        multiplier = 10;
+    } else if (sscanf(s, "%u:%u:%u.%1u,%u:%u:%u.%1u",
+                      &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) {
+        multiplier = 100;
+    }
+    if (sscanf(s, "%u:%u:%u.%u,%u:%u:%u.%u",
+               &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) {
+        ms1 = FFMIN(ms1, 999);
+        ms2 = FFMIN(ms2, 999);
+        end    = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2 * multiplier;
+        *start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1 * multiplier;
         *duration = end - *start;
         return 0;
     }
--- FFmpeg-n4.4.4/libavformat/tee.c
+++ Ascendffmpeg/libavformat/tee.c
@@ -124,7 +124,6 @@
     unsigned i;
     int ret = 0;
 
-    av_dict_free(&tee_slave->fifo_options);
     avf = tee_slave->avf;
     if (!avf)
         return 0;
@@ -230,7 +229,6 @@
 
         av_dict_free(&options);
         options = tee_slave->fifo_options;
-        tee_slave->fifo_options = NULL;
     }
     ret = avformat_alloc_output_context2(&avf2, NULL,
                                          tee_slave->use_fifo ? "fifo" :format, filename);
@@ -405,8 +403,6 @@
     av_free(format);
     av_free(select);
     av_free(on_fail);
-    av_free(use_fifo);
-    av_free(fifo_options_str);
     av_dict_free(&options);
     av_dict_free(&bsf_options);
     av_freep(&tmp_select);
--- FFmpeg-n4.4.4/libavformat/tls_mbedtls.c
+++ Ascendffmpeg/libavformat/tls_mbedtls.c
@@ -19,7 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <mbedtls/version.h>
+#include <mbedtls/certs.h>
+#include <mbedtls/config.h>
 #include <mbedtls/ctr_drbg.h>
 #include <mbedtls/entropy.h>
 #include <mbedtls/net_sockets.h>
@@ -129,15 +130,9 @@
 static void handle_handshake_error(URLContext *h, int ret)
 {
     switch (ret) {
-#if MBEDTLS_VERSION_MAJOR < 3
     case MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE:
         av_log(h, AV_LOG_ERROR, "None of the common ciphersuites is usable. Was the local certificate correctly set?\n");
         break;
-#else
-    case MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE:
-        av_log(h, AV_LOG_ERROR, "TLS handshake failed.\n");
-        break;
-#endif
     case MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE:
         av_log(h, AV_LOG_ERROR, "A fatal alert message was received from the peer, has the peer a correct certificate?\n");
         break;
@@ -200,28 +195,23 @@
         }
     }
 
-    // seed the random number generator
-    if ((ret = mbedtls_ctr_drbg_seed(&tls_ctx->ctr_drbg_context,
-                                     mbedtls_entropy_func,
-                                     &tls_ctx->entropy_context,
-                                     NULL, 0)) != 0) {
-        av_log(h, AV_LOG_ERROR, "mbedtls_ctr_drbg_seed returned %d\n", ret);
-        goto fail;
-    }
-
     // load key file
     if (shr->key_file) {
         if ((ret = mbedtls_pk_parse_keyfile(&tls_ctx->priv_key,
                                             shr->key_file,
-                                            tls_ctx->priv_key_pw
-#if MBEDTLS_VERSION_MAJOR >= 3
-                                            , mbedtls_ctr_drbg_random,
-                                            &tls_ctx->ctr_drbg_context
-#endif
-                                            )) != 0) {
+                                            tls_ctx->priv_key_pw)) != 0) {
             handle_pk_parse_error(h, ret);
             goto fail;
         }
+    }
+
+    // seed the random number generator
+    if ((ret = mbedtls_ctr_drbg_seed(&tls_ctx->ctr_drbg_context,
+                                     mbedtls_entropy_func,
+                                     &tls_ctx->entropy_context,
+                                     NULL, 0)) != 0) {
+        av_log(h, AV_LOG_ERROR, "mbedtls_ctr_drbg_seed returned %d\n", ret);
+        goto fail;
     }
 
     if ((ret = mbedtls_ssl_config_defaults(&tls_ctx->ssl_config,
--- FFmpeg-n4.4.4/libavformat/udp.c
+++ Ascendffmpeg/libavformat/udp.c
@@ -740,10 +740,8 @@
     /* XXX: fix av_url_split */
     if (hostname[0] == '\0' || hostname[0] == '?') {
         /* only accepts null hostname if input */
-        if (!(flags & AVIO_FLAG_READ)) {
-            ret = AVERROR(EINVAL);
+        if (!(flags & AVIO_FLAG_READ))
             goto fail;
-        }
     } else {
         if ((ret = ff_udp_set_remote_url(h, uri)) < 0)
             goto fail;
@@ -756,10 +754,8 @@
         udp_fd = udp_socket_create(h, &my_addr, &len, localaddr);
     else
         udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
-    if (udp_fd < 0) {
-        ret = AVERROR(EIO);
+    if (udp_fd < 0)
         goto fail;
-    }
 
     s->local_addr_storage=my_addr; //store for future multicast join
 
--- FFmpeg-n4.4.4/libavformat/utils.c
+++ Ascendffmpeg/libavformat/utils.c
@@ -4997,7 +4997,7 @@
         key_len = ptr - key;
 
         callback_get_buf(context, key, key_len, &dest, &dest_len);
-        dest_end = dest ? dest + dest_len - 1 : NULL;
+        dest_end = dest + dest_len - 1;
 
         if (*ptr == '\"') {
             ptr++;
--- FFmpeg-n4.4.4/libavformat/vividas.c
+++ Ascendffmpeg/libavformat/vividas.c
@@ -683,7 +683,6 @@
 
     if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
         uint64_t v_size = ffio_read_varlen(pb);
-        int last = 0, last_start;
 
         if (!viv->num_audio)
             return AVERROR_INVALIDDATA;
@@ -707,18 +706,12 @@
 
             if (i > 0 && start == 0)
                 break;
-            if (start < last)
-                return AVERROR_INVALIDDATA;
 
             viv->n_audio_subpackets = i + 1;
-            last =
             viv->audio_subpackets[i].start = start;
             viv->audio_subpackets[i].pcm_bytes = pcm_bytes;
         }
-        last_start =
         viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb));
-        if (last_start < last)
-            return AVERROR_INVALIDDATA;
         viv->current_audio_subpacket = 0;
 
     } else {
--- FFmpeg-n4.4.4/libavformat/vivo.c
+++ Ascendffmpeg/libavformat/vivo.c
@@ -26,7 +26,6 @@
  * @sa http://wiki.multimedia.cx/index.php?title=Vivo
  */
 
-#include "libavutil/avstring.h"
 #include "libavutil/parseutils.h"
 #include "avformat.h"
 #include "internal.h"
@@ -121,7 +120,7 @@
 static int vivo_read_header(AVFormatContext *s)
 {
     VivoContext *vivo = s->priv_data;
-    AVRational fps = { 0 };
+    AVRational fps = { 1, 25};
     AVStream *ast, *vst;
     unsigned char *line, *line_end, *key, *value;
     long value_int;
@@ -207,21 +206,17 @@
                     return AVERROR_INVALIDDATA;
                 value_used = 1;
             } else if (!strcmp(key, "FPS")) {
-                double d;
-                if (av_sscanf(value, "%f", &d) != 1)
-                    return AVERROR_INVALIDDATA;
+                AVRational tmp;
 
                 value_used = 1;
-                if (!fps.num && !fps.den)
-                    fps = av_inv_q(av_d2q(d, 10000));
+                if (!av_parse_ratio(&tmp, value, 10000, AV_LOG_WARNING, s))
+                    fps = av_inv_q(tmp);
             }
 
             if (!value_used)
                 av_dict_set(&s->metadata, key, value, 0);
         }
     }
-    if (!fps.num || !fps.den)
-        fps = (AVRational){ 1, 25 };
 
     avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate);
     avpriv_set_pts_info(vst, 64, fps.num, fps.den);
--- FFmpeg-n4.4.4/libavformat/webmdashenc.c
+++ Ascendffmpeg/libavformat/webmdashenc.c
@@ -93,7 +93,7 @@
     }
     avio_printf(pb, "  minBufferTime=\"PT%gS\"\n", min_buffer_time);
     avio_printf(pb, "  profiles=\"%s\"%s",
-                w->is_live ? "urn:mpeg:dash:profile:isoff-live:2011" : "urn:mpeg:dash:profile:webm-on-demand:2012",
+                w->is_live ? "urn:mpeg:dash:profile:isoff-live:2011" : "urn:webm:dash:profile:webm-on-demand:2012",
                 w->is_live ? "\n" : ">\n");
     if (w->is_live) {
         time_t local_time = time(NULL);
--- FFmpeg-n4.4.4/libavformat/xwma.c
+++ Ascendffmpeg/libavformat/xwma.c
@@ -278,7 +278,7 @@
          * the total duration using the average bits per sample and the
          * total data length.
          */
-        st->duration = av_rescale((size<<3), st->codecpar->sample_rate, st->codecpar->bit_rate);
+        st->duration = (size<<3) * st->codecpar->sample_rate / st->codecpar->bit_rate;
     }
 
 fail:
--- FFmpeg-n4.4.4/libavutil/Makefile
+++ Ascendffmpeg/libavutil/Makefile
@@ -35,6 +35,7 @@
           hdr_dynamic_metadata.h                                        \
           hmac.h                                                        \
           hwcontext.h                                                   \
+          hwcontext_ascend.h                                            \
           hwcontext_cuda.h                                              \
           hwcontext_d3d11va.h                                           \
           hwcontext_drm.h                                               \
@@ -174,6 +175,7 @@
        film_grain_params.o                                              \
 
 
+OBJS-$(CONFIG_ASCEND)                   += hwcontext_ascend.o
 OBJS-$(CONFIG_CUDA)                     += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)                  += hwcontext_d3d11va.o
 OBJS-$(CONFIG_DXVA2)                    += hwcontext_dxva2.o
@@ -192,6 +194,7 @@
 # Windows resource file
 SLIBOBJS-$(HAVE_GNU_WINDRES)            += avutilres.o
 
+SKIPHEADERS-$(CONFIG_ASCEND)           += hwcontext_ascend.h
 SKIPHEADERS-$(HAVE_CUDA_H)             += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_CUDA)             += hwcontext_cuda_internal.h     \
                                           cuda_check.h
--- FFmpeg-n4.4.4/libavutil/hwcontext.c
+++ Ascendffmpeg/libavutil/hwcontext.c
@@ -62,6 +62,9 @@
 #if CONFIG_VULKAN
     &ff_hwcontext_type_vulkan,
 #endif
+#if CONFIG_ASCEND
+    &ff_hwcontext_type_ascend,
+#endif
     NULL,
 };
 
@@ -77,6 +80,7 @@
     [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
     [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec",
     [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
+    [AV_HWDEVICE_TYPE_ASCEND] = "ascend",
 };
 
 enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
--- FFmpeg-n4.4.4/libavutil/hwcontext.h
+++ Ascendffmpeg/libavutil/hwcontext.h
@@ -37,6 +37,7 @@
     AV_HWDEVICE_TYPE_OPENCL,
     AV_HWDEVICE_TYPE_MEDIACODEC,
     AV_HWDEVICE_TYPE_VULKAN,
+    AV_HWDEVICE_TYPE_ASCEND,
 };
 
 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
--- /dev/null
+++ Ascendffmpeg/libavutil/hwcontext_ascend.c
@@ -0,0 +1,330 @@
+/*
+ * Copyright(c) 2020. Huawei Technologies Co.,Ltd. All rights reserved. 
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except int compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "buffer.h"
+#include "common.h"
+#include "hwcontext.h"
+#include "hwcontext_ascend.h"
+#include "hwcontext_internal.h"
+#include "mem.h"
+#include "pixdesc.h"
+#include "imgutils.h"
+#include "acl/acl.h"
+#include "acl/dvpp/hi_dvpp.h"
+#include "acl/acl_base.h"
+
+static int init_flag = 0;
+
+static const enum AVPixelFormat supported_formats[] = {
+    AV_PIX_FMT_NV12,
+};
+
+#define ASCEND_FRAME_ALIGNMENT 1
+
+typedef struct ASCENDFramesContext {
+    int width;
+    int height;
+} ASCENDFramesContext;
+
+static int ascend_device_init(AVHWDeviceContext *ctx)
+{
+    AVASCENDDeviceContext *hwctx = ctx->hwctx;
+    if(!hwctx->ascend_ctx) {
+        hwctx->ascend_ctx = av_mallocz(sizeof(*hwctx->ascend_ctx));
+        if (!hwctx->ascend_ctx) {
+            return AVERROR_UNKNOWN;
+        }
+    }
+    return 0;
+}
+
+static void ascend_device_uninit(AVHWDeviceContext *device_ctx)
+{
+    AVASCENDDeviceContext *hwctx = device_ctx->hwctx;
+
+    if (hwctx->ascend_ctx) {
+        av_freep(&hwctx->ascend_ctx);
+        hwctx->ascend_ctx = NULL;
+    }
+}
+
+static int ascend_device_create(AVHWDeviceContext *device_ctx, const char *device, AVDictionary *opts, int flags)
+{
+    AVASCENDDeviceContext *hwctx = device_ctx->hwctx;
+    AscendContext *ascend_ctx = NULL;
+
+    int ret = 0;
+    int device_idx = 0;
+    if (device) {
+        device_idx = strtol(device, NULL, 0);
+    }
+    av_log(device_ctx, AV_LOG_INFO, "device id is: %d.\n", device_idx);
+
+    if (ascend_device_init(device_ctx) < 0)
+        goto error;
+
+    int device_count = 0;
+    ret = aclrtGetDeviceCount(&device_count);
+    if (ret != 0) {
+        goto error;
+    }
+    if (device_idx >= device_count) {
+        av_log(device_ctx, AV_LOG_ERROR, "device id must less than: %d.\n", device_count);
+        goto error;
+    }
+
+    ascend_ctx = hwctx->ascend_ctx;
+    ascend_ctx->device_id = device_idx;
+
+    if (!init_flag) {
+        ret = aclInit(NULL);
+        if (ret == ACL_ERROR_REPEAT_INITIALIZE) {
+            av_log(device_ctx, AV_LOG_WARNING, "Repeat Initialize, ret = %d.\n", ret);
+        }
+        if (ret != 0 && ret != ACL_ERROR_REPEAT_INITIALIZE) {
+            av_log(device_ctx, AV_LOG_ERROR, "InitDevices failed, ret = %d.\n", ret);
+            goto error;
+        }
+        init_flag = 1;
+    }
+    
+
+    ret = aclrtSetDevice(device_idx);
+    if (ret != 0) {
+        av_log(device_ctx, AV_LOG_ERROR, "SetDevice failed, ret = %d.\n", ret);
+        goto error;
+    }
+
+    aclrtContext context;
+    ret = aclrtCreateContext(&context, device_idx);
+    if(ret != 0) {
+        av_log(device_ctx, AV_LOG_ERROR, "CreateContext failed, ret = %d.\n", ret);
+        goto error;
+    }
+
+    hwctx->ascend_ctx->context = context;
+    return 0;
+    error:
+        ascend_device_uninit(device_ctx);
+        return AVERROR_UNKNOWN;
+
+}
+
+static int ascend_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig,
+                                         AVHWFramesConstraints *constraints)
+{
+    int i;
+    constraints->valid_sw_formats = av_malloc_array(FF_ARRAY_ELEMS(supported_formats) + 1,
+                                                    sizeof(*constraints->valid_sw_formats));
+    if (!constraints->valid_sw_formats) {
+        return AVERROR_EXTERNAL;
+    }
+
+    for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
+        constraints->valid_sw_formats[i] = supported_formats[i];
+    }
+
+    constraints->valid_sw_formats[FF_ARRAY_ELEMS(supported_formats)] = AV_PIX_FMT_NONE;
+
+    constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
+    if (!constraints->valid_sw_formats) {
+        return AVERROR_EXTERNAL;
+    }
+
+    constraints->valid_hw_formats[0] = AV_PIX_FMT_ASCEND;
+    constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
+
+    return 0;
+
+}
+
+static void ascend_buffer_free(void * opaque, uint8_t* data)
+{
+    AVHWFramesContext *ctx = opaque;
+    if (data) {
+        aclError ret = hi_mpi_dvpp_free(data);
+        data = NULL;
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "HiMpi free faile: dev addr %p \n", data);
+        }
+    }
+}
+
+static AVBufferRef *ascend_pool_alloc(void *opaque, int size)
+{
+    AVHWFramesContext *ctx = opaque;
+    AVHWDeviceContext *device_ctx = ctx->device_ctx;
+    AVASCENDDeviceContext *hwctx = device_ctx->hwctx;
+    AscendContext *ascend_ctx = hwctx->ascend_ctx;
+
+    AVBufferRef *buffer = NULL;
+    void *data = NULL;
+
+    aclError ret = hi_mpi_dvpp_malloc(ascend_ctx->device_id, (void **)(&data), size);
+    if (ret != 0) {
+        av_log(ctx, AV_LOG_ERROR, "HiMpi Malloc failed: dev addr %p, size %d.\n", data, size);
+        return NULL;
+    }
+    buffer = av_buffer_create((uint8_t*)data, size, ascend_buffer_free, ctx, 0);
+    if (!buffer) {
+        ret = hi_mpi_dvpp_free(data);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "HiMpi Free failed with no buffer: dev addr %p.\n", data);
+        }
+    }
+    return buffer;
+}
+
+static int ascend_frames_init(AVHWFramesContext *ctx)
+{
+    ASCENDFramesContext * priv = ctx->internal->priv;
+    int i;
+    for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
+        if (av_get_pix_fmt_name(ctx->sw_format) == 
+            av_get_pix_fmt_name(supported_formats[i])) {
+            break;
+        }
+    }
+
+    if (i == FF_ARRAY_ELEMS(supported_formats)) {
+        av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported.\n",
+               av_get_pix_fmt_name(ctx->sw_format));
+        return AVERROR_EXTERNAL;
+    }
+
+    av_pix_fmt_get_chroma_sub_sample(ctx->sw_format, &priv->width, &priv->height);
+
+    if (!ctx->pool) {
+        int size = av_image_get_buffer_size(ctx->sw_format, ctx->width,
+                                            ctx->height, ASCEND_FRAME_ALIGNMENT);
+        if (size < 0)
+            return size;
+        
+        ctx->internal->pool_internal = av_buffer_pool_init2(size, ctx, ascend_pool_alloc, NULL);
+        if (!ctx->internal->pool_internal) {
+            av_log(ctx, AV_LOG_DEBUG, "internal pool init failed.\n");
+            return AVERROR_EXTERNAL;
+        }
+    }
+
+    return 0;
+}
+
+static int ascend_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
+{
+    frame->buf[0] = av_buffer_pool_get(ctx->pool);
+    if (!frame->buf[0])
+        return AVERROR_EXTERNAL;
+    
+    int ret = av_image_fill_arrays(frame->data, frame->linesize, frame->buf[0]->data,
+                               ctx->sw_format, ctx->width, ctx->height, ASCEND_FRAME_ALIGNMENT);
+    if (ret < 0)
+        return ret;
+    
+    frame->format = AV_PIX_FMT_ASCEND;
+    frame->width = ctx->width;
+    frame->height = ctx->height;
+
+    return 0;
+}
+
+static int ascend_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir,
+                                       enum AVPixelFormat **formats)
+{
+    enum AVPixelFormat *fmts;
+
+    fmts = av_malloc_array(2, sizeof(*fmts));
+    if (!fmts)
+        return AVERROR_EXTERNAL;
+    
+    fmts[0] = ctx->sw_format;
+    fmts[1] = AV_PIX_FMT_NONE;
+
+    *formats = fmts;
+    return 0;
+}
+
+static int ascend_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
+{
+    AVHWDeviceContext *device_ctx = ctx->device_ctx;
+    AVASCENDDeviceContext *hwctx = ctx->hwctx;
+    AscendContext *ascend_ctx = hwctx->ascend_ctx;
+
+    int i;
+    size_t dstBytes;
+    size_t srcBytes;
+    aclError ret;
+    for (i = 0; i < FF_ARRAY_ELEMS(src->data) && src->data[i]; i++) {
+        dstBytes = src->width * src->height * (i ? 1.0 / 2 : 1);
+        srcBytes = src->width * src->height * (i ? 1.0 / 2 : 1);
+        ret = aclrtMemcpy(dst->data[i], dstBytes, src->data[i], srcBytes, ACL_MEMCPY_HOST_TO_DEVICE);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Mem copy h2d: host %p wigh %lu -> dev %p with %lu.\n",
+                   src->data[i], srcBytes, dst->data[i], dstBytes);
+            av_log(ctx, AV_LOG_ERROR, "ascendMemcoy H2D error occur, func: %s, line %d.\n",
+                   __func__, __LINE__);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+static int ascend_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
+{
+    AVHWDeviceContext *device_ctx = ctx->device_ctx;
+    AVASCENDDeviceContext *hwctx = ctx->hwctx;
+    AscendContext *ascend_ctx = hwctx->ascend_ctx;
+
+    int i;
+    size_t dstBytes;
+    size_t srcBytes;
+    aclError ret;
+    for (i = 0; i < FF_ARRAY_ELEMS(src->data) && src->data[i]; i++) {
+        dstBytes = src->width * src->height * (i ? 1.0 / 2 : 1);
+        srcBytes = src->width * src->height * (i ? 1.0 / 2 : 1);
+        ret = aclrtMemcpy(dst->data[i], dstBytes, src->data[i], srcBytes, ACL_MEMCPY_DEVICE_TO_HOST);
+        if (ret != 0) {
+            av_log(ctx, AV_LOG_ERROR, "Mem copy d2h: dev %p wigh %lu -> host %p with %lu.\n",
+                   src->data[i], srcBytes, dst->data[i], dstBytes);
+            av_log(ctx, AV_LOG_ERROR, "ascendMemcoy D2H error occur, func: %s, line %d.\n",
+                   __func__, __LINE__);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+const HWContextType ff_hwcontext_type_ascend = {
+    .type                   = AV_HWDEVICE_TYPE_ASCEND,
+    .name                   = "ASCEND",
+    
+    .device_hwctx_size      = sizeof(AVASCENDDeviceContext),
+    .frames_priv_size       = sizeof(ASCENDFramesContext),
+    
+    .device_create          = ascend_device_create,
+    .device_init            = ascend_device_init,
+    .device_uninit          = ascend_device_uninit,
+    .frames_get_constraints = ascend_frames_get_constraints,
+    .frames_init            = ascend_frames_init,
+    .frames_get_buffer      = ascend_get_buffer,
+    .transfer_get_formats   = ascend_transfer_get_formats,
+    .transfer_data_to       = ascend_transfer_data_to,
+    .transfer_data_from     = ascend_transfer_data_from,
+
+    .pix_fmts               = (const enum AVPixelFormat[]) {AV_PIX_FMT_ASCEND, AV_PIX_FMT_NONE},
+};
\ No newline at end of file
--- /dev/null
+++ Ascendffmpeg/libavutil/hwcontext_ascend.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright(c) 2020. Huawei Technologies Co.,Ltd. All rights reserved. 
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except int compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FFMPEG_ASCEND_HWCONTEXT_ASCEND_H
+#define FFMPEG_ASCEND_HWCONTEXT_ASCEND_H
+
+#include "acl/acl.h"
+#include "pixfmt.h"
+
+typedef struct AscendContext {
+    int device_id;
+    aclrtContext context;
+} AscendContext;
+
+typedef struct AVASCENDDeviceContext {
+    AscendContext *ascend_ctx;
+} AVASCENDDeviceContext;
+
+#endif //FFMPEG_ASCEND_HWCONTEXT_ASCEND_H
\ No newline at end of file
--- FFmpeg-n4.4.4/libavutil/hwcontext_internal.h
+++ Ascendffmpeg/libavutil/hwcontext_internal.h
@@ -174,5 +174,6 @@
 extern const HWContextType ff_hwcontext_type_videotoolbox;
 extern const HWContextType ff_hwcontext_type_mediacodec;
 extern const HWContextType ff_hwcontext_type_vulkan;
+extern const HWContextType ff_hwcontext_type_ascend;
 
 #endif /* AVUTIL_HWCONTEXT_INTERNAL_H */
--- FFmpeg-n4.4.4/libavutil/pixdesc.c
+++ Ascendffmpeg/libavutil/pixdesc.c
@@ -2395,6 +2395,10 @@
         .name = "vulkan",
         .flags = AV_PIX_FMT_FLAG_HWACCEL,
     },
+    [AV_PIX_FMT_ASCEND] = {
+        .name = "ascend",
+        .flags = AV_PIX_FMT_FLAG_HWACCEL,
+    }
 };
 #if FF_API_PLUS1_MINUS1
 FF_ENABLE_DEPRECATION_WARNINGS
--- FFmpeg-n4.4.4/libavutil/pixfmt.h
+++ Ascendffmpeg/libavutil/pixfmt.h
@@ -232,6 +232,7 @@
      * HW acceleration through CUDA. data[i] contain CUdeviceptr pointers
      * exactly as for system memory frames.
      */
+    AV_PIX_FMT_ASCEND,
     AV_PIX_FMT_CUDA,
 
     AV_PIX_FMT_0RGB,        ///< packed RGB 8:8:8, 32bpp, XRGBXRGB...   X=unused/undefined
--- FFmpeg-n4.4.4/libavutil/utils.c
+++ Ascendffmpeg/libavutil/utils.c
@@ -37,6 +37,10 @@
 
 unsigned avutil_version(void)
 {
+    static int checks_done;
+    if (checks_done)
+        return LIBAVUTIL_VERSION_INT;
+
     av_assert0(AV_SAMPLE_FMT_DBLP == 9);
     av_assert0(AVMEDIA_TYPE_ATTACHMENT == 4);
     av_assert0(AV_PICTURE_TYPE_BI == 7);
@@ -54,6 +58,7 @@
         av_log(NULL, AV_LOG_ERROR, "Libavutil has been linked to a broken llrint()\n");
     }
 
+    checks_done = 1;
     return LIBAVUTIL_VERSION_INT;
 }
 
--- FFmpeg-n4.4.4/libswscale/aarch64/yuv2rgb_neon.S
+++ Ascendffmpeg/libswscale/aarch64/yuv2rgb_neon.S
@@ -118,8 +118,8 @@
 .endm
 
 .macro increment_yuv422p
-    add                 x6,  x6,  w7, SXTW                              // srcU += incU
-    add                 x13, x13, w14, SXTW                             // srcV += incV
+    add                 x6,  x6,  w7, UXTW                              // srcU += incU
+    add                 x13, x13, w14, UXTW                             // srcV += incV
 .endm
 
 .macro compute_rgba r1 g1 b1 a1 r2 g2 b2 a2
@@ -189,8 +189,8 @@
     st4                 {v16.8B,v17.8B,v18.8B,v19.8B}, [x2], #32
     subs                w8, w8, #16                                     // width -= 16
     b.gt                2b
-    add                 x2, x2, w3, SXTW                                // dst  += padding
-    add                 x4, x4, w5, SXTW                                // srcY += paddingY
+    add                 x2, x2, w3, UXTW                                // dst  += padding
+    add                 x4, x4, w5, UXTW                                // srcY += paddingY
     increment_\ifmt
     subs                w1, w1, #1                                      // height -= 1
     b.gt                1b
--- FFmpeg-n4.4.4/libswscale/input.c
+++ Ascendffmpeg/libswscale/input.c
@@ -84,9 +84,9 @@
     int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
     av_assert1(src1==src2);
     for (i = 0; i < width; i++) {
-        unsigned r_b = (input_pixel(&src1[8 * i + 0]) + input_pixel(&src1[8 * i + 4]) + 1) >> 1;
-        unsigned   g = (input_pixel(&src1[8 * i + 1]) + input_pixel(&src1[8 * i + 5]) + 1) >> 1;
-        unsigned b_r = (input_pixel(&src1[8 * i + 2]) + input_pixel(&src1[8 * i + 6]) + 1) >> 1;
+        int r_b = (input_pixel(&src1[8 * i + 0]) + input_pixel(&src1[8 * i + 4]) + 1) >> 1;
+        int   g = (input_pixel(&src1[8 * i + 1]) + input_pixel(&src1[8 * i + 5]) + 1) >> 1;
+        int b_r = (input_pixel(&src1[8 * i + 2]) + input_pixel(&src1[8 * i + 6]) + 1) >> 1;
 
         dstU[i]= (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
         dstV[i]= (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
@@ -156,9 +156,9 @@
     int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
     av_assert1(src1 == src2);
     for (i = 0; i < width; i++) {
-        unsigned r_b = input_pixel(&src1[i * 3 + 0]);
-        unsigned g   = input_pixel(&src1[i * 3 + 1]);
-        unsigned b_r = input_pixel(&src1[i * 3 + 2]);
+        int r_b = input_pixel(&src1[i * 3 + 0]);
+        int g   = input_pixel(&src1[i * 3 + 1]);
+        int b_r = input_pixel(&src1[i * 3 + 2]);
 
         dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
         dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
@@ -178,12 +178,12 @@
     int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
     av_assert1(src1 == src2);
     for (i = 0; i < width; i++) {
-        unsigned r_b = (input_pixel(&src1[6 * i + 0]) +
-                        input_pixel(&src1[6 * i + 3]) + 1) >> 1;
-        unsigned g   = (input_pixel(&src1[6 * i + 1]) +
-                        input_pixel(&src1[6 * i + 4]) + 1) >> 1;
-        unsigned b_r = (input_pixel(&src1[6 * i + 2]) +
-                        input_pixel(&src1[6 * i + 5]) + 1) >> 1;
+        int r_b = (input_pixel(&src1[6 * i + 0]) +
+                   input_pixel(&src1[6 * i + 3]) + 1) >> 1;
+        int g   = (input_pixel(&src1[6 * i + 1]) +
+                   input_pixel(&src1[6 * i + 4]) + 1) >> 1;
+        int b_r = (input_pixel(&src1[6 * i + 2]) +
+                   input_pixel(&src1[6 * i + 5]) + 1) >> 1;
 
         dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
         dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
--- FFmpeg-n4.4.4/libswscale/output.c
+++ Ascendffmpeg/libswscale/output.c
@@ -1043,8 +1043,8 @@
         Y2 -= c->yuv2rgb_y_offset;
         Y1 *= c->yuv2rgb_y_coeff;
         Y2 *= c->yuv2rgb_y_coeff;
-        Y1 += (1 << 13) - (1 << 29); // 21
-        Y2 += (1 << 13) - (1 << 29);
+        Y1 += 1 << 13; // 21
+        Y2 += 1 << 13;
         // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
 
         R = V * c->yuv2rgb_v2r_coeff;
@@ -1052,20 +1052,20 @@
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
-        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
-        output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
-        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
+        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
+            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
             dest += 6;
         }
     }
@@ -1102,8 +1102,8 @@
         Y2 -= c->yuv2rgb_y_offset;
         Y1 *= c->yuv2rgb_y_coeff;
         Y2 *= c->yuv2rgb_y_coeff;
-        Y1 += (1 << 13) - (1 << 29);
-        Y2 += (1 << 13) - (1 << 29);
+        Y1 += 1 << 13;
+        Y2 += 1 << 13;
 
         R = V * c->yuv2rgb_v2r_coeff;
         G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
@@ -1117,20 +1117,20 @@
             A2 += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
-        output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
-        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
+        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
+            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-            output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
             dest += 6;
         }
     }
@@ -1158,8 +1158,8 @@
             Y2 -= c->yuv2rgb_y_offset;
             Y1 *= c->yuv2rgb_y_coeff;
             Y2 *= c->yuv2rgb_y_coeff;
-            Y1 += (1 << 13) - (1 << 29);
-            Y2 += (1 << 13) - (1 << 29);
+            Y1 += 1 << 13;
+            Y2 += 1 << 13;
 
             if (hasAlpha) {
                 A1 = abuf0[i * 2    ] << 11;
@@ -1173,20 +1173,20 @@
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
-            output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
-            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
+            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
+                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
                 dest += 6;
             }
         }
@@ -1204,8 +1204,8 @@
             Y2 -= c->yuv2rgb_y_offset;
             Y1 *= c->yuv2rgb_y_coeff;
             Y2 *= c->yuv2rgb_y_coeff;
-            Y1 += (1 << 13) - (1 << 29);
-            Y2 += (1 << 13) - (1 << 29);
+            Y1 += 1 << 13;
+            Y2 += 1 << 13;
 
             if (hasAlpha) {
                 A1 = abuf0[i * 2    ] << 11;
@@ -1219,20 +1219,20 @@
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
-            output_pixel(&dest[1], av_clip_uintp2(((  G + Y1) >> 14) + (1<<15), 16));
-            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
+            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[5], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
+                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[4], av_clip_uintp2(((  G + Y2) >> 14) + (1<<15), 16));
-                output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
+                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
                 dest += 6;
             }
         }
@@ -1283,7 +1283,7 @@
         // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
         Y -= c->yuv2rgb_y_offset;
         Y *= c->yuv2rgb_y_coeff;
-        Y += (1 << 13) - (1<<29); // 21
+        Y += 1 << 13; // 21
         // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
 
         R = V * c->yuv2rgb_v2r_coeff;
@@ -1291,9 +1291,9 @@
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
-        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y)>>14) + (1<<15), 16));
-        output_pixel(&dest[1], av_clip_uintp2(((  G + Y)>>14) + (1<<15), 16));
-        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y)>>14) + (1<<15), 16));
+        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1331,7 +1331,7 @@
 
         Y -= c->yuv2rgb_y_offset;
         Y *= c->yuv2rgb_y_coeff;
-        Y += (1 << 13) - (1 << 29);
+        Y += 1 << 13;
 
         R = V * c->yuv2rgb_v2r_coeff;
         G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
@@ -1343,9 +1343,9 @@
             A += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
-        output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) + (1<<15), 16));
-        output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
+        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1374,7 +1374,7 @@
 
             Y -= c->yuv2rgb_y_offset;
             Y *= c->yuv2rgb_y_coeff;
-            Y += (1 << 13) - (1 << 29);
+            Y += 1 << 13;
 
             if (hasAlpha) {
                 A = abuf0[i] << 11;
@@ -1386,9 +1386,9 @@
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
-            output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) + (1<<15), 16));
-            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
+            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
@@ -1407,7 +1407,7 @@
 
             Y -= c->yuv2rgb_y_offset;
             Y *= c->yuv2rgb_y_coeff;
-            Y += (1 << 13) - (1 << 29);
+            Y += 1 << 13;
 
             if (hasAlpha) {
                 A = abuf0[i] << 11;
@@ -1419,9 +1419,9 @@
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
-            output_pixel(&dest[1], av_clip_uintp2(((  G + Y) >> 14) + (1<<15), 16));
-            output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
+            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
--- FFmpeg-n4.4.4/tools/target_dec_fuzzer.c
+++ Ascendffmpeg/tools/target_dec_fuzzer.c
@@ -172,7 +172,6 @@
     case AV_CODEC_ID_INTERPLAY_ACM: maxsamples /= 16384;  break;
     case AV_CODEC_ID_LAGARITH:    maxpixels  /= 1024;  break;
     case AV_CODEC_ID_LSCR:        maxpixels  /= 16;    break;
-    case AV_CODEC_ID_MMVIDEO:     maxpixels  /= 256;   break;
     case AV_CODEC_ID_MOTIONPIXELS:maxpixels  /= 256;   break;
     case AV_CODEC_ID_MP4ALS:      maxsamples /= 65536; break;
     case AV_CODEC_ID_MSA1:        maxpixels  /= 16384; break;