<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>ffmpeg &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/ffmpeg/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Mon, 09 Mar 2026 11:04:45 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>ffmpeg &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Reprojecting Dual Fisheye Videos to Equirectangular (LG 360)]]></title>
		<link>https://shkspr.mobi/blog/2026/04/reprojecting-dual-fisheye-videos-to-equirectangular-lg-360/</link>
					<comments>https://shkspr.mobi/blog/2026/04/reprojecting-dual-fisheye-videos-to-equirectangular-lg-360/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Sun, 19 Apr 2026 11:34:32 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[LG360]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[video]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=67087</guid>

					<description><![CDATA[I still use my obsolete LG 360 Camera. When copying MP4 videos from its SD card, they come out in &#34;Dual Fisheye&#34; format - which looks like this:    VLC and YouTube will only play &#34;Equirectangular&#34; videos in spherical mode. So, how to convert a dual fisheye to equirectangualr?  The Simple Way  ffmpeg \   -i original.mp4 \   -vf &#34;v360=input=dfisheye:output=equirect:ih_fov=189:iv_fov=189&#34; \  …]]></description>
										<content:encoded><![CDATA[<p>I still use my <a href="https://shkspr.mobi/blog/2021/11/lg-killed-its-360-camera-after-only-4-years-heres-how-to-get-it-back/">obsolete LG 360 Camera</a>. When copying MP4 videos from its SD card, they come out in "Dual Fisheye" format - which looks like this:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2026/02/Original.webp" alt="Dual fisheye photo of us and some elephants." width="2560" height="1280" class="aligncenter size-full wp-image-67108">

<p>VLC and YouTube will only play "Equirectangular" videos in spherical mode. So, how to convert a dual fisheye to equirectangualr?</p>

<h2 id="the-simple-way"><a href="https://shkspr.mobi/blog/2026/04/reprojecting-dual-fisheye-videos-to-equirectangular-lg-360/#the-simple-way">The Simple Way</a></h2>

<pre><code class="language-bash">ffmpeg \
  -i original.mp4 \
  -vf "v360=input=dfisheye:output=equirect:ih_fov=189:iv_fov=189" \
  360.mp4
</code></pre>

<p>However, this has some "quirks".</p>

<p>The first part of the video filter is <code>v360=input=dfisheye:output=equirect</code> - that just says to use the 360 filter on an input which is dual fisheye and then output in equirectangular.</p>

<p>The next part is <code>:ih_fov=189:iv_fov=189</code> which says that the input video has a horizontal and vertical field of view of 189°. That's a <em>weird</em> number, right?</p>

<p>You'd kind of expect each lens to be 180°, right? Here's what happens if <code>:ih_fov=180:iv_fov=180</code> is used:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2026/02/360-180.webp" alt="Flattened image, but there are overlaps at the seams." width="2560" height="1280" class="aligncenter size-full wp-image-67109">

<p>The lenses overlaps a little bit. So using 180° means that certain portions are duplicated.</p>

<p>I <em>think</em> the lenses technically offer 200°, but the physical casing prevents all of that from being viewed. I got to the value of 189° by trial and error. Mostly error! Using <code>:ih_fov=189:iv_fov=189</code> get this image which has less overlap:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2026/02/360-189.webp" alt="A flattened image which has less overlap at the edges." width="2560" height="1280" class="aligncenter size-full wp-image-67110">

<p>It isn't <em>perfect</em> - but it preserves most of the image coherence.</p>

<h2 id="cut-off-images"><a href="https://shkspr.mobi/blog/2026/04/reprojecting-dual-fisheye-videos-to-equirectangular-lg-360/#cut-off-images">Cut Off Images</a></h2>

<p>There's another thing worth noticing - the top, right, bottom, and left "corners" of the circle are cut off. If the image sensor captured everything, the resultant fisheye would look something like this:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2026/02/Repaged.webp" alt="Two circular images with gaps between them." width="2626" height="1313" class="aligncenter size-full wp-image-67111">

<p>I tried repaging the video to include the gaps, but it didn't make any noticeable difference.</p>

<h2 id="making-equirectangular-videos-work-with-vlc"><a href="https://shkspr.mobi/blog/2026/04/reprojecting-dual-fisheye-videos-to-equirectangular-lg-360/#making-equirectangular-videos-work-with-vlc">Making Equirectangular Videos Work With VLC</a></h2>

<p>Sadly, ffmpeg will not write the metadata necessary to let playback devices know the video is spherical. Instead, according to <a href="https://bino3d.org/metadata-for-stereo-3d-and-surround-video.html">Bino3D</a>, you have to use <code>exiftool</code> like so:</p>

<pre><code class="language-bash">exiftool \
        -XMP-GSpherical:Spherical="true" \
        -XMP-GSpherical:Stitched="true" \
        -XMP-GSpherical:ProjectionType="equirectangular" \
        video.mp4
</code></pre>

<h2 id="putting-it-all-together"><a href="https://shkspr.mobi/blog/2026/04/reprojecting-dual-fisheye-videos-to-equirectangular-lg-360/#putting-it-all-together">Putting It All Together</a></h2>

<p>The LG 360 records audio in 5.1 surround using AAC. That's already fairly well compressed, so there's no point squashing it down to Opus.</p>

<p>The default video codec is h264, but the picture is going to be reprojected, so quality is always going to take a bit of a hit. Pick whichever code you like to give the best balance of quality, file size, and encoding time.</p>

<p>Run:</p>

<pre><code class="language-bash">ffmpeg \
  -i original.mp4 \
  -vf "v360=input=dfisheye:output=equirect:ih_fov=189:iv_fov=189" \
  -c:v libx265 -preset fast -crf 28 -c:a copy \
  out.mp4; exiftool \
        -XMP-GSpherical:Spherical="true" \
        -XMP-GSpherical:Stitched="true" \
        -XMP-GSpherical:ProjectionType="equirectangular" \
        out.mp4
</code></pre>

<p>That will produce a reasonable equirectangular file suitable for viewing in VLC or in VR.</p>

<p>If this has been useful to you, please stick a comment in the box!</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=67087&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2026/04/reprojecting-dual-fisheye-videos-to-equirectangular-lg-360/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[M🞵A🞵S🞵H - De-Specialised Edition]]></title>
		<link>https://shkspr.mobi/blog/2024/03/m%f0%9f%9e%b5a%f0%9f%9e%b5s%f0%9f%9e%b5h-de-specialised-edition/</link>
					<comments>https://shkspr.mobi/blog/2024/03/m%f0%9f%9e%b5a%f0%9f%9e%b5s%f0%9f%9e%b5h-de-specialised-edition/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Wed, 06 Mar 2024 12:34:12 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[tv]]></category>
		<category><![CDATA[video]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=49793</guid>

					<description><![CDATA[A few years ago, classic TV comedy MASH, was remastered and released on streaming platforms.  The picture quality was massively increased with just one minor flaw.  They cropped the image to 16:9 widescreen 😱  This upset some fans.  The thing about widescreen is that it chops off the top and bottom of the picture. The top of Hawkeye&#039;s head? Gone! The bottom of Hot-Lips&#039; boots? Vanished! אױ װײ איז …]]></description>
										<content:encoded><![CDATA[<p>A few years ago, <a href="https://shkspr.mobi/blog/2023/05/mash-war-is-heaven/">classic TV comedy MASH</a>, was remastered and released on streaming platforms.  The picture quality was massively increased with just one <em>minor</em> flaw.  They cropped the image to 16:9 widescreen 😱</p>

<p><a href="https://web.archive.org/web/20240313131833/https://www.mash4077tv.com/forums/viewtopic.php?t=949">This upset some fans</a>.</p>

<p>The thing about widescreen is that it chops off the top and bottom of the picture. The top of Hawkeye's head? Gone! The bottom of Hot-Lips' boots? Vanished! <strong lang="he" title="Oh, woe is me">אױ װײ איז מיר</strong></p>

<p>But, there is an upside. Or should that be side-side? Anyway, the new remaster <em>adds</em> some previous unseen detail to the left and right of the picture.</p>

<p>Here's a grab from the original:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2024/02/orig.jpg" alt="Three men in an office. There's also a skeleton." width="640" height="480" class="aligncenter size-full wp-image-49796">

<p>And here's the remastered wide version:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2024/02/wide.jpg" alt="The top and bottom are cropped but there's more details at the edges." width="720" height="405" class="aligncenter size-full wp-image-49797">

<p>Perhaps an animated GIF will help?</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2024/02/Radar-and-friends.gif" alt="The two images flipping between each other." width="720" height="480" class="aligncenter size-full wp-image-49798">

<p>As you can see, the remaster has great picture quality <em>and</em> bonus content at the sides. However, you might also be able to notice that the widescreen image has been stretched a fair bit. By my calculation it was originally a 1.72 aspect ratio before been distorted to 1.777.</p>

<p>This GIF makes it a bit more obvious what has been stretched and how the image has moved from the centre:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2024/02/MASH.gif" alt="Two people sat at a bar. The image shows the difference between the two frames." width="720" height="480" class="aligncenter size-full wp-image-49800">

<p>So, is it possible to take the sides of the widescreen version and stitch them on to the edges of the 4:3 version?  Yes!</p>

<p>With a bit of ffmpeg magic, I scaled the 16:9 version back to its original ratio, then I added some black padding around it, then I overlaid the 4:3 on top - giving it some transparency so you can see how well it fits.</p>

<p>The (frankly overwhelming) command is:</p>

<pre><code class="language-bash">ffmpeg -i wide.mp4 -i orig.mp4 \
   -filter_complex \
   "[0]scale=670:390,setsar=1,pad=670:480:(ow-iw)/2:(oh-ih)/2:black,setpts=PTS-0.375/TB[v0];[1]scale=640:480,setsar=1,format=rgba,colorchannelmixer=aa=0.5[fg];[v0][fg]overlay=(W-w)/2:(H-h)/2[vid];[0:a][1:a]amerge=inputs=2[aout]" \
   -map "[vid]" -map "[aout]" -c:v copy -c:a aac -strict experimental -b:a 192k copy output.mp4
</code></pre>

<p>That also shifts the first video by a couple of frames due to the files being slightly out of synch. I've also kept both soundtracks, for your discordant joy.</p>

<p>Here it is - the intro to M*A*S*H with extra side bits:</p>

<p></p><div style="width: 620px;" class="wp-video"><video class="wp-video-shortcode" id="video-49793-2" width="620" height="444" preload="metadata" controls="controls"><source type="video/mp4" src="https://shkspr.mobi/blog/wp-content/uploads/2024/02/mash-overlay.mp4?_=2"><a href="https://shkspr.mobi/blog/wp-content/uploads/2024/02/mash-overlay.mp4">https://shkspr.mobi/blog/wp-content/uploads/2024/02/mash-overlay.mp4</a></video></div><p></p>

<p>As you can see, they adjusted the font size of the main titles. As the video progresses, you'll notice the vertical offset changes - I don't know how much manual adjustment was made. The videos shift in and out of synchronisation - I assume the original was transferred from film to tape in a less precise process than the remaster.</p>

<h2 id="todo"><a href="https://shkspr.mobi/blog/2024/03/m%f0%9f%9e%b5a%f0%9f%9e%b5s%f0%9f%9e%b5h-de-specialised-edition/#todo">ToDo</a></h2>

<ul>
<li>Get AI to fill in the missing corners?</li>
<li>Get AI to continually correct the placement of the video?</li>
<li>Get AI to add a laugh track?</li>
</ul>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=49793&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2024/03/m%f0%9f%9e%b5a%f0%9f%9e%b5s%f0%9f%9e%b5h-de-specialised-edition/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		<enclosure url="https://shkspr.mobi/blog/wp-content/uploads/2024/02/mash-overlay.mp4" length="7032025" type="video/mp4" />

			</item>
		<item>
		<title><![CDATA[HOWTO: Split WAV and CUE files on Linux]]></title>
		<link>https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/</link>
					<comments>https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Mon, 04 Feb 2019 20:48:18 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mkv]]></category>
		<category><![CDATA[mkvmerge]]></category>
		<category><![CDATA[surround sound]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=31357</guid>

					<description><![CDATA[Mostly notes to myself, as a follow-up to this older post.  This is a 3-step process.  Add the file to an MKV  Use MKVmerge:  mkvmerge &#34;audio.wav&#34; --chapters &#34;audio.cue&#34; -o &#34;audio.mkv&#34;   You can see that chapter names have been added to the .mkv if you run ffmpeg -i or mkvinfo.  Split the MKV by chapter  This generates one file per chapter:  mkvmerge -D -S &#34;audio.mkv&#34; --split chapters:all -o…]]></description>
										<content:encoded><![CDATA[<p>Mostly notes to myself, as a follow-up to <a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/">this older post</a>.  This is a 3-step process.</p>

<h2 id="add-the-file-to-an-mkv"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#add-the-file-to-an-mkv">Add the file to an MKV</a></h2>

<p>Use <a href="https://mkvtoolnix.download/">MKVmerge</a>:</p>

<pre><code class="language-_">mkvmerge "audio.wav" --chapters "audio.cue" -o "audio.mkv"
</code></pre>

<p>You can see that chapter names have been added to the .mkv if you run <code>ffmpeg -i</code> or <code>mkvinfo</code>.</p>

<h2 id="split-the-mkv-by-chapter"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#split-the-mkv-by-chapter">Split the MKV by chapter</a></h2>

<p>This generates one file per chapter:</p>

<pre><code class="language-_">mkvmerge -D -S "audio.mkv" --split chapters:all -o "split-%02d.mkv"
</code></pre>

<p>The <code>-D</code> switch means no video will be copied. <code>-S</code> means no subtitles.</p>

<h2 id="extract-the-audio"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#extract-the-audio">Extract the audio</a></h2>

<p>This quickly pulls out the audio, raw, without changing anything.</p>

<pre><code class="language-_">mkvextract split-01.mkv tracks "0:output"
</code></pre>

<p>The raw audio is placed in a file called <code>output</code></p>

<p>You can also do this with:</p>

<pre><code class="language-_">ffmpeg -i "split-01.mkv" -acodec copy "whatever.wav"
</code></pre>

<p>Replace <code>.wav</code> with <code>.ac3</code> or <code>.flac</code> or whatever the audio format is.
You can transcode the audio to something else. I recommend <a href="https://opus-codec.org/">Opus</a></p>

<pre><code class="language-_">ffmpeg -i "split-01.mkv" -af aformat=channel_layouts="7.1|5.1|stereo" -b:a 1536k "whatever.opus"
</code></pre>

<p>There is a <a href="https://trac.ffmpeg.org/ticket/5718">bug with the surround sound mapping in ffmpeg</a>.</p>

<h2 id="rename-it"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#rename-it">Rename it</a></h2>

<p>This is bit convoluted. <code>ffprobe</code> can get the chapter name:</p>

<pre><code class="language-_">ffprobe -i "split-01.mkv" -show_chapters -loglevel error
</code></pre>

<p>The use of <code>-loglevel error</code> means you only get the data, rather than the debug cruft.</p>

<p>In order to get the title, we get <code>ffprobe</code> to spit out JSON and then get <code>jq</code> to interpret it:</p>

<pre><code class="language-_">ffprobe -i "split-01.mkv" -print_format json -show_chapters -loglevel error | jq ".chapters[0].tags.title" -r
</code></pre>

<h2 id="all-in-one-script-to-extract-the-audio-and-rename-it"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#all-in-one-script-to-extract-the-audio-and-rename-it">All in one script to extract the audio <em>and</em> rename it</a></h2>

<pre><code class="language-_">#!/bin/bash
AUDIO="audio.wav"
CUE="audio.cue"
MKV="audio.mkv"

# What's the audio format?
FORMAT=$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$AUDIO")

# Create the MKV
mkvmerge "$AUDIO" --chapters "$CUE" -o "$MKV"

# How many chapters are there?
JSON=$(ffprobe -i "$MKV" -print_format json -show_chapters -loglevel error)
COUNT=$(echo $JSON | jq ".chapters | length" )

# Split the MKV into chapters
mkvmerge -D -S "$MKV" --split chapters:all -o "split-%02d.mkv"

# Loop through all the created .mkv files
COUNTER=1
while [ $COUNTER -le $COUNT ]; do

  # Zero pad the counter
  printf -v ZEROTRACK "%02d" $COUNTER

  # Get the chapter name
  JSON=$(ffprobe -i "split-$ZEROTRACK.mkv" -print_format json -show_chapters -loglevel error)
  TITLE=$(echo $JSON | jq ".chapters[0].tags.title" -r)
  FILENAME="[$ZEROTRACK] $TITLE.$FORMAT"

  # Raw Audio
  mkvextract "split-$ZEROTRACK.mkv" tracks "0:$FILENAME"
  # Transcode. Optional
  #ffmpeg -i "split-$ZEROTRACK.mkv" "$FILENAME.opus"

  let COUNTER=COUNTER+1 
done

# Delete the generated MKVs. Optional
#rm *.mkv
</code></pre>

<p>Note, there is <a href="https://gitlab.com/mbunkus/mkvtoolnix/issues/2498">no single command in MKVtools to do this</a></p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=31357&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
