MP3 is a format designed for streaming and highly tolerant of damage, so it's expected to work no matter how you slice and dice it apart or together. Most other formats are not this tolerant.
WAV = RIFF container. Once you get past the header is a sequence of amplitude values (assuming uncompressed PCM). Errors in the stream will manifest as clicks or other noise, as long as the number of bytes doesn't change during corruption (otherwise channel interleaving will cause havoc). Should behave reasonably well to truncation. If it's a compressed WAV file, truncation behaviour will likely be less good, but probably still OK (dependant on the codec used).
M4A = Quicktime container. Complex recursive file structure, I wouldn't be surprised if it misbehaves upon truncation. If you demux the audio data out of the M4A container into a raw AAC file, truncation should be on par with MP3, but you'll lose the metadata in the container (artist/title, etc)
Ogg (presumably Vorbis) file is divided into "pages" -- I don't have a lot of experience with truncated or otherwise corrupt Ogg files, I'm not sure how to predict behaviour.
In any case, behaviour is likely player-dependant -- it might fail to play with Winamp and Windows Media Player but play fine in foobar2000 or BSplayer (random examples).
Ideally the file should be properly rewritten to close off the file structure after the desired amount of audio.
Practically it would be much easier to generate "sample" files in a standard format, MP3 for example, irrespective of the input file format. This should be easy enough to automate (if needed) with command-line encoders and decoders appropriate to each format. I'm not sure if any CLI decoders will enable range clipping (to give you only 30 seconds) but if you encode to a CBR MP3 file it would be trivial to truncate the output MP3 to the necessary length:
Code: Select all
$mp3bitrate = 128000;
$sample_seconds = 30;
$sample_filesize = ($mp3bitrate / 8) * $sample_seconds;
file_put_contents('sample_filename.mp3', substr(file_get_contents($temp_encoded_mp3filename), 0, $sample_filesize));