Losslessly convert FLV to MP4

Audio editors, music players, video players, burning software, etc.
Post Reply
Message
Author
User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

Losslessly convert FLV to MP4

#1 Post by mikeb »

If you happen to gather flv video from say the /tmp folder or elsewhere on the net you probably have come across the problem that some video players don't like them or have problems navigating through them.

Been trying out this which seems to work a treat and produces an mp4 that even me olde vlc 0.8.6 gets on with.

There are ways with ffmpeg but this is another fast approach plus links for the tools which are a little elusive on linux or special builds.

1. split the video using
FLVExtractCL -v -a INPUT.flv
or
flvextract -v -a INPUT.flv
for the python version
The result is a 264 and aac file....

2. Join them...
MP4Box -add INPUT.h264:fps=25.000 -add INPUT.aac OUTPUT.mp4
the fps is important...flvextract will give you the figure...this keeps sound in sync happily.

Done...one nicely playable no hidden codec definitions scrollable mp4 in the time it takes to read and write the files. Yes you do need room to pack and unpack the stuff...MP4box uses /root(pwd) by default but thats changeable. with the -tmp option....handy if you have a small save file for example.

Ok tools... not really petable stuff since what you use and what you have will vary.

FLVextractCL...standalone binary but needs Lucid kernel or newer ??!!
https://www.dropbox.com/s/oixoksfomeza3 ... actCL?dl=1

flvextract ... standalone python version...runs on anything you have python 2.6 or newer...still needs python if that makes sense.
https://www.dropbox.com/s/64bzcvbgptdxp ... tract?dl=1

MP4box ...the swiss army knife of mp4... this was my build to work on older systems.... ok for puppy 4 for example/non SSE2
https://www.dropbox.com/s/4sxcxi2nwllotdv/MP4Box?dl=1

All the above will need making executable since they are direct web downloads. All use basic dependencies only.

python 2.7 in squash 4...way way smaller than using the devx...and includes img2pdf.py...a lossless jpg to pdf converter....very fast.
https://www.dropbox.com/s/hrg0uslg0eb84 ... 4.sfs?dl=1
If anyone wants a squash 3 version let me know.

that's it

mike

User avatar
neerajkolte
Posts: 516
Joined: Mon 10 Feb 2014, 07:05
Location: Pune, India.

#2 Post by neerajkolte »

I have some 'undf' videos which were given by friends but their extension say mp4. I don't know how he downloaded them from tube. maybe they were flv and because of not playing he may have changed their extension to mp4 to see if it works.

I will play with this tool on Fatdog.

Thanks.

- Neeraj.
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

“We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.â€￾
- Amara’s Law.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#3 Post by mikeb »

Yes...one site I originally tried this on had the .avi extension.... but a hex editor showed them to be flv.

Apart from the undf usually you cannot scroll through them either .... just rename to .flv to avoid confusion.

They mainly appear when you watch on say you tube with older flashplayer and you use the temporary file in /tmp.... they have hidden the codec info but flashplayer is ok because it only expects certain formats anyway....h264/aac was the later flv format for flash after soreson spark. After that they went to true mp4 handling and vp8 I think but that seems to have remained unpopular...cos its crap lol. A you tube downloader will get you a true mp4/webm or whatever.

mike

User avatar
neerajkolte
Posts: 516
Joined: Mon 10 Feb 2014, 07:05
Location: Pune, India.

#4 Post by neerajkolte »

Sorry Mike didn't get time to test this out until now.
Ok.. so I have 4 files with extensions .3gp which return "undf" when run from vlc.
I changed their extensions to .flv by renaming.
Then ran

Code: Select all

# ./flvextract -v -a Humpty_Dumpty_-_3D_Animation_English_Nursery_Rhyme_songs_For_Children_with_Lyrics.flv 
FLV Extract CL v1.6.2 - Python version by Gianluigi Tiesi <sherpya@netfarm.it>
Copyright 2006-2012 J.D. Purcell
http://www.moitah.net/

Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "./flvextract/__main__.py", line 5, in <module>
  File "./flvextract/flvextract.py", line 54, in main
  File "./flvextract/flvfile.py", line 96, in ExtractStreams
flvfile.FLVException: Not a flv file
# 
You said you used hex editor to see if file is an flv. I haven't used a hex editor ever. Fatdog has tweak hex editor but I don't know what to look for. Is this something to do with Magic numbers and I also saw why linux doesn't need file extensions. When I use file command I get this for all four files

Code: Select all

# file Humpty_Dumpty_-_3D_Animation_English_Nursery_Rhyme_songs_For_Children_with_Lyrics.flv 
Humpty_Dumpty_-_3D_Animation_English_Nursery_Rhyme_songs_For_Children_with_Lyrics.flv: data
# file Nursery_Rhymes_-_Skip_Skip_Skip_to_my_-_Krunal_Videos.flv 
Nursery_Rhymes_-_Skip_Skip_Skip_to_my_-_Krunal_Videos.flv: data
# file Ringa_Ringa_Roses_-_3D_Animation_English_Nursery_Rhyme_Songs_for_Children.flv 
Ringa_Ringa_Roses_-_3D_Animation_English_Nursery_Rhyme_Songs_for_Children.flv: data
# file Teddy_Bear_Teddy_Bear_nursery_rhyme.flv 
Teddy_Bear_Teddy_Bear_nursery_rhyme.flv: data
# 
Thanks.

- Neeraj.
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

“We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.â€￾
- Amara’s Law.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#5 Post by mikeb »

No problem..... its one of those when you get spare time topics really :)

Ok my test file gives...

bash-3.1# file /mnt/sdd1/mission.impossible.s01e06.dvdrip.xvid-saints.avi
/mnt/sdd1/mission.impossible.s01e06.dvdrip.xvid-saints.avi: Macromedia Flash Video

Which means yours are returning 'data'.... a non specific binary file.... this may well be a deliberate hack by whoever sourced the files.
With the flv files I come across they simply hide the type of codecs in use (further into the file) which some players foul up on.

I use wxhexeditor but mickey is a neat one too.
The screen shot of the same file shows FLV right at the beginning so I assume thats the bunny to look for.

Not to keen on the extensionless magic mimes.... gets confused if the file in question is using compression as part of its format for starters and the executable bit also throws a big spanner in the works I find.
Rox gtk1 was straight up file extension only and there was never any ambiguity but I digress.

mike
Attachments
flv.png
(33.19 KiB) Downloaded 318 times

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#6 Post by mikeb »

Ok here is a sample definite FLV (not hidden codecs) ..its only 5MB but you could use it to test the script at your end and compare with what you have
https://www.dropbox.com/s/b96nv5bign058 ... 0.flv?dl=1
Mike

User avatar
neerajkolte
Posts: 516
Joined: Mon 10 Feb 2014, 07:05
Location: Pune, India.

#7 Post by neerajkolte »

Thanks Mike,
I will look at it when I go home and take some sleep.
I am in night shift this week.
I hate night shifts.

- Neeraj.
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

“We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.â€￾
- Amara’s Law.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#8 Post by mikeb »

No worries.... shift work sucks.... heathrow used to totally throw out my sleep pattern even though on paper the hours were really good.

mike

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#9 Post by mikeb »

forum glitch again...been twice today

User avatar
neerajkolte
Posts: 516
Joined: Mon 10 Feb 2014, 07:05
Location: Pune, India.

#10 Post by neerajkolte »

Being in maintenance department I get some rest though.
But production people... ahh I see them working round the clock.
I only work when they stop.
I work at a big automobiles company.
The wheels just keep turning.

- Neeraj.
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

“We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.â€￾
- Amara’s Law.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#11 Post by mikeb »

The wheels just keep turning.
hopefully otherwise sales would suffer :D

mike

User avatar
neerajkolte
Posts: 516
Joined: Mon 10 Feb 2014, 07:05
Location: Pune, India.

#12 Post by neerajkolte »

Hi Mike,
When I open those files with tweak hex editor I get

Code: Select all

00000000   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000010   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000020   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000050   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000060   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000070   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000080   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000090   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
000000A0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
000000B0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
000000C0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
000000D0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
000000E0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
000000F0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000100   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000110   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000120   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000130   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000140   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00000150   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
   TWEAK 3.01: Teddy_Bear_Teddy_B (Ovrwrt) posn=0x0        size=0x186636
I went down till row no 6000 or something, still the same. What are the files made up of, bunch of zeros?

Anyway when I tried to convert your file, I got

Code: Select all

# ./flvextract -v -a HAND-Kirsten-Oct-2010.flv 
FLV Extract CL v1.6.2 - Python version by Gianluigi Tiesi <sherpya@netfarm.it>
Copyright 2006-2012 J.D. Purcell
http://www.moitah.net/

Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "./flvextract/__main__.py", line 5, in <module>
  File "./flvextract/flvextract.py", line 54, in main
  File "./flvextract/flvfile.py", line 115, in ExtractStreams
  File "./flvextract/flvfile.py", line 125, in CloseOutput
  File "./flvextract/audio/mp3writer.py", line 108, in Finish
  File "./flvextract/audio/mp3writer.py", line 197, in WriteVBRHeader
TypeError: an integer or string of size 1 is required
#
# python --version
Python 2.7.6
# 
Thanks.

- Neeraj.
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

“We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.â€￾
- Amara’s Law.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#13 Post by mikeb »

Wow yes that's blank city...all evidence of what the file is removed!!! Would make splitting hard too...probably the idea.

As for my test file yes I get the same error...sorry about that. It was made in avidemux as I cannot find something small for you to test with. Likely candidates I can no longer get as FLV from you tube any more as it happens...only got addons for MP$ and flash 10.0.15 does not work for many files now which did download to /tmp. The ones I have got have come from other flash based media sites but they are full shows and stuff.

So as you can see FLV comes in many forms and they are all awkward and the python script only seems to handle certain ones. Standards for FLV and MP4 for that matter are notorious for not being followed.

Not sure what to suggest now but thanks for the input.

Take it easy whenever possible

mike

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#14 Post by mikeb »

Hold the phone...I just looked in root and the file was indeed split in spite of the error message.
I now have an avi containing the flv1 (the codec) video and the mp3.!

Note most online with be h264 in a flv wrapper......

mike

User avatar
neerajkolte
Posts: 516
Joined: Mon 10 Feb 2014, 07:05
Location: Pune, India.

#15 Post by neerajkolte »

No problem Mike.
My problem is solved now that I know the files are blanks.
I will just delete them.
But in the process I got to learn about hex editor and magic numbers in files.
Edit: I read your new reply while posting and again used flvextractor on your file and this time it worked.
I deleted the files created and again ran got error. Again ran worked ok.

Code: Select all

# ./flvextract -v -a HAND-Kirsten-Oct-2010.flv 
FLV Extract CL v1.6.2 - Python version by Gianluigi Tiesi <sherpya@netfarm.it>
Copyright 2006-2012 J.D. Purcell
http://www.moitah.net/

Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "./flvextract/__main__.py", line 5, in <module>
  File "./flvextract/flvextract.py", line 54, in main
  File "./flvextract/flvfile.py", line 115, in ExtractStreams
  File "./flvextract/flvfile.py", line 125, in CloseOutput
  File "./flvextract/audio/mp3writer.py", line 108, in Finish
  File "./flvextract/audio/mp3writer.py", line 197, in WriteVBRHeader
TypeError: an integer or string of size 1 is required
#
# ./flvextract -v -a HAND-Kirsten-Oct-2010.flv 
FLV Extract CL v1.6.2 - Python version by Gianluigi Tiesi <sherpya@netfarm.it>
Copyright 2006-2012 J.D. Purcell
http://www.moitah.net/

True Frame Rate: 29.969963 (6296000/210077)
Average Frame Rate: 29.969963 (6296000/210077)

Finished
# 
Thanks.

- Neeraj.
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

“We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.â€￾
- Amara’s Law.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#16 Post by mikeb »

Ah cool...

so a useful tool at times then :)

mike

Post Reply