Skip to content

Instantly share code, notes, and snippets.

@orumin
Last active February 10, 2023 09:25
Show Gist options
  • Save orumin/785dd5da8c29c5b24754 to your computer and use it in GitHub Desktop.
Save orumin/785dd5da8c29c5b24754 to your computer and use it in GitHub Desktop.
MPEG2-TS to H.264 within gstreamer on RaspberryPi
#!/usr/bin/bash
#
# Usage: mpegts2h264.sh <src.ts> <dst.mp4>
#
program_no=$(ffmpeg -i $1 2>&1 | grep Program | head -n 1 | awk '{ print $2 }')
video_sid=$(ffmpeg -i $1 2>&1 | grep Stream | grep Video | sed -e "s/^.*Stream #0:0\[0x\([0-9a-f][0-9a-f][0-9a-f]\)\].*$/\1/g")
audio_sid=$(ffmpeg -i $1 2>&1 | grep Stream | grep Audio | sed -e "s/^.*Stream #0:1\[0x\([0-9a-f][0-9a-f][0-9a-f]\)\].*$/\1/g")
gst-launch-1.0 filesrc location=./$1 ! progressreport ! \
tsdemux program-number=$program_no name=demuxer \
demuxer.video_0$video_sid ! video/mpeg ! queue max-size-time=0 max-size-buffers=0 ! \
mpegvideoparse ! omxmpeg2videodec ! \
videoconvert ! omxh264enc target-bitrate=4500000 control-rate=variable periodicty-idr=240 ! \
video/x-h264,stream-format=byte-stream,profile=high ! h264parse ! mux. \
demuxer.audio_0$audio_sid ! audio/mpeg ! queue max-size-time=0 max-size-buffers=0 ! \
aacparse ! avdec_aac ! audioresample ! audioconvert dithering=0 ! faac bitrate=128000 ! \
mp4mux streamable=true name=mux ! filesink location=$2
@orumin
Copy link
Author

orumin commented Dec 25, 2014

自動でProgram numberとStream IDを指定するようにしてみた。あとリサイズ処理はオミット

@xswqaz
Copy link

xswqaz commented Oct 22, 2015

Menu IDがあれば、勝手にやってくれます。(SID指定しなくても)

@orumin
Copy link
Author

orumin commented Jun 20, 2016

これやったの大分前なのでMenu IDがあったか覚えてないです.
たぶん録画データに1SEG用のも入ってたりして辛いしなんとかしようとおもってSID指定した気がするのできっとわざとです.
覚えてないですが

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment