LoginSignup
0
0

More than 1 year has passed since last update.

LINEに投稿されたMP4ファイルの作成時刻を知る (残課題あり)

Last updated at Posted at 2023-03-27

試してみたこと

LINE BOTに投稿された動画の作成時刻を、動画のメタデータから取得してみました

結果

MP4のメタデータから creation_time を取得することができました
しかし、LINEに投稿した動画の場合
creation_time は、撮影開始時刻とも、撮影終了時刻とも異なるものでした

18:28:01から19秒間撮影された動画

  • 撮影開始時刻 : 18:28:01
  • 撮影終了時刻 : 18:28:20
    image.png

creation_time18:28:35
うーん、これは何の時間なのだろうか...
image.png

コード

LINE BOT

動画ファイルが投稿されたら、ローカルに保存するLINE BOT

server.js
'use strict';

const express = require('express');
const line = require('@line/bot-sdk');
const exec = require('child_process').exec;

const PORT = process.env.PORT || 3000;

// LINE credentials
const config = {
    channelSecret: process.env.CHANNEL_SECRET,
    channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN,
};

const app = express();

app.post('/webhook', line.middleware(config), (req, res) => {
    Promise
      .all(req.body.events.map(handleEvent))
      .then((result) => res.json(result));
});

const client = new line.Client(config);

async function handleEvent(event) {
  if (event.message.type == 'video' && event.message.contentProvider.type == 'line') {
    exec("curl -v -X GET https://api-data.line.me/v2/bot/message/" + event.message.id + "/content -H 'Authorization: Bearer " + process.env.CHANNEL_ACCESS_TOKEN + "' --output video." + event.message.id + ".mp4", (err, stdout, stderr) => {
      return client.replyMessage(event.replyToken, {
        type: 'text',
        text: '動画を保存したよ'
    });
  }
  else {
    return Promise.resolve(null);
  }
}

app.listen(PORT);
console.log(`Server running at ${PORT}`);

メタデータ (creation_time) 取得

ローカルに保存されたMP4ファイルから creation_time を取得するコード

get_creation_time.js
'use strict';

const exec = require('child_process').exec;

console.log(process.argv[2]);

exec("ffmpeg -i " + process.argv[2], (err, stdout, stderr) => {
	var lines = stderr.split('\n');
	var result = lines.find(line => line.includes('creation_time'));
	console.log(result);

  var sep = result.split(':');
  var time = sep[1].trim() + ':' + sep[2].trim() + ':' + sep[3].trim();
  console.log(time);
  var utc_time = new Date(time);
  console.log("creation time:");
  console.log(utc_time);
  console.log(utc_time.toLocaleString('sv'));
  // var jst_time = new Date(utc_time.getTime() + (9 * 60 * 60 * 1000));
  // console.log(jst_time);

  var now = new Date();
  console.log("now:");
  console.log(now);
  console.log(now.toLocaleString('sv'));

});

参考

LINE BOTを作るには、こちらの記事が参考になります。

EOF

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0