Keith C. Perry via plug on 30 Aug 2020 22:47:38 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Transcoding MTS vids to something else for frame extraction


Hmmm, ok, I have a some other things you can try after I dug though my media conversion script that's been growing for... what decade is this?  :)

(So I don't have edit, wherever you see $1 that is the source and $2 is the target file)

1) Cinelerra... before I started use OpenShot (you might want to try that too), I used to convert to an mjpeg/wav file with this:

ffmpeg -y -i $1 -f avi -c:a pcm_s16le -c:v mjpeg -q:v 1 $2

Often ffmpeg's default are not the full set of parameters you need so if you look at that line compared to yours, the most important thing is the -q:v 1 (if your ffmpeg is older you might need to use "-sameq" instead) which is a quick way to tell ffmpeg to give you the same quality.  I would try mjpeg again with the above string because it really is the sane intermediate video format these days and every frame produced looks good.

2) "raw" format... make sure you have A LOT of space for this one:

mencoder $1 -oac pcm -ovc raw -vf format=yuy2 -o $2

Yep, I sometimes mencoder.  I'm sure this can do this in ffmpeg but as I said, this script is ancient.  Speaking of ancient, I see you tried to convert the files to an XVID spec too.  My version of that is:

3) XVID spec...  I used to use this so my LG DVD player could stream content from my DLNA server

mencoder -forceidx $1 -ffourcc XVID -ovc xvid -xvidencopts fixed_quant=5:trellis:vhq=2:autoaspect -oac mp3lame -lameopts cbr:preset=224 -vf scale=720:-3,expand=720:540 -of a
vi -o $2

Now, lets get more modern...

4) mp4

ffmpeg -y -i $1 -ar 44100 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset veryfast -f mp4 -crf 17 -threads 0 $2

5) mkv

ffmpeg -y -i $1 -vcodec libx264 -acodec libfaac -ar 48000 -vpre slower -f matroska -qscale 1 -threads 0 $2


Either of those may work but I suspect you might have to search through more frames around the timestamp you want for a good shot.  The ghosting you're seeing I don't think is interlacing.  It is the progressive nature of modern video formats to only update the blocks that change frame to frame which simultaneously employing various analytics to reduce "noise" from frame to frame so the playback looks good.  Frame by frame, no so much.

BTW, you can generally omit the audio stream by removing the audio parameters and adding "-an".


~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
Keith C. Perry, MS E.E. 
Managing Member, DAO Technologies LLC 
(O) +1.215.525.4165 x2033 
(M) +1.215.432.5167 
www.daotechnologies.com

----- Original Message -----
From: "JP Vossen via plug" <plug@lists.phillylinux.org>
To: "Philadelphia Linux User's Group Discussion List" <plug@lists.phillylinux.org>
Sent: Sunday, August 30, 2020 8:49:03 PM
Subject: Re: [PLUG] Transcoding MTS vids to something else for frame extraction

Typo in subject fixed, sigh.

Thanks Keith, I figured you'd have thoughts.  Unfortunately, mjpeg was a 
bit worse, as least after using these then re-extracting:
	ffmpeg -i 00023.MTS 00023.mjpeg
	ffmpeg -i 00023.MTS -b:v 10000k 00023.mjpeg

`ffmpeg -i 00023.MTS 00023.avi` resulted in less interlaced pictures (I 
think?), but they were very pixelated and fuzzy.

`ffmpeg -i 00023.MTS 00023.mp4` was much slower than the others and the 
frames where as bad or worse than the MTS.

Interestingly, all the transcoded formats above were about half the size 
of the original MTS, which I did not expect.  Perhaps some `ffmpeg` 
default is at work there?


This was a bit better, and the output file was larger than the input, 
which I'd expect.  But most frames were still interlaced or just off:
	ffmpeg -i 00023.MTS -c:v libxvid -qscale:v 2 00023.avi

I tried to combine things, but this was no better than previous:
	ffmpeg -hide_banner -i 00023.MTS -acodec copy -vcodec rawvideo \
		-y -force_key_frames 'expr:gte(t,n_forced*5)' 00023.avi

I ended up doing this, then extracting the frames again, but I'm not 
sure it was really much better:
```
for file in *.MTS; do
     ffmpeg -hide_banner -loglevel error -nostdin -i $file -acodec copy \
         -vcodec rawvideo -y /tmp/dolphins/"${file//MTS/avi}"
done
```

When I say "interlaced" frames, I mean there are sometimes fuzzy ghost 
images and/or bars and spaces in things, mostly things in motion.  I was 
assuming that was artifacts from the keyframe and diff thing, 
but...maybe that's just how this camera works?  Nothing I do seems to 
improve it, at any rate.


On 8/30/20 3:42 PM, Keith C. Perry wrote:
> Try going to mjpeg first at the same quality. That format is usually 
> best for intermittent work and for pulling stills out.
> 
> On August 30, 2020 3:03:49 PM EDT, JP Vossen via plug 
> <plug@lists.phillylinux.org> wrote:
> 
>     My wife has some MTS videos we took on vacation from which we want to
>     extract some frames.  No problem:
>     ```
>     ffmpeg -hide_banner -loglevel error -nostdin \
>        -i $file -ss $start -to $stop -r $fps $dir/$output_file-$loop-%06d.$ext
>     ```
> 
>     But most of the resulting frames are fuzzy or interlaced, presumably
>     because MTS (about which I know nothing) uses a key frame and then diffs
>     (whatever that's called).  Note I got the same results using `-r 30` and
>     `-r 5`.
> 
>     I was thinking that I could transcode MTS to something better (read
>     much, much larger), then extract the frames I want from that.  I know
>     the answer is also `ffmpeg` but...with what settings?
Later,
JP
--  -------------------------------------------------------------------
JP Vossen, CISSP | http://www.jpsdomain.org/ | http://bashcookbook.com/
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug