Nhận thời lượng video từ URL JavaScript

get-video-thời lượng

Nhận thời lượng của tệp/luồng video với ffprobe

Cài đặt

$ npm install --save get-video-duration

Cách sử dụng

const { getVideoDurationInSeconds } = require['get-video-duration']

// From a local path...
getVideoDurationInSeconds['video.mov'].then[[duration] => {
  console.log[duration]
}]

// From a URL...
getVideoDurationInSeconds[
  '//clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
].then[[duration] => {
  console.log[duration]
}]

// From a readable stream...

const fs = require['fs']
const stream = fs.createReadStream['video.mov']

getVideoDurationInSeconds[stream].then[[duration] => {
  console.log[duration]
}]

// If you need to customize the path to ffprobe...
getVideoDurationInSeconds['video.mov', '/path/to/ffprobe'].then[[duration] => {
  console.log[duration]
}]

Giấy phép

MIT. Dựa trên get-video-dimensions

Gói npm get-video-duration nhận được tổng cộng 6.460 lượt tải xuống mỗi tuần. Do đó, chúng tôi cho rằng mức độ phổ biến của thời lượng tải video là Nhỏ

Dựa trên số liệu thống kê dự án từ kho lưu trữ GitHub cho gói npm get-video-duration, chúng tôi thấy rằng nó đã được gắn dấu sao 110 lần và 11 dự án khác trong hệ sinh thái phụ thuộc vào nó

Số lượt tải xuống được tính là trung bình động trong khoảng thời gian 12 tháng qua, không bao gồm các ngày cuối tuần và các điểm dữ liệu bị thiếu đã xác định

Giá trị dấu phẩy động có độ chính xác kép cho biết thời lượng của phương tiện tính bằng giây. Nếu không có sẵn dữ liệu phương tiện, giá trị NaN được trả về. Nếu phương tiện của phần tử không có thời lượng đã biết—chẳng hạn như đối với luồng phương tiện trực tiếp—giá trị của duration+Infinity

Video HTML5 rất thú vị, nếu chỉ vì lý do chúng tôi không còn cần Flash hoặc plugin của bên thứ ba khác để hiển thị phương tiện. Chúng tôi cũng có thể tạo các điều khiển và màn hình tùy chỉnh xung quanh video và một trong những màn hình đó phải là thời lượng của video. Để tôi chỉ cho bạn cách lấy và hiển thị thời lượng video

JavaScript

Phần tử video có thuộc tính duration đại diện cho số giây trong video. Để hiển thị thời lượng một cách đẹp mắt, bạn cần phải sử dụng parseInt và mô-đun [

const { getVideoDurationInSeconds } = require['get-video-duration']

// From a local path...
getVideoDurationInSeconds['video.mov'].then[[duration] => {
  console.log[duration]
}]

// From a URL...
getVideoDurationInSeconds[
  '//clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
].then[[duration] => {
  console.log[duration]
}]

// From a readable stream...

const fs = require['fs']
const stream = fs.createReadStream['video.mov']

getVideoDurationInSeconds[stream].then[[duration] => {
  console.log[duration]
}]

// If you need to customize the path to ffprobe...
getVideoDurationInSeconds['video.mov', '/path/to/ffprobe'].then[[duration] => {
  console.log[duration]
}]
0]

// Assume "video" is the video node
var i = setInterval[function[] {
	if[video.readyState > 0] {
		var minutes = parseInt[video.duration / 60, 10];
		var seconds = video.duration % 60;

		// [Put the minutes and seconds in the display]

		clearInterval[i];
	}
}, 200];

Điều quan trọng là sử dụng

const { getVideoDurationInSeconds } = require['get-video-duration']

// From a local path...
getVideoDurationInSeconds['video.mov'].then[[duration] => {
  console.log[duration]
}]

// From a URL...
getVideoDurationInSeconds[
  '//clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
].then[[duration] => {
  console.log[duration]
}]

// From a readable stream...

const fs = require['fs']
const stream = fs.createReadStream['video.mov']

getVideoDurationInSeconds[stream].then[[duration] => {
  console.log[duration]
}]

// If you need to customize the path to ffprobe...
getVideoDurationInSeconds['video.mov', '/path/to/ffprobe'].then[[duration] => {
  console.log[duration]
}]
1 và kiểm tra
const { getVideoDurationInSeconds } = require['get-video-duration']

// From a local path...
getVideoDurationInSeconds['video.mov'].then[[duration] => {
  console.log[duration]
}]

// From a URL...
getVideoDurationInSeconds[
  '//clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
].then[[duration] => {
  console.log[duration]
}]

// From a readable stream...

const fs = require['fs']
const stream = fs.createReadStream['video.mov']

getVideoDurationInSeconds[stream].then[[duration] => {
  console.log[duration]
}]

// If you need to customize the path to ffprobe...
getVideoDurationInSeconds['video.mov', '/path/to/ffprobe'].then[[duration] => {
  console.log[duration]
}]
2 của video phòng trường hợp video chưa tải vào thời điểm bạn cố gắng kéo dài thời lượng. parseInt được dùng để lấy số phút và mô-đun được dùng để lấy số thứ hai

Làm cách nào để lấy thời lượng video từ URL trong JavaScript?

JavaScript . // Giả sử "video" là nút video var i = setInterval[function[] { if[video. readyState > 0] { var phút = parseInt[video. thời lượng / 60, 10]; . use parseInt and modulus [ % ]: // Assume "video" is the video node var i = setInterval[function[] { if[video. readyState > 0] { var minutes = parseInt[video. duration / 60, 10]; var seconds = video.

Làm cách nào để có được thời lượng video trong JavaScript codepen?

var vid = tài liệu. getElementById["Video của tôi"];
hàm myFunction[] {
cảnh báo [vid. khoảng thời gian];
[chức năng localFileVideoPlayer[] {
'Sử dụng nghiêm ngặt'

Làm cách nào để có thời lượng trong JavaScript?

abs[ngày1 - ngày2]; . tầng [khoảng cách / 3600000]; . sàn [khoảng cách / 60000]; . sàn [khoảng cách / 1000]; . ${['0' + phút]

Làm cách nào để có được thời lượng của video YouTube bằng JavaScript?

Thời lượng YouTube trong 4 dòng JavaScript .
Thời lượng phải có tối thiểu 4 ký tự–video 1 giây được biểu thị bằng 0. 01
Bất cứ điều gì dưới một phút phải được đệm bằng 0. , như 0. 59 hoặc 0. 12
Bất cứ điều gì dưới mười giây phải được đệm bằng 0. 0, như 0. 09 hoặc 0. 01

Chủ Đề