
Recherche avancée
Médias (2)
-
Valkaama DVD Label
4 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Image
-
Podcasting Legal guide
16 mai 2011, par
Mis à jour : Mai 2011
Langue : English
Type : Texte
Autres articles (48)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
Soumettre améliorations et plugins supplémentaires
10 avril 2011Si vous avez développé une nouvelle extension permettant d’ajouter une ou plusieurs fonctionnalités utiles à MediaSPIP, faites le nous savoir et son intégration dans la distribution officielle sera envisagée.
Vous pouvez utiliser la liste de discussion de développement afin de le faire savoir ou demander de l’aide quant à la réalisation de ce plugin. MediaSPIP étant basé sur SPIP, il est également possible d’utiliser le liste de discussion SPIP-zone de SPIP pour (...)
Sur d’autres sites (10736)
-
Laravel ffmpeg hls encode multi-bitrate x264 error
4 octobre 2022, par Osman ŞimşekI wanted to encode mutliple bitrate hls using Laravel protonomedia library. When I give a single bitrate, it performs the encode operation without error, but when I want to work with mutliple bitrate, it gives an error.


FFmpeg Version : 5.1.1


FFmpeg Command :


[2022-10-04 08:42:47] local.INFO: ffmpeg running command '/opt/ffmpeg-amd64-static/ffmpeg' '-version' 
[2022-10-04 08:42:47] local.INFO: ffmpeg executed command successfully 
[2022-10-04 08:42:47] local.INFO: ffmpeg running command '/opt/ffmpeg-amd64-static/ffmpeg' '-y' '-threads' '12' '-i' '/tmp/phpLH0wts' '-map' '0' '-vcodec' 'libx264' '-b:v' '250k' '-sc_threshold' '0' '-g' '48' '-hls_playlist_type' 'vod' '-hls_time' '10' '-hls_segment_filename' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_0_250_%05d.ts' '-master_pl_name' 'temporary_segment_playlist_0.m3u8' '-hls_key_info_file' '/tmp/78627e6a6355dc72/hls_encryption.keyinfo' '-hls_flags' 'periodic_rekey' '-acodec' 'aac' '-b:a' '128k' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_0_250.m3u8' '-map' '0' '-vcodec' 'libx264' '-b:v' '500k' '-sc_threshold' '0' '-g' '48' '-hls_playlist_type' 'vod' '-hls_time' '10' '-hls_segment_filename' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_1_500_%05d.ts' '-master_pl_name' 'temporary_segment_playlist_1.m3u8' '-hls_key_info_file' '/tmp/78627e6a6355dc72/hls_encryption.keyinfo' '-hls_flags' 'periodic_rekey' '-acodec' 'aac' '-b:a' '128k' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_1_500.m3u8' '-map' '0' '-vcodec' 'libx264' '-b:v' '1000k' '-sc_threshold' '0' '-g' '48' '-hls_playlist_type' 'vod' '-hls_time' '10' '-hls_segment_filename' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_2_1000_%05d.ts' '-master_pl_name' 'temporary_segment_playlist_2.m3u8' '-hls_key_info_file' '/tmp/78627e6a6355dc72/hls_encryption.keyinfo' '-hls_flags' 'periodic_rekey' '-acodec' 'aac' '-b:a' '128k' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_2_1000.m3u8' 
[2022-10-04 08:42:47] local.INFO: ffprobe running command '/opt/ffmpeg-amd64-static/ffprobe' '-help' '-loglevel' 'quiet' 
[2022-10-04 08:42:47] local.INFO: ffprobe executed command successfully 
[2022-10-04 08:42:47] local.INFO: ffprobe running command '/opt/ffmpeg-amd64-static/ffprobe' '/tmp/phpLH0wts' '-show_format' '-print_format' 'json' 
[2022-10-04 08:42:47] local.INFO: ffprobe executed command successfully 
[2022-10-04 08:42:47] local.ERROR: ffmpeg failed to execute command '/opt/ffmpeg-amd64-static/ffmpeg' '-y' '-threads' '12' '-i' '/tmp/phpLH0wts' '-map' '0' '-vcodec' 'libx264' '-b:v' '250k' '-sc_threshold' '0' '-g' '48' '-hls_playlist_type' 'vod' '-hls_time' '10' '-hls_segment_filename' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_0_250_%05d.ts' '-master_pl_name' 'temporary_segment_playlist_0.m3u8' '-hls_key_info_file' '/tmp/78627e6a6355dc72/hls_encryption.keyinfo' '-hls_flags' 'periodic_rekey' '-acodec' 'aac' '-b:a' '128k' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_0_250.m3u8' '-map' '0' '-vcodec' 'libx264' '-b:v' '500k' '-sc_threshold' '0' '-g' '48' '-hls_playlist_type' 'vod' '-hls_time' '10' '-hls_segment_filename' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_1_500_%05d.ts' '-master_pl_name' 'temporary_segment_playlist_1.m3u8' '-hls_key_info_file' '/tmp/78627e6a6355dc72/hls_encryption.keyinfo' '-hls_flags' 'periodic_rekey' '-acodec' 'aac' '-b:a' '128k' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_1_500.m3u8' '-map' '0' '-vcodec' 'libx264' '-b:v' '1000k' '-sc_threshold' '0' '-g' '48' '-hls_playlist_type' 'vod' '-hls_time' '10' '-hls_segment_filename' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_2_1000_%05d.ts' '-master_pl_name' 'temporary_segment_playlist_2.m3u8' '-hls_key_info_file' '/tmp/78627e6a6355dc72/hls_encryption.keyinfo' '-hls_flags' 'periodic_rekey' '-acodec' 'aac' '-b:a' '128k' '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_2_1000.m3u8': ffmpeg version N-63101-gc92edd969a-static https://johnvansickle.com/ffmpeg/ 



FFmpeg Error Message :


Output #2, hls, to '/home/crowiaftp/public_html/yeni/public/uploads/streams/1664862167633bc7d76b09b_2_1000.m3u8':
 Metadata:
 major_brand : mp42
 minor_version : 0
 compatible_brands: isommp42
 encoder : Lavf59.30.101
 Stream #2:0(und): Video: h264, yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1000 kb/s, 25 fps, 90k tbn (default)
 Metadata:
 creation_time : 2022-04-19T07:50:11.000000Z
 handler_name : ISO Media file produced by Google Inc. Created on: 04/19/2022.
 vendor_id : [0][0][0][0]
 encoder : Lavc59.42.104 libx264
 Side data:
 cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: N/A
 Stream #2:1(eng): Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s (default)
 Metadata:
 creation_time : 2022-04-19T07:50:11.000000Z
 handler_name : ISO Media file produced by Google Inc. Created on: 04/19/2022.
 vendor_id : [0][0][0][0]
 encoder : Lavc59.42.104 aac
frame= 0 fps=0.0 q=0.0 q=0.0 q=0.0 size=N/A time=00:00:00.41 bitrate=N/A speed=5.41x 
x264 [error]: malloc of size 3325760 failed
Error submitting video frame to the encoder
[libx264 @ 0x5a8cec0] final ratefactor: 40.36
[aac @ 0x5abc000] Qavg: 19883.271
[aac @ 0x5abc000] 2 frames left in the queue on closing
[libx264 @ 0x5b20d80] final ratefactor: 34.36
[aac @ 0x5ab7a40] Qavg: 19883.271
[aac @ 0x5ab7a40] 2 frames left in the queue on closing
[libx264 @ 0x5ab6440] final ratefactor: 28.36
[aac @ 0x5a89580] Qavg: 19883.271
[aac @ 0x5a89580] 2 frames left in the queue on closing
Conversion failed!



Hls encoding code :


$uniqFileName = uniqid(time());

FFMpeg::open($file)->exportForHLS()
 ->withRotatingEncryptionKey(function($fileName, $contents){
 Storage::disk('streams')->put("secrets/$fileName", $contents);
 })
 ->addFormat((new \FFMpeg\Format\Video\X264)->setKiloBitrate(250))
 ->addFormat((new \FFMpeg\Format\Video\X264)->setKiloBitrate(500))
 ->addFormat((new \FFMpeg\Format\Video\X264)->setKiloBitrate(1000))
 ->toDisk('streams')
 ->save($uniqFileName.'.m3u8');

 FFMpeg::cleanupTemporaryFiles();



-
Hello. I'd like to play a video on my app on android, I tried with videoplayer, it works but doesn't load the video simply open theUI but not thevideo
26 octobre 2022, par AbdulI'd like to play a video on my app on android, I tried with videoplayer, it works but doesn't load the video ( simply open the UI but not the video).


I found out i may need ffpyplayer so I changed buildozer requirements :
requirements = python3,kivy, android,ffpyplayer


but buildozer failed to build apk when i added ffpyplayer and ffmpeg in buildozer.spec file in requirement.


[DEBUG]: If you think configure made a mistake, make sure you are using the latest
[DEBUG]: version from Git. If the latest version fails, report the problem to the
[DEBUG]: ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
[DEBUG]: Include the log file "ffbuild/config.log" produced by configure as this will help
[DEBUG]: solve the problem.
Exception in thread background thread for pid 77802:
Traceback (most recent call last):
 File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
 self.run()
 File "/usr/lib/python3.7/threading.py", line 870, in run
 self._target(*self._args, **self._kwargs)
 File "/usr/local/lib/python3.7/dist-packages/sh.py", line 1641, in wrap
 fn(*rgs, **kwargs)
 File "/usr/local/lib/python3.7/dist-packages/sh.py", line 2569, in background_thread
 handle_exit_code(exit_code)
 File "/usr/local/lib/python3.7/dist-packages/sh.py", line 2269, in fn
 return self.command.handle_command_exit_code(exit_code)
 File "/usr/local/lib/python3.7/dist-packages/sh.py", line 869, in handle_command_exit_code
 raise exc
sh.ErrorReturnCode_1: 

 RAN: /content/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/ffmpeg/armeabi-v7a__ndk_target_21/ffmpeg/configure --disable-everything --enable-openssl --enable-nonfree --enable-protocol=https,tls_openssl --enable-gpl --enable-libx264 --enable-libshine --enable-libvpx --enable-parsers --enable-decoders --enable-encoders --enable-muxers --enable-demuxers --disable-symver --disable-programs --disable-doc --enable-filter=aresample,resample,crop,adelay,volume,scale --enable-protocol=file,http,hls,udp,tcp --enable-small --enable-hwaccels --enable-pic --disable-static --disable-debug --enable-shared --target-os=android --enable-cross-compile --cross-prefix=armv7a-linux-androideabi21- --arch=arm --strip=/root/.buildozer/android/platform/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip --sysroot=/root/.buildozer/android/platform/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/sysroot --enable-neon --prefix=/content/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/ffmpeg/armeabi-v7a__ndk_target_21/ffmpeg

 STDOUT:
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
armv7a-linux-androideabi21-clang is unable to create an executable file.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.


 STDERR:


Traceback (most recent call last):
 File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
 "__main__", mod_spec)
 File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
 exec(code, run_globals)
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1297, in <module>
 main()
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
 ToolchainCL()
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 730, in __init__
 getattr(self, command)(args)
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 153, in wrapper_func
 build_dist_from_args(ctx, dist, args)
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 215, in build_dist_from_args
 args, "ignore_setup_py", False
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 505, in build_recipes
 recipe.build_arch(arch)
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipes/ffmpeg/__init__.py", line 143, in build_arch
 shprint(configure, *flags, _env=env)
 File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
 for line in output:
 File "/usr/local/lib/python3.7/dist-packages/sh.py", line 915, in next
 self.wait()
 File "/usr/local/lib/python3.7/dist-packages/sh.py", line 845, in wait
 self.handle_command_exit_code(exit_code)
 File "/usr/local/lib/python3.7/dist-packages/sh.py", line 869, in handle_command_exit_code
 raise exc
sh.ErrorReturnCode_1: 

 RAN: /content/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/ffmpeg/armeabi-v7a__ndk_target_21/ffmpeg/configure --disable-everything --enable-openssl --enable-nonfree --enable-protocol=https,tls_openssl --enable-gpl --enable-libx264 --enable-libshine --enable-libvpx --enable-parsers --enable-decoders --enable-encoders --enable-muxers --enable-demuxers --disable-symver --disable-programs --disable-doc --enable-filter=aresample,resample,crop,adelay,volume,scale --enable-protocol=file,http,hls,udp,tcp --enable-small --enable-hwaccels --enable-pic --disable-static --disable-debug --enable-shared --target-os=android --enable-cross-compile --cross-prefix=armv7a-linux-androideabi21- --arch=arm --strip=/root/.buildozer/android/platform/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip --sysroot=/root/.buildozer/android/platform/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/sysroot --enable-neon --prefix=/content/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/ffmpeg/armeabi-v7a__ndk_target_21/ffmpeg

 STDOUT:
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
armv7a-linux-androideabi21-clang is unable to create an executable file.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.


 STDERR:

# Command failed: /usr/bin/python3 -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=python3,ffpyplayer,kivy,openssl,certifi,android,pytube,plyer,pyjnius,kivmob,jnius,future,libshine,libx264,ffpyplayer_codecs,Pillow,liblzma,opencv,requests,urllib3,chardet,idna,youtube_search --arch armeabi-v7a --copy-libs --color=always --storage-dir="/content/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21 --ignore-setup-py --debug
# ENVIRONMENT:
# NV_LIBCUBLAS_DEV_VERSION = '11.4.1.1043-1'
# NV_CUDA_COMPAT_PACKAGE = 'cuda-compat-11-2'
# NV_CUDNN_PACKAGE_DEV = 'libcudnn8-dev=8.1.1.33-1+cuda11.2'
# PYDEVD_USE_FRAME_EVAL = 'NO'
# LD_LIBRARY_PATH = '/usr/local/nvidia/lib:/usr/local/nvidia/lib64'
# NV_LIBNCCL_DEV_PACKAGE = 'libnccl-dev=2.8.4-1+cuda11.2'
# TCLLIBPATH = '/usr/share/tcltk/tcllib1.19'
# CLOUDSDK_PYTHON = 'python3'
# LANG = 'en_US.UTF-8'
# NV_LIBNPP_DEV_PACKAGE = 'libnpp-dev-11-2=11.3.2.152-1'
# ENABLE_DIRECTORYPREFETCHER = '1'
# HOSTNAME = '875ade0bb031'
# OLDPWD = '/'
# CLOUDSDK_CONFIG = '/content/.config'
# USE_AUTH_EPHEM = '1'
# NV_LIBNPP_VERSION = '11.3.2.152-1'
# NV_NVPROF_DEV_PACKAGE = 'cuda-nvprof-11-2=11.2.152-1'
# NVIDIA_VISIBLE_DEVICES = 'all'
# NV_NVPROF_VERSION = '11.2.152-1'
# NV_LIBCUSPARSE_VERSION = '11.4.1.1152-1'
# DATALAB_SETTINGS_OVERRIDES = '{"kernelManagerProxyPort":6000,"kernelManagerProxyHost":"172.28.0.3","jupyterArgs":["--ip=172.28.0.2"],"debugAdapterMultiplexerPath":"/usr/local/bin/dap_multiplexer","enableLsp":true}'
# NV_LIBCUBLAS_DEV_PACKAGE = 'libcublas-dev-11-2=11.4.1.1043-1'
# ENV = '/root/.bashrc'
# PAGER = 'cat'
# NCCL_VERSION = '2.8.4-1'
# TF_FORCE_GPU_ALLOW_GROWTH = 'true'
# JPY_PARENT_PID = '60'
# NO_GCE_CHECK = 'False'
# PWD = '/content'
# NVARCH = 'x86_64'
# NV_LIBCUSPARSE_DEV_VERSION = '11.4.1.1152-1'
# HOME = '/root'
# KMP_LISTEN_PORT = '6000'
# LAST_FORCED_REBUILD = '20221021'
# CLICOLOR = '1'
# NV_LIBNCCL_PACKAGE_VERSION = '2.8.4-1'
# NV_LIBNCCL_PACKAGE = 'libnccl2=2.8.4-1+cuda11.2'
# DEBIAN_FRONTEND = 'noninteractive'
# NV_LIBNCCL_DEV_PACKAGE_NAME = 'libnccl-dev'
# NV_CUDA_LIB_VERSION = '11.2.2-1'
# NV_LIBNPP_PACKAGE = 'libnpp-11-2=11.3.2.152-1'
# NV_LIBNCCL_PACKAGE_NAME = 'libnccl2'
# LIBRARY_PATH = '/usr/local/cuda/lib64/stubs'
# NV_NVTX_VERSION = '11.2.152-1'
# NV_LIBCUBLAS_VERSION = '11.4.1.1043-1'
# NV_LIBCUBLAS_PACKAGE = 'libcublas-11-2=11.4.1.1043-1'
# GCE_METADATA_TIMEOUT = '3'
# NV_CUDNN_VERSION = '8.1.1.33'
# VM_GCE_METADATA_HOST = '169.254.169.254'
# NV_CUDA_CUDART_DEV_VERSION = '11.2.152-1'
# KMP_TARGET_PORT = '9000'
# GLIBCPP_FORCE_NEW = '1'
# TBE_CREDS_ADDR = '172.28.0.1:8008'
# TERM = 'xterm-color'
# SHELL = '/bin/bash'
# GCS_READ_CACHE_BLOCK_SIZE_MB = '16'
# NV_NVML_DEV_VERSION = '11.2.152-1'
# PYTHONWARNINGS = 'ignore:::pip._internal.cli.base_command'
# MPLBACKEND = 'module://ipykernel.pylab.backend_inline'
# CUDA_VERSION = '11.2.2'
# NV_LIBCUBLAS_PACKAGE_NAME = 'libcublas-11-2'
# NVIDIA_DRIVER_CAPABILITIES = 'compute,utility'
# TBE_RUNTIME_ADDR = '172.28.0.1:8011'
# SHLVL = '1'
# PYTHONPATH = '/env/python'
# NV_LIBCUBLAS_DEV_PACKAGE_NAME = 'libcublas-dev-11-2'
# NVIDIA_REQUIRE_CUDA = ('cuda>=11.2 brand=tesla,driver>=418,driver<419 '
 'brand=tesla,driver>=450,driver<451')
# NV_LIBNPP_DEV_VERSION = '11.3.2.152-1'
# TBE_EPHEM_CREDS_ADDR = '172.28.0.1:8009'
# NV_CUDA_CUDART_VERSION = '11.2.152-1'
# NV_CUDNN_PACKAGE_NAME = 'libcudnn8'
# GLIBCXX_FORCE_NEW = '1'
# PATH = '/root/.buildozer/android/platform/apache-ant-1.9.4/bin:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin'
# NV_LIBNCCL_DEV_PACKAGE_VERSION = '2.8.4-1'
# LD_PRELOAD = '/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4'
# NV_CUDNN_PACKAGE = 'libcudnn8=8.1.1.33-1+cuda11.2'
# GIT_PAGER = 'cat'
# _ = '/usr/local/bin/buildozer'
# PACKAGES_PATH = '/root/.buildozer/android/packages'
# ANDROIDSDK = '/root/.buildozer/android/platform/android-sdk'
# ANDROIDNDK = '/root/.buildozer/android/platform/android-ndk-r23b'
# ANDROIDAPI = '30'
# ANDROIDMINAPI = '21'
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2
</module>


kindly help me anyone would be very appreciate thank you.


-
ffmpeg encoding leaves me with blank space at the end where the video pauses and there is nothing ahead
6 novembre 2022, par Nisarg DesaiI was trying to slice some of the video being played and clip it in mpv.net using a .lua script which uses ffmpeg to encode the webm output. ffmpeg sometimes leaves some seconds blank and without any video/audio ahead while clipping from source. Is there any solution to this ?


The code for the script is given below (was taken from here https://github.com/occivink/mpv-scripts) :


local utils = require "mp.utils"
local msg = require "mp.msg"
local options = require "mp.options"

local ON_WINDOWS = (package.config:sub(1,1) ~= "/")

local start_timestamp = nil
local profile_start = ""

-- implementation detail of the osd message
local timer = nil
local timer_duration = 2

-- folder creation if it doesnt exist
function exists(file)
 local ok, err, code = os.rename(file, file)
 if not ok then
 if code == 13 then
 return true
 end
 end
 return ok, err
end

--- Check if a directory exists in this path
function create_dir(path)
 local dir = "\"" .. path .. "\""
 if not exists(path .."/") then
 os.execute("mkdir " .. dir)
 end
end

function append_table(lhs, rhs)
 for i = 1,#rhs do
 lhs[#lhs+1] = rhs[i]
 end
 return lhs
end

function file_exists(name)
 local f = io.open(name, "r")
 if f ~= nil then
 io.close(f)
 return true
 else
 return false
 end
end

function get_extension(path)
 local candidate = string.match(path, "%.([^.]+)$")
 if candidate then
 for _, ext in ipairs({ "mkv", "webm", "mp4", "avi" }) do
 if candidate == ext then
 return candidate
 end
 end
 end
 return "mkv"
end

function get_output_string(dir, format, input, extension, title, from, to, profile)
 local res = utils.readdir(dir)
 if not res then
 return nil
 end
 local files = {}
 for _, f in ipairs(res) do
 files[f] = true
 end
 local output = format
 output = string.gsub(output, "$f", function() return input end)
 output = string.gsub(output, "$t", function() return title end)
 output = string.gsub(output, "$s", function() return seconds_to_time_string(from, true) end)
 output = string.gsub(output, "$e", function() return seconds_to_time_string(to, true) end)
 output = string.gsub(output, "$d", function() return seconds_to_time_string(to-from, true) end)
 output = string.gsub(output, "$x", function() return extension end)
 output = string.gsub(output, "$p", function() return profile end)
 if ON_WINDOWS then
 output = string.gsub(output, "[/\\|<>?:\"*]", "_")
 end
 if not string.find(output, "$n") then
 return files[output] and nil or output
 end
 local i = 1
 while true do
 local potential_name = string.gsub(output, "$n", tostring(i))
 if not files[potential_name] then
 return potential_name
 end
 i = i + 1
 end
end

function get_video_filters()
 local filters = {}
 for _, vf in ipairs(mp.get_property_native("vf")) do
 local name = vf["name"]
 name = string.gsub(name, '^lavfi%-', '')
 local filter
 if name == "crop" then
 local p = vf["params"]
 filter = string.format("crop=%d:%d:%d:%d", p.w, p.h, p.x, p.y)
 elseif name == "mirror" then
 filter = "hflip"
 elseif name == "flip" then
 filter = "vflip"
 elseif name == "rotate" then
 local rotation = vf["params"]["angle"]
 -- rotate is NOT the filter we want here
 if rotation == "90" then
 filter = "transpose=clock"
 elseif rotation == "180" then
 filter = "transpose=clock,transpose=clock"
 elseif rotation == "270" then
 filter = "transpose=cclock"
 end
 end
 filters[#filters + 1] = filter
 end
 return filters
end

function get_input_info(default_path, only_active)
 local accepted = {
 video = true,
 audio = not mp.get_property_bool("mute"),
 sub = mp.get_property_bool("sub-visibility")
 }
 local ret = {}
 for _, track in ipairs(mp.get_property_native("track-list")) do
 local track_path = track["external-filename"] or default_path
 if not only_active or (track["selected"] and accepted[track["type"]]) then
 local tracks = ret[track_path]
 if not tracks then
 ret[track_path] = { track["ff-index"] }
 else
 tracks[#tracks + 1] = track["ff-index"]
 end
 end
 end
 return ret
end

function seconds_to_time_string(seconds, full)
 local ret = string.format("%02d:%02d.%03d"
 , math.floor(seconds / 60) % 60
 , math.floor(seconds) % 60
 , seconds * 1000 % 1000
 )
 if full or seconds > 3600 then
 ret = string.format("%d:%s", math.floor(seconds / 3600), ret)
 end
 return ret
end

function start_encoding(from, to, settings)
 local args = {
 settings.ffmpeg_command,
 "-loglevel", "panic", "-hide_banner",
 }
 local append_args = function(table) args = append_table(args, table) end

 local path = mp.get_property("path")
 local is_stream = not file_exists(path)
 if is_stream then
 path = mp.get_property("stream-path")
 end

 local track_args = {}
 local start = seconds_to_time_string(from, false)
 local input_index = 0
 for input_path, tracks in pairs(get_input_info(path, settings.only_active_tracks)) do
 append_args({
 "-ss", start,
 "-i", input_path,
 })
 if settings.only_active_tracks then
 for _, track_index in ipairs(tracks) do
 track_args = append_table(track_args, { "-map", string.format("%d:%d", input_index, track_index)})
 end
 else
 track_args = append_table(track_args, { "-map", tostring(input_index)})
 end
 input_index = input_index + 1
 end

 append_args({"-to", tostring(to-from)})
 append_args(track_args)

 -- apply some of the video filters currently in the chain
 local filters = {}
 if settings.preserve_filters then
 filters = get_video_filters()
 end
 if settings.append_filter ~= "" then
 filters[#filters + 1] = settings.append_filter
 end
 if #filters > 0 then
 append_args({ "-filter:v", table.concat(filters, ",") })
 end

 -- split the user-passed settings on whitespace
 for token in string.gmatch(settings.codec, "[^%s]+") do
 args[#args + 1] = token
 end

 -- path of the output
 local output_directory = mp.get_property("options/screenshot-directory")
 -- local checkbool = exists(output_directory.."/")
 -- mp.osd_message("" .. type(checkbool), timer_duration)
 -- if not checkbool then 
 -- os.execute("mkdir" .. output_directory)
 -- end
 if output_directory == "" then
 if is_stream then
 output_directory = "."
 else
 output_directory, _ = utils.split_path(path)
 end
 else
 output_directory = string.gsub(output_directory, "^~", os.getenv("HOME") or "~")
 end
 local input_name = mp.get_property("filename/no-ext") or "encode"
 local title = mp.get_property("media-title")
 local extension = get_extension(path)
 local output_name = get_output_string(output_directory, settings.output_format, input_name, extension, title, from, to, settings.profile)
 if not output_name then
 mp.osd_message("Invalid path " .. output_directory)
 return
 end
 args[#args + 1] = utils.join_path(output_directory, output_name)

 if settings.print then
 local o = ""
 -- fuck this is ugly
 for i = 1, #args do
 local fmt = ""
 if i == 1 then
 fmt = "%s%s"
 elseif i >= 2 and i <= 4 then
 fmt = "%s"
 elseif args[i-1] == "-i" or i == #args or args[i-1] == "-filter:v" then
 fmt = "%s '%s'"
 else
 fmt = "%s %s"
 end
 o = string.format(fmt, o, args[i])
 end
 print(o)
 end
 if settings.detached then
 utils.subprocess_detached({ args = args })
 else
 local res = utils.subprocess({ args = args, max_size = 0, cancellable = false })
 if res.status == 0 then
 mp.osd_message("Finished encoding succesfully")
 else
 mp.osd_message("Failed to encode, check the log")
 end
 end
end

function clear_timestamp()
 timer:kill()
 start_timestamp = nil
 profile_start = ""
 mp.remove_key_binding("encode-ESC")
 mp.remove_key_binding("encode-ENTER")
 mp.osd_message("", 0)
end

function set_timestamp(profile)
 if not mp.get_property("path") then
 mp.osd_message("No file currently playing")
 return
 end
 if not mp.get_property_bool("seekable") then
 mp.osd_message("Cannot encode non-seekable media")
 return
 end
 create_dir(mp.get_property("options/screenshot-directory"))
 if not start_timestamp or profile ~= profile_start then
 profile_start = profile
 start_timestamp = mp.get_property_number("time-pos")
 local msg = function()
 mp.osd_message(
 string.format("encode [%s]: waiting for end timestamp", profile or "default"),
 timer_duration
 )
 end
 msg()
 timer = mp.add_periodic_timer(timer_duration, msg)
 mp.add_forced_key_binding("ESC", "encode-ESC", clear_timestamp)
 mp.add_forced_key_binding("ENTER", "encode-ENTER", function() set_timestamp(profile) end)
 else
 local from = start_timestamp
 local to = mp.get_property_number("time-pos")
 if to <= from then
 mp.osd_message("Second timestamp cannot be before the first", timer_duration)
 timer:kill()
 timer:resume()
 return
 end
 clear_timestamp()
 mp.osd_message(string.format("Encoding from %s to %s"
 , seconds_to_time_string(from, false)
 , seconds_to_time_string(to, false)
 ), timer_duration)
 -- include the current frame into the extract
 local fps = mp.get_property_number("container-fps") or 30
 to = to + 1 / fps / 2
 local settings = {
 detached = false,
 container = "",
 only_active_tracks = false,
 preserve_filters = true,
 append_filter = "",
 codec = "-c:v libvpx-vp9 -lossless 1 -b:v 1000k -deadline good",
 output_format = "$f_$n.webm",
 output_directory = "",
 ffmpeg_command = "ffmpeg",
 print = true,
 }
 if profile then
 options.read_options(settings, profile)
 if settings.container ~= "" then
 msg.warn("The 'container' setting is deprecated, use 'output_format' now")
 settings.output_format = settings.output_format .. "." .. settings.container
 end
 settings.profile = profile
 else
 settings.profile = "default"
 end 
 start_encoding(from, to, settings)
 end
end

mp.add_key_binding(nil, "set-timestamp", set_timestamp)