0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

libavで特定のStreamだけ取り出したい/除外したい

Posted at

debian jessieのmainレポジトリに入っているlibav-11.7での設定例です。

ffmpegでも流用できるかもしれません。

参照 https://libav.org/documentation/avprobe.html#Stream-specifiers-1

TL;DR

  • SID単位でStreamを分離
  • data streamの除去
  • 再エンコードは行わない

上記のようなことを行うスクリプト

#!/bin/sh
SID="$1"
INPUT="$2"
OUTPUT="$3"
exec avconv -i "$INPUT" -map p:"$SID" -map -d -codec copy "$OUTPUT"

avprobe

変換前

$ avprobe 'hoge.ts'
avprobe version 11.7-6:11.7-1~deb8u1, Copyright (c) 2007-2016 the Libav developers
  built on Jun 12 2016 21:51:35 with gcc 4.9.2 (Debian 4.9.2-10)
Input #0, mpegts, from 'hoge.m2ts':
  Duration: 00:30:00.95, start: 15279.402967, bitrate: 14618 kb/s
  Program 23608
    Metadata:
      service_name    : ▒▒▒▒▒!!▒ر
      service_provider:
    Stream #0.0[0x111]: Video: mpeg2video (Main), yuv420p, 1440x1080 [PAR 4:3 DAR 16:9], 20000 kb/s, 29.97 fps, 90k tbn, 59.94 tbc
    Stream #0.1[0x112]: Audio: aac, 48000 Hz, stereo, fltp, 243 kb/s
    Stream #0.2[0x740]: Data: [13][0][0][0] / 0x000D
    Stream #0.3[0x750]: Data: [13][0][0][0] / 0x000D
    Stream #0.4[0x751]: Data: [13][0][0][0] / 0x000D
    Stream #0.5[0x752]: Data: [13][0][0][0] / 0x000D
    Stream #0.6[0x960]: Data: [13][0][0][0] / 0x000D
    Stream #0.7[0x961]: Data: [13][0][0][0] / 0x000D
    Stream #0.8[0x75e]: Data: [13][0][0][0] / 0x000D
    Stream #0.9[0x75f]: Data: [13][0][0][0] / 0x000D
    Stream #0.10[0x96e]: Data: [13][0][0][0] / 0x000D
  Program 23610
    Metadata:
      service_name    : ▒▒▒▒▒!!▒ز
      service_provider:
    Stream #0.12[0x131]: Video: mpeg2video (Main), yuv420p, 720x480 [PAR 32:27 DAR 16:9], 15000 kb/s, 29.97 fps, 90k tbn, 59.94 tbc
    Stream #0.11[0x132]: Audio: aac, 48000 Hz, stereo, fltp, 255 kb/s
    Stream #0.13[0x840]: Data: [13][0][0][0] / 0x000D
    Stream #0.3[0x750]: Data: [13][0][0][0] / 0x000D
    Stream #0.4[0x751]: Data: [13][0][0][0] / 0x000D
    Stream #0.5[0x752]: Data: [13][0][0][0] / 0x000D
    Stream #0.6[0x960]: Data: [13][0][0][0] / 0x000D
    Stream #0.7[0x961]: Data: [13][0][0][0] / 0x000D
    Stream #0.14[0x85e]: Data: [13][0][0][0] / 0x000D
    Stream #0.15[0x85f]: Data: [13][0][0][0] / 0x000D
    Stream #0.10[0x96e]: Data: [13][0][0][0] / 0x000D
  Program 23609
    Metadata:
      service_name    : ▒▒▒▒▒!!▒ر
      service_provider:
    Stream #0.0[0x111]: Video: mpeg2video (Main), yuv420p, 1440x1080 [PAR 4:3 DAR 16:9], 20000 kb/s, 29.97 fps, 90k tbn, 59.94 tbc
    Stream #0.1[0x112]: Audio: aac, 48000 Hz, stereo, fltp, 243 kb/s
    Stream #0.2[0x740]: Data: [13][0][0][0] / 0x000D
    Stream #0.3[0x750]: Data: [13][0][0][0] / 0x000D
    Stream #0.4[0x751]: Data: [13][0][0][0] / 0x000D
    Stream #0.5[0x752]: Data: [13][0][0][0] / 0x000D
    Stream #0.6[0x960]: Data: [13][0][0][0] / 0x000D
    Stream #0.7[0x961]: Data: [13][0][0][0] / 0x000D
    Stream #0.8[0x75e]: Data: [13][0][0][0] / 0x000D
    Stream #0.9[0x75f]: Data: [13][0][0][0] / 0x000D
    Stream #0.10[0x96e]: Data: [13][0][0][0] / 0x000D
  Program 23992
    Metadata:
      service_name    : ▒▒▒▒▒
      service_provider:
    Stream #0.17[0x281]: Video: h264 (Constrained Baseline), yuv420p, 320x180, 10 fps, 90k tbn, 29.97 tbc
    Stream #0.16[0x283]: Audio: aac, 48000 Hz, stereo, fltp, 30 kb/s
    Stream #0.18[0x780]: Data: [13][0][0][0] / 0x000D
    Stream #0.19[0x789]: Data: [13][0][0][0] / 0x000D
    Stream #0.20[0x98a]: Data: [13][0][0][0] / 0x000D
    Stream #0.21[0x98b]: Data: [13][0][0][0] / 0x000D
  Program 23993
    Metadata:
      service_name    : ▒▒▒▒▒
      service_provider:
    Stream #0.22[0x381]: Video: h264 (Constrained Baseline), yuv420p, 320x180, 14.99 fps, 90k tbn, 29.97 tbc
    Stream #0.23[0x383]: Audio: aac, 48000 Hz, stereo, fltp, 29 kb/s
    Stream #0.24[0x880]: Data: [13][0][0][0] / 0x000D
    Stream #0.25[0x889]: Data: [13][0][0][0] / 0x000D
    Stream #0.20[0x98a]: Data: [13][0][0][0] / 0x000D
    Stream #0.21[0x98b]: Data: [13][0][0][0] / 0x000D
  Program 23615
    Metadata:
      service_name    : ▒▒▒▒▒!!▒▒NW;~
      service_provider:
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 0 for input stream 3
Unsupported codec with id 0 for input stream 4
Unsupported codec with id 0 for input stream 5
Unsupported codec with id 0 for input stream 6
Unsupported codec with id 0 for input stream 7
Unsupported codec with id 0 for input stream 8
Unsupported codec with id 0 for input stream 9
Unsupported codec with id 0 for input stream 10
Unsupported codec with id 0 for input stream 13
Unsupported codec with id 0 for input stream 14
Unsupported codec with id 0 for input stream 15
Unsupported codec with id 0 for input stream 18
Unsupported codec with id 0 for input stream 19
Unsupported codec with id 0 for input stream 20
Unsupported codec with id 0 for input stream 21
Unsupported codec with id 0 for input stream 24
Unsupported codec with id 0 for input stream 25
# avprobe output

SID:23608を取り出しデータstreamを除去する

変換後

$ avprobe fuga.mp4
avprobe version 11.7-6:11.7-1~deb8u1, Copyright (c) 2007-2016 the Libav developers
  built on Jun 12 2016 21:51:35 with gcc 4.9.2 (Debian 4.9.2-10)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8f6d00] multiple edit list entries, a/v desync might occur, patch welcome
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8f6d00] multiple edit list entries, a/v desync might occur, patch welcome
[aac @ 0x8f8660] channel element 3.5 is not allocated
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'fuga.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf56.1.0
  Duration: 00:30:00.55, start: 0.014000, bitrate: 8601 kb/s
    Stream #0.0(und): Video: mpeg2video (Main), yuv420p, 1440x1080 [PAR 4:3 DAR 16:9], 20000 kb/s, 29.97 fps, 90k tbn, 59.94 tbc (default)
    Stream #0.1(und): Audio: aac, 48000 Hz, stereo, fltp, 255 kb/s (default)
# avprobe output
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?