<p>Here's a method that should, in principle, work. It assumes VAVA interleaving and for somewhat efficient processing requires the packet sizes for both video and audio having a reasonably large greatest common divisor.</p>

<p>The examples below assume a video packet size of <code>1382400</code> bytes and audio of <code>7680</code> bytes. As it happens, the former is exactly 180 times the latter. The idea is we can ingest the raw stream as a raw "audio" stream and deinterleave using a selection expression, which routes 180 "frames" to one output and the 181st frame to another. Then the separated outputs are dumped into regular or fifo files which can then be read by another ffmpeg process with a sane interpretation of the input. </p>

<p>Command 1:</p>

<p><code>ffmpeg -f u8 -channels 1 -i raw-input-url -filter_complex "asetnsamples=7680,aselect='1+not(mod(n+1,181))':n=2[vid][aud]" -map [vid] -f u8 file-vid -map [aud] -f u8 file-aud</code></p>

<p>Command 1 with input offset:</p>

<p><code>ffmpeg -f u8 -channels 1 -i "subfile,,start,3248615,end,0,,:raw-input-url" -filter_complex "asetnsamples=7680,aselect='1+not(mod(n+1,181))':n=2[vid][aud]" -map [vid] -f u8 file-vid -map [aud] -f u8 file-aud</code></p>

<p>where <code>3248615</code> is in bytes and should point to the start of a video frame for this to work.</p>

<p>Command 2:</p>

<p><code>ffmpeg -f rawvideo -pixel_format yuv420p -framerate F -video_size WxH -i file-vid -f f32le -channels N -sample_rate R -i file-aud { -encoding parameters } output</code></p>

CC BY-SA 4.0
2019-04-30T15:04:53.667Z
Thanks Gyan. Weird as SE did not notify me of this answer. I'll let you know how it turns out.
Mike Versteeg
CC BY-SA 4.0
2019-05-06T13:14:42.893Z
I am thoroughly impressed. Except for a required vflip this worked the first time. Thanks!
Mike Versteeg
CC BY-SA 4.0
2019-04-29T13:57:27.963Z
2019-04-29T13:57:27.963Z
Gyan
<p>I'm always impressed how smart FFmpeg has been designed so giving this a go. Can I use FFmpeg to convert part of a file to a compressed video file w/audio? The file I have consists of YUV420 frames interleaved with (floating point) audio PCM. So raw video &amp; audio. I would like to convert part of it, so would want to give an offset into the file. It is part of a ring buffer so the file is opened and growing, but I have full control over this. </p>

CC BY-SA 4.0
2019-04-28T14:45:28.643Z
All raw demuxers expect a single stream. Can you deinterleave it yourself?
Gyan
CC BY-SA 4.0
2019-04-28T18:13:07.907Z
@Gyan Ah, I was hoping to avoid this as resource usage is at a premium. De-interleave to file or memory would not be my first choice. First time FFmpeg lets me down! If this is not possible I probably prefer to first look into some container format that supports the interleaved raw data, I can then copy it and slap a header in front of it. If something like that exists. It would not be compressed, but at least it can be exported.
Mike Versteeg
CC BY-SA 4.0
2019-04-28T18:31:57.390Z
what's the interleaving interval in bytes?
Gyan
CC BY-SA 4.0
2019-04-28T18:46:11.570Z
@Gyan It's VAVA.. The interval depends on the video resolution, e.g. a typical video frame would be 1382400 bytes, followed by 7680 bytes of audio. Repeat.
Mike Versteeg
CC BY-SA 4.0
2019-04-28T19:18:22.280Z
I may be able to do something about this. Give me a day or two.
Gyan
CC BY-SA 4.0
2019-04-28T19:39:42.423Z
Can ffmpeg write to intermediate files ? And can multiple ffmpeg instances be run?
Gyan
CC BY-SA 4.0
2019-04-29T06:51:09.350Z
@Gyan sure, but resources are at a premium.. So if what you have in mind requires more than me de-interleaving then you might overshoot my goal. Unless there's a way to add throttling when writing to disk. Mmm..
Mike Versteeg
<ffmpeg><raw>
use ffmpeg to convert interleaved raw yuv/pcm to compressed
Mike Versteeg
# use ffmpeg to convert interleaved raw yuv/pcm to compressed

(Asked by: username_0 on 2019-04-28)

I'm always impressed how smart FFmpeg has been designed so giving this a go. Can I use FFmpeg to convert part of a file to a compressed video file w/audio? The file I have consists of YUV420 frames interleaved with (floating point) audio PCM. So raw video & audio. I would like to convert part of it, so would want to give an offset into the file. It is part of a ring buffer so the file is opened and growing, but I have full control over this.

**Tags:** ffmpeg, raw

> **Comments:**
> **username_1**: All raw demuxers expect a single stream. Can you deinterleave it yourself?  
> **username_0**: @username_1 Ah, I was hoping to avoid this as resource usage is at a premium. De-interleave to file or memory would not be my first choice. First time FFmpeg lets me down! If this is not possible I probably prefer to first look into some container format that supports the interleaved raw data, I can then copy it and slap a header in front of it. If something like that exists. It would not be compressed, but at least it can be exported.  
> **username_1**: what's the interleaving interval in bytes?  
> **username_0**: @username_1 It's VAVA.. The interval depends on the video resolution, e.g. a typical video frame would be 1382400 bytes, followed by 7680 bytes of audio. Repeat.  
> **username_1**: I may be able to do something about this. Give me a day or two.  
> **username_1**: Can ffmpeg write to intermediate files ? And can multiple ffmpeg instances be run?  
> **username_0**: @username_1 sure, but resources are at a premium.. So if what you have in mind requires more than me de-interleaving then you might overshoot my goal. Unless there's a way to add throttling when writing to disk. Mmm..  

---

## 1 answers

### Answer by username_1 on 2019-04-29. Score: 1 | Accepted answer

Here's a method that should, in principle, work. It assumes VAVA interleaving and for somewhat efficient processing requires the packet sizes for both video and audio having a reasonably large greatest common divisor.

The examples below assume a video packet size of `1382400` bytes and audio of `7680` bytes. As it happens, the former is exactly 180 times the latter. The idea is we can ingest the raw stream as a raw "audio" stream and deinterleave using a selection expression, which routes 180 "frames" to one output and the 181st frame to another. Then the separated outputs are dumped into regular or fifo files which can then be read by another ffmpeg process with a sane interpretation of the input.

Command 1:

`ffmpeg -f u8 -channels 1 -i raw-input-url -filter_complex "asetnsamples=7680,aselect='1+not(mod(n+1,181))':n=2[vid][aud]" -map [vid] -f u8 file-vid -map [aud] -f u8 file-aud`

Command 1 with input offset:

`ffmpeg -f u8 -channels 1 -i "subfile,,start,3248615,end,0,,:raw-input-url" -filter_complex "asetnsamples=7680,aselect='1+not(mod(n+1,181))':n=2[vid][aud]" -map [vid] -f u8 file-vid -map [aud] -f u8 file-aud`

where `3248615` is in bytes and should point to the start of a video frame for this to work.

Command 2:

`ffmpeg -f rawvideo -pixel_format yuv420p -framerate F -video_size WxH -i file-vid -f f32le -channels N -sample_rate R -i file-aud { -encoding parameters } output`

> **Comments:**
> **username_0**: Thanks username_1. Weird as SE did not notify me of this answer. I'll let you know how it turns out.  
> **username_0**: I am thoroughly impressed. Except for a required vflip this worked the first time. Thanks!  

---

